From 43e07d67fe346737c1dd4abb03eaa72d0b84b08c Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 14 Apr 2010 12:35:36 +0200 Subject: [PATCH] Play alarm sound in ajax interface. --- horde/js/sound.js | 59 +++++++++++++++++++++++++++++++++++++++++++++ kronolith/js/kronolith.js | 3 +++ kronolith/lib/Kronolith.php | 1 + 3 files changed, 63 insertions(+) create mode 100644 horde/js/sound.js diff --git a/horde/js/sound.js b/horde/js/sound.js new file mode 100644 index 000000000..a286eb98e --- /dev/null +++ b/horde/js/sound.js @@ -0,0 +1,59 @@ +// script.aculo.us sound.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009 + +// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// +// Based on code created by Jules Gravinese (http://www.webveteran.com/) +// +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ + +Sound = { + tracks: {}, + _enabled: true, + template: + new Template(''), + enable: function(){ + Sound._enabled = true; + }, + disable: function(){ + Sound._enabled = false; + }, + play: function(url){ + if(!Sound._enabled) return; + var options = Object.extend({ + track: 'global', url: url, replace: false + }, arguments[1] || {}); + + if(options.replace && this.tracks[options.track]) { + $R(0, this.tracks[options.track].id).each(function(id){ + var sound = $('sound_'+options.track+'_'+id); + sound.Stop && sound.Stop(); + sound.remove(); + }); + this.tracks[options.track] = null; + } + + if(!this.tracks[options.track]) + this.tracks[options.track] = { id: 0 }; + else + this.tracks[options.track].id++; + + options.id = this.tracks[options.track].id; + $$('body')[0].insert( + Prototype.Browser.IE ? new Element('bgsound',{ + id: 'sound_'+options.track+'_'+options.id, + src: options.url, loop: 1, autostart: true + }) : Sound.template.evaluate(options)); + } +}; + +if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){ + if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 })) + Sound.template = new Template(''); + else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 })) + Sound.template = new Template(''); + else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 })) + Sound.template = new Template(''); + else + Sound.play = function(){}; +} \ No newline at end of file diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index fab8d2a68..4ded84267 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -152,6 +152,9 @@ KronolithCore = { message = new Element('a', { href: alarm.params.notify.url }) .insert(message); } + if (alarm.params.notify.sound) { + Sound.play(alarm.params.notify.sound); + } } message = new Element('div') .insert(message); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index ca5f9ff01..617d1225d 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -66,6 +66,7 @@ class Kronolith $datejs = 'en-US.js'; } Horde::addScriptFile('effects.js', 'horde'); + Horde::addScriptFile('sound.js', 'horde'); Horde::addScriptFile('horde.js', 'horde'); Horde::addScriptFile('dragdrop2.js', 'horde'); Horde::addScriptFile('Growler.js', 'horde'); -- 2.11.0