options._container.innerHTML = attrib;
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
target && target.appendChild( options._container );
},
/**
var p = Popcorn('#video')
- .code({
- start: 1,
- end: 3,
- onStart: function( options ) {
- $('#test1').innerHTML = 'Yes';
- }
- })
+ .code({})
.code({
start: 5,
} )();
if ( !options.onStart || typeof options.onStart !== 'function' ) {
- throw 'Popcorn Code Plugin Error: onStart must be a function.';
+
+ if ( Popcorn.plugin.debug ) {
+ throw new Error( 'Popcorn Code Plugin Error: onStart must be a function.' );
+ }
+ options.onStart = Popcorn.nop;
}
if ( options.onEnd && typeof options.onEnd !== 'function' ) {
- throw 'Popcorn Code Plugin Error: onEnd must be a function.';
+
+ if ( Popcorn.plugin.debug ) {
+ throw new Error( 'Popcorn Code Plugin Error: onEnd must be a function.' );
+ }
+ options.onEnd = undefined;
}
if ( options.onFrame && typeof options.onFrame !== 'function' ) {
- throw 'Popcorn Code Plugin Error: onFrame must be a function.';
+
+ if ( Popcorn.plugin.debug ) {
+ throw new Error( 'Popcorn Code Plugin Error: onFrame must be a function.' );
+ }
+ options.onFrame = undefined;
}
return {
test('Popcorn Code Plugin', function () {
var popped = Popcorn('#video'),
- expects = 8,
+ expects = 9,
count = 0,
frames = 0,
codeDiv = document.getElementById('code-div');
}
});
+ // empty track events should be safe
+ popped.code({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.code({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
+
popped.volume(0);
popped.play();
});
},
_setup: function( options ) {
+
+ var target = document.getElementById( options.target );
+
// facebook script requires a div named fb-root
if ( !document.getElementById( "fb-root" ) ) {
var fbRoot = document.createElement( "div" );
setOptions[ options.type ]();
- if ( document.getElementById( options.target ) ) {
- document.getElementById( options.target ).appendChild( options._container );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "flickr target container doesn't exist" );
}
+ target && target.appendChild( options._container );
},
/**
* @member facebook
Popcorn.plugin( "flickr" , function( options ) {
var containerDiv,
+ target = document.getElementById( options.target ),
_userid,
_uri,
_link,
idx++;
// ensure the target container the user chose exists
- if ( document.getElementById( options.target ) ) {
- document.getElementById( options.target ).appendChild( containerDiv );
- } else {
- throw ( "flickr target container doesn't exist" );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "flickr target container doesn't exist" );
}
+ target && target.appendChild( containerDiv );
// get the userid from Flickr API by using the username and apikey
var isUserIDReady = function() {
test("Popcorn Flickr Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 10,
+ expects = 11,
count = 0,
setupId,
flickrdiv = document.getElementById( "flickrdiv" );
ok( !flickrdiv.children[2], "Removed flickr was properly destroyed" );
plus();
});
-
+
+ // empty track events should be safe
+ popped.flickr({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.flickr({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
+
popped.volume(0).play();
});
}
},
_setup: function(options) {
+
+ var target = document.getElementById( options.target );
+
options._container = document.createElement( 'div' );
options._container.style.display = "none";
options._container.innerHTML = options.text;
- document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ target && target.appendChild( options._container );
},
/**
* @member footnote
_setup : function( options ) {
- var self = this;
+ var self = this,
+ target = document.getElementById( options.target );
options.endDrawing = options.endDrawing || options.end;
options.container.style.display = "none";
options.container.setAttribute( "id", "canvas" + options.gmltag );
- document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.container );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ target && target.appendChild( options.container );
if ( !window.Processing ) {
<div id="feed1" style="position:relative;float:left;width:600px;height:200px"><p>Horizontal Feed:</p></div>
</div>
</body>
-</html>
\ No newline at end of file
+</html>
// create a new div and append it to the parent div so nothing
// that already exists in the parent div gets overwritten
var newdiv = document.createElement( "div" ),
+ target = document.getElementById( options.target ),
initialize = function() {
//ensure that the script has been loaded
if ( !scriptLoaded ) {
newdiv.style.height = "100%";
i++;
- document.getElementById( options.target ).appendChild( newdiv );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ target && target.appendChild( newdiv );
initialize();
test("Popcorn Google Feed Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 12,
+ expects = 13,
setupId,
count = 0;
ok( !document.getElementById('feed1').children[0], "removed feed was properly destroyed" );
plus();
});
-
+
+ // empty track events should be safe
+ popped.googlefeed({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.googlefeed({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
+
popped.play();
});
*
*/
Popcorn.plugin("googlemap", function (options) {
- var newdiv, map, location;
+ var newdiv, map, location,
+ target = document.getElementById( options.target );
// if this is the firest time running the plugins
// call the function that gets the sctipt
i++;
// ensure the target container the user chose exists
- if (document.getElementById(options.target)) {
- document.getElementById(options.target).appendChild(newdiv);
- } else {
- throw ("map target container doesn't exist");
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
}
+ target && target.appendChild( newdiv );
// ensure that google maps and its functions are loaded
// before setting up the map parameters
test("Popcorn Google Map Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 14,
+ expects = 15,
count = 0,
setupId;
plus();
});
+ // empty track events should be safe
+ popped.googlemap({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.googlemap({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
+
popped.play();
});
},
_setup : function( options ) {
+ var target = document.getElementById( options.target );
+ options.container = document.createElement( 'div' );
+
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+
+ var container = document.createElement( "div" );
+ target && target.appendChild( options.container );
+ options.container.appendChild( container );
+
if ( !scriptLoading ) {
scriptLoading = true;
Popcorn.getScript( "http://www.google.com/jsapi", callBack );
}
- options.container = document.createElement( 'div' );
- var container = document.createElement( 'div' );
- if ( document.getElementById( options.target ) ) {
- document.getElementById( options.target ).appendChild( options.container );
- options.container.appendChild( container );
- }
-
var readyCheck = setInterval(function() {
if ( !scriptLoaded ) {
return;
}
clearInterval( readyCheck );
- options.newsShow = new google.elements.NewsShow( container, {
+ options.newsShow = target && new google.elements.NewsShow( container, {
format : "300x250",
queryList : [
{ q: options.topic || "Top Stories" }
test( "Popcorn google news Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 8,
+ expects = 9,
count = 0,
setupId,
googlenewsdiv = document.getElementById( "googlenewsdiv" );
equals ( googlenewsdiv.innerHTML, "", "initially, there is nothing inside the googlenewsdiv" );
plus();
+
+ // empty track events should be safe
+ popped.googlenews({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.googlenews({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
popped.googlenews({
start: 0, // seconds
ok( !googlenewsdiv.children[1], "removed google news was properly destroyed" );
plus();
});
-
+
popped.play();
});
}
},
_setup: function( options ) {
- var img = document.createElement( "img" );
+ var img = document.createElement( "img" ),
+ target = document.getElementById( options.target );
options.link = document.createElement( "a" );
options.link.style.position = "relative";
options.link.style.textDecoration = "none";
- if ( document.getElementById( options.target ) ) {
- // add the widget's div to the target div
- document.getElementById( options.target ).appendChild( options.link );
+
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
}
+ // add the widget's div to the target div
+ target && target.appendChild( options.link );
img.addEventListener( "load", function() {
.lastfm({
start: 5, // seconds
end: 15, // seconds
- artist: 'yacht',
target: 'lastfmdiv',
apikey: '30ac38340e8be75f9268727cb4526b3d'
} )
options._container = document.createElement( 'div' );
options._container.style.display = "none";
options._container.innerHTML = "";
-
- options.artist = options.artist.toLowerCase();
+ options.artist = options.artist && options.artist.toLowerCase() || "";
+
+ var target = document.getElementById( options.target );
- document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ target && target.appendChild( options._container );
if(!_artists[options.artist]) {
plugin. Please do not use it for other purposes.
*/
var popped = Popcorn("#video"),
- expects = 9,
+ expects = 10,
count = 0,
setupId,
lastfmdiv = document.getElementById('lastfmdiv');
.lastfm({
start: 4, // seconds
end: 7, // seconds
- artist: '',
target: 'lastfmdiv',
apikey: '30ac38340e8be75f9268727cb4526b3d'
});
ok( !lastfmdiv.children[2], "removed artist was properly destroyed" );
plus();
});
+
+ // empty track events should be safe
+ popped.lastfm({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.lastfm({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
popped.volume(0).play();
});
script.innerHTML = "api_key: " + apikey;
}
- options.type = options.type.toLowerCase();
+ options.type = options.type && options.type.toLowerCase() || "";
// Replace the LinkedIn plugin's error message to something more helpful
var errorMsg = function() {
-
options._container = document.createElement( "p" );
options._container.innerHTML = "Plugin requires a valid <a href='https://www.linkedin.com/secure/developer'>apikey</a>";
- document.getElementById( options.target ).appendChild( options._container );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw ( "target container doesn't exist" );
+ }
+ target && target.appendChild( options._container );
};
var setOptions = (function ( options ) {
} else {
setOptions[ options.type ] && setOptions[ options.type ]();
}
-
- if ( document.getElementById( options.target ) ) {
- document.getElementById( options.target ).appendChild( options._container );
+
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
}
+ target && target.appendChild( options._container );
- target.style.display = "none";
+ options._container.style.display = "none";
},
/**
* @member linkedin
* options variable
*/
start: function( event, options ) {
- options._container.parentNode.style.display = "block";
+ options._container.style.display = "block";
},
/**
* @member linkedin
* options variable
*/
end: function( event, options ) {
- options._container.parentNode.style.display = "none";
+ options._container.style.display = "none";
},
_teardown: function( options ) {
var tar = document.getElementById( options.target );
// run tests on localhost
var popped = Popcorn("#video"),
- expects = 22,
+ expects = 23,
count = 0,
setupId,
sharediv = document.getElementById( "sharediv" ),
popped.exec( 2, function() {
- ok( /block/.test( sharediv.style.display ), "sharediv contents are displayed" );
+ ok( /block/.test( sharediv.children[ 0 ].style.display ), "sharediv contents are displayed" );
plus();
- ok( /script/.test( sharediv.innerHTML ), "share plugin exists" );
+ ok( /script/.test( sharediv.children[ 0 ].innerHTML ), "share plugin exists" );
plus();
});
popped.exec( 4, function() {
- ok( /none/.test( sharediv.style.display ), "sharediv contents are hidden again" );
+ ok( /none/.test( sharediv.children[ 0 ].style.display ), "sharediv contents are hidden again" );
plus();
});
popped.exec( 2, function() {
- ok( /block/.test( recommenddiv.style.display ), "recommenddiv contents are displayed" );
+ ok( /block/.test( recommenddiv.children[ 0 ].style.display ), "recommenddiv contents are displayed" );
plus();
- ok( /script/.test( recommenddiv.innerHTML ), "recommend plugin exists" );
+ ok( /script/.test( recommenddiv.children[ 0 ].innerHTML ), "recommend plugin exists" );
plus();
});
popped.exec( 4, function() {
- ok( /none/.test( recommenddiv.style.display ), "recommenddiv contents are hidden again" );
+ ok( /none/.test( recommenddiv.children[ 0 ].style.display ), "recommenddiv contents are hidden again" );
plus();
});
popped.exec( 2, function() {
- ok( /block/.test( memberprofilediv.style.display ), "memberprofilediv contents are displayed" );
+ ok( /block/.test( memberprofilediv.children[ 0 ].style.display ), "memberprofilediv contents are displayed" );
plus();
- ok( /script/.test( memberprofilediv.innerHTML ), "member profile plugin exists" );
+ ok( /script/.test( memberprofilediv.children[ 0 ].innerHTML ), "member profile plugin exists" );
plus();
});
popped.exec( 4, function() {
- ok( /none/.test( memberprofilediv.style.display ), "memberprofilediv contents are hidden again" );
+ ok( /none/.test( memberprofilediv.children[ 0 ].style.display ), "memberprofilediv contents are hidden again" );
plus();
});
popped.exec( 2, function() {
- ok( /block/.test( companyinsiderdiv.style.display ), "companyinsiderdiv contents are displayed" );
+ ok( /block/.test( companyinsiderdiv.children[ 0 ].style.display ), "companyinsiderdiv contents are displayed" );
plus();
- ok( /script/.test( companyinsiderdiv.innerHTML ), "company insider plugin exists" );
+ ok( /script/.test( companyinsiderdiv.children[ 0 ].innerHTML ), "company insider plugin exists" );
plus();
});
popped.exec( 4, function() {
- ok( /none/.test( companyinsiderdiv.style.display ), "companyinsiderdiv contents are hidden again" );
+ ok( /none/.test( companyinsiderdiv.children[ 0 ].style.display ), "companyinsiderdiv contents are hidden again" );
plus();
});
popped.exec( 2, function() {
- ok( /block/.test( companyprofilediv.style.display ), "companyprofilediv contents are displayed" );
+ ok( /block/.test( companyprofilediv.children[ 0 ].style.display ), "companyprofilediv contents are displayed" );
plus();
- ok( /script/.test( companyprofilediv.innerHTML ), "company profile plugin exists" );
+ ok( /script/.test( companyprofilediv.children[ 0 ].innerHTML ), "company profile plugin exists" );
plus();
});
popped.exec( 4, function() {
- ok( /none/.test( companyprofilediv.style.display ), "companyprofilediv contents are hidden again" );
+ ok( /none/.test( companyprofilediv.children[ 0 ].style.display ), "companyprofilediv contents are hidden again" );
plus();
// Make sure _teardown functionality works
ok( !companyprofilediv.children[1], "companyprofilediv plugin was properly destroyed" );
plus();
});
-
+
+ // empty track events should be safe
+ popped.linkedin({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.linkedin({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
+
popped.volume( 0 ).play();
} else {
<script src="popcorn.lowerthird.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
+
var p = Popcorn('#video')
.play()
.lowerthird({
_setup: function( options ) {
+ var target = document.getElementById( options.target );
+
// Creates a div for all Lower Thirds to use
if ( !this.container ) {
this.container = document.createElement('div');
}
// if a target is specified, use that
- if ( options.target && options.target !== 'lowerthird-container' ) {
- options.container = document.getElementById( options.target );
+ if ( options.target && options.target !== "lowerthird-container") {
+ options.container = document.createElement( "div" );
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ target && target.appendChild( options.container );
} else { // use shared default container
options.container = this.container;
}
-
-
},
/**
* @member lowerthird
test( "Popcorn lower third Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 7,
+ expects = 8,
count = 0,
lowerthirddiv = document.getElementById( "lowerthirddiv" );
ok( !popped.container, "initially, there is no default div" );
plus();
-
+ // empty track events should be safe
+ popped.lowerthird({});
+
+ // debug should log errors on error track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.lowerthird({
+ target: "does not exist"
+ });
+ } catch( e ) {
+ ok(true, 'invalid target event was caught by debug');
+ plus();
+ }
+
popped.lowerthird({
start: 0, // seconds
end: 2, // seconds
});
popped.exec( 3, function() {
- equals ( lowerthirddiv.innerHTML, "Dr Jekyll<br>Person", "second lowerthird is visible" );
+ equals ( lowerthirddiv.innerHTML, "<div>Dr Jekyll<br>Person</div>", "second lowerthird is visible" );
plus();
});
popped.exec( 5, function() {
equals ( popped.container.innerHTML, "", "first lowerthird is empty" );
plus();
- equals ( lowerthirddiv.innerHTML, "", "second lowerthird is empty" );
+ equals ( lowerthirddiv.innerHTML, "<div></div>", "second lowerthird is empty" );
plus();
});
Popcorn.plugin( 'mustache' , function( options ) {
- var getData, data, getTemplate, template, loaded = false;
+ var getData, data, getTemplate, template;
- Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js', function() {
- loaded = true;
- });
+ Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js');
var shouldReload = !!options.dynamic,
typeOfTemplate = typeof options.template,
- typeOfData = typeof options.data;
+ typeOfData = typeof options.data,
+ target = document.getElementById( options.target );
+
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ options.container = target || document.createElement( "div" );
if ( typeOfTemplate === 'function' ) {
if ( !shouldReload ) {
} else if ( typeOfTemplate === 'string' ) {
template = options.template;
} else {
- Popcorn.error( 'Mustache Plugin Error: options.template must be a String or a Function.' );
+ Popcorn.plugin.debug && Popcorn.error( 'Mustache Plugin Error: options.template must be a String or a Function.' );
+ template = "";
}
if ( typeOfData === 'function' ) {
} else if ( typeOfData === 'object' ) {
data = options.data;
} else {
- Popcorn.error( 'Mustache Plugin Error: options.data must be a String, Object, or Function.' );
+ Popcorn.plugin.debug && Popcorn.error( 'Mustache Plugin Error: options.data must be a String, Object, or Function.' );
+ data = "";
}
return {
start: function( event, options ) {
var interval = function() {
-
- if( !loaded ) {
+
+ if( !window.Mustache ) {
setTimeout( function() {
interval();
}, 10 );
var html = Mustache.to_html( template,
data
).replace( /^\s*/mg, '' );
- document.getElementById( options.target ).innerHTML = html;
+ options.container.innerHTML = html;
}
};
},
end: function( event, options ) {
- document.getElementById( options.target ).innerHTML = '';
+ options.container.innerHTML = '';
},
_teardown: function( options ) {
getData = data = getTemplate = template = null;
test('Popcorn Mustache Plugin', function () {
var popped = Popcorn('#video'),
- expects = 5,
+ expects = 6,
count = 0,
mustacheDiv = document.getElementById('mustache-div');
}, false);
+ // empty track events should be safe
+ popped.mustache({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.mustache({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
+
popped.volume(0);
popped.play();
});
displayProjection,
pointLayer,
selectControl,
- popup;
+ popup,
+ target = document.getElementById( options.target );
// create a new div within the target div
// this is later passed on to the maps api
newdiv.style.height = "100%";
i++;
- document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( newdiv );
+
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+ target && target.appendChild( newdiv );
// callback function fires when the script is run
var isGeoReady = function() {
<script>
document.addEventListener( "DOMContentLoaded", function () {
+Popcorn.plugin.debug = true;
var p = Popcorn( "#video" )
.volume( 0 )
.play()
- .processing({
- start: 2,
- end: 10,
- target: "processing-div",
- sketch: "test.pjs",
- noPause: true
- })
+ .processing({})
.processing({
start: 10,
end: 15,
options.parentTarget = document.getElementById( options.target );
- if ( !options.parentTarget ) {
- throw ( "target container doesn't exist" );
+ if ( !options.parentTarget && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
}
initProcessing = function() {
canvas.style.display = "none";
options.canvas = canvas;
- options.parentTarget.appendChild( options.canvas );
-
- Popcorn.xhr({
- url: options.sketch,
- dataType: "text",
- success: function( responseCode ) {
- options.codeReady = true;
- options.processingCode = responseCode;
- initProcessing();
+ options.parentTarget && options.parentTarget.appendChild( options.canvas );
+
+ if ( options.sketch ) {
+
+ Popcorn.xhr({
+ url: options.sketch,
+ dataType: "text",
+ success: function( responseCode ) {
+ options.codeReady = true;
+ options.processingCode = responseCode;
+ initProcessing();
+ }
+ });
+ } else {
+
+ if ( Popcorn.plugin.debug ) {
+ throw new Error( "options.sketch is undefined" );
}
- });
+ }
};
return {
test( "Processing plugin tests", function() {
var popped = Popcorn( "#video" ),
- expects = 31,
+ expects = 32,
count = 0,
processingDiv = document.getElementById( "processing-div-1" ),
processingDiv2 = document.getElementById( "processing-div-2" ),
equals( ctx.style.display, "none", ctx.id + " is hidden initially" );
plus();
});
+
+ // empty track events should be safe
+ popped.processing({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.processing({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
popped.play();
});
}
},
_setup: function( options ) {
- var exists = false;
+ var exists = false,
+ target = document.getElementById( options.target );
+
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+
// loop through the existing objects to ensure no duplicates
// the idea here is to have one object per unique options.target
for ( var i = 0; i < peopleArray.length; i++ ) {
.volume(0)
.play()
.timeline({
- start: 1, // seconds
- target: "timeline",
- title: "This is a title",
- text: "this is some interesting text that goes inside",
- innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
- direction: "down"
} )
.timeline({
start: 3, // seconds
var target = document.getElementById( options.target ),
newdiv = document.createElement( "div" );
- target.style.width = "400px";
- target.style.height = "200px";
- target.style.overflow = "auto";
-
newdiv.style.display = "none";
newdiv.id = "timelineDiv" + i;
if ( target ) {
+ target.style.width = "400px";
+ target.style.height = "200px";
+ target.style.overflow = "auto";
target.appendChild( newdiv );
// if this isnt the first div added to the target div
target.insertBefore( newdiv, document.getElementById( "timelineDiv" + ( i - 1 ) ) );
}
+ } else if ( Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
}
i++;
Popcorn.getScript("http://widgets.twimg.com/j/2/widget.js");
}
+ var target = document.getElementById( options.target );
+
// setup widget div that is unique per track
options.container = document.createElement( 'div' ); // create the div to store the widget
options.container.setAttribute('id', Popcorn.guid()); // use this id to connect it to the widget
options.container.style.display = "none"; // display none by default
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
// add the widget's div to the target div
- document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.container );
+ target && target.appendChild( options.container );
// setup info for the widget
var src = options.src || "",
}
},
_setup : function( options ) {
- // make an iframe
+
+ var target = document.getElementById( options.target );
+
+ // make an iframe
options._iframe = document.createElement( 'iframe' );
options._iframe.setAttribute('width', "100%");
options._iframe.setAttribute('height', "100%");
options._iframe.src = options.src;
options._iframe.style.display = 'none';
+ if ( !target && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+
// add the hidden iframe to the DOM
- document.getElementById( options.target ) && document.getElementById( options.target ).appendChild(options._iframe);
+ target && target.appendChild(options._iframe);
},
/**
<script src="popcorn.wikipedia.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
+Popcorn.plugin.debug = true;
var p = Popcorn('#video')
.volume(0)
.play()
- .wikipedia({
- start: 0, // seconds
- end: 10, // seconds
- src: 'http://en.wikipedia.org/wiki/Cape_Town',
- title: "this is an article",
- target: 'wikidiv'
- } )
+ .wikipedia({} )
.wikipedia({
start: 7, // seconds
end: 20, // seconds
if ( options.src ) {
Popcorn.getScript( "http://" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&page=" +
options.src.slice( options.src.lastIndexOf("/")+1) + "&format=json&callback=wikiCallback" + _guid);
- } else {
- throw ( "Wikipedia plugin needs a 'src'" );
+ } else if ( Popcorn.plugin.debug ) {
+ throw new Error( "Wikipedia plugin needs a 'src'" );
}
},
test("Popcorn wikipedia Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 11,
+ expects = 12,
count = 0,
theArticle = document.getElementById( "wikidiv" );
equals ( theArticle.innerHTML, "", "wikidiv is now empty" );
plus();
});
+
+ // empty track events should be safe
+ popped.wikipedia({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.wikipedia({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
});
_setup: function( options ) {
+ if ( !document.getElementById( options.target ) && Popcorn.plugin.debug ) {
+ throw new Error( "target container doesn't exist" );
+ }
+
options._duration = options.end - options.start;
options._container = container[ options.target ] || setupContainer( options.target );
spanLocation = spanLocation % ( options._container.offsetWidth - options.word.offsetWidth );
options.word.style.left = spanLocation + "px";
spanLocation += options.word.offsetWidth + 10;
-
options.word.style[ supports.transform ] = "translateY(" +
- ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)";
+ ( options._container.offsetHeight - options.word.offsetHeight ) + "px)";
options.word.style.opacity = 1;
test( "Popcorn wordriver Plugin", function () {
var popped = Popcorn( "#video" ),
- expects = 16,
+ expects = 17,
count = 0,
firstTrack,
secondTrack,
equals( wordriverdiv.childElementCount, 0, "wordriverdiv now has no inner element, even though one still exists, but was never called" );
plus();
});
+
+ // empty track events should be safe
+ popped.wordriver({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.wordriver({});
+ } catch( e ) {
+ ok(true, 'empty event was caught by debug');
+ plus();
+ }
popped.play();