From 5835bbf749fcb7ac38dadca65543370711c447d3 Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Thu, 20 Feb 2014 15:46:09 +0100 Subject: [PATCH] Added the possibility to specify the id of the document element that the subtitles are appended to. Made target an options object, with keys and values, as suggested by @ScottDowne. --- modules/parser/popcorn.parser.js | 12 +++++++++--- parsers/parserSRT/popcorn.parserSRT.js | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/parser/popcorn.parser.js b/modules/parser/popcorn.parser.js index 52d0307cb..d4ad4552a 100644 --- a/modules/parser/popcorn.parser.js +++ b/modules/parser/popcorn.parser.js @@ -39,12 +39,18 @@ parseFn, parser = {}; - parseFn = function( filename, callback ) { + parseFn = function( filename, callback, options ) { if ( !filename ) { return this; } + // fixes parameters for overloaded function call + if ( typeof callback !== "function" && !options ) { + options = callback; + callback = null; + } + var that = this; Popcorn.xhr({ @@ -52,7 +58,7 @@ dataType: type, success: function( data ) { - var tracksObject = definition( data ), + var tracksObject = definition( data, options ), tracksData, tracksDataLen, tracksDef, @@ -100,4 +106,4 @@ return parser; }; -})( Popcorn ); \ No newline at end of file +})( Popcorn ); diff --git a/parsers/parserSRT/popcorn.parserSRT.js b/parsers/parserSRT/popcorn.parserSRT.js index 9d1d34c56..ef699572b 100644 --- a/parsers/parserSRT/popcorn.parserSRT.js +++ b/parsers/parserSRT/popcorn.parserSRT.js @@ -26,7 +26,7 @@ SSA tags with {\i1} would open and close italicize {\i0}, but 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 var retObj = { @@ -84,6 +84,11 @@ // Later modified by kev: http://kevin.deldycke.com/2007/03/ultimate-regular-expression-for-html-tag-parsing-with-php/ sub.text = sub.text.replace( /<(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)(\/?)>/gi, "<$1$3$7>" ); sub.text = sub.text.replace( /\\N/gi, "
" ); + + if ( options && options[ "target" ] ) { + sub.target = options[ "target" ]; + } + subs.push( createTrack( "subtitle", sub ) ); }