]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#t592] flash in semantic demo effect
authorScottDowne <sdowne@learn.senecac.on.ca>
Thu, 23 Jun 2011 17:33:23 +0000 (13:33 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Thu, 23 Jun 2011 17:33:23 +0000 (13:33 -0400)
demos/semantic_video/index.html
demos/semantic_video/popcorn.applyclass.js [new file with mode: 0644]

index 8a6cccf647bdfa58730393c253046265e0779a49..7c721342733448adbb0a2eb7a3071cc6f371ebc9 100644 (file)
@@ -17,7 +17,7 @@
   <script src="../../plugins/flickr/popcorn.flickr.js"></script>
   <script src="../../plugins/attribution/popcorn.attribution.js"></script>
   <script src="../../plugins/lastfm/popcorn.lastfm.js"></script>
-  <script src="../../effects/applyclass/popcorn.applyclass.js"></script>
+  <script src="popcorn.applyclass.js"></script>
 
   <script src="../../parsers/parserXML/popcorn.parserXML.js"></script>
 
diff --git a/demos/semantic_video/popcorn.applyclass.js b/demos/semantic_video/popcorn.applyclass.js
new file mode 100644 (file)
index 0000000..4ac815d
--- /dev/null
@@ -0,0 +1,85 @@
+// EFFECT: applyclass
+
+(function (Popcorn) {
+
+  /**
+   * apply css class to jquery selector
+   * selector is relative to plugin target's id
+   * so .overlay is actually jQuery( "#target .overlay")
+   *
+   * @param {Object} options
+   * 
+   * Example:
+     var p = Popcorn('#video')
+        .footnote({
+          start: 5, // seconds
+          end: 15, // seconds
+          text: 'This video made exclusively for drumbeat.org',
+          target: 'footnotediv',
+          effect: 'applyclass',
+          applyclass: 'selector: class'
+        })
+   *
+   */
+
+  Popcorn.compose( "applyclass", {
+    
+    manifest: {
+      about: {
+        name: "Popcorn applyclass Effect",
+        version: "0.1",
+        author: "@scottdowne",
+        website: "scottdowne.wordpress.com"
+      },
+      options: {}
+    },
+    _setup: function( options ) {
+
+      options.classes = {};
+      options.applyclass = options.applyclass || "";
+
+      var classes = options.applyclass.replace( /\s/g, "" ).split( "," ),
+          item = [],
+          idx = 0, len = classes.length;
+
+      for ( ; idx < len; idx++ ) {
+
+        item = classes[ idx ].split( ":" );
+
+        if ( item[ 0 ] ) {
+          options.classes[ item[ 0 ] ] = item[ 1 ] || "";
+        }
+      }
+    },
+    start: function( event, options ) {
+
+      var idx = 0, len = 0, elements;
+
+      Popcorn.forEach( options.classes, function( key, val ) {
+
+        elements = [];
+
+        if ( key === "parent" ) {
+
+          var item = document.querySelectorAll("#" + options.target )[ 0 ];
+
+          item && item.parentNode && elements.push( item.parentNode );
+        } else {
+
+          elements = document.querySelectorAll("#" + options.target + " " + key );
+        }
+
+        for ( idx = 0, len = elements.length; idx < len; idx++ ) {
+
+          var element = elements[ idx ];
+          element.classList.toggle( val );
+
+          setTimeout( function() {
+
+            element.classList.toggle( val );
+          }, 250 );
+        }
+      });
+    }
+  });
+})( Popcorn );