This repository was archived by the owner on Sep 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathflowplayer.thumbnails.js
More file actions
159 lines (140 loc) · 6.39 KB
/
flowplayer.thumbnails.js
File metadata and controls
159 lines (140 loc) · 6.39 KB
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
/*jslint browser: true, node: true */
/*global window */
/*!
Thumbnail image plugin for Flowplayer HTML5
Copyright (c) 2015-2017, Flowplayer Drive Oy
Released under the MIT License:
http://www.opensource.org/licenses/mit-license.php
requires:
- Flowplayer HTML5 version 6.x or greater
revision: $GIT_ID$
*/
(function () {
"use strict";
var extension = function (flowplayer) {
flowplayer(function (api, root) {
var common = flowplayer.common,
bean = flowplayer.bean,
extend = flowplayer.extend,
support = flowplayer.support,
timeline = common.find('.fp-timeline', root)[0],
timelineTooltip = common.find('.fp-time' + (flowplayer.version.indexOf('6.') === 0
? 'line-tooltip'
: 'stamp'), root)[0];
if (support.touch || !support.inlineVideo) {
return;
}
api.on('ready', function (_ev, a, video) {
// cleanup
bean.off(root, '.thumbnails');
common.css(timelineTooltip, {
width: '',
height: '',
'background-image': '',
'background-repeat': '',
'background-size': '',
'background-position': '',
'border': '',
'text-shadow': ''
});
var c = extend({
lazyload: true,
responsive: true
}, a.conf.thumbnails, video.thumbnails),
template = c.template,
sprite = template && template.indexOf('{time}') < 0;
if (!template || (sprite && (!c.rows || !c.columns || !c.width || !c.height))) {
return;
}
var height = sprite
? c.height / c.rows
: c.height || 80,
engine = common.find('.fp-engine', root)[0],
ratio = (video.height || common.height(engine)) / (video.width || common.width(engine)),
width = sprite
? c.width / c.columns
: height / ratio,
interval = c.interval || 1,
time_format = c.time_format || function (t) {
return t;
},
startIndex = typeof c.startIndex === 'number'
? c.startIndex
: 1,
thumb = c.lazyload && !sprite
? new Image()
: null,
preloadImages = function (max, start) {
max = Math.floor(max / interval + start);
function load() {
if (start > max) {
return;
}
var img = new Image();
img.src = template.replace('{time}', time_format(start));
img.onload = function () {
start += 1;
load();
};
}
load();
};
if (c.preload) {
preloadImages(video.duration, startIndex);
}
bean.on(root, 'mousemove.thumbnails', '.fp-timeline', function (ev) {
var x = ev.pageX || ev.clientX,
delta = x - common.offset(timeline).left,
percentage = delta / common.width(timeline),
seconds = Math.round(percentage * api.video.duration),
url,
displayThumb = function () {
var scale = (c.responsive && common.hasClass(root, 'is-small'))
? 0.7
: (c.responsive && common.hasClass(root, 'is-tiny'))
? 0.6
: 1,
css = {
width: (width * scale) + 'px',
height: (height * scale) + 'px',
'background-image': "url('" + url + "')",
'background-repeat': 'no-repeat',
border: '1px solid #333',
'text-shadow': '1px 1px #000'
};
if (sprite) {
var left = Math.floor(seconds % c.columns) * -width - (width - width * scale) / 2,
top = Math.floor(seconds / c.columns) * -height - (height - height * scale) / 2;
css['background-position'] = left + 'px ' + top + 'px';
} else {
extend(css, {
'background-size': 'cover',
'background-position': 'center'
});
}
common.css(timelineTooltip, css);
};
// 2nd condition safeguards at out of range retrieval attempts
if (seconds < 0 || seconds > Math.round(api.video.duration)) {
return;
}
// enables greater interval than one second between thumbnails
seconds = Math.floor(seconds / interval);
// {time} template expected to start at 1, video time/first frame starts at 0
url = template.replace('{time}', time_format(seconds + startIndex));
if (c.lazyload && !sprite) {
thumb.src = url;
bean.on(thumb, 'load', displayThumb);
} else {
displayThumb();
}
});
});
});
};
if (typeof module === 'object' && module.exports) {
module.exports = extension;
} else if (window.flowplayer) {
extension(window.flowplayer);
}
}());