From: Mohammed Buttu Date: Mon, 16 May 2011 19:51:12 +0000 (-0400) Subject: #485 Fixed leaking divTextStyle variable and corrected code style X-Git-Tag: v0.6~6^2~7 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=cb025655ef41121b4447494c7abf5025b7888578;p=popcorn-js.git #485 Fixed leaking divTextStyle variable and corrected code style --- diff --git a/plugins/image/popcorn.image.js b/plugins/image/popcorn.image.js index b8b0837..3d99a3d 100644 --- a/plugins/image/popcorn.image.js +++ b/plugins/image/popcorn.image.js @@ -1,53 +1,56 @@ // PLUGIN: IMAGE - (function (Popcorn) { +/** + * Images popcorn plug-in + * Shows an image element + * Options parameter will need a start, end, href, target and src. + * Start is the time that you want this plug-in to execute + * End is the time that you want this plug-in to stop executing + * href is the url of the destination of a link - optional + * Target is the id of the document element that the iframe needs to be attached to, + * this target element must exist on the DOM + * Src is the url of the image that you want to display + * text is the overlayed text on the image - optional + * + * @param {Object} options + * + * Example: + var p = Popcorn('#video') + .image({ + start: 5, // seconds + end: 15, // seconds + href: 'http://www.drumbeat.org/', + src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png', + text: 'DRUMBEAT', + target: 'imagediv' + } ) + * + */ - /** - * Images popcorn plug-in - * Shows an image element - * Options parameter will need a start, end, href, target and src. - * Start is the time that you want this plug-in to execute - * End is the time that you want this plug-in to stop executing - * href is the url of the destination of a link - optional - * Target is the id of the document element that the iframe needs to be attached to, - * this target element must exist on the DOM - * Src is the url of the image that you want to display - * text is the overlayed text on the image - optional - * - * @param {Object} options - * - * Example: - var p = Popcorn('#video') - .image({ - start: 5, // seconds - end: 15, // seconds - href: 'http://www.drumbeat.org/', - src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png', - text: 'DRUMBEAT', - target: 'imagediv' - } ) - * - */ Popcorn.plugin( "image", { manifest: { + about:{ - name: "Popcorn image Plugin", - version: "0.1", - author: "Scott Downe", - website: "http://scottdowne.wordpress.com/" + + name : "Popcorn image Plugin", + version : "0.1", + author : "Scott Downe", + website : "http://scottdowne.wordpress.com/" }, + options:{ - start : {elem:'input', type:'number', label:'In'}, - end : {elem:'input', type:'number', label:'Out'}, - href : {elem:'input', type:'text', label:'Link URL'}, + start : {elem:'input', type:'number', label:'In'}, + end : {elem:'input', type:'number', label:'Out'}, + href : {elem:'input', type:'text', label:'Link URL'}, target : 'Image-container', - src : {elem:'input', type:'text', label:'Source URL'}, - text: {elem:'input', type:'text', label:'TEXT'} + src : {elem:'input', type:'text', label:'Source URL'}, + text : {elem:'input', type:'text', label:'TEXT'} } }, _setup: function( options ) { + var img = document.createElement( 'img' ); options.link = document.createElement( 'a' ); options.link.style.position = "relative"; @@ -57,31 +60,29 @@ document.getElementById( options.target ).appendChild( options.link ); // add the widget's div to the target div } - var img = document.createElement( 'img' ); img.addEventListener( "load", function() { + 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"; + + var fontHeight = ( img.height / 12 ) + "px", + divText = document.createElement( "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 ( var st in divTextStyle ) { - divText.style[ st ] = divTextStyle[ st ]; - } - + Popcorn.extend( divText.style, { + + color : "black", + fontSize : fontHeight, + fontWeight : "bold", + position : "relative", + textAlign : "center", + width : img.width + "px", + zIndex : "10" + }); + divText.innerHTML = options.text || ""; options.link.appendChild( divText ); options.link.appendChild( img ); @@ -109,7 +110,6 @@ end: function( event, options ) { options.link.style.display = "none"; } - }); })( Popcorn );