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
|
(function() {
"use strict";
onReady(() =>
getConfig().then(getVideoInfo)
);
function injectPlayer(conf) {
try {
let player_container, player, stl;
if (conf.isEmbed) {
player_container = document.body;
} else if (conf.isWatch) {
player_container = document.getElementById("video") ||
document.getElementById("video_wrapper");
if ((stl = player_container.children[0]) &&
(stl = stl.sheet) &&
(stl.cssRules.length > 0)) {
stl = stl.cssRules[0].cssText;
}
} else {
player_container = document.getElementById("clip_" + conf.id);
}
if (!player_container)
return;
var vp = new VP(player_container);
vp.srcs(conf.fmts, {
"high/mp4": "hd",
"medium/mp4": "sd",
"low/mp4": "mobile"
}, (fmt) => fmt.url);
vp.props({
className: conf.className,
autoplay: autoPlay(),
preload: preLoad(),
loop: isLoop(),
controls: true,
poster: conf.poster,
volume: OPTIONS.volume / 100
});
vp.tracksList(conf.tracks.map(l => l.lang), (lang, resolve, reject) => {
var l = conf.tracks.find(l => l.lang === lang);
if (l === undefined)
reject();
else
resolve(l.direct_url || l.url);
});
if (stl)
vp.addCSSRule(stl);
vp.setup();
if (conf.isWatch)
brozarEvents();
} catch (e) {
logify("Exception on changePlayer()", e.lineNumber, e.columnNumber, e.message, e.stack);
}
}
function getConfig() {
return new Promise((resolve, reject) => {
var isWatch = /https?:\/\/vimeo.com\/[\d]+/.test(location.href) ||
ogType().indexOf("video") > -1;
var isEmbed = /https?:\/\/player.vimeo.com\/video/.test(location.href);
var isChannel = /https?:\/\/vimeo.com\/(channels\/|)\w+/.test(location.href) ||
ogType().match(/channel|profile/) !== null;
if (!isWatch && !isChannel && !isEmbed)
reject();
var player_id, player_class;
if (isWatch) {
player_id = location.pathname.match(/\/([\d]+)/)[1];
player_class = "player";
} else if (isEmbed) {
player_id = location.pathname.match(/video\/([\d]+)/)[1];
player_class = "fallback";
} else if (isChannel) {
player_class = "player";
}
if (!player_id && !isChannel)
reject();
resolve({
isWatch: isWatch,
isEmbed: isEmbed,
isChannel: isChannel,
id: player_id,
className: player_class
});
});
}
function getVideoInfo(conf) {
const processData = (conf) => (data) => {
data = JSON.parse(data);
conf.fmts = data.request.files.h264;
conf.poster = data.video.thumbs.base;
conf.tracks = data.request.text_tracks || [];
return Promise.resolve(conf);
};
const INFO_URL = "//player.vimeo.com/video/";
if (conf.isChannel) {
return Array.map(document.getElementsByClassName("player_container"), (el) => {
var _conf = {};
for (var va in conf)
_conf[va] = conf[va];
_conf.id = el.id.replace("clip_", "");
return asyncGet(INFO_URL + _conf.id + "/config").then(processData(_conf))
.then(injectPlayer);
});
} else {
return asyncGet(INFO_URL + conf.id + "/config").then(processData(conf))
.then(injectPlayer);
}
}
function brozarEvents() {
// change Vimeo default click events of items on brozar element
var clips = document.getElementById("clips");
if (clips)
clips.onclick = function(e) {
if (e.target === e.currentTarget)
return;
var li = e.target;
while (li.tagName !== "LI")
li = li.parentElement;
window.location = "/" + li.id.replace("clip_", "");
};
var promos = document.getElementsByClassName("js-promo_link");
var promoClick = function(e) {
window.location = "/" + e.currentTarget.dataset.clipId;
};
for (var i = 0; promos && i < promos.length; i++)
promos[i].onclick = promoClick;
}
function ogType() {
var t = document.head.querySelector("meta[property=\"og:type\"]");
return (t) ? t.content : "";
}
}());
|