PageSourceSearch

https://izba-mechty.ru/bitrix/components/bitrix/player/videojs/videojs-playlist-dev.js

js izba-mechty.ru collected 2026-10-08 23:39:06 UTC 12,856 bytes, 440 lines download raw bytes

1/**
2 * videojs-playlist-thumbs
3 * @version 0.1.5
4 * @copyright 2016 Emmanuel Alves <[email protected]>
5 * @license MIT
6 */
7(function(f){
8	if(typeof exports==="object" && typeof module!=="undefined")
9	{
10		module.exports=f()
11	}
12	else if(typeof define==="function"&&define.amd)
13	{
14		define([],f)
15	}
16	else
17	{
18		var g;
19		if(typeof this!=="undefined")
20		{
21			g=this
22		}
23		else if(typeof self!=="undefined")
24		{
25			g=self
26		}
27		else if(typeof window!=="undefined")
28		{
29			g=window
30		}
31		else if(typeof global!=="undefined")
32		{
33			g=global
34		}
35		g.videojsPlaylist = f()
36	}
37})(function()
38{
39	var define,module,exports;
40	return (function e(t,n,r)
41	{
42		function s(o,u)
43		{
44			if(!n[o])
45			{
46				if(!t[o])
47				{
48					var a=typeof require=="function"&&require;
49					if(!u&&a)
50						return a(o,!0);
51					if(i)
52						return i(o,!0);
53					var f=new Error("Cannot find module '"+o+"'");
54					throw f.code="MODULE_NOT_FOUND",f
55				}
56				var l=n[o]={exports:{}};
57				t[o][0].call(l.exports,function(e)
58				{
59					var n=t[o][1][e];
60					return s(n?n:e)
61				},l,l.exports,e,t,n,r)
62			}return n[o].exports
63		}
64		var i=typeof require=="function"&&require;
65		for(var o=0;o<r.length;o++)
66			s(r[o]);
67		return s
68	})({1:[function(require,module,exports){
69		(function (global){
70			"use strict";
71
72			Object.defineProperty(exports, "__esModule", {
73				value: true
74			});
75
76			function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
77
78			var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
79
80			var _videoJs2 = _interopRequireDefault(_videoJs);
81
82//var _videoJs2 = _interopRequireDefault(_videoJs);
83
84// Default options for the plugin.
85			var defaults = {
86				thumbnailSize: 190,
87				playlistItems: 3,
88				hideIcons: false,
89				upNext: true,
90				hideSidebar: false,
91				mobile: false
92			};
93
94			var player = undefined;
95			var mobile = false;
96			var currentIdx = [];
97			var videos = [];
98			var players = [];
99			var playlistsElemens = [];
100			var playlistsElemen = null;
101
102			/**
103			 * creates each video on the playlist
104			 */
105			var createVideoElement = function createVideoElement(player_id, idx, title, thumbnail) {
106				var videoElement = document.createElement("li");
107				var videoTitle = document.createElement("div");
108				videoTitle.className = "vjs-playlist-video-title";
109				videoTitle.setAttribute("data-index", idx);
110
111				if (idx == 0) {
112					if (defaults.upNext) {
113						var upNext = document.createElement("div");
114						upNext.className = "vjs-playlist-video-upnext";
115						upNext.innerText = "UP Next";
116
117						videoTitle.appendChild(upNext);
118					}
119				}
120
121				if (title) {
122					var videoTitleText = document.createElement("div");
123					videoTitleText.innerText = title;
124					videoTitleText.setAttribute("data-index", idx);
125
126					videoTitle.appendChild(videoTitleText); // = "<span>" + title + "</span>";
127
128					videoElement.appendChild(videoTitle);
129				}
130
131				if (thumbnail)
132					videoElement.setAttribute("style", "background-image: url('" + thumbnail + "');");
133				videoElement.setAttribute("data-index", idx);
134
135				// when the user clicks on the playlist, the video will start playing
136				videoElement.onclick = function (ev) {
137
138					var idx = parseInt(ev.target.getAttribute("data-index"));
139
140					// and play this video
141					playVideo(player_id, idx, true);
142				};
143
144				return videoElement;
145			};
146
147			/**
148			 * Function to invoke when the player is ready.
149			 *
150			 * This is a great place for your plugin to initialize itself. When this
151			 * function is called, the player will have its DOM and child components
152			 * in place.
153			 *
154			 * @function onPlayerReady
155			 * @param    {Player} player
156			 * @param    {Object} [options={}]
157			 */
158			var onPlayerReady = function onPlayerReady(player, options) {
159				videos[player.id_] = options.videos;
160				currentIdx[player.id_] = 0;
161				mobile = options.playlist.mobile;
162
163				if (options.playlist && options.playlist.thumbnailSize) {
164					defaults.thumbnailSize = options.playlist.thumbnailSize.toString().replace("px", "");
165				}
166
167				if (options.playlist && options.playlist.items) {
168					defaults.playlistItems = options.playlist.items;
169				}
170
171				if (options.playlist && options.playlist.hideIcons) {
172					defaults.hideIcons = options.playlist.hideIcons;
173				}
174
175				if (options.playlist && options.playlist.hideSidebar) {
176					defaults.hideSidebar = options.playlist.hideSidebar;
177				}
178
179				createElements(player, options);
180				updateElementWidth(player);
181			};
182
183			/**
184			 * Creates the root html elements for the playlist
185			 */
186			var createElements = function createElements(player, options) {
187				// creates the playlist items and add on the video player
188				playlistsElemen = document.createElement("ul");
189				playlistsElemen.className = "vjs-playlist-items";
190
191				if (!defaults.hideSidebar) {
192					player.el().appendChild(playlistsElemen);
193				}
194
195				playlistsElemens[player.id_] = playlistsElemen;
196
197				// plays the first video
198				if (videos[player.id_].length > 0) {
199					videos[player.id_].map(function (video, idx) {
200						playlistsElemens[player.id_].appendChild(createVideoElement(player.id_, idx, video.title, video.thumbnail));
201					});
202					playVideo(player.id_, 0, false);
203				}
204
205				// create next and previous button
206				if (!defaults.hideIcons) {
207					var prevBtn = document.createElement("button");
208					prevBtn.className = "vjs-button-prev";
209					prevBtn.onclick = onPrevClick;
210
211					player.controlBar.el().insertBefore(prevBtn, player.controlBar.playToggle.el());
212
213					var nextBtn = document.createElement("button");
214					nextBtn.className = "vjs-button-next";
215					nextBtn.onclick = onNextClick;
216
217					player.controlBar.el().insertBefore(nextBtn, player.controlBar.volumeMenuButton.el());
218				}
219
220				// creates the loading next on video ends
221				player.on("ended", createPlayingNext);
222
223				// adds the main class on the player
224				player.addClass('vjs-playlist');
225
226			};
227
228			var createPlayingNext = function createPlayingNext() {
229				nextVideo();
230			};
231
232			var onNextClick = function onNextClick(ev) {
233				var player_id = ev.target.parentNode.parentNode.id;
234				nextVideo(player_id);
235			};
236
237			var onPrevClick = function onPrevClick(ev) {
238				var player_id = ev.target.parentNode.parentNode.id;
239				previousVideo(player_id);
240			};
241
242			/**
243			 * updates the main video player width
244			 */
245			var updateElementWidth = function updateElementWidth(player) {
246				var resize = function resize(p) {
247					var itemWidth = defaults.thumbnailSize;
248					var playerId = p.el().id;
249					var playerWidth = p.el().offsetWidth;
250					var playerHeight = p.el().offsetHeight;
251					var itemHeight = Math.floor((playerHeight - 10) / defaults.playlistItems) - 10;
252
253					var youtube = p.$(".vjs-tech");
254					var newSize = playerWidth - itemWidth;
255
256					if (newSize >= 0) {
257						var styleTagId = playerId + '_styles';
258						var style = document.getElementById(styleTagId);
259						if (!style)
260							style = document.createElement('style');
261						var def = ' #' + playerId + '.vjs-playlist .vjs-poster { width: ' + newSize + 'px !important; }' +
262							' #' + playerId + '.vjs-playlist .vjs-playlist-items { width: ' + itemWidth + 'px !important; }' +
263							' #' + playerId + '.vjs-playlist .vjs-playlist-items li { height: ' + itemHeight + 'px !important; }' +
264							' #' + playerId + '.vjs-playlist .vjs-modal-dialog { width: ' + newSize + 'px !important; } ' +
265							' #' + playerId + '.vjs-playlist .vjs-control-bar, #' + playerId + '.vjs-playlist .vjs-tech { width: ' + newSize + 'px !important; } ' +
266							' #' + playerId + '.vjs-playlist .vjs-big-play-button, #' + playerId + '.vjs-playlist .vjs-loading-spinner { left: ' + Math.round(newSize / 2) + 'px !important; } ' +
267							' #' + playerId + ' .vimeoFrame { width: ' + newSize + 'px !important; } ' +
268							' #' + playerId + ' .vimeoFrame.vimeoHidden { padding-bottom: 0 !important; } ';
269						style.setAttribute('id', styleTagId);
270						style.setAttribute('type', 'text/css');
271						document.getElementsByTagName('head')[0].appendChild(style);
272
273						if (style.firstChild) {
274							style.firstChild.textContent = def;
275						} else {
276							style.appendChild(document.createTextNode(def));
277						}
278					}
279				};
280
281				if (!defaults.hideSidebar) {
282					player.on('fullscreenchange', function () {
283						resize(this);
284					});
285					window.addEventListener('resize', function(event){
286						resize(player);
287					});
288
289					if (player) {
290						resize(player);
291					}
292				}
293			};
294
295			/**
296			 * plays the video based on an index
297			 */
298			var playVideo = function playVideo(player_id, idx, autoPlay) {
299
300				if (!player_id)
301				{
302					player_id = player.id_;
303				}
304				currentIdx[player_id] = idx;
305				var playlistsElemen = players[player_id].el().querySelectorAll('ul.vjs-playlist-items li');
306				for (var i = 0; i < playlistsElemen.length; i++) {
307					if (i == idx)
308					{
309						playlistsElemen[i].classList.add('current');
310						//playlistsElemen[i].parentNode.scrollTop = playlistsElemen[i].offsetHeight * i;
311					}
312					else
313					{
314						playlistsElemen[i].classList.remove('current');
315					}
316				}
317				try
318				{
319					if(!players[player_id].paused())
320					{
321						players[player_id].pause();
322						players[player_id].error(null);
323					}
324				}
325				catch (e) {}
326				var video = { type: videos[player_id][idx].type, src: videos[player_id][idx].src };
327				var wmvPlayerId = player_id + '_wmv_player';
328				if (video.type == 'video/x-ms-wmv')
329				{
330					var wmvPlayerDiv = document.getElementById(wmvPlayerId);
331					if (!wmvPlayerDiv)
332					{
333						wmvPlayerDiv = document.createElement('div');
334						wmvPlayerDiv.setAttribute('id', wmvPlayerId);
335						wmvPlayerDiv.setAttribute('class', 'vjs-tech');
336						players[player_id].el().appendChild(wmvPlayerDiv);
337					}
338					var wmvConfig = players[player_id].wmvConfig;
339					wmvConfig.file = video.src;
340					if (!!videos[player_id][idx].thumbnail)
341						wmvConfig.image = videos[player_id][idx].thumbnail;
342					var wmvPlayer = new window.jeroenwijering.Player(wmvPlayerDiv, '/bitrix/components/bitrix/player/wmvplayer/wmvplayer.xaml',  players[player_id].wmvConfig);
343				}
344				else
345				{
346					// disable wmv-player
347					var wmvPlayerDiv = document.getElementById (wmvPlayerId);
348					if (!!wmvPlayerDiv)
349						wmvPlayerDiv.parentNode.removeChild (wmvPlayerDiv);
350					var vimeos = players[player_id].el().getElementsByClassName('vimeoFrame');
351					for (var i = 0; i < vimeos.length; i++)
352					{
353						vimeos[i].classList.add('vimeoHidden');
354					}
355					if (video.type == 'video/vimeo')
356					{
357						var curVideoId = 'vimeo_wrapper_' + player_id;
358						if (!!document.getElementById(curVideoId))
359							document.getElementById(curVideoId).classList.remove('vimeoHidden');
360					}
361					players[player_id].src(video);
362					players[player_id].poster(videos[player_id][idx].thumbnail);
363					if (!mobile && (autoPlay || players[player_id].options_.autoplay)) {
364						try {
365							players[player_id].play();
366						} catch (e) {}
367					}
368				}
369			};
370
371			/**
372			 * plays the next video, if it comes to the end, loop
373			 */
374			var nextVideo = function nextVideo(player_id) {
375
376				if (!player_id)
377				{
378					player_id = player.id_;
379				}
380
381				if (currentIdx[player_id] < videos[player_id].length - 1) {
382					currentIdx[player_id]++;
383				} else {
384					currentIdx[player_id] = 0;
385				}
386
387				playVideo(player_id, currentIdx[player_id], true);
388			};
389
390			/**
391			 * plays the previous video, if it comes to the first video, loop
392			 */
393			var previousVideo = function previousVideo(player_id) {
394				if (!player_id)
395				{
396					player_id = player.id_;
397				}
398				if (currentIdx[player_id] > 0) {
399					currentIdx[player_id]--;
400				} else {
401					currentIdx[player_id] = videos[player_id].length - 1;
402				}
403				playVideo(player_id, currentIdx[player_id], true);
404			};
405
406			/**
407			 * A video.js plugin.
408			 *
409			 * In the plugin function, the value of `this` is a video.js `Player`
410			 * instance. You cannot rely on the player being in a "ready" state here,
411			 * depending on how the plugin is invoked. This may or may not be important
412			 * to you; if not, remove the wait for "ready"!
413			 *
414			 * @function playlist
415			 * @param    {Object} [options={}]
416			 *           An object of options left to the plugin author to define.
417			 */
418			var playlist = function playlist(options) {
419
420				var _this = this;
421
422				this.ready(function () {
423					player = _this;
424					players[player.id_] = player;
425					onPlayerReady(_this, _videoJs2["default"].mergeOptions(options, defaults));
426				});
427			};
428
429			_videoJs2["default"].plugin('playlist', playlist);
430
431			exports["default"] = playlist;
432			module.exports = exports["default"];
433		}).call(this,
434			typeof this !== "undefined" ? this:
435				typeof self !== "undefined" ? self :
436					typeof global !== "undefined" ? global :
437						typeof window !== "undefined" ? window : {}
438		)
439	},{}]},{},[1])(1)
440});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.