ability to specify options for interval, id and url - need to add documentation

This commit is contained in:
Sanjay B 2009-11-21 21:09:12 +05:30
parent 8701bd5a8b
commit c0fce19bab
2 changed files with 15 additions and 9 deletions

View File

@ -9,7 +9,7 @@
<script type="text/javascript" src="jquery.srt.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.srt').srt();
// $('.srt').srt();
});
</script>

View File

@ -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);
}
});
};