From: ScottDowne Date: Wed, 22 Jun 2011 15:27:00 +0000 (-0400) Subject: [#t366] simplified the applyclass signature for most use cases X-Git-Tag: v0.7^2~22^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=38b739baabbd537d7457e64c9d3942c8a53ecb93;p=popcorn-js.git [#t366] simplified the applyclass signature for most use cases --- diff --git a/demos/semantic_video/xml/webMadeMovies.xml b/demos/semantic_video/xml/webMadeMovies.xml index 36b9821..21145bc 100644 --- a/demos/semantic_video/xml/webMadeMovies.xml +++ b/demos/semantic_video/xml/webMadeMovies.xml @@ -81,7 +81,7 @@ - + Look around the page as info is updated! diff --git a/effects/applyclass/popcorn.applyclass.html b/effects/applyclass/popcorn.applyclass.html index a34052b..3b0903d 100644 --- a/effects/applyclass/popcorn.applyclass.html +++ b/effects/applyclass/popcorn.applyclass.html @@ -18,15 +18,15 @@ target: "footnotediv", text: "This video made exclusively for drumbeat.org", effect: "applyclass", - applyclass: ".overlay: applyoverlay, parent: hover" + applyclass: "applyoverlay: .overlay, hover: parent" }) .footnote({ start: 20, // seconds end: 45, // seconds - target: "footnotediv", + target: "footnotediv2", text: "Visit webmademovies.org for more details", effect: "applyclass", - applyclass: ".overlay: applyoverlay, parent: hover" + applyclass: "applyoverlay: .overlay, hover: parent" }); }, false); diff --git a/effects/applyclass/popcorn.applyclass.js b/effects/applyclass/popcorn.applyclass.js index c045295..cc76fdc 100644 --- a/effects/applyclass/popcorn.applyclass.js +++ b/effects/applyclass/popcorn.applyclass.js @@ -22,38 +22,30 @@ * */ - var startFunction = Popcorn.nop, - applyFunction = function() { + var toggleClass = function( event, options ) { - if ( !window.jQuery ) { + var idx = 0, len = 0, elements; - Popcorn.getScript( "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js", applyFunction ); - return; - } + Popcorn.forEach( options.classes, function( key, val ) { - startFunction = function( event, options ) { + elements = []; - Popcorn.forEach( options.classes, function( val, key ) { + if ( key === "parent" ) { - var obj; - if ( key === "parent" ) { + elements[ 0 ] = document.querySelectorAll("#" + options.target )[ 0 ].parentNode; + } else { - obj = jQuery("#" + options.target ).parent(); - } else { - - obj = jQuery("#" + options.target + " " + key ); - } + elements = document.querySelectorAll("#" + options.target + " " + key ); + } - obj.addClass( val ); - setTimeout( function() { + for ( idx = 0, len = elements.length; idx < len; idx++ ) { - obj.removeClass( val ); - }, 250 ); - }); - }; - }; + var element = elements[ idx ]; - applyFunction(); + element.classList.toggle( val ); + } + }); + }; Popcorn.compose( "applyclass", { @@ -77,12 +69,10 @@ for ( ; idx < len; idx++ ) { item = array[ idx ].split( ":"); - options.classes[ item[ 0 ] ] = item[ 1 ]; + options.classes[ item[ 0 ] ] = item[ 1 ] || ""; } }, - start: function( event, options ) { - - startFunction.call( this, event, options ); - } + start: toggleClass, + end: toggleClass }); })( Popcorn );