uri += "lang=en-us&format=json&jsoncallback=flickr";
Popcorn.xhr.getJSONP( uri, function( data ) {
- //$.getJSON( uri, function( data ) {
options.container.innerHTML = "<p style='padding:" + padding + ";'>" + data.title + "<p/>";
Popcorn.forEach( data.items, function ( item, i ) {
*
*/
- var newdiv, i = 1, _mapFired = false, _mapLoaded = false;
+ var newdiv,
+ i = 1,
+ _mapFired = false,
+ _mapLoaded = false;
// callback function fires when the script is run
googleCallback = function() {
// insert google api script once
if (!_mapFired) {
_mapFired = true;
- var loadScriptTime = (new Date).getTime();
- var head = document.getElementsByTagName("head")[0];
- var script = document.createElement("script");
-
- script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=googleCallback";
- script.type = "text/javascript";
- head.insertBefore( script, head.firstChild );
+ Popcorn.getScript("http://maps.google.com/maps/api/js?sensor=false&callback=googleCallback");
}
Popcorn.plugin( "googlemap" , function( options ) {
- var newdiv, map, location;
+ var newdiv,
+ map,
+ location;
// create a new div this way anything in the target div
// this is later passed on to the maps api
newdiv = document.createElement("div");
- newdiv.id = "actualmap"+i;
+ newdiv.id = "actualmap" + i;
newdiv.style.width = "100%";
newdiv.style.height = "100%";
i++;
<script src="../../popcorn.js"></script>
- <script src="http://google.com/jsapi"></script>
- <script>google.load("elements", "1", {packages : ["newsshow"]});</script>
-
<script src="popcorn.googlenews.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// PLUGIN: Google News
(function (Popcorn) {
-
+ var scriptLoaded = false;
+
+ Popcorn.getScript( "http://www.google.com/jsapi", function() {
+ google.load("elements", "1", {packages : ["newsshow"], callback: function() {scriptLoaded = true;}});
+ });
+
/**
*/
Popcorn.plugin( "googlenews" , {
if ( document.getElementById( options.target ) ) {
document.getElementById( options.target ).appendChild( options.container );
}
- var newsShow = new google.elements.NewsShow( options.container, {
- format : "300x250",
- queryList : [
- { q: options.topic || "Top Stories" }
- ]
- } );
+
+ var readyCheck = setInterval(function() {
+ if ( !scriptLoaded ) {
+ return;
+ }
+ clearInterval(readyCheck);
+
+ var newsShow = new google.elements.NewsShow( options.container, {
+ format : "300x250",
+ queryList : [
+ { q: options.topic || "Top Stories" }
+ ]
+ } );
+
+ }, 5);
+
options.container.style.display = "none";
},
// PLUGIN: LASTFM
-var lastFMcallback;
+ var _artists = [],
+ lastFMcallback = function(data){
+ if (data.artist) {
+ var htmlString = '<h3>'+data.artist.name+'</h3>';
+ htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
+ htmlString += '<p>'+ data.artist.bio.summary +'</p>';
+ htmlString += '<hr /><p><h4>Tags</h4><ul>';
+
+ Popcorn.forEach( data.artist.tags.tag, function( val, i) {
+ htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
+ });
+
+ htmlString += '</ul></p>';
+ htmlString += '<hr /><p><h4>Similar</h4><ul>';
+
+ Popcorn.forEach( data.artist.similar.artist, function( val, i) {
+ htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
+ });
+
+ htmlString += '</ul></p>';
+
+ _artists[data.artist.name.toLowerCase()] = htmlString;
+ }
+ };
(function (Popcorn) {
*/
Popcorn.plugin( "lastfm" , (function(){
- var _artists = [];
return {
manifest: {
}
if(!_artists[options.artist]) {
- var loadScriptTime = (new Date).getTime();
- var head = document.getElementsByTagName('head')[0];
- var script = document.createElement('script');
-
- script.src = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ options.artist +"&api_key="+options.apikey+"&format=json&callback=lastFMcallback";
- script.type = "text/javascript";
- head.insertBefore( script, head.firstChild );
-
+
_artists[options.artist] = "Unknown Artist";
+ Popcorn.getScript("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ options.artist +"&api_key="+options.apikey+"&format=json&callback=lastFMcallback");
+
}
- lastFMcallback = function(data){
- if (data.artist) {
- var htmlString = '<h3>'+data.artist.name+'</h3>';
- htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
- htmlString += '<p>'+ data.artist.bio.summary +'</p>';
- htmlString += '<hr /><p><h4>Tags</h4><ul>';
-
- Popcorn.forEach( data.artist.tags.tag, function( val, i) {
- htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
- });
-
- htmlString += '</ul></p>';
- htmlString += '<hr /><p><h4>Similar</h4><ul>';
-
- Popcorn.forEach( data.artist.similar.artist, function( val, i) {
- htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
- });
-
- htmlString += '</ul></p>';
-
- _artists[data.artist.name.toLowerCase()] = htmlString;
- }
- };
},
/**
* @member LastFM
<title>Popcorn Subtitle Plug-in Demo</title>
<script src="../../popcorn.js"></script>
- <script src="http://google.com/jsapi"></script>
- <script>google.load("language", "1");</script>
<script src="popcorn.subtitle.js"></script>
<script>
// PLUGIN: Subtitle
(function (Popcorn) {
-
+
+ var scriptLoaded = false;
+
+ Popcorn.getScript( "http://www.google.com/jsapi", function() {
+ google.load("language", "1", {callback: function() {scriptLoaded = true;}});
+ });
+
/**
*/
} );
};
-
-/*
- // Find element offset
- if (element.offsetParent) {
- do {
- offsetX += element.offsetLeft;
- offsetY += element.offsetTop;
- } while ((element = element.offsetParent));
- }
-*/
-
Popcorn.plugin( "subtitle" , {
manifest: {
options.toggleSubtitles = function() {};
options.that = this;
-
- if ( options.languagesrc ) {
- options.showSubtitle = translate;
- options.languageSrc = document.getElementById( options.languagesrc );
- options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
-
- if ( !this.languageSources ) {
- this.languageSources = {};
+ var readyCheck = setInterval(function() {
+ if ( !scriptLoaded ) {
+ return;
}
+ clearInterval(readyCheck);
-
+ if ( options.languagesrc ) {
+ options.showSubtitle = translate;
+ options.languageSrc = document.getElementById( options.languagesrc );
+ options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
+
+ if ( !this.languageSources ) {
+ this.languageSources = {};
+ }
- if ( !this.languageSources[ options.languagesrc ] ) {
- this.languageSources[ options.languagesrc ] = {};
+ if ( !this.languageSources[ options.languagesrc ] ) {
+ this.languageSources[ options.languagesrc ] = {};
- }
+ }
- if ( !this.languageSources[ options.languagesrc ][ options.target ] ) {
- this.languageSources[ options.languagesrc ][ options.target ] = true;
+ if ( !this.languageSources[ options.languagesrc ][ options.target ] ) {
+ this.languageSources[ options.languagesrc ][ options.target ] = true;
- options.languageSrc.addEventListener( "change", function() {
+ options.languageSrc.addEventListener( "change", function() {
+ options.toggleSubtitles();
+ options.showSubtitle( options, options.container.innerHTML );
- options.toggleSubtitles();
- options.showSubtitle( options, options.container.innerHTML );
+ }, false );
- }, false );
+ }
}
+ if ( accessibility ) {
+ options.accessibility = accessibility;
- }
+ options.toggleSubtitles = function() {
+ options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
+ if ( options.accessibility.checked || options.selectedLanguage !== ( options.language || "") ) {
+ options.display = "inline";
+ options.container.style.display = options.display;
+ } else if ( options.selectedLanguage === ( options.language || "") ) {
+ options.display = "none";
+ options.container.style.display = options.display;
+ }
+
+ };
+
+ options.accessibility.addEventListener( "change", options.toggleSubtitles, false );
+
+ // initiate it once to set starting state
+ options.toggleSubtitles();
+ }
+ }, 5);
- if ( accessibility ) {
- options.accessibility = accessibility;
- options.toggleSubtitles = function() {
- options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
- if ( options.accessibility.checked || options.selectedLanguage !== ( options.language || "") ) {
- options.display = "inline";
- options.container.style.display = options.display;
- } else if ( options.selectedLanguage === ( options.language || "") ) {
- options.display = "none";
- options.container.style.display = options.display;
- }
- };
- options.accessibility.addEventListener( "change", options.toggleSubtitles, false );
- // initiate it once to set starting state
- options.toggleSubtitles();
- }
},
/**
*/
if ( !window.TWTR ) {
- var head = document.getElementsByTagName("head")[0] || document.documentElement,
- script = document.createElement("script");
-
- script.src = "http://widgets.twimg.com/j/2/widget.js";
-
- head.insertBefore( script, head.firstChild );
+ Popcorn.getScript("http://widgets.twimg.com/j/2/widget.js");
}
Popcorn.plugin( "twitter" , {
options._fired = true;
};
- var head = document.getElementsByTagName( "head" )[0];
- var script = document.createElement( "script" );
- script.src = "http://" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice( options.src.lastIndexOf("/")+1) ) + "&format=json&callback=wikiCallback" + _guid;
-
- head.insertBefore( script, head.firstChild );
+ Popcorn.getScript("http://" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice( options.src.lastIndexOf("/")+1) ) + "&format=json&callback=wikiCallback" + _guid);
},
/**
* @member wikipedia
test("Popcorn wikipedia Plugin", function () {
var popped = Popcorn("#video"),
- expects = 9,
+ expects = 10,
count = 0,
theArticle = document.getElementById('wikidiv'),
wikiInterval,
plus();
equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
plus();
- equals (theArticle.childElement[0].innerHTML, "this is an article", "wikidiv has the right title" );
+ equals (theArticle.childNodes[0].innerHTML, "this is an article", "wikidiv has the right title" );
plus();
- equals (theArticle.childElement[1].innerHTML, "Cape Town metropolitan municipality. It is the provincial capital and primate city ...", "wikidiv has the right content" );
+ equals (theArticle.childNodes[1].innerHTML, "Cape Town is the second-most populous city in South Africa, and the largest in land area, forming part of the City of Cape Town metropolitan municipality. It is the provincial capital and primate city ...", "wikidiv has the right content" );
plus();
clearInterval( wikiInterval );
}
plus();
equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
plus();
- equals (theArticle.childElement[1].innerHTML, "São Paulo is the largest city in Brazil, the largest city in the southern hemisphere, and the world's 7th largest metropolitan area. The city is the capital of the state of São Paulo, the most populou ...", "wikidiv has the right content" );
+ equals (theArticle.childNodes[1].innerHTML, "São Paulo is the largest city in Brazil, the largest city in the southern hemisphere, and the world's 7th largest metropolitan area. The city is the capital of the state of São Paulo, the most populou ...", "wikidiv has the right content" );
plus();
clearInterval( wikiInterval3 );
}