]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
added the eventListener to img -#368
authorMinoo <minoo.ziaei@gmail.com>
Wed, 20 Apr 2011 00:53:16 +0000 (20:53 -0400)
committerMinoo <minoo.ziaei@gmail.com>
Wed, 20 Apr 2011 00:53:16 +0000 (20:53 -0400)
plugins/image/popcorn.image.js

index 734ac938048893938a998879c7965f37db825708..98d904e01220daed6c343abd0d03cfc2a7fb01fd 100644 (file)
         options.link.style.textDecoration = "none";
 
         var img = document.createElement( 'img' );
+        img.addEventListener( "load", function() {
+          //img.src = options.src;
+          img.style.borderStyle = "none"; // borders look really bad, if someone wants it they can put it on their div target
+          
+          if ( options.href ) {
+            options.link.href = options.href;
+          }
+          options.link.target = "_blank";
+          if ( document.getElementById( options.target ) ) {
+            document.getElementById( options.target ).appendChild( options.link ); // add the widget's div to the target div
+          }
+          
+          var fontHeight = ( img.height / 12 ) + "px";
+          
+          var divText = document.createElement( 'div' );
+          divTextStyle = {
+              position: "relative",
+              width: img.width + "px",
+              textAlign: "center",
+              fontSize: fontHeight,
+              color: "black",
+              fontWeight : "bold",
+              zIndex: "10"
+          };
+          for ( st in divTextStyle ) {
+            divText.style[ st ] = divTextStyle[ st ];
+          }
+          
+          divText.innerHTML = options.text || "";
+          options.link.appendChild( divText );
+          options.link.appendChild( img );
+          divText.style.top = ( img.height / 2 ) - ( divText.offsetHeight / 2 ) + "px"; 
+          options.link.style.display = "none";
+        }, false );
         img.src = options.src;
-        img.style.borderStyle = "none"; // borders look really bad, if someone wants it they can put it on their div target
-        
-        if ( options.href ) {
-          options.link.href = options.href;
-        }
-        options.link.target = "_blank";
-        if ( document.getElementById( options.target ) ) {
-          document.getElementById( options.target ).appendChild( options.link ); // add the widget's div to the target div
-        }
-        
-        var fontHeight = ( img.height / 12 ) + "px";
-        
-        var divText = document.createElement( 'div' );
-        divTextStyle = {
-            position: "relative",
-            width: img.width + "px",
-            textAlign: "center",
-            fontSize: fontHeight,
-            color: "black",
-            fontWeight : "bold",
-            zIndex: "10"
-        };
-        for ( st in divTextStyle ) {
-          divText.style[ st ] = divTextStyle[ st ];
-        }
-        
-        divText.innerHTML = options.text || "";
-        options.link.appendChild( divText );
-        options.link.appendChild( img );
-        divText.style.top = ( img.height / 2 ) - ( divText.offsetHeight / 2 ) + "px"; 
-        options.link.style.display = "none";
       },
 
       /**