1/** 2* DBJ-SOUND 1.0.2 3* jQuery dbj_sound plugin (no flash, or any other simillar control used) 4* 5* Loosely inspired on code by Joern Zaefferer (also Jules Gravinese http://www.webveteran.com/ ) 6* 7* Copyright (c) 2009 Dusan Jovanovic ( http://dbj.org ) 8* 9* Licensed under the MIT license: 10* http://www.opensource.org/licenses/mit-license.php 11* 12************************************************************************************ 13* Crash course: 14* 15* return sound file url from host element 16* host must be valid html element with attribute href present 17* $.dbj_sound.url( host_element ) 18* 19* play a sound as defined by the href of the host_element 20* if looping arg present, then loop 21* $.dbj_sound.play( host_element, looping ) 22* 23* play "forever" a sound as defined by the href of the host_element 24* $.dbj_sound.loop( host_element ) 25* 26* stop a playback of the sound from the href of the host_element 27* $.dbj_sound.stop( host_element ) 28* 29* return true if sounds are on and sound defined by href of the host_element 30* is playing 31* $.dbj_sound.playing( host_element ) 32* 33* toggle on/off all sounds on the current page, controlled by this plugin 34* $.dbj_sound.enabledisable( host_element ) 35* 36*/ 37 38(function ($) { 39 $.dbj_sound = { 40 tracks: {}, 41 enabled: true, 42 43 url: function (host_element) { 44 var url = $(host_element).attr("href"); 45 if ("undefined" == typeof (url)) throw new Error(0xFF, "DBJ-SOUND EXCEPTION: host element invalid or missing a valid HREF attribute"); 46 return url; 47 }, 48 49 loop: function (host_element) { this.play(host_element, true); }, 50 51 play: function (host_element, looping) { 52 // 53 var sound_jq = function (src) { 54 /* I might introduce this for very old browsers, or ... ? 55 if ($.browser.msie) 56 return $('<bgsound/>').attr({ src: options.track, 57 loop: "infinite", // dbj changed from 1 58 autostart: true 59 }); */ 60 // 61 return $('<embed />').attr({ 62 style: "height:0;", 63 loop: (looping ? "true" : "false"), 64 src: options.track, 65 autostart: "true" 66 //hidden: "true" 67 }); 68 } 69 70 // sanity checks 71 if (!this.enabled) return; 72 if (!host_element) return; 73 74 var options = { track: this.url(host_element) }; 75 if (this.tracks[options.track]) { 76 var current = this.tracks[options.track]; 77 current.remove(); 78 } 79 80 var element = sound_jq(); 81 element.appendTo(document.body); 82 this.tracks[options.track] = element; 83 return element; // which is jQuery object 84 } 85 86 // DBJ added 87 , stop: function (host_element) { 88 var url = this.url(host_element); 89 if (this.tracks[url]) { 90 var current = this.tracks[url]; 91 // Check when Stop is avaiable, but not on a jQuery object 92 if ('undefined' != typeof [0].Stop) current[0].Stop(); 93 else if ('undefined' != typeof current[0].stop) current[0].stop(); 94 current.remove(); 95 this.tracks[url] = null; 96 } 97 } 98 99 // DBJ added 100 , playing: function (host_element) { 101 if (!$.dbj_sound.enabled) return false; 102 return this.tracks[this.url(host_element)] != null; 103 } 104 105 // DBJ added 106 , enabledisable: function () { 107 this.enabled = !this.enabled; 108 if (this.enabled == false) 109 for (var j in this.tracks) { 110 if (this.tracks[j]) { 111 this.tracks[j].remove(); 112 this.tracks[j] = null; 113 } 114 } 115 return this.enabled; 116 } 117 118 }; 119 120})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.