From d9d7bb98d9629cd8a3694490333f1dc16c572849 Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Thu, 20 Feb 2014 15:46:09 +0100 Subject: [PATCH 1/4] Added the possibility to specify the id of the document element that the subtitles are appended to. --- modules/parser/popcorn.parser.js | 12 +++++++++--- parsers/parserSRT/popcorn.parserSRT.js | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/parser/popcorn.parser.js b/modules/parser/popcorn.parser.js index 52d0307cb..3d2644ac3 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, target ) { if ( !filename ) { return this; } + // fixes parameters for overloaded function call + if (typeof callback !== "function" && !target) { + target = 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, target ), 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..933d7c3ec 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, target ) { // declare needed variables var retObj = { @@ -84,6 +84,7 @@ // 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, "
" ); + sub.target = target; subs.push( createTrack( "subtitle", sub ) ); } From d9d167e9d7bc79093908b6b9d417ca679723758e Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Thu, 20 Feb 2014 17:02:53 +0100 Subject: [PATCH 2/4] Made target an options object, with keys and values, as suggested by @ScottDowne. --- modules/parser/popcorn.parser.js | 8 ++++---- parsers/parserSRT/popcorn.parserSRT.js | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/parser/popcorn.parser.js b/modules/parser/popcorn.parser.js index 3d2644ac3..041c5dd94 100644 --- a/modules/parser/popcorn.parser.js +++ b/modules/parser/popcorn.parser.js @@ -39,15 +39,15 @@ parseFn, parser = {}; - parseFn = function( filename, callback, target ) { + parseFn = function( filename, callback, options ) { if ( !filename ) { return this; } // fixes parameters for overloaded function call - if (typeof callback !== "function" && !target) { - target = callback; + if (typeof callback !== "function" && !options) { + options = callback; callback = null; } @@ -58,7 +58,7 @@ dataType: type, success: function( data ) { - var tracksObject = definition( data, target ), + var tracksObject = definition( data, options ), tracksData, tracksDataLen, tracksDef, diff --git a/parsers/parserSRT/popcorn.parserSRT.js b/parsers/parserSRT/popcorn.parserSRT.js index 933d7c3ec..2368ed9d4 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, target ) { + Popcorn.parser( "parseSRT", function( data, options ) { // declare needed variables var retObj = { @@ -84,7 +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, "
" ); - sub.target = target; + + if (options && options["target"]) { + sub.target = options["target"]; + } + subs.push( createTrack( "subtitle", sub ) ); } From 6509b9f990dde96cd6326b9152c0a158d3399589 Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Thu, 20 Feb 2014 17:55:36 +0100 Subject: [PATCH 3/4] Added some whitespaces to be consistent with the style of the rest of the code --- modules/parser/popcorn.parser.js | 2 +- parsers/parserSRT/popcorn.parserSRT.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/parser/popcorn.parser.js b/modules/parser/popcorn.parser.js index 041c5dd94..d4ad4552a 100644 --- a/modules/parser/popcorn.parser.js +++ b/modules/parser/popcorn.parser.js @@ -46,7 +46,7 @@ } // fixes parameters for overloaded function call - if (typeof callback !== "function" && !options) { + if ( typeof callback !== "function" && !options ) { options = callback; callback = null; } diff --git a/parsers/parserSRT/popcorn.parserSRT.js b/parsers/parserSRT/popcorn.parserSRT.js index 2368ed9d4..76189a24d 100644 --- a/parsers/parserSRT/popcorn.parserSRT.js +++ b/parsers/parserSRT/popcorn.parserSRT.js @@ -85,8 +85,8 @@ 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"]; + if ( options && options[ "target" ] ) { + sub.target = options[ "target" ]; } subs.push( createTrack( "subtitle", sub ) ); From 7b8f313e39bf8eccf61164a43c46c32e96c53582 Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Thu, 20 Feb 2014 18:08:17 +0100 Subject: [PATCH 4/4] Change tabs to two spaces --- parsers/parserSRT/popcorn.parserSRT.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsers/parserSRT/popcorn.parserSRT.js b/parsers/parserSRT/popcorn.parserSRT.js index 76189a24d..ef699572b 100644 --- a/parsers/parserSRT/popcorn.parserSRT.js +++ b/parsers/parserSRT/popcorn.parserSRT.js @@ -86,8 +86,8 @@ sub.text = sub.text.replace( /\\N/gi, "
" ); if ( options && options[ "target" ] ) { - sub.target = options[ "target" ]; - } + sub.target = options[ "target" ]; + } subs.push( createTrack( "subtitle", sub ) ); }