]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#565] Made some performance changes as well as some style changes, also fixed the...
authorDavid Seifried <david.c.seifried@gmail.com>
Thu, 23 Jun 2011 14:53:13 +0000 (10:53 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Thu, 23 Jun 2011 14:53:13 +0000 (10:53 -0400)
plugins/subtitle/popcorn.subtitle.js
plugins/subtitle/popcorn.subtitle.unit.js

index 6f5753381c4b3933ce5c35f210cc3838c34c48c9..c1fb4e81d13f5769c2633f70950c7c24a9cc1cfb 100755 (executable)
@@ -8,7 +8,11 @@
 
         if ( typeof google !== 'undefined' && google.load ) {
 
-          google.load( "language", "1", { callback: function() { scriptLoaded = true; } } );
+          google.load( "language", "1", { 
+            callback: function() {
+              scriptLoaded = true; 
+            }
+          });
         } else {
 
           setTimeout( function() {
         }
       },
       createDefaultContainer = function( context ) {
-
+        
         // clear this function from future calls; we are done
         createDefaultContainer = Popcorn.nop;
 
         var updatePosition = function() {
 
           // the video element must have height and width defined
-          context.container.style.fontSize = "18px";
-          context.container.style.width = context.media.offsetWidth + "px";
-          context.container.style.top = context.position().top  + context.media.offsetHeight - context.container.offsetHeight - 40 + "px";
-          context.container.style.left = context.position().left + "px";
+          style.fontSize = "18px";
+          style.width = context.media.offsetWidth + "px";
+          style.top = context.position().top  + context.media.offsetHeight - context.container.offsetHeight - 40 + "px";
+          style.left = context.position().left + "px";
 
           setTimeout( updatePosition, 10 );
         };
 
-        context.container = document.createElement( 'div' );
-        context.container.id = "subtitlediv";
-        context.container.style.position = "absolute";
-        context.container.style.color = "white";
-        context.container.style.textShadow = "black 2px 2px 6px";
-        context.container.style.fontWeight = "bold";
-        context.container.style.textAlign = "center";
+        var ctxContainer = context.container = document.createElement( 'div' ),
+            style = ctxContainer.style;
+
+        ctxContainer.id = "subtitlediv";
+        style.position = "absolute";
+        style.color = "white";
+        style.textShadow = "black 2px 2px 6px";
+        style.fontWeight = "bold";
+        style.textAlign = "center";
 
         updatePosition();
 
-        document.body.appendChild( context.container );
+        document.body.appendChild( ctxContainer );
       };
 
   Popcorn.getScript( "http://www.google.com/jsapi", callBack );
   var translate = function( options, text ) {
 
     options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
-    google.language.translate( text, '', options.selectedLanguage, function( result ) {
+    google.language.translate( text, "", options.selectedLanguage, function( result ) {
       
-      for( var k = 0; k < options.container.children.length; k++ ) {
-        if ( options.container.children[ k ].style.display === "inline" ) {   
-          options.container.children[ k ].innerHTML = result.translation;    
+      for( var k = 0, children = options.container.children, len = children.length; k < len; k++ ) {
+        if ( children[ k ].style.display === "inline" ) {   
+          children[ k ].innerHTML = result.translation;    
         }  
       }
 
-    } );
+    });
   };
 
   Popcorn.plugin( "subtitle" , {
         },
         options: {
           start: {
-            elem: 'input', 
-            type: 'text', 
-            label: 'In'
+            elem: "input", 
+            type: "text", 
+            label: "In"
           },
           end: {
-            elem: 'input', 
-            type: 'text', 
-            label: 'Out'
+            elem: "input", 
+            type: "text", 
+            label: "Out"
           },
-          target: 'subtitle-container',
+          target: "subtitle-container",
           text: {
-            elem: 'input', 
-            type: 'text', 
-            label: 'Text'
+            elem: "input", 
+            type: "text", 
+            label: "Text"
           }
         }
       },
 
       _setup: function( options ) {
-        var newdiv = document.createElement( "div" );
+        var newdiv = document.createElement( "div" ),
+            accessibility = document.getElementById( options.accessibilitysrc );
+
         newdiv.id = "subtitle-" + i;
         newdiv.style.display = "none";
         i++;
 
         // Creates a div for all subtitles to use
-        ( !this.container && !options.target || options.target === 'subtitle-container' ) && 
+        ( !this.container && !options.target || options.target === "subtitle-container" ) && 
           createDefaultContainer( this );
 
         // if a target is specified, use that
-        if ( options.target && options.target !== 'subtitle-container' ) {
+        if ( options.target && options.target !== "subtitle-container" ) {
           options.container = document.getElementById( options.target );
         } else { // use shared default container
           options.container = this.container;
         document.getElementById( options.container.id ).appendChild( newdiv );
         options.innerContainer = newdiv;
 
-        var accessibility = document.getElementById( options.accessibilitysrc );
-
         options.showSubtitle = function() {
           options.innerContainer.innerHTML = options.text;
         };
 
                 options.toggleSubtitles();
 
-                for( var k = 0; k < options.container.children.length; k++ ) {
-                  if ( options.container.children[ k ].style.display === "inline" ) {   
-                    options.showSubtitle( options, options.container.children[ k ].innerHTML );   
+                for( var k = 0, children = options.container.children, len = children.length; k < len; k++ ) {
+                  if ( children[ k ].style.display === "inline" ) {   
+                    options.showSubtitle( options, children[ k ].innerHTML );   
                   }  
                 }
 
         options.container.removeChild( options.innerContainer );
       }
    
-  } );
+  });
 
 })( Popcorn );
index fe3e965fb6c6a686ab4651cd81a8222956b48cdc..57f2bc309b9524697dc00db4794c01aaa797732b 100755 (executable)
@@ -114,7 +114,7 @@ test("Popcorn Subtitle Plugin", function () {
   });
 
   popped.exec( 5, function() {
-    ok ( document.getElementById( 'subtitle-0 ').style.display === "none" && 
+    ok ( document.getElementById( 'subtitle-0' ).style.display === "none" && 
         document.getElementById( 'subtitle-1' ).style.display === "none" &&
         document.getElementById( 'subtitle-2' ).style.display === "none", "All subtitles are no longer visible" );
     plus();