})()
);
+ Popcorn.forEach( "enable disable".split(" "), function( method ) {
+ Popcorn.p[ method ] = function( plugin ) {
+ return Popcorn[ method ]( this, plugin );
+ };
+ });
+
Popcorn.extend(Popcorn.p, {
// Rounded currentTime
},
position: function() {
return Popcorn.position( this.media );
+ },
+ toggle: function( plugin ) {
+ return Popcorn[ this.data.disabled.indexOf( plugin ) > -1 ? "enable" : "disable" ]( this, plugin );
}
});
- Popcorn.forEach( "enable disable".split(" "), function( method ) {
- Popcorn.p[ method ] = function( plugin ) {
- return Popcorn[ method ]( this, plugin );
- };
- });
-
Popcorn.Events = {
UIEvents: "blur focus focusin focusout load resize scroll unload ",
MouseEvents: "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave click dblclick",
});
-test("Popcorn.disable/enable", function() {
+test("Popcorn.disable/enable/toggle", function() {
- var $pop = Popcorn.getInstanceById( "video" ),
+ var $pop = Popcorn( "#video" ),
count = 0,
- expects = 4;
+ expects = 5;
expect( expects );
function plus() {
if ( ++count === expects ) {
start();
+
+ Popcorn.removeInstance( $pop );
}
}
- stop( 10000 );
+ Popcorn.plugin("toggler", function () {
+ return {
+ start: function () {
+ var div = document.createElement("div");
+ div.id = "toggler-test";
+ div.innerHTML = "foo";
- // rw/ff
+ document.body.appendChild(div);
+ },
+ end: function () {
+ document.getElementById("toggler-test").parentNode.removeChild(document.getElementById("toggler-test"));
+ }
+ };
+ });
- // Test static function call
- Popcorn.disable( $pop, "rw" );
+ $pop.exec( 40, function() {
- ok( $pop.data.disabled.indexOf("rw") > -1, "Plugin: rw is disabled" );
- plus();
+ console.log( "WOO!" );
+ // make sure toggler never happened
+ // look for: "toggler-test"
- // Test per-instance function call
- $pop.disable( "ff" );
-
- ok( $pop.data.disabled.indexOf("ff") > -1, "Plugin: ff is disabled" );
- plus();
+ ok( !document.getElementById("toggler-test"), "No toggler container, disabled toggler plugin correctly never ran" );
+ plus();
- // Test static function call
- Popcorn.enable( $pop, "rw" );
+ // Test per-instance toggle on
+ $pop.toggle( "toggler" );
+ ok( $pop.data.disabled.indexOf("toggler") === -1, "toggle() plugin: toggler is re-enabled" );
+ plus();
+ });
+
+ $pop.toggler({
+ start: 40,
+ end: 50
+ });
+
+ // rw/ff
+
+ // Test per-instance function call
+ $pop.disable( "toggler" );
+
+ ok( $pop.data.disabled.indexOf("toggler") > -1, "disable() plugin: toggler is disabled" );
+ plus();
- ok( $pop.data.disabled.indexOf("rw") === -1, "Plugin: rw is enabled" );
- plus();
+ // Test per-instance function call
+ $pop.enable( "toggler" );
+
+ ok( $pop.data.disabled.indexOf("toggler") === -1, "enable() plugin: toggler is enabled" );
+ plus();
- // Test per-instance function call
- $pop.enable( "ff" );
-
- ok( $pop.data.disabled.indexOf("ff") === -1, "Plugin: ff is enabled" );
- plus();
+ // Test per-instance toggle off
+ $pop.toggle( "toggler" );
+
+ ok( $pop.data.disabled.indexOf("toggler") > -1, "toggle() plugin: toggler is disabled" );
+ plus();
- //console.log( Popcorn.instances[ Popcorn.instanceIds.video ], );
+ stop( 10000 );
});
module("Popcorn XHR");