summaryrefslogtreecommitdiff
path: root/chimere/static/jme/plugins/ui.sounds.js
blob: 1ec4a7871e621d9da89bf497acd5e02fd1831188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function($){
	
	var $m 			= $.multimediaSupport,
		bgWrapper 	= $('<div class="jme-bg-wrapper" style="position: absolute; overflow: hidden;display: block; width: 10px; height: 10px;" />'),
		appended 	= false
	;
	
	bgWrapper.css( ($('html').css('dir') === 'rtl') ? 'right' : 'left', '-99999px'  );
		
	$m.createBGSound = function(mediasrces, embedOpts){
		if( !appended ){
			bgWrapper
				.appendTo(document.documentElement)
				.bind('play playing loadedmeta pause waiting ended mediareset mute volumelevelchange', function(e){
					e.stopPropagation();
				})
			;
			appended = true;	
		}
		
		 var audio = $( $.fixHTML5('<audio style="display: block; width: 10px; height: 10px;" role="presentation" tabindex="-1" preload="auto" />') )
			.appendTo(bgWrapper)
			.attr('srces', mediasrces)
			.jmeEmbed(embedOpts)
		;
		
		return audio;
	};
	var _createWidget = $.Widget.prototype._createWidget;
	
	
	$.extend(true, $.Widget.prototype, {
		options: {sound: {}, soundEmbed: {}},
		_createWidget: function(){
			var ret = _createWidget.apply(this, arguments);
			this._createSound();
			return ret;
		},
		_soundAPI: {},
		_createSound: function(){
		var o 			= this.options,
			element 	= this.element,
			that 		= this
		;
		$.each(o.sound || {}, function(type, mediasrces){
				type = ( type === that.widgetEventPrefix ?
					type :
					that.widgetEventPrefix + type ).toLowerCase();
				that._soundAPI[type] = $m.createBGSound(mediasrces, o.soundEmbed || {});
				element.bind(type, function(){
					that._soundAPI[type].stopAndPlay();
				});
			});
		}//,
		/* todo:
		 option: function(){},
		 destroy: function(){}
		 */
		
	});
	
	$.multimediaSupport.fn._extend({
		stopAndPlay: function(){
			this.currentTime(0);
			this.play();
		}
	});
	
})(jQuery);