options.link.style.position = "relative";
options.link.style.textDecoration = "none";
- var img = document.createElement( 'img' );
+ if ( document.getElementById( options.target ) ) {
+ // add the widget's div to the target div
+ document.getElementById( options.target ).appendChild( options.link );
+ }
+
img.addEventListener( "load", function() {
- // borders look really bad, if someone wants it they can put it on their div target
- img.style.borderStyle = "none";
+ // borders look really bad, if someone wants it they can put it on their div target
+ img.style.borderStyle = "none";
if ( options.href ) {
options.link.href = options.href;
}
+
options.link.target = "_blank";
- divText = document.createElement( "div" );
+ var fontHeight = ( img.height / 12 ) + "px",
++ divText = document.createElement( "div" );
+ // add the widget's div to the target div
+ document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.link );
- 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 );
*/
end: function( event, options ) {
options.link.style.display = "none";
+ },
+ _teardown: function( options ) {
+ document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options.link );
}
});
-
})( Popcorn );
test("Popcorn Image Plugin", function () {
--
- var popped = Popcorn("#video"),
- expects = 6,
++
+ var popped = Popcorn( "#video" ),
+ expects = 8,
count = 0,
- imagediv = document.getElementById('imagediv');
+ setupId,
+ imagediv = document.getElementById( "imagediv" ),
+ sources = [
+ "https://www.drumbeat.org/media//images/drumbeat-logo-splash.png",
+ "http://www.petmountain.com/category/mini/organic-dog-supplies/520/organic-dog-supplies.jpg",
+ "http://www.botskool.com/sites/default/files/images/javascript.png"
+ ];
expect( expects );
plus();
popped.image({
- start: 1, // seconds
- end: 3, // seconds
- href: 'http://www.drumbeat.org/',
- src: 'https://www.drumbeat.org/media//images/drumbeat-logo-splash.png',
- text: 'DRUMBEAT',
- target: 'imagediv'
+ // seconds
+ start: 1,
+ // seconds
+ end: 3,
+ href: "http://www.drumbeat.org/",
+ src: sources[0],
+ text: "DRUMBEAT",
+ target: "imagediv"
+ })
+ .image({
+ // seconds
- start: 4,
++ start: 5,
+ // seconds
- end: 6,
++ end: 7,
+ // no href
+ src: sources[1],
+ target: "imagediv"
+ })
+ .image({
+ // seconds
- start: 4,
++ start: 5,
+ // seconds
- end: 6,
++ end: 7,
+ // no href
+ src: sources[2],
+ target: "imagediv"
});
+ setupId = popped.getLastTrackEventId();
+
popped.exec( 2, function() {
ok( /display: block;/.test( imagediv.innerHTML ), "Div contents are displayed" );
plus();
popped.exec( 4, function() {
ok( /display: none;/.test( imagediv.innerHTML ), "Div contents are hidden again" );
plus();
-
+ });
+
- popped.exec( 5, function() {
++ popped.exec( 6, function() {
+ [].forEach.call( document.querySelectorAll( "#imagediv a img" ), function( img, idx ) {
+ ok( img.src === sources[ idx ], "Image " + idx + " is in the right order" );
+ plus();
- });
++ });
++
++ popped.exec( 8, function() {
+ popped.pause().removeTrackEvent( setupId );
+ ok( !imagediv.children[0], "removed image was properly destroyed" );
+ plus();
});
- popped.volume(0).play();
+ popped.volume( 0 ).play();
});