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

Added the possibility to specify the id of the document element that the subtitles are appended to. #383

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions modules/parser/popcorn.parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,26 @@
parseFn,
parser = {};

parseFn = function( filename, callback ) {
parseFn = function( filename, callback, target ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, and I appreciate the patch :)

Only comment is what if we made target an options object, with keys and values.

Example:

pop.parseSRT( "my-video.srt", {
target: "my-div"
});

It works well for optional parameters because order doesn't matter. It also means in the future it is going to be easy to add other properties.

Also means custom parsers and plugins could use it for properties other than just target.

Thoughts?


if ( !filename ) {
return this;
}

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

var that = this;

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

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

return parser;
};
})( Popcorn );
})( Popcorn );
3 changes: 2 additions & 1 deletion parsers/parserSRT/popcorn.parserSRT.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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( /&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.target = target;
subs.push( createTrack( "subtitle", sub ) );
}

Expand Down