ability to specify options for interval, id and url - need to add documentation
This commit is contained in:
parent
8701bd5a8b
commit
c0fce19bab
|
@ -9,7 +9,7 @@
|
||||||
<script type="text/javascript" src="jquery.srt.js"></script>
|
<script type="text/javascript" src="jquery.srt.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('.srt').srt();
|
// $('.srt').srt();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
return s.replace(/^\s+|\s+$/g,"");
|
return s.replace(/^\s+|\s+$/g,"");
|
||||||
}
|
}
|
||||||
|
|
||||||
function playSubtitles(subtitleElement) {
|
function playSubtitles(subtitleElement, opts) {
|
||||||
var videoId = subtitleElement.attr('data-video');
|
var videoId = opts.id;
|
||||||
var srt = subtitleElement.text();
|
var srt = subtitleElement.text();
|
||||||
subtitleElement.html('');
|
subtitleElement.html('');
|
||||||
srt = srt.replace('\r\n|\r|\n', '\n')
|
srt = srt.replace('\r\n|\r|\n', '\n')
|
||||||
|
@ -84,19 +84,25 @@
|
||||||
subtitleElement.html('');
|
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() {
|
this.each(function() {
|
||||||
var subtitleElement = $(this);
|
var subtitleElement = $(this);
|
||||||
var videoId = subtitleElement.attr('data-video');
|
var videoId = opts.id;
|
||||||
if(!videoId) return;
|
if(!videoId) return;
|
||||||
var srtUrl = subtitleElement.attr('data-srt');
|
var srtUrl = opts.url;
|
||||||
if(srtUrl) {
|
if(srtUrl) {
|
||||||
$(this).load(srtUrl, function (responseText, textStatus, req) { playSubtitles(subtitleElement)});
|
$(this).load(srtUrl, function (responseText, textStatus, req) { playSubtitles(subtitleElement, opts)});
|
||||||
} else {
|
} else {
|
||||||
playSubtitles(subtitleElement);
|
playSubtitles(subtitleElement, opts);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user