зеркало из https://github.com/mozilla/popcorn-js.git
Merge pull request #65 from mjschranz/t1069
[#1069]Fixed Whitespace issues in all Wikipedia plugin files
This commit is contained in:
Коммит
13558e0fff
|
@ -2,14 +2,14 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Popcorn Wikipedia Plug-in Demo</title>
|
||||
|
||||
|
||||
<script src="../../popcorn.js"></script>
|
||||
<script src="popcorn.wikipedia.js"></script>
|
||||
<script>
|
||||
document.addEventListener( "DOMContentLoaded", function() {
|
||||
var p = Popcorn( "#video" )
|
||||
.volume( 0 )
|
||||
.play()
|
||||
.play()
|
||||
.wikipedia({
|
||||
start: 0,
|
||||
end: 10,
|
||||
|
@ -32,22 +32,22 @@
|
|||
<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"
|
||||
controls
|
||||
<video id="video"
|
||||
controls
|
||||
width="250px"
|
||||
poster="../../test/poster.png">
|
||||
poster="../../test/poster.png">
|
||||
|
||||
<source id="mp4"
|
||||
src="../../test/trailer.mp4"
|
||||
type='video/mp4; codecs="avc1, mp4a"'>
|
||||
type='video/mp4; codecs="avc1, mp4a"'>
|
||||
|
||||
<source id="ogv"
|
||||
src="../../test/trailer.ogv"
|
||||
type='video/ogg; codecs="theora, vorbis"'>
|
||||
type='video/ogg; codecs="theora, vorbis"'>
|
||||
|
||||
<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>
|
||||
<div id="wikidiv"> </div>
|
||||
</body>
|
||||
|
|
|
@ -4,23 +4,23 @@
|
|||
var wikiCallback;
|
||||
|
||||
(function ( Popcorn ) {
|
||||
|
||||
|
||||
/**
|
||||
* Wikipedia popcorn plug-in
|
||||
* Wikipedia popcorn plug-in
|
||||
* Displays a wikipedia aricle in the target specified by the user by using
|
||||
* new DOM element instead overwriting them
|
||||
* Options parameter will need a start, end, target, lang, src, title and numberofwords.
|
||||
* -Start is the time that you want this plug-in to execute
|
||||
* -End is the time that you want this plug-in to stop executing
|
||||
* -Target is the id of the document element that the text from the article needs to be
|
||||
* -End is the time that you want this plug-in to stop executing
|
||||
* -Target is the id of the document element that the text from the article needs to be
|
||||
* attached to, this target element must exist on the DOM
|
||||
* -Lang (optional, defaults to english) is the language in which the article is in.
|
||||
* -Src is the url of the article
|
||||
* -Src is the url of the article
|
||||
* -Title (optional) is the title of the article
|
||||
* -numberofwords (optional, defaults to 200) is the number of words you want displaid.
|
||||
* -numberofwords (optional, defaults to 200) is the number of words you want displaid.
|
||||
*
|
||||
* @param {Object} options
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
var p = Popcorn("#video")
|
||||
.wikipedia({
|
||||
|
@ -32,7 +32,7 @@ var wikiCallback;
|
|||
*
|
||||
*/
|
||||
Popcorn.plugin( "wikipedia" , {
|
||||
|
||||
|
||||
manifest: {
|
||||
about:{
|
||||
name: "Popcorn Wikipedia Plugin",
|
||||
|
@ -42,35 +42,35 @@ var wikiCallback;
|
|||
},
|
||||
options:{
|
||||
start: {
|
||||
elem: "input",
|
||||
type: "text",
|
||||
elem: "input",
|
||||
type: "text",
|
||||
label: "In"
|
||||
},
|
||||
end: {
|
||||
elem: "input",
|
||||
type: "text",
|
||||
elem: "input",
|
||||
type: "text",
|
||||
label: "Out"
|
||||
},
|
||||
lang: {
|
||||
elem: "input",
|
||||
type: "text",
|
||||
elem: "input",
|
||||
type: "text",
|
||||
label: "Language",
|
||||
optional: true
|
||||
},
|
||||
src: {
|
||||
elem: "input",
|
||||
type: "url",
|
||||
elem: "input",
|
||||
type: "url",
|
||||
label: "Src"
|
||||
},
|
||||
title: {
|
||||
elem: "input",
|
||||
type: "text",
|
||||
elem: "input",
|
||||
type: "text",
|
||||
label: "Title",
|
||||
optional: true
|
||||
},
|
||||
numberofwords: {
|
||||
elem: "input",
|
||||
type: "text",
|
||||
elem: "input",
|
||||
type: "text",
|
||||
label: "Num Of Words",
|
||||
optional: true
|
||||
},
|
||||
|
@ -78,30 +78,30 @@ var wikiCallback;
|
|||
}
|
||||
},
|
||||
/**
|
||||
* @member wikipedia
|
||||
* The setup function will get all of the needed
|
||||
* items in place before the start function is called.
|
||||
* @member wikipedia
|
||||
* The setup function will get all of the needed
|
||||
* items in place before the start function is called.
|
||||
* This includes getting data from wikipedia, if the data
|
||||
* is not received and processed before start is called start
|
||||
* is not received and processed before start is called start
|
||||
* will not do anything
|
||||
*/
|
||||
_setup : function( options ) {
|
||||
// declare needed variables
|
||||
// get a guid to use for the global wikicallback function
|
||||
var _text, _guid = Popcorn.guid();
|
||||
|
||||
var _text, _guid = Popcorn.guid();
|
||||
|
||||
// if the user didn't specify a language default to english
|
||||
if ( !options.lang ) {
|
||||
options.lang = "en";
|
||||
if ( !options.lang ) {
|
||||
options.lang = "en";
|
||||
}
|
||||
|
||||
// if the user didn't specify number of words to use default to 200
|
||||
// if the user didn't specify number of words to use default to 200
|
||||
options.numberofwords = options.numberofwords || 200;
|
||||
|
||||
|
||||
// wiki global callback function with a unique id
|
||||
// function gets the needed information from wikipedia
|
||||
// and stores it by appending values to the options object
|
||||
window[ "wikiCallback" + _guid ] = function ( data ) {
|
||||
window[ "wikiCallback" + _guid ] = function ( data ) {
|
||||
|
||||
options._link = document.createElement( "a" );
|
||||
options._link.setAttribute( "href", options.src );
|
||||
|
@ -116,15 +116,15 @@ var wikiCallback;
|
|||
// get the article text and remove any special characters
|
||||
_text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf( "<p>" ) );
|
||||
_text = _text.replace( /((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "" );
|
||||
|
||||
|
||||
_text = _text.split( " " );
|
||||
options._desc.innerHTML = ( _text.slice( 0, ( _text.length >= options.numberofwords ? options.numberofwords : _text.length ) ).join (" ") + " ..." ) ;
|
||||
|
||||
|
||||
options._fired = true;
|
||||
};
|
||||
|
||||
|
||||
if ( options.src ) {
|
||||
Popcorn.getScript( "//" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&page=" +
|
||||
Popcorn.getScript( "//" + 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 if ( Popcorn.plugin.debug ) {
|
||||
throw new Error( "Wikipedia plugin needs a 'src'" );
|
||||
|
@ -132,21 +132,21 @@ var wikiCallback;
|
|||
|
||||
},
|
||||
/**
|
||||
* @member wikipedia
|
||||
* The start function will be executed when the currentTime
|
||||
* of the video reaches the start time provided by the
|
||||
* @member wikipedia
|
||||
* The start function will be executed when the currentTime
|
||||
* of the video reaches the start time provided by the
|
||||
* options variable
|
||||
*/
|
||||
start: function( event, options ){
|
||||
// dont do anything if the information didn't come back from wiki
|
||||
var isReady = function () {
|
||||
|
||||
|
||||
if ( !options._fired ) {
|
||||
setTimeout( function () {
|
||||
isReady();
|
||||
}, 13);
|
||||
} else {
|
||||
|
||||
|
||||
if ( options._link && options._desc ) {
|
||||
if ( document.getElementById( options.target ) ) {
|
||||
document.getElementById( options.target ).appendChild( options._link );
|
||||
|
@ -156,17 +156,17 @@ var wikiCallback;
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
isReady();
|
||||
},
|
||||
/**
|
||||
* @member wikipedia
|
||||
* The end function will be executed when the currentTime
|
||||
* of the video reaches the end time provided by the
|
||||
* @member wikipedia
|
||||
* The end function will be executed when the currentTime
|
||||
* of the video reaches the end time provided by the
|
||||
* options variable
|
||||
*/
|
||||
end: function( event, options ){
|
||||
// ensure that the data was actually added to the
|
||||
// ensure that the data was actually added to the
|
||||
// DOM before removal
|
||||
if ( options._added ) {
|
||||
document.getElementById( options.target ).removeChild( options._link );
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
<title>Popcorn API</title>
|
||||
<link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../../test/qunit/qunit.js"></script>
|
||||
<!--
|
||||
do not move - this must be called immediately prior to
|
||||
<!--
|
||||
do not move - this must be called immediately prior to
|
||||
popcorn-api-draft.js
|
||||
-->
|
||||
|
||||
|
||||
<script src="../../popcorn.js"></script>
|
||||
<script src="popcorn.wikipedia.js"></script>
|
||||
|
||||
|
@ -22,27 +22,27 @@
|
|||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture"> </div>
|
||||
|
||||
<video id="video"
|
||||
controls
|
||||
|
||||
<video id="video"
|
||||
controls
|
||||
width= "250px"
|
||||
poster="../../test/poster.png">
|
||||
poster="../../test/poster.png">
|
||||
|
||||
<source id="mp4"
|
||||
src="../../test/trailer.mp4"
|
||||
type='video/mp4; codecs="avc1, mp4a"'>
|
||||
type='video/mp4; codecs="avc1, mp4a"'>
|
||||
|
||||
<source id="ogv"
|
||||
src="../../test/trailer.ogv"
|
||||
type='video/ogg; codecs="theora, vorbis"'>
|
||||
|
||||
type='video/ogg; codecs="theora, vorbis"'>
|
||||
|
||||
<source id='webm'
|
||||
src="../../test/trailer.webm"
|
||||
type='video/webm; codecs="vp8, vorbis"'>
|
||||
|
||||
<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>
|
||||
<div id="wikidiv"></div>
|
||||
</video>
|
||||
<div id="wikidiv"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
test( "Popcorn wikipedia Plugin", function() {
|
||||
|
||||
|
||||
var popped = Popcorn( "#video" ),
|
||||
expects = 13,
|
||||
expects = 13,
|
||||
count = 0,
|
||||
theArticle = document.getElementById( "wikidiv" );
|
||||
|
||||
|
||||
expect( expects );
|
||||
|
||||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stop();
|
||||
|
||||
|
||||
ok( "wikipedia" in popped, "wikipedia is a mehtod of the popped instance" );
|
||||
plus();
|
||||
|
||||
|
||||
equal( theArticle.innerHTML, "", "initially, there is nothing in the wikidiv" );
|
||||
plus();
|
||||
|
||||
|
||||
popped.wikipedia({
|
||||
start: 1,
|
||||
end: 3,
|
||||
|
@ -38,7 +38,7 @@ test( "Popcorn wikipedia Plugin", function() {
|
|||
})
|
||||
.volume( 0 )
|
||||
.play();
|
||||
|
||||
|
||||
popped.exec( 2, function() {
|
||||
notEqual( theArticle.innerHTML, "", "wikidiv now contains information" );
|
||||
plus();
|
||||
|
@ -52,12 +52,12 @@ test( "Popcorn wikipedia Plugin", function() {
|
|||
equal( theArticle.children[ 1 ].innerHTML.split( " " ).length -1, 22, "wikidiv contains 22 words" );
|
||||
plus();
|
||||
});
|
||||
|
||||
|
||||
popped.exec( 3, function() {
|
||||
equal( theArticle.innerHTML, "", "wikidiv was cleared properly" );
|
||||
plus();
|
||||
});
|
||||
|
||||
|
||||
popped.exec( 4, function() {
|
||||
notEqual( theArticle.innerHTML, "", "wikidiv now contains information" );
|
||||
plus();
|
||||
|
|
Загрузка…
Ссылка в новой задаче