зеркало из https://github.com/mozilla/popcorn-js.git
starting tests
This commit is contained in:
Родитель
93059f825e
Коммит
3821b595bd
|
@ -11,10 +11,16 @@
|
||||||
.volume(0)
|
.volume(0)
|
||||||
.play()
|
.play()
|
||||||
.wikipedia({
|
.wikipedia({
|
||||||
start: 10, // seconds
|
start: 5, // seconds
|
||||||
end: 50, // seconds
|
end: 10, // seconds
|
||||||
src: 'http://en.wikipedia.org/wiki/Cape_Town',
|
src: 'http://en.wikipedia.org/wiki/Cape_Town',
|
||||||
target: 'wikidiv'
|
target: 'wikidiv'
|
||||||
|
} )
|
||||||
|
.wikipedia({
|
||||||
|
start: 12, // seconds
|
||||||
|
end: 20, // seconds
|
||||||
|
src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo',
|
||||||
|
target: 'wikidiv2'
|
||||||
} );
|
} );
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -23,11 +29,11 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
|
<h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
|
||||||
<p> A Webpage displaying webmademovies.org will appear at 5 seconds and disappear at 15 seconds.</p>
|
<p> A Wiki article about Cape Town will appear at 5 seconds and disappear at 10 seconds.</p>
|
||||||
<p> A Webpage displaying zenit Processing.js wiki will appear at 20 seconds and disappear at 45 seconds.</p>
|
<p> A Wiki article about Sao Paolo will appear at 12 seconds and disappear at 20 seconds.</p>
|
||||||
<div>
|
<div>
|
||||||
<video id='video'
|
<video id='video'
|
||||||
controls preload='none'
|
controls
|
||||||
width= '250px'
|
width= '250px'
|
||||||
poster="../../test/poster.png">
|
poster="../../test/poster.png">
|
||||||
|
|
||||||
|
@ -44,6 +50,9 @@
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
<div id="wikidiv" width="50%" height="50%">
|
<div id="wikidiv" width="50%" height="50%">
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<div id="wikidiv2" width="50%" height="50%"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
// PLUGIN: WIKIPEDIA
|
// PLUGIN: WIKIPEDIA
|
||||||
|
|
||||||
|
|
||||||
// wikipedia callback functions executes when data is retrieved from the wiki
|
var wikiCallback;
|
||||||
// stores the data in a global variable
|
|
||||||
var wikidatastring;
|
|
||||||
var wikiCallback = function (data) {
|
|
||||||
wikidatastring = data;
|
|
||||||
};
|
|
||||||
|
|
||||||
(function (Popcorn) {
|
(function (Popcorn) {
|
||||||
|
|
||||||
|
@ -61,28 +56,22 @@ var wikiCallback = function (data) {
|
||||||
var getJson = function(url) {
|
var getJson = function(url) {
|
||||||
var head = document.getElementsByTagName("head")[0];
|
var head = document.getElementsByTagName("head")[0];
|
||||||
var script = document.createElement("script");
|
var script = document.createElement("script");
|
||||||
// once you get the data store it
|
|
||||||
script.onload = function () {
|
|
||||||
if (wikidatastring) {
|
|
||||||
// create a link that the user can use to view the whole article
|
|
||||||
link = document.createElement('a');
|
|
||||||
link.setAttribute('href', options.src);
|
|
||||||
link.setAttribute('target', '_blank');
|
|
||||||
// create a paragraph that the title of the article can go into
|
|
||||||
p = document.createElement('p');
|
|
||||||
p.innerHTML = wikidatastring.parse.displaytitle;
|
|
||||||
link.appendChild(p);
|
|
||||||
// get the first 140 characters of the wiki content
|
|
||||||
desc = document.createElement('p');
|
|
||||||
text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('<p>'));
|
|
||||||
text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
|
|
||||||
desc.innerHTML = text.substr(0, length ) + " ...";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
script.src = url;
|
script.src = url;
|
||||||
head.insertBefore( script, head.firstChild );
|
head.insertBefore( script, head.firstChild );
|
||||||
};
|
};
|
||||||
|
wikiCallback = function (data) {
|
||||||
|
wikidatastring = data;
|
||||||
|
link = document.createElement('a');
|
||||||
|
link.setAttribute('href', options.src);
|
||||||
|
link.setAttribute('target', '_blank');
|
||||||
|
// add the title of the article to the link
|
||||||
|
link.innerHTML = wikidatastring.parse.displaytitle;
|
||||||
|
// get the content of the wiki article
|
||||||
|
desc = document.createElement('p');
|
||||||
|
text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('<p>'));
|
||||||
|
text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
|
||||||
|
desc.innerHTML = text.substr(0, length ) + " ...";
|
||||||
|
};
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @member wikipedia
|
* @member wikipedia
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script src="../../popcorn.js"></script>
|
<script src="../../popcorn.js"></script>
|
||||||
<script src="popcorn.webpage.js"></script>
|
<script src="popcorn.wikipedia.js"></script>
|
||||||
|
|
||||||
<script src="popcorn.webpage.unit.js"></script>
|
<script src="popcorn.wikipedia.unit.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 id="qunit-header">Popcorn Webpage UI</h1>
|
<h1 id="qunit-header">Popcorn wikipedia UI</h1>
|
||||||
<h2 id="qunit-banner"></h2>
|
<h2 id="qunit-banner"></h2>
|
||||||
<div id="qunit-testrunner-toolbar"></div>
|
<div id="qunit-testrunner-toolbar"></div>
|
||||||
<h2 id="qunit-userAgent"></h2>
|
<h2 id="qunit-userAgent"></h2>
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<div id="qunit-fixture"> </div>
|
<div id="qunit-fixture"> </div>
|
||||||
|
|
||||||
<video id='video'
|
<video id='video'
|
||||||
controls preload='none'
|
controls
|
||||||
width= '250px'
|
width= '250px'
|
||||||
poster="../../test/poster.png">
|
poster="../../test/poster.png">
|
||||||
|
|
||||||
|
@ -38,6 +38,6 @@
|
||||||
<p>Your user agent does not support the HTML5 Video element.</p>
|
<p>Your user agent does not support the HTML5 Video element.</p>
|
||||||
|
|
||||||
</video>
|
</video>
|
||||||
<div id="webpagediv"></div>
|
<div id="wikidiv"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
test("Popcorn Webpage Plugin", function () {
|
test("Popcorn wikipedia Plugin", function () {
|
||||||
|
|
||||||
var popped = Popcorn("#video"),
|
var popped = Popcorn("#video"),
|
||||||
expects = 11,
|
expects = 5,
|
||||||
count = 0,
|
count = 0,
|
||||||
iframeInterval,
|
wikiInterval,
|
||||||
iframeInterval2,
|
wikiInterval2,
|
||||||
iframeInterval3,
|
wikiInterval3,
|
||||||
iframeInterval4;
|
wikiInterval4;
|
||||||
theiFrame = document.getElementsByTagName('iframe');
|
theArticle = document.getElementById('wikidiv');
|
||||||
|
|
||||||
expect(expects);
|
expect(expects);
|
||||||
|
|
||||||
function plus() {
|
function plus() {
|
||||||
|
@ -18,63 +19,57 @@ test("Popcorn Webpage Plugin", function () {
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
ok ('webpage' in popped, "webpages is a mehtod of the popped instance");
|
ok ('wikipedia' in popped, "wikipedia is a mehtod of the popped instance");
|
||||||
plus();
|
plus();
|
||||||
|
|
||||||
equals (theiFrame.length, 0, "initially, there is no iframes on the page" );
|
equals (theArticle.innerHTML, "", "initially, there is nothing in the wikidiv" );
|
||||||
plus();
|
plus();
|
||||||
|
|
||||||
popped.webpage({
|
popped.wikipedia({
|
||||||
id: "webpages-a",
|
|
||||||
start: 5, // seconds
|
start: 5, // seconds
|
||||||
end: 25, // seconds
|
end: 10, // seconds
|
||||||
src: 'http://webmademovies.org',
|
src: 'http://en.wikipedia.org/wiki/Cape_Town',
|
||||||
target: 'webpagediv'
|
target: 'wikidiv'
|
||||||
})
|
} )
|
||||||
.webpage({
|
.wikipedia({
|
||||||
id: "webpages-b",
|
start: 12, // seconds
|
||||||
start: 35, // seconds
|
end: 20, // seconds
|
||||||
end: 50, // seconds
|
src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo',
|
||||||
src: 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js',
|
target: 'wikidiv'
|
||||||
target: 'webpagediv'
|
} )
|
||||||
})
|
|
||||||
.play();
|
.play();
|
||||||
|
|
||||||
|
|
||||||
iframeInterval = setInterval( function() {
|
wikiInterval = setInterval( function() {
|
||||||
if( popped.currentTime() > 7 && popped.currentTime() <= 25 ) {
|
if( popped.currentTime() > 7 && popped.currentTime() <= 10 ) {
|
||||||
ok (!!theiFrame[0], "iframe was created" );
|
ok (theArticle.innerHTML !== "", "wikidiv now contains information" );
|
||||||
plus();
|
plus();
|
||||||
equals (theiFrame.length, 1, "there is only one iframe on the page" );
|
equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
||||||
plus();
|
plus();
|
||||||
equals (theiFrame[0].id, "webpages-a", "iframe has the id 'webpages-a'" );
|
|
||||||
plus();
|
clearInterval( wikiInterval );
|
||||||
equals (theiFrame[0].src, "http://webmademovies.org/", "iframe has the src 'http://webmademovies.org/'" );
|
|
||||||
plus();
|
|
||||||
clearInterval( iframeInterval );
|
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
iframeInterval2 = setInterval( function() {
|
wikiInterval2 = setInterval( function() {
|
||||||
if( popped.currentTime() > 27 && popped.currentTime() < 35 ) {
|
if( popped.currentTime() > 10 && popped.currentTime() < 12 ) {
|
||||||
equals (theiFrame.length, 0, "the iframe has been removed" );
|
equals (theArticle.innerHTML, "", "wikidiv was cleared properly" );
|
||||||
plus();
|
plus();
|
||||||
clearInterval( iframeInterval2 );
|
clearInterval( wikiInterval2 );
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
iframeInterval3 = setInterval( function() {
|
wikiInterval3 = setInterval( function() {
|
||||||
if( popped.currentTime() > 37 && popped.currentTime() <= 50 ) {
|
if( popped.currentTime() > 13 && popped.currentTime() <= 20 ) {
|
||||||
ok (!!theiFrame[0], "iframe was created" );
|
ok (theArticle.innerHTML !== "", "wikidiv now contains information" );
|
||||||
plus();
|
plus();
|
||||||
equals (theiFrame.length, 1, "there is only one iframe on the page" );
|
equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
||||||
plus();
|
plus();
|
||||||
equals (theiFrame[0].id, "webpages-b", "iframe has the id 'webpages-b'" );
|
|
||||||
plus();
|
clearInterval( wikiInterval3 );
|
||||||
equals (theiFrame[0].src,"http://zenit.senecac.on.ca/wiki/index.php/Processing.js", "iframe has the src 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js'" );
|
|
||||||
plus();
|
|
||||||
clearInterval( iframeInterval3 );
|
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче