From c0fce19babb1595d02c3c1bd0b7ac7d88ce46a86 Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Sat, 21 Nov 2009 21:09:12 +0530 Subject: [PATCH] ability to specify options for interval, id and url - need to add documentation --- index.html | 2 +- jquery.srt.js | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index e58760c..b638fa6 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ diff --git a/jquery.srt.js b/jquery.srt.js index f29b5cc..9011ed1 100644 --- a/jquery.srt.js +++ b/jquery.srt.js @@ -36,8 +36,8 @@ return s.replace(/^\s+|\s+$/g,""); } - function playSubtitles(subtitleElement) { - var videoId = subtitleElement.attr('data-video'); + function playSubtitles(subtitleElement, opts) { + var videoId = opts.id; var srt = subtitleElement.text(); subtitleElement.html(''); srt = srt.replace('\r\n|\r|\n', '\n') @@ -84,19 +84,25 @@ subtitleElement.html(''); } } - }, 100); + }, opts.interval); } - jQuery.fn.srt = function() { + jQuery.fn.srt = function(o) { + var that = this; + var opts = $.extend({ + 'interval': 100, + 'id': that.attr('data-video'), + 'url': that.attr('data-srt') + }, o); this.each(function() { var subtitleElement = $(this); - var videoId = subtitleElement.attr('data-video'); + var videoId = opts.id; if(!videoId) return; - var srtUrl = subtitleElement.attr('data-srt'); + var srtUrl = opts.url; if(srtUrl) { - $(this).load(srtUrl, function (responseText, textStatus, req) { playSubtitles(subtitleElement)}); + $(this).load(srtUrl, function (responseText, textStatus, req) { playSubtitles(subtitleElement, opts)}); } else { - playSubtitles(subtitleElement); + playSubtitles(subtitleElement, opts); } }); };