зеркало из https://github.com/mozilla/popcorn-js.git
[#340] plugins now using getScript
This commit is contained in:
Родитель
d9b7ee4c8f
Коммит
4c4061ad18
|
@ -87,7 +87,6 @@
|
|||
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 ) {
|
||||
|
|
|
@ -32,7 +32,10 @@ var googleCallback;
|
|||
*
|
||||
*/
|
||||
|
||||
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() {
|
||||
|
@ -41,23 +44,19 @@ var googleCallback;
|
|||
// 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++;
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
|
||||
<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 () {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
// 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" , {
|
||||
|
@ -26,12 +31,22 @@
|
|||
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";
|
||||
|
||||
},
|
||||
|
|
|
@ -1,5 +1,28 @@
|
|||
// 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) {
|
||||
|
||||
|
@ -29,7 +52,6 @@ var lastFMcallback;
|
|||
*/
|
||||
Popcorn.plugin( "lastfm" , (function(){
|
||||
|
||||
var _artists = [];
|
||||
|
||||
return {
|
||||
manifest: {
|
||||
|
@ -59,40 +81,12 @@ var lastFMcallback;
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<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>
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
// PLUGIN: Subtitle
|
||||
|
||||
(function (Popcorn) {
|
||||
|
||||
|
||||
var scriptLoaded = false;
|
||||
|
||||
Popcorn.getScript( "http://www.google.com/jsapi", function() {
|
||||
google.load("language", "1", {callback: function() {scriptLoaded = true;}});
|
||||
});
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
|
@ -34,17 +40,6 @@
|
|||
} );
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
// Find element offset
|
||||
if (element.offsetParent) {
|
||||
do {
|
||||
offsetX += element.offsetLeft;
|
||||
offsetY += element.offsetTop;
|
||||
} while ((element = element.offsetParent));
|
||||
}
|
||||
*/
|
||||
|
||||
Popcorn.plugin( "subtitle" , {
|
||||
|
||||
manifest: {
|
||||
|
@ -99,58 +94,65 @@
|
|||
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 ( !this.languageSources[ options.languagesrc ] ) {
|
||||
this.languageSources[ options.languagesrc ] = {};
|
||||
|
||||
}
|
||||
|
||||
if ( !this.languageSources[ options.languagesrc ][ options.target ] ) {
|
||||
this.languageSources[ options.languagesrc ][ options.target ] = true;
|
||||
|
||||
options.languageSrc.addEventListener( "change", function() {
|
||||
|
||||
|
||||
options.toggleSubtitles();
|
||||
options.showSubtitle( options, options.container.innerHTML );
|
||||
|
||||
}, false );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( accessibility ) {
|
||||
options.accessibility = accessibility;
|
||||
|
||||
options.toggleSubtitles = function() {
|
||||
if ( options.languagesrc ) {
|
||||
options.showSubtitle = translate;
|
||||
options.languageSrc = document.getElementById( options.languagesrc );
|
||||
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;
|
||||
|
||||
if ( !this.languageSources ) {
|
||||
this.languageSources = {};
|
||||
}
|
||||
|
||||
};
|
||||
if ( !this.languageSources[ options.languagesrc ] ) {
|
||||
this.languageSources[ options.languagesrc ] = {};
|
||||
|
||||
}
|
||||
|
||||
if ( !this.languageSources[ options.languagesrc ][ options.target ] ) {
|
||||
this.languageSources[ options.languagesrc ][ options.target ] = true;
|
||||
|
||||
options.languageSrc.addEventListener( "change", function() {
|
||||
|
||||
options.toggleSubtitles();
|
||||
options.showSubtitle( options, options.container.innerHTML );
|
||||
|
||||
}, 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);
|
||||
|
||||
|
||||
|
||||
|
||||
options.accessibility.addEventListener( "change", options.toggleSubtitles, false );
|
||||
|
||||
// initiate it once to set starting state
|
||||
options.toggleSubtitles();
|
||||
}
|
||||
|
||||
},
|
||||
/**
|
||||
|
|
|
@ -31,12 +31,7 @@
|
|||
*/
|
||||
|
||||
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" , {
|
||||
|
|
|
@ -87,11 +87,7 @@ var wikiCallback;
|
|||
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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("Popcorn wikipedia Plugin", function () {
|
||||
|
||||
var popped = Popcorn("#video"),
|
||||
expects = 9,
|
||||
expects = 10,
|
||||
count = 0,
|
||||
theArticle = document.getElementById('wikidiv'),
|
||||
wikiInterval,
|
||||
|
@ -49,9 +49,9 @@ test("Popcorn wikipedia Plugin", function () {
|
|||
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 );
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ test("Popcorn wikipedia Plugin", function () {
|
|||
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 );
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче