Skip to content

Commit

Permalink
Merge pull request tholman#68 from SacmaIslerOfisi/master
Browse files Browse the repository at this point in the history
Option to not preload audio
  • Loading branch information
tholman committed Apr 25, 2015
2 parents c19284d + c8c8016 commit 35cdce6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h1>Elevator.js</h1>
var elevator = new Elevator({
element: elementButton,
mainAudio: './music/elevator-music.mp3', // Music from http://www.bensound.com/
endAudio: './music/ding.mp3', // Music from http://www.bensound.com/
endAudio: './music/ding.mp3' // Music from http://www.bensound.com/
});

</script>
Expand Down
25 changes: 23 additions & 2 deletions elevator.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,32 @@ var Elevator = (function() {
element.addEventListener('click', elevate, false);
}

function extendParameters(options, defaults){
for(var option in defaults){
var t = options[option] === undefined && typeof option !== "function";
if(t){
options[option] = defaults[option];
}
}
return options;
}

function main( options ) {

// Bind to element click event, if need be.
body = document.body;

var defaults = {
duration: undefined,
mainAudio: true,
preloadAudio: true,
loopAudio: true,
endAudio: true
};

options = extendParameters(options, defaults);


if( options.element ) {
bindElevateToElement( options.element );
}
Expand All @@ -166,8 +187,8 @@ var Elevator = (function() {

if( options.mainAudio ) {
mainAudio = new Audio( options.mainAudio );
mainAudio.setAttribute( 'preload', 'true' ); //@TODO: Option to not preload audio.
mainAudio.setAttribute( 'loop', 'true' );
mainAudio.setAttribute( 'preload', options.preloadAudio );
mainAudio.setAttribute( 'loop', options.loopAudio );
}

if( options.endAudio ) {
Expand Down
2 changes: 1 addition & 1 deletion elevator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35cdce6

Please sign in to comment.