diff --git a/dist/harlowe-audio.min.js b/dist/harlowe-audio.min.js index 3ecc743..57cc95b 100644 --- a/dist/harlowe-audio.min.js +++ b/dist/harlowe-audio.min.js @@ -25,6 +25,6 @@ } }; - !function(){"use strict";var e=$(document.createElement("div")).attr("id","audio-container").css("display","none").appendTo(document.body),t=function(t,e){if(window.localStorage)try{t=""+t,"string"!=typeof e&&(e=JSON.stringify(e)),window.localStorage.setItem(t,e)}catch(t){console.error(t)}},o=function(t){if(window.localStorage)try{return t=""+t,window.localStorage.getItem(t)}catch(t){console.error(t)}},n=function(t){if(window.localStorage)try{t=""+t,window.localStorage.removeItem(t)}catch(t){console.error(t)}};function i(e,o){if("object"!=typeof e||"object"!=typeof o)throw new Error("Invalid extension.");Object.keys(o).forEach(function(t){if(void 0!==e[t])throw new Error('Invalid extension: cannot clobber existing property "'+t+'"');e[t]=o[t]})}var a={loaded:[],classes:{},master:{volume:options.startingVol,mute:!1},groups:{playing:[],looping:[],custom:{}},mute:function(t){a.master.mute=!!t,$(document).trigger({type:":master-mute",mute:!!t})},isMuted:function(){return!!a.master.mute},volume:function(t){t=Number(t),Number.isNaN(t)||(1this.unwrap.duration&&(t=this.unwrap.duration),this.unwrap.currentTime=t,this},fadeIn:function(t){var e=this;t=t||1;var o=this.getVolume();return this.volume(0),this.play(),this.$el.animate({volume:o*a.master.volume},1e3*t,function(){e.volume(o),s.emit(":volume",e),s.emit(":fade",e)}),this},fadeOut:function(t){t=t||1;var e=this,o=this.getVolume();return this.$el.animate({volume:0},1e3*t,function(){e.stop(),e.volume(o),s.emit(":volume",e),s.emit(":fade",e)}),this},fadeTo:function(t,e){var o=this;if(t=t||1,e=Number(e),!Number.isNaN(e))return 1=e.tracks.length&&e.looping)t=0;else if(t>=e.tracks.length)return e.current="",void(e.playing=!1);var o=e.tracks[t],n=o.isLooping();return o.loop(!1),o.play(),e.playing=!0,setTimeout(function(){o.isPlaying()||(e.playing=!1)},20),e.current=o.id,o.$el.one("ended.playlist",function(){t++,o.loop(n),e.play(t)}),e},loop:function(t){return this.looping=!!t,this},stop:function(){var t=s.get(this.current);return t.stop(),t.$el.off(".playlist"),this.current="",this.playing=!1,this},pause:function(){return s.get(this.current).pause(),this.playing=!1,this}},a.classes.Playlist=c,a.createPlaylist=c.add,a.playlist=function(t){return c.list[t]||null},a.extend=function(t){i(a,t)},a.extendTrack=s.extend,a.extendTrackProto=s.extendPrototype,a.extendGroup=a.group.extend,a.extendGroupProto=a.group.extendPrototype,a.extendPlaylist=c.extend,a.extendPlaylistProto=c.extendPrototype,window.Chapel=window.Chapel||{},window.Chapel.Audio=a,options.persistPrefs&&a.loadPrefs()}(),function(){"use strict";if(options.controls.show){var t=$(document.createElement("div")).attr("id","story-menu").css("display","none"),e=$(document.createElement("span")).attr("id","vol-title").append("Volume");options.controls.volumeDisplay||e.css("display","none");var o=$(document.createElement("input")).attr({id:"audio-volume",type:"range",min:1,max:99,step:1,title:"Volume"}),n=Math.trunc(100*window.Chapel.Audio.master.volume);n<0?n=0:100").on("click",function(t){t.preventDefault(),$(this).toggleClass("muted"),Chapel.Audio.mute(!Chapel.Audio.isMuted())});Chapel.Audio.isMuted()&&r.addClass("muted");var a=$(document.createElement("tw-link")).attr("id","audio-panel-toggle").on("click",function(t){t.preventDefault(),u.toggleClass("closed")}),u=$(document.createElement("div")).attr("id","audio-controls").append(t,e,o,r,a).appendTo(document.body);options.controls.startClosed&&u.addClass("closed"),window.Chapel=window.Chapel||{},window.Chapel.Audio=window.Chapel.Audio||{},window.Chapel.Audio.controls={$panel:u,$volume:o,$mute:r,$user:t,close:function(){u.addClass("closed")},open:function(){u.removeClass("closed")},toggle:function(){u.toggleClass("closed")},hide:function(){u.css("display","none")},show:function(){u.css("display","block")},updateVolume:i}}}(),function(t){(jQuery.browser=jQuery.browser||{}).mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4))}(navigator.userAgent||navigator.vendor||window.opera),function(){"use strict";var e=State,t=$(document.createElement("div")).attr("id","audio-overlay").css("display","none").appendTo(document.body);function o(){t.css("display","block").append('
')}function u(){t.fadeOut(function(){t.empty()})}window.Chapel=window.Chapel||{},window.Chapel.Audio=window.Chapel.Audio||{},window.Chapel.Audio.loadScreen={show:o,dismiss:u,kill:function(){$("#audio-overlay").remove()}},window.Chapel.Audio.$overlay=t,window.Chapel.Audio.preload=function(){if(!(e.pastLength||e.futureLength||$.browser.mobile)){$(document).ready(function(){o()});var i=100+options.loadDelay,t=Chapel.Audio.classes.Track.list,r=Chapel.Audio.loaded;if(t.length){var a=t.map(function(t){return t.id});options.forceDismiss&&setTimeout(function(){u()},options.loadLimit.total),function t(){if(a.length){var e=a.shift();if(r.includes(e))t();else{var o=Chapel.Audio.classes.Track.get(e);if(o.unwrap.readyState<2){var n=!1;o.$el.one("canplay",function(){t(),n=!0}),setTimeout(function(){n||(o.$el.off("canplay"),t())},options.loadLimit.track)}else r.includes(e)||r.push(e),t()}}else setTimeout(u,i)}()}else setTimeout(u,i)}}}(),function(){"use strict";options.globalA&&void 0===window.A&&(window.A=window.Chapel.Audio),$(document).on("unload",function(){window.Chapel.Audio.savePrefs()}),Chapel.Audio.classes.Track.renew(),Chapel.Audio.controls&&Chapel.Audio.controls.updateVolume()}(),function(){"use strict";if(options.controls.show){var u=Engine,s=Chapel.Audio.controls.$user,t=function(){return"none"!==s.css("display")},c=function(){return t()||s.css("display","block"),s},e=function(){return t()&&s.css("display","none"),s};Chapel.Audio.menu={hide:e,show:c,isShown:t,links:{add:function(t,e,o){var n,i;if(!t||"string"!=typeof t){var r="undefined";return alert(r),void console.error(r)}o||"function"!=typeof e?(e&&"string"==typeof e&&(n=e),o&&"function"==typeof o&&(i=o)):(i=e,n=null);var a=$(document.createElement("tw-link")).append(t).attr({tabindex:"0",name:t.toLowerCase().trim()}).on("click",function(){n&&u.goToPassage(n),i&&i()}).addClass("story-menu").appendTo(s);return c(),a},clear:function(){return s.empty(),e()},hide:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').addClass("hide")},show:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').removeClass("hide")},toggle:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').toggleClass("hide")},remove:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').remove()}}}}}(),function(){"use strict";var n=window.prompt;window.prompt=function(){var t,e,o=n.apply(null,[].slice.call(arguments));return t=o,e=(new DOMParser).parseFromString(t,"text/html"),Array.from(e.body.childNodes).some(function(t){return 1===t.nodeType})?o.replace(/[<>]/g,""):o}}(); + !function(){"use strict";var e=$(document.createElement("div")).attr("id","audio-container").css("display","none").appendTo(document.body),t=function(t,e){if(window.localStorage)try{t=""+t,"string"!=typeof e&&(e=JSON.stringify(e)),window.localStorage.setItem(t,e)}catch(t){console.error(t)}},o=function(t){if(window.localStorage)try{return t=""+t,window.localStorage.getItem(t)}catch(t){console.error(t)}},n=function(t){if(window.localStorage)try{t=""+t,window.localStorage.removeItem(t)}catch(t){console.error(t)}};function i(e,o){if("object"!=typeof e||"object"!=typeof o)throw new Error("Invalid extension.");Object.keys(o).forEach(function(t){if(void 0!==e[t])throw new Error('Invalid extension: cannot clobber existing property "'+t+'"');e[t]=o[t]})}var a={loaded:[],classes:{},master:{volume:options.startingVol,mute:!1},groups:{playing:[],looping:[],custom:{}},mute:function(t){a.master.mute=!!t,$(document).trigger({type:":master-mute",mute:!!t})},isMuted:function(){return!!a.master.mute},volume:function(t){t=Number(t),Number.isNaN(t)||(1this.unwrap.duration&&(t=this.unwrap.duration),this.unwrap.currentTime=t,this},fadeIn:function(t){var e=this;t=t||1;var o=this.getVolume();return this.volume(0),this.play(),this.$el.animate({volume:o*a.master.volume},1e3*t,function(){e.volume(o),c.emit(":volume",e),c.emit(":fade",e)}),this},fadeOut:function(t){t=t||1;var e=this,o=this.getVolume();return this.$el.animate({volume:0},1e3*t,function(){e.stop(),e.volume(o),c.emit(":volume",e),c.emit(":fade",e)}),this},fadeTo:function(t,e){var o=this;if(t=t||1,e=Number(e),!Number.isNaN(e))return 1.on() -> invalid event type"),this)):(console.error(".on() -> invalid callback"),this)},one:function(){return cb&&"function"==typeof cb?(type=type.trim().toLowerCase(),":"!==type[0]&&(type=":"+type),r.track.includes(type)?void this.$el.one(type,cb):(console.error(".one() -> invalid event type"),this)):(console.error(".one() -> invalid callback"),this)}};var l=r.track.concat(r.master);function p(t,e){if(!(this instanceof p))return new p(t,e);this.id=t,this.tracks=e.map(function(t){return c.get(t)}),this.looping=!1,this.current="",this.playing=!1}a.on=function(t,e){e&&"function"==typeof e?(":"!==(t=t.trim().toLowerCase())[0]&&(t=":"+t),l.includes(t)?$(document).on(t,e):console.error("Chapel.Audio.on() -> invalid event type")):console.error("Chapel.Audio.on() -> invalid callback")},a.one=function(t,e){e&&"function"==typeof e?(":"!==(t=t.trim().toLowerCase())[0]&&(t=":"+t),l.includes(t)?$(document).one(t,e):console.error("Chapel.Audio.one() -> invalid event type")):console.error("Chapel.Audio.one() -> invalid callback")},a.on(":master-mute",c.renew),a.on(":master-volume",c.renew),options.persistPrefs&&(a.on(":master-mute",a.savePrefs),a.on(":master-volume",a.savePrefs)),a.on(":play",function(t){t.track.addToGroup("playing")}),a.on(":stop",function(t){t.track.removeFromGroup("playing")}),options.muteOnBlur&&$(window).on("blur",function(){a.isMuted()||(a.mute(!0),$(window).one("focus",function(){a.mute(!1)}))}),a.classes.Track=c,a.newTrack=c.add,a.track=c.get,a.createGroup=function(t,e,o){var n,i,r;n=o?[].slice.call(arguments).slice(1):e,i=t,(r=n)&&Array.isArray(r)||(r=[]),a.groups.custom[i]=r.map(function(t){return c.get(t)})},a.group=function(t){if(!(this instanceof a.group))return new a.group(t);Object.keys(a.groups.custom).includes(t)?this.members=a.groups.custom[t]:this.members=a.groups[t],Array.isArray(this.members)||(this.members=[],console.error('Could not find members for track group "'+t+'"!'))},a.group.is=function(t){return this instanceof a.group},a.group.runOnAll=function(t,e,o){t.members.forEach(function(t){t[e].apply(t,o&&Array.isArray(o)?o:[])})},a.group.extend=function(t){i(a.group,t)},a.group.extendPrototype=function(t){i(a.group.prototype,t)},a.group.prototype={constructor:a.group,run:function(t,e,o){null!=o&&(e=[].slice.call(arguments).slice(1)),c.prototype.hasOwnProperty(t)&&a.group.runOnAll(this,t,e)},play:function(){return this.run("play"),this},pause:function(){return this.run("pause"),this},stop:function(){return this.run("stop"),this},mute:function(t){return this.run("mute",[t]),this},volume:function(t){return this.run("volume",[t]),this},loop:function(t){return this.run("loop",[t]),this}},p.list={},p.is=function(t){return t instanceof p},p.add=function(t,e,o){return o&&(e=[].slice.call(arguments).slice(1)),p.list[t]=new p(t,e),p.list[t]},p.extend=function(t){i(p,t)},p.extendPrototype=function(t){i(p.prototype,t)},p.prototype={constructor:p,clone:function(){return new p(this.id,this.tracks.map(function(t){return t.id}))},shuffle:function(){var t,e,o,n=this.tracks;for(o=n.length-1;0=e.tracks.length&&e.looping)t=0;else if(t>=e.tracks.length)return e.current="",void(e.playing=!1);var o=e.tracks[t],n=o.isLooping();return o.loop(!1),o.play(),e.playing=!0,setTimeout(function(){o.isPlaying()||(e.playing=!1)},20),e.current=o.id,o.$el.one("ended.playlist",function(){t++,o.loop(n),e.play(t)}),e},loop:function(t){return this.looping=!!t,this},stop:function(){var t=c.get(this.current);return t.stop(),t.$el.off(".playlist"),this.current="",this.playing=!1,this},pause:function(){return c.get(this.current).pause(),this.playing=!1,this}},a.classes.Playlist=p,a.createPlaylist=p.add,a.playlist=function(t){return p.list[t]||null},a.extend=function(t){i(a,t)},a.extendTrack=c.extend,a.extendTrackProto=c.extendPrototype,a.extendGroup=a.group.extend,a.extendGroupProto=a.group.extendPrototype,a.extendPlaylist=p.extend,a.extendPlaylistProto=p.extendPrototype,window.Chapel=window.Chapel||{},window.Chapel.Audio=a,options.persistPrefs&&a.loadPrefs()}(),function(){"use strict";if(options.controls.show){var t=$(document.createElement("div")).attr("id","story-menu").css("display","none"),e=$(document.createElement("span")).attr("id","vol-title").append("Volume");options.controls.volumeDisplay||e.css("display","none");var o=$(document.createElement("input")).attr({id:"audio-volume",type:"range",min:1,max:99,step:1,title:"Volume"}),n=Math.trunc(100*window.Chapel.Audio.master.volume);n<0?n=0:100").on("click",function(t){t.preventDefault(),$(this).toggleClass("muted"),Chapel.Audio.mute(!Chapel.Audio.isMuted())});Chapel.Audio.isMuted()&&r.addClass("muted");var a=$(document.createElement("tw-link")).attr("id","audio-panel-toggle").on("click",function(t){t.preventDefault(),u.toggleClass("closed")}),u=$(document.createElement("div")).attr("id","audio-controls").append(t,e,o,r,a).appendTo(document.body);options.controls.startClosed&&u.addClass("closed"),window.Chapel=window.Chapel||{},window.Chapel.Audio=window.Chapel.Audio||{},window.Chapel.Audio.controls={$panel:u,$volume:o,$mute:r,$user:t,close:function(){u.addClass("closed")},open:function(){u.removeClass("closed")},toggle:function(){u.toggleClass("closed")},hide:function(){u.css("display","none")},show:function(){u.css("display","block")},updateVolume:i}}}(),function(t){(jQuery.browser=jQuery.browser||{}).mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4))}(navigator.userAgent||navigator.vendor||window.opera),function(){"use strict";var e=State,t=$(document.createElement("div")).attr("id","audio-overlay").css("display","none").appendTo(document.body);function o(){t.css("display","block").append('
')}function u(){t.fadeOut(function(){t.empty()})}window.Chapel=window.Chapel||{},window.Chapel.Audio=window.Chapel.Audio||{},window.Chapel.Audio.loadScreen={show:o,dismiss:u,kill:function(){$("#audio-overlay").remove()}},window.Chapel.Audio.$overlay=t,window.Chapel.Audio.preload=function(){if(!(e.pastLength||e.futureLength||$.browser.mobile)){$(document).ready(function(){o()});var i=100+options.loadDelay,t=Chapel.Audio.classes.Track.list,r=Chapel.Audio.loaded;if(t.length){var a=t.map(function(t){return t.id});options.forceDismiss&&setTimeout(function(){u()},options.loadLimit.total),function t(){if(a.length){var e=a.shift();if(r.includes(e))t();else{var o=Chapel.Audio.classes.Track.get(e);if(o.unwrap.readyState<2){var n=!1;o.$el.one("canplay",function(){t(),n=!0}),setTimeout(function(){n||(o.$el.off("canplay"),t())},options.loadLimit.track)}else r.includes(e)||r.push(e),t()}}else setTimeout(u,i)}()}else setTimeout(u,i)}}}(),function(){"use strict";options.globalA&&void 0===window.A&&(window.A=window.Chapel.Audio),$(document).on("unload",function(){window.Chapel.Audio.savePrefs()}),Chapel.Audio.classes.Track.renew(),Chapel.Audio.controls&&Chapel.Audio.controls.updateVolume()}(),function(){"use strict";if(options.controls.show){var u=Engine,s=Chapel.Audio.controls.$user,t=function(){return"none"!==s.css("display")},c=function(){return t()||s.css("display","block"),s},e=function(){return t()&&s.css("display","none"),s};Chapel.Audio.menu={hide:e,show:c,isShown:t,links:{add:function(t,e,o){var n,i;if(!t||"string"!=typeof t){var r="undefined";return alert(r),void console.error(r)}o||"function"!=typeof e?(e&&"string"==typeof e&&(n=e),o&&"function"==typeof o&&(i=o)):(i=e,n=null);var a=$(document.createElement("tw-link")).append(t).attr({tabindex:"0",name:t.toLowerCase().trim()}).on("click",function(){n&&u.goToPassage(n),i&&i()}).addClass("story-menu").appendTo(s);return c(),a},clear:function(){return s.empty(),e()},hide:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').addClass("hide")},show:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').removeClass("hide")},toggle:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').toggleClass("hide")},remove:function(t){t=t.toLowerCase().trim(),$('tw-link.story-menu[name="'+t+'"]').remove()}}}}}(),function(){"use strict";var n=window.prompt;window.prompt=function(){var t,e,o=n.apply(null,[].slice.call(arguments));return t=o,e=(new DOMParser).parseFromString(t,"text/html"),Array.from(e.body.childNodes).some(function(t){return 1===t.nodeType})?o.replace(/[<>]/g,""):o}}(); }()); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index b2966c5..8f4ce45 100644 --- a/docs/README.md +++ b/docs/README.md @@ -423,6 +423,30 @@ Returns the track's current volume; this is the track's volume state and does no --- +- **the `.on(type, callback)` method** + +- Arguments: + - `type`: a valid event type + - `callback`: a function to run as a handler for the indicated event + +- Returns: none. + +Sets up a recurring event handler. Read more [here](#events). + +--- + +- **the `.one(type, callback)` method** + +- Arguments: + - `type`: a valid event type + - `callback`: a function to run as a handler for the indicated event + +- Returns: none. + +Sets up a single-use event handler. Read more [here](#events). + +--- + ## Master Audio Methods The master audio methods are used for controlling *all* sound in the game at once. The master audio does not change you tracks, instead it overrides them. For example, if you have the `'theme'` track muted and the `'beep'` track unmuted, `A.mute(true)` will make `'beep'` silent. `A.mute(false)` will not make `'theme'` audible, however. None of these methods are chainable. @@ -511,6 +535,30 @@ Shows a loading screen while all previously defined tracks are cached by the bro --- +- **the `A.on(type, callback)` method** + +- Arguments: + - `type`: a valid event type + - `callback`: a function to run as a handler for the indicated event + +- Returns: none. + +Sets up a recurring event handler. Read more [here](#events). + +--- + +- **the `A.one(type, callback)` method** + +- Arguments: + - `type`: a valid event type + - `callback`: a function to run as a handler for the indicated event + +- Returns: none. + +Sets up a single-use event handler. Read more [here](#events). + +--- + ## Groups Groups are ways to collect and organize tracks, but should *not* be confused with playlists (read on for those). These are designed to allow you to select and control a large number of tracks and do something to them. The methods used by groups are very similar to some of the track methods, but as said, generally do something to all of them at once. @@ -867,38 +915,77 @@ This method removes a story menu link. If there are multiple links with the same There are two kinds of events that are triggered by HAL--events triggered on the document *only* and events triggered on *both* the track element and the document. -## Event Handlers +## Track Event Methods -It is recommended that you write events using [jQuery's `on()`](http://api.jquery.com/on/) or [`one()` methods](http://api.jquery.com/one/). For example: +There are two track event methods you can use; `.on()` and `.one()`. The former triggers a handler each time the indicated event occurs, the latter triggers a handler only once. These methods can only be used with [track events](#list-of-track-events). ```javascript -$(document).on(':volume', function (ev) { - console.log('track "' + ev.track.$el.attr('data-track') + '"" volume changed'); +A.track('some-song').one(':volume', function () { + // occurs only once when the volume of "some-song" is changed + console.log('track "some-song" volume changed'); }); ``` ```javascript -A.track('some-song').$el.one(':volume', function () { +A.track('some-song').on(':volume', function () { + // occurs each time the volume of "some-song" is changed console.log('track "some-song" volume changed'); }); ``` +## Global Event Methods + +As with track event methods, there are two: `A.on()` and `A.one()`. These event methods monitor *all* tracks for events, and also monitor for [master audio events](#list-of-master-audio-events). + +```javascript +A.one(':volume', function (ev) { + // occurs only once when the volume of a track is changed + console.log('track "' + ev.track.id + '" volume changed'); +}); +``` + +```javascript +A.on(':volume', function (ev) { + // occurs each time the volume of any track is changed + console.log('track "' + ev.track.id + '" volume changed'); +}); +``` + ## List of Track Events -These events are triggered on both the document and the track element. The track's definition is available as `.track`. +These events are triggered on both the document and the track element. The track's definition is available as `.track`. These events may be used with `.on()` and `.one()` to listen for events on specific tracks, or with `A.on()` and `A.one()` to listen for events on any and all tracks. + +| Event | Description | +| --- | --- | +| `:available` | a track's metadata is loaded | +| `:loaded` | a track can be played from start to finish | +| `:play` | a track starts playing | +| `:pause` | a track is paused | +| `:stop` | a track reaches the end or is stopped | +| `:mute` | a track is muted or unmuted | +| `:volume` | a track's volume is changed | + +## List of Master Audio Events + +These events are only available for use with `A.on()` and `A.one()`, and are only triggered on the document element. + +| Event | Description | +| --- | --- | +| `:master-mute` | the master mute control is muted or unmuted | +| `:master-volume` | the master volume is changed | + +## The Event Object -- `:available` -> a track's metadata is loaded -- `:loaded` -> a track can be played from start to finish -- `:play` -> a track starts playing -- `:pause` -> a track is paused -- `:stop` -> a track reaches the end or is stopped -- `:mute` -> a track is muted or unmuted -- `:volume` -> a track's volume is changed +The event object in track events contains the `track` property, which contains the definition of the track that triggered the event. -## Other Events +| Property | Description | +| --- | --- | +| `.track.id` | The track's name/id. | +| `.track.$el` | The track's jQuery-wrapped audio element. | +| `.track.unwrap` | The track's `