15
$.fn.readingTime = function(options) {
25
readingTimeTarget: '.eta',
26
wordCountTarget: null,
30
lessThanAMinuteString: '',
31
minShortFormString: '',
32
prependTimeString: '',
33
prependWordString: '',
45
plugin.settings = $.extend({}, defaults, options);
48
var readingTimeTarget = plugin.settings.readingTimeTarget;
49
var wordCountTarget = plugin.settings.wordCountTarget;
50
var wordsPerMinute = plugin.settings.wordsPerMinute;
51
var round = plugin.settings.round;
52
var lang = plugin.settings.lang;
53
var lessThanAMinuteString = plugin.settings.lessThanAMinuteString;
54
var prependTimeString = plugin.settings.prependTimeString;
55
var prependWordString = plugin.settings.prependWordString;
56
var minShortFormString = plugin.settings.minShortFormString
57
var remotePath = plugin.settings.remotePath;
58
var remoteTarget = plugin.settings.remoteTarget;
64
var lessThanAMinute = lessThanAMinuteString || "Meno di un minuto";
66
var minShortForm = minShortFormString || 'min';
69
} else if(lang == 'fr') {
71
var lessThanAMinute = lessThanAMinuteString || "Moins d'une minute";
73
var minShortForm = minShortFormString || 'min';
76
} else if(lang == 'de') {
78
var lessThanAMinute = lessThanAMinuteString || "Weniger als eine Minute";
80
var minShortForm = minShortFormString || 'min';
83
} else if(lang == 'es') {
85
var lessThanAMinute = lessThanAMinuteString || "Menos de un minuto";
87
var minShortForm = minShortFormString || 'min';
90
} else if(lang == 'nl') {
92
var lessThanAMinute = lessThanAMinuteString || "Minder dan een minuut";
94
var minShortForm = minShortFormString || 'min';
99
var lessThanAMinute = lessThanAMinuteString || 'Less than a minute';
101
var minShortForm = minShortFormString || 'min';
105
var setTime = function(text) {
108
var totalWords = text.trim().split(/\s+/g).length;
111
var wordsPerSecond = wordsPerMinute / 60;
114
var totalReadingTimeSeconds = totalWords / wordsPerSecond;
120
var readingTimeMinutes = Math.round(totalReadingTimeSeconds / 60);
125
var readingTimeMinutes = Math.floor(totalReadingTimeSeconds / 60);
130
var readingTimeSeconds = Math.round(totalReadingTimeSeconds - readingTimeMinutes * 60);
136
if(readingTimeMinutes > 0) {
139
$(readingTimeTarget).text(prependTimeString + readingTimeMinutes + ' ' + minShortForm);
144
$(readingTimeTarget).text(prependTimeString + lessThanAMinute);
152
var readingTime = readingTimeMinutes + ':' + readingTimeSeconds;
155
$(readingTimeTarget).text(prependTimeString + readingTime);
160
if(wordCountTarget !== '' && wordCountTarget !== undefined) {
163
$(wordCountTarget).text(prependWordString + totalWords);
173
if(remotePath != null && remoteTarget != null) {
176
$.get(remotePath, function(data) {
179
setTime($('<div>').html(data).find(remoteTarget).text());