зеркало из https://github.com/mozilla/popcorn-js.git
made changes as per Ricks review [#158 state:peer-review-requested]
This commit is contained in:
Родитель
b848db6678
Коммит
be01c4db82
|
@ -11,7 +11,7 @@
|
|||
.volume(0)
|
||||
.play()
|
||||
.wikipedia({
|
||||
start: 5, // seconds
|
||||
start: 0, // seconds
|
||||
end: 10, // seconds
|
||||
src: 'http://en.wikipedia.org/wiki/Cape_Town',
|
||||
target: 'wikidiv'
|
||||
|
@ -29,7 +29,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
|
||||
<p> A Wiki article about Cape Town will appear at 5 seconds and disappear at 10 seconds.</p>
|
||||
<p> A Wiki article about Cape Town will appear at 0 seconds and disappear at 10 seconds.</p>
|
||||
<p> A Wiki article about Sao Paolo will appear at 7 seconds and disappear at 20 seconds.</p>
|
||||
<div>
|
||||
<video id='video'
|
||||
|
|
|
@ -69,21 +69,28 @@ var wikiCallback;
|
|||
_text = data.parse.text["*"].substr(data.parse.text["*"].indexOf('<p>'));
|
||||
_text = _text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
|
||||
options._desc.innerHTML = _text.substr(0, options.numOfWords ) + " ...";
|
||||
|
||||
options._fired = true;
|
||||
};
|
||||
|
||||
// get the wiki article on a separate thread
|
||||
// call the wikiCallback function above once the script is loaded
|
||||
setTimeout(function() {
|
||||
getJson("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);
|
||||
}, 500);
|
||||
//setTimeout(function() {
|
||||
// getJson("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);
|
||||
//}, 500);
|
||||
|
||||
// add the script to the DOM
|
||||
var getJson = function(url) {
|
||||
/*var getJson = function(url) {
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
var script = document.createElement("script");
|
||||
script.src = url;
|
||||
head.insertBefore( script, head.firstChild );
|
||||
};
|
||||
}; */
|
||||
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 );
|
||||
},
|
||||
/**
|
||||
* @member wikipedia
|
||||
|
@ -93,11 +100,23 @@ var wikiCallback;
|
|||
*/
|
||||
start: function(event, options){
|
||||
// dont do anything if the information didn't come back from wiki
|
||||
if (options._link && options._desc) {
|
||||
options.target.appendChild(options._link);
|
||||
options.target.appendChild(options._desc);
|
||||
options._added = true;
|
||||
}
|
||||
var isReady = function () {
|
||||
|
||||
if ( !options._fired ) {
|
||||
setTimeout(function () {
|
||||
isReady();
|
||||
}, 13);
|
||||
} else {
|
||||
|
||||
if (options._link && options._desc) {
|
||||
options.target.appendChild(options._link);
|
||||
options.target.appendChild(options._desc);
|
||||
options._added = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
isReady();
|
||||
},
|
||||
/**
|
||||
* @member wikipedia
|
||||
|
@ -106,6 +125,8 @@ var wikiCallback;
|
|||
* options variable
|
||||
*/
|
||||
end: function(event, options){
|
||||
// ensure that the data was actually added to the
|
||||
// DOM before removal
|
||||
if (options._added) {
|
||||
options.target.removeChild(options._link);
|
||||
options.target.removeChild(options._desc);
|
||||
|
|
Загрузка…
Ссылка в новой задаче