This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
timeslidertooltipplugin.uncompressed.js
executable file
·438 lines (393 loc) · 18.4 KB
/
timeslidertooltipplugin.uncompressed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
(function (jwplayer) {
var template = function (player, config, div) {
var _div = div,
_dotNotation = _detectOldNotation(),
// Cached elements references to HTML nodes
_controlbar = null,
_rail = null,
_preview = null,
_time = null,
// Safety flags...
_ready = false,
_previewVisible,
// Cache
_pool = {},
_preloadQueue,
_preloader = null,
_jw = jwplayer.utils;
function setup(evt) {
// Setting variables
_controlbar = _jw.selectors("#" + player.id + "_jwplayer_controlbar_elements", document);
_rail = _jw.selectors("#" + player.id + "_jwplayer_controlbar_timeSliderRail", document);
// Parsing the config object
_parseConfig();
};
player.onReady(setup);
this.resize = function (width, height) {
if(null != _div && null != _rail && null != _controlbar) {
_jw.append(_controlbar, _div);
// Update Styles
var map = {};
var marginBottom = isNaN(config.marginbottom) ? 0 : config.marginbottom;
var controlBarHeight = _jw.getElementHeight(_controlbar);
map.bottom = 0 + controlBarHeight + marginBottom + "px";
map.left = Math.round(width/2) + 'px';
_jw.css(_div, map);
}
};
function _detectOldNotation() {
for(k in config) {
if("pluginmode"!=k) {
return false;
}
}
return true;
};
function _getConfigValue(prop) {
if (_dotNotation) {
return player.config['timeslidertooltipplugin.'+prop];
} else {
var arr = prop.split(".");
var tot = arr.length;
var val = config;
for(var i = 0; i < tot; i++) {
val = val[arr[i]];
if(i+1>=tot) {
return val;
}
}
}
};
function _parseConfig() {
_preloadQueue = new Array();
// displayhours (H:MM:SS or MM:SS)
config.displayhours = ("true" == String(_getConfigValue('displayhours'))) ? true : false;
// marginbottom (adjusts the vertical position of the tooltip % to the controlbar)
var marginBottom = parseInt(_getConfigValue('marginbottom'));
config.marginbottom = isNaN(marginBottom) ? 0 : marginBottom;
// labelheight
var labelHeight = parseInt(_getConfigValue('labelheight'));
config.labelheight = (isNaN(labelHeight)) ? 17 : labelHeight;
// font, fontsize, fontcolor, fontweight, fontstyle
var fontFamily = _getConfigValue('font');
config.font = (!fontFamily) ? "Arial,sans-serif" : fontFamily;
var fontSize = parseInt(_getConfigValue('fontsize'));
config.fontsize = isNaN(fontSize) ? 11 : fontSize;
var fontColor = String(_getConfigValue('fontcolor'));
if (0 === fontColor.indexOf("0x")) {
fontColor = "#"+fontColor.substr(2);
}
config.fontcolor = (!fontColor) ? "#000" : fontColor;
var fontWeight = _getConfigValue('fontweight');
config.fontweight = (fontWeight!="normal" && fontWeight!="bold") ? "normal" : fontWeight;
var fontStyle = _getConfigValue('fontstyle');
config.fontstyle = (fontStyle!="normal" && fontStyle!="italic") ? "normal" : fontStyle;
// image
//config.image = (null!=config.image) ? config.image : _getDefaultImage();
var imageSrc = _getConfigValue('image');
config.image = (null!=imageSrc && 'undefined'!=imageSrc) ? imageSrc : "";
if (""!=config.image) {
_preloadQueue.push({target:'config.image', url:config.image});
}
// New feature "Preview"
// =====================
// Enabled
var enabled = ("true" == String(_getConfigValue('preview.enabled'))) ? true : false;
// Path
var file = player.getPlaylistItem().file;
var path = String(_getConfigValue('preview.path'));
// Prefix
var prefix = String(_getConfigValue('preview.prefix'));
// Image
var previewImageSrc = String(_getConfigValue('preview.image'));
previewImageSrc = (null!=previewImageSrc && 'undefined'!=previewImageSrc) ? previewImageSrc : "";
var frequency = parseInt(_getConfigValue('preview.frequency'));
var linelength = parseInt(_getConfigValue('preview.linelength'));
var spritelength = parseInt(_getConfigValue('preview.spritelength'));
// Setting values
config.preview = {};
config.preview.preloadtext = "Loading...";
config.preview.extension = "jpg";
config.preview.preload = false;
config.preview.cache = true;
// User settings
config.preview.enabled = enabled;
config.preview.path = path;
config.preview.prefix = prefix;
config.preview.image = previewImageSrc;
if ('undefined'==config.preview.path) {
config.preview.path = null;
}
if ('undefined'==config.preview.prefix) {
config.preview.prefix = null;
}
if (""!=config.preview.image) {
_preloadQueue.push({target:'config.preview.image', url:config.preview.image});
}
if (isNaN(frequency)) {
config.preview.frequency = 1;
}else{
config.preview.frequency = frequency;
}
if (isNaN(linelength)) {
config.preview.linelength = 5;
}else{
config.preview.linelength = linelength;
}
if (isNaN(spritelength)) {
config.preview.spritelength = 25;
}else{
config.preview.spritelength = spritelength;
}
_launchNextPreloadQueue();
};
function _launchNextPreloadQueue() {
if (0 == _preloadQueue.length) {
// Create the Tooltip
_createTooltip();
// If everything went fine...
if ( null != _rail && null != _controlbar ) {
_ready = true;
_jw.append(_controlbar, _div);
_controlbar.addEventListener('mousemove', _mousemove);
_controlbar.addEventListener('mouseout', _mouseout);
}
} else {
if (null == _preloader) {
_preloader = new Image();
_preloader.onload = _onImagePreloadingDone;
_preloader.onerror = _onImagePreloadingDone;
}
_preloader.src = _preloadQueue[0].url;
}
};
function _onImagePreloadingDone(event) {
var obj = _preloadQueue.shift();
var var_str = obj['target'];
switch ( event.type ) {
case "load":
break;
case "error":
// Overwrite the user settings because image was not loaded
// We fall back to default backgrounds in this case...
if ("config.image"==var_str) {
config.image = "";
} else if ("config.preview.image"==var_str){
config.preview.image = "";
}
break;
}
_launchNextPreloadQueue();
};
function _getCurrentFile() {
// The currently playing item's file URL
return player.getPlaylistItem().file;;
};
function _getPath() {
var path_str;
if ( null==config.preview.path ) {
var currentFile = _getCurrentFile();
path_str = currentFile.substr(0, currentFile.lastIndexOf('/')+1)
} else {
path_str = config.preview.path;
}
return path_str;
};
function _getPrefix() {
var prefix_str;
if ( null==config.preview.prefix ) {
var currentFile = _getCurrentFile();
var filename = currentFile.substr(currentFile.lastIndexOf('/')+1, currentFile.length);
var lastDot = filename.lastIndexOf('.');
if(0 < lastDot) {
filename = filename.substr(0, lastDot);
}
prefix_str = filename;
} else {
prefix_str = config.preview.prefix;
}
return prefix_str;
};
function _createTooltip() {
// Build Markup
// ============
_jw.html(_div, '<div class="tstt-preview"></div><span class="tstt-time">...</span>');
_preview = _jw.selectors.getElementsByTagAndClass('div', 'tstt-preview', _div)[0];
_time = _jw.selectors.getElementsByTagAndClass('span', 'tstt-time', _div)[0];
_show(false);
var map;
// Applying CSS
// ============
// General
map = {};
map.position = 'absolute';
map.pointerEvents = "none";
_jw.css(_div, map);
// Preview
map = {};
map.width = '108px'; //160px
map.height = '60px'; //90px
map.position = 'absolute';
map.top = '2px';
map.left = '2px';
map.overflow = 'hidden';
_jw.css(_preview, map);
// Time
map = {};
map.display = "block";
map.color = config.fontcolor;
map.fontFamily = config.font;
map.fontSize = config.fontsize + "px";
map.fontWeight = config.fontweight;
map.color = config.fontcolor;
map.fontStyle = config.fontstyle;
map.textAlign = "center";
map.lineHeight = config.labelheight + "px";
map.pointerEvents = "none";
_jw.css(_time, map);
_updateTooltipUI(config.preview.enabled);
_previewVisible = config.preview.enabled;
};
function _updateTooltipUI(withPreview) {
var map = {};
if (withPreview!=_previewVisible) {
_previewVisible = !_previewVisible;
var bg_src = withPreview ? config.preview.image : config.image;
if (""===bg_src) {
// Default Background
// ==================
if (withPreview) {
map.width = "112px";
map.height = "82px";
map.background = "url('" + _getDefaultPreviewImage() + "') left top no-repeat transparent";
} else {
map.width = "41px";
map.height = "22px";
map.background = "url('" + _getDefaultImage() + "') left top no-repeat transparent";
}
_jw.css(_div, map);
} else {
// Custom background
// =================
var img = new Image();
img.onload = function () {
// Resize the tooltip to match the Tooltip background size
map.background = "url('" + this.src + "') left top no-repeat transparent";
map.width = this.width + "px";
map.height = this.height + "px";
_jw.css(_div, map);
};
img.onerror = function () {
// Implement fallback to default?
};
img.src = withPreview ? config.preview.image : config.image;
}
// Preview
// =======
if (withPreview) {
_preview.style.display = "block";
_time.style.marginTop = "62px";
} else {
_preview.style.display = "none";
_time.style.marginTop = "0px";
}
}
};
function _show(state) {
div.style.display = (false===state) ? "none" : "block";
};
function _mousemove(event) {
var dur = player.getDuration();
if (_ready && dur > 0) {
var railOffset = _jw.getBoundingClientRect(_rail);
var x_pos = event.pageX - railOffset.left;
var width = _jw.getElementWidth(_rail);
var percent = x_pos/width;
var parentDiv = _jw.parentNode(_div);
var parentOffset = _jw.getBoundingClientRect(parentDiv);
var tooltip_x = event.pageX - parentOffset.left;
var seconds = Math.round(percent*dur);
// Preview
if (config.preview.enabled) {
var pt = _getSpriteCoordinates(seconds);
var url = _getPreviewSpriteUrl(seconds);
var map = {};
map.backgroundImage = "url('"+url+"')";
map.backgroundPosition = "-"+(pt.x*108)+"px -"+(pt.y*60)+"px";
_jw.css(_preview, map);
//_updateTooltipUI(1===_getImageFromPool(url));
_updateTooltipUI(-1!=_getImageFromPool(url));
}
// Time
_jw.html(_time, _toTimeString(seconds));
var tooltipWidth = _jw.getElementWidth(_div);
tooltip_x -= Math.ceil(tooltipWidth/2);
_div.style.left = tooltip_x + "px";
_show(x_pos >= 0 && x_pos <= width);
} else {
_show(false)
}
};
function _getImageFromPool(src) {
// Doesn't save the images, just remember if loading failed/succeeded
//-1 The image loading failed to load
// 0 The image loading is pending
// 1 The image loading was successful
if ('undefined'==typeof(_pool[src])) {
_pool[src] = 0;
var pool_img = new Image();
pool_img.onerror = function () { _pool[src] = -1; };
pool_img.onload = function () { _pool[src] = 1; };
pool_img.src = src;
return 0;
} else {
return _pool[src];
}
};
function _getPreviewSpriteUrl(seconds) {
seconds = (0 > seconds) ? 0 : seconds;
var n = seconds / config.preview.frequency / config.preview.spritelength;
var url = _getPath();
url += _getPrefix();
url += _pad(Math.floor(n), 4);
url += "."+config.preview.extension;
return url;
};
function _getSpriteCoordinates(seconds) {
var sec = Math.floor(seconds / config.preview.frequency);
var ratio = (config.preview.spritelength/config.preview.linelength);
var point = {};
point.x = sec % config.preview.linelength;
point.y = Math.floor(sec/config.preview.linelength) % ratio;
return point;
};
function _mouseout(event) {
_show(false);
};
function _toTimeString(n) {
var time_str = "";
if (n >= 3600 && true===config.displayhours) {
// Longer than one hour
var hours = Math.floor(n / 3600);
time_str += Math.floor(n / 3600) + ":";
n -= 3600 * hours;
}
time_str += _pad(Math.floor(n / 60), 2) + ":" + _pad(Math.floor(n % 60), 2);
return time_str;
};
function _pad(n, padLength) {
var str = n.toString();
while ( str.length < padLength ) {
str = "0" + str;
}
return str;
};
function _getDefaultImage() {
return "data:;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAAWCAYAAABdTLWOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRp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