Created
December 5, 2012 18:19
-
-
Save cadecairos/4218119 to your computer and use it in GitHub Desktop.
A CodePen by Christopher De Cairos. Popcorn.js Update bug - Options do not update if there's no explicit setup method (i.e. the google map plugin style of plugin definition)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="foo">LOOK IN YOUR CONSOLE, BRO</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When you update an existing event in Popcorn.js, it fails to apply the new option values to the trackEvent if there's no _setup method defined by the plugin. | |
// This demo shows how it is failing to do so by defining similar plugins using each pattern and updating a value within. calling the toString function on | |
// each plugin will log the current value of `text` which is updated between each call. | |
// this pattern fails updating, with no defined setup | |
Popcorn.plugin( "notWorking", function( options ) { | |
options.toString = function() { | |
console.log( "notWorking text value: " + options.text ) | |
}; | |
return { | |
start: Popcorn.nop, | |
end: Popcorn.nop, | |
_update: function( trackEvent, options ) { | |
trackEvent.text = options.text; | |
} | |
}; | |
}); | |
// This pattern works when updating, with a defined _setup | |
Popcorn.plugin( "working", function() { | |
return { | |
start: Popcorn.nop, | |
end: Popcorn.nop, | |
_setup: function( options ) { | |
options.toString = function() { | |
console.log( "working text value:" + options.text ) | |
}; | |
}, | |
_update: function( trackEvent, options ) { | |
trackEvent.text = options.text; | |
} | |
}; | |
}); | |
function readyFn() { | |
var popcornInstance = Popcorn( Popcorn.HTMLNullVideoElement( "#foo" ) ), | |
fail, | |
pass; | |
// FAIL CASE | |
popcornInstance.notWorking( "fail", { text: "foo" } ); | |
fail = popcornInstance.getTrackEvent( "fail" ); | |
fail.toString(); | |
popcornInstance.notWorking( "fail", { text: "newFoo" } ); | |
fail.toString(); | |
// PASS CASE | |
popcornInstance.working( "pass", { text: "foo" } ); | |
pass = popcornInstance.getTrackEvent( "pass" ); | |
pass.toString(); | |
popcornInstance.working( "pass", { text: "newFoo" } ); | |
pass.toString(); | |
} | |
Popcorn.getScript( "https://raw.github.com/mozilla/popcorn-js/master/wrappers/common/popcorn._MediaElementProto.js", function() { | |
Popcorn.getScript( "https://raw.github.com/mozilla/popcorn-js/master/wrappers/null/popcorn.HTMLNullVideoElement.js", readyFn ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment