Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Commit

Permalink
Added the possibility to specify the id of the document element that …
Browse files Browse the repository at this point in the history
…the subtitles are appended to.

Made target an options object, with keys and values, as suggested by @ScottDowne.
  • Loading branch information
aldatsa authored and ScottDowne committed Feb 21, 2014
1 parent 373097d commit 5835bbf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions modules/parser/popcorn.parser.js
Expand Up @@ -39,20 +39,26 @@
parseFn, parseFn,
parser = {}; parser = {};


parseFn = function( filename, callback ) { parseFn = function( filename, callback, options ) {


if ( !filename ) { if ( !filename ) {
return this; return this;
} }


// fixes parameters for overloaded function call
if ( typeof callback !== "function" && !options ) {
options = callback;
callback = null;
}

var that = this; var that = this;


Popcorn.xhr({ Popcorn.xhr({
url: filename, url: filename,
dataType: type, dataType: type,
success: function( data ) { success: function( data ) {


var tracksObject = definition( data ), var tracksObject = definition( data, options ),
tracksData, tracksData,
tracksDataLen, tracksDataLen,
tracksDef, tracksDef,
Expand Down Expand Up @@ -100,4 +106,4 @@


return parser; return parser;
}; };
})( Popcorn ); })( Popcorn );
7 changes: 6 additions & 1 deletion parsers/parserSRT/popcorn.parserSRT.js
Expand Up @@ -26,7 +26,7 @@
SSA tags with {\i1} would open and close italicize {\i0}, but are stripped SSA tags with {\i1} would open and close italicize {\i0}, but are stripped
Multiple {\pos(142,120)\b1}SSA tags are stripped Multiple {\pos(142,120)\b1}SSA tags are stripped
*/ */
Popcorn.parser( "parseSRT", function( data ) { Popcorn.parser( "parseSRT", function( data, options ) {


// declare needed variables // declare needed variables
var retObj = { var retObj = {
Expand Down Expand Up @@ -84,6 +84,11 @@
// Later modified by kev: http://kevin.deldycke.com/2007/03/ultimate-regular-expression-for-html-tag-parsing-with-php/ // Later modified by kev: http://kevin.deldycke.com/2007/03/ultimate-regular-expression-for-html-tag-parsing-with-php/
sub.text = sub.text.replace( /&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)(\/?)&gt;/gi, "<$1$3$7>" ); sub.text = sub.text.replace( /&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)(\/?)&gt;/gi, "<$1$3$7>" );
sub.text = sub.text.replace( /\\N/gi, "<br />" ); sub.text = sub.text.replace( /\\N/gi, "<br />" );

if ( options && options[ "target" ] ) {
sub.target = options[ "target" ];
}

subs.push( createTrack( "subtitle", sub ) ); subs.push( createTrack( "subtitle", sub ) );
} }


Expand Down

0 comments on commit 5835bbf

Please sign in to comment.