Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.20 KB | None | 0 0
  1. /*!
  2. * Responsive Video Gallery - A jQuery plugin that provides a slider with horizontal and vertical thumb layouts for video galleries.
  3. * @version 1.0.9
  4. * @link http://fooplugins.github.io/rvslider/
  5. * @copyright Steven Usher & Brad Vincent 2015
  6. * @license Released under the GPLv3 license.
  7. */
  8. (function($, FP){
  9.  
  10. $.fn.rvslider = function(options){
  11. return this.each(function(){
  12. var rvs = $(this).data('__RVSlider__');
  13. if (rvs instanceof FP.RVSlider) rvs.destroy();
  14. FP.RVSlider(this, options);
  15. });
  16. };
  17.  
  18. FP.RVSlider = function(el, options){
  19. if (!(this instanceof FP.RVSlider)) return new FP.RVSlider(el, options);
  20. var $el = $(el);
  21. this.$ = {
  22. el: $el,
  23. empty: $el.find('.rvs-empty')
  24. };
  25. this.o = $.extend(true, {}, FP.RVSlider.defaults, options);
  26. this.index = this.o.selected;
  27. this.breakpoints = '[object Array]' === Object.prototype.toString.call(this.o.breakpoints) ? this.o.breakpoints : [ // number of items to display at various widths and the classes to apply
  28. [480, 'rvs-xs', 2], // Width less than 320 equals 2 items
  29. [768, 'rvs-xs rvs-sm', 3], // W > 320 && W < 768 = 3 items
  30. [1024, 'rvs-xs rvs-sm rvs-md', 4], // W > 768 && W < 1024 = 4 items
  31. [1280, 'rvs-xs rvs-sm rvs-md rvs-lg', 5], // W > 1024 && W < 1280 = 5 items
  32. [1600, 'rvs-xs rvs-sm rvs-md rvs-lg rvs-xl', 6] // Effectively anything greater than 1280 will equal 6 items as this last value is used for anything larger.
  33. ];
  34. this.breakpoint = null;
  35. this.useViewport = this.$.el.hasClass('rvs-use-viewport');
  36. this.items = new FP.RVSliderItems(this);
  37. this.nav = new FP.RVSliderNav(this);
  38. this.player = new FP.RVSliderPlayer(this);
  39. this.resize();
  40. this.setActive(this.index);
  41. this.$.el.addClass('rvs-animate').data('__RVSlider__', this);
  42. $(window).on('resize.rvs', {self: this}, this.onWindowResize);
  43. };
  44.  
  45. FP.RVSlider.defaults = {
  46. selected: 0,
  47. swipe: {
  48. deadzone: 10, // in pixels - the swipe must travel further than this value before it is registered and the plugin takes control of the touch move event
  49. items: 0.05, // in percent - this is the percent of an items width a swipe must travel before it switches to the next item
  50. nav: 0.1, // in percent - this is the percent of a nav items height a swipe must travel before it scrolls the nav items.
  51. touches: 1 // the minimum number of touches that must be registered in order to swipe
  52. },
  53. breakpoints: null // number of items to display at various widths when using the horizontal layout
  54. };
  55.  
  56. var prefixes = ['Webkit', 'Moz', 'ms', 'O', 'Khtml'],
  57. elem = document.createElement('div');
  58.  
  59. function supports(name){
  60. if (typeof elem.style[name] !== 'undefined') return true;
  61. for (var i = 0, len = prefixes.length; i < len; i++){
  62. var n = prefixes[i] + name.charAt(0).toUpperCase() + name.substr(1);
  63. if (typeof elem.style[n] !== 'undefined') return true;
  64. }
  65. return false;
  66. }
  67.  
  68. FP.RVSlider.supportsTransitions = supports('transition');
  69.  
  70. FP.RVSlider.prototype.destroy = function(){
  71. $(window).off('resize.rvs', this.onWindowResize);
  72. this.$.el.removeClass('rvs-animate').removeData('__RVSlider__');
  73. this.player.destroy();
  74. this.nav.destroy();
  75. this.items.destroy();
  76. };
  77.  
  78. FP.RVSlider.prototype._breakpoint = function(){
  79. var ratio = 'devicePixelRatio' in window && typeof window.devicePixelRatio === 'number' ? window.devicePixelRatio : 1,
  80. i = 0, len = this.breakpoints.length, current,
  81. width = this.useViewport
  82. ? (window.innerWidth || document.documentElement.clientWidth || (document.body ? document.body.offsetWidth : 0)) / ratio
  83. : this.$.el.parent().innerWidth();
  84.  
  85. this.breakpoints.sort(function(a,b){ return a[0] - b[0]; });
  86. for (; i < len; i++){
  87. if (this.breakpoints[i][0] >= width){
  88. current = this.breakpoints[i];
  89. break;
  90. }
  91. }
  92. if (!current) current = this.breakpoints[len - 1];
  93. return current;
  94. };
  95.  
  96. FP.RVSlider.prototype.preresize = function(){
  97. this.$.el.removeClass('rvs-animate');
  98. };
  99.  
  100. FP.RVSlider.prototype.resize = function(){
  101. this.breakpoint = this._breakpoint();
  102. this.$.el.removeClass(this.breakpoints[this.breakpoints.length - 1][1]).addClass(this.breakpoint[1]);
  103. this.items.resize();
  104. this.nav.resize();
  105. this.$.el.addClass('rvs-animate');
  106. };
  107.  
  108. FP.RVSlider.prototype.setActive = function(index){
  109. if (this.items.count == 0){
  110. this.$.empty.show();
  111. } else {
  112. this.$.empty.hide();
  113. this.items.setActive(index);
  114. this.nav.setActive(index);
  115. this.player.setActive(index);
  116. this.index = index;
  117. }
  118. };
  119.  
  120. FP.RVSlider.prototype.onWindowResize = function(e){
  121. var self = e.data.self;
  122. if (self.__resize__) clearTimeout(self.__resize__);
  123. self.preresize();
  124. self.__resize__ = setTimeout(function(){
  125. self.__resize__ = false;
  126. self.resize();
  127. }, 50);
  128. };
  129.  
  130. })(jQuery, window.FooPlugins = window.FooPlugins || {});
  131. (function($, FP){
  132.  
  133. FP.RVSliderItems = function(rvs){
  134. if (!(this instanceof FP.RVSliderItems)) return new FP.RVSliderItems(rvs);
  135. this.rvs = rvs;
  136. var self = this;
  137. this.$ = {
  138. container: self.rvs.$.el.find('.rvs-item-container'),
  139. stage: self.rvs.$.el.find('.rvs-item-stage').on('touchstart.rvs', {self: self}, self.onTouchStart),
  140. items: self.rvs.$.el.find('.rvs-item')
  141. };
  142. this.count = self.$.items.length;
  143. this.touched = false;
  144. this.start = [0,0];
  145. this.diff = [0,0];
  146. this.width = 0;
  147. this.height = 0;
  148. };
  149.  
  150. FP.RVSliderItems.prototype.destroy = function(){
  151. this.$.stage.off('touchstart.rvs', this.onTouchStart)
  152. .off('touchmove.rvs', this.onTouchMove)
  153. .off('touchend.rvs', this.onTouchEnd);
  154. this.$.stage.css({width: '', transform: ''});
  155. this.$.items.css({width: '', left: ''}).removeClass('rvs-active');
  156. };
  157.  
  158. FP.RVSliderItems.prototype.resize = function(){
  159. var self = this;
  160. self.width = self.$.container.width();
  161. self.height = self.$.container.height();
  162. self.$.items.each(function(i){
  163. $(this).css({
  164. 'width': self.width,
  165. 'left': i * self.width
  166. });
  167. });
  168. self.$.stage.css({
  169. width: self.width * self.count,
  170. transform: 'translateX(-'+(self.rvs.index * self.width)+'px)'
  171. });
  172. };
  173.  
  174. var $elem = $('<div/>').css({position: 'absolute',top: -9999,left: -9999,visibility: 'hidden'}),
  175. matrix = function(index, width){
  176. $elem.appendTo('body').css('transform', 'translateX(-'+(index * width)+'px)');
  177. return $elem.css('transform');
  178. };
  179.  
  180. FP.RVSliderItems.prototype.setActive = function(index){
  181. if (index >= 0 && index < this.count){
  182. var self = this, before = this.$.stage.css('transform'), after = matrix(index, this.width);
  183. this.$.stage.one('transitionend', function(){
  184. self.$.items.removeClass('rvs-active').eq(index).addClass('rvs-active');
  185. }).css('transform', 'translateX(-'+(index * this.width)+'px)');
  186. if (!FP.RVSlider.supportsTransitions || before === after){
  187. this.$.stage.trigger('transitionend');
  188. }
  189. } else {
  190. this.$.stage.css('transform', 'translateX(-'+(this.rvs.index * this.width)+'px)');
  191. }
  192. };
  193.  
  194. FP.RVSliderItems.prototype.onTouchStart = function(e){
  195. var self = e.data.self, touches = e.originalEvent.touches || e.touches;
  196. if (touches.length == self.rvs.o.swipe.touches){
  197. self.touched = true;
  198. self.start = [touches[0].pageX,touches[0].pageY];
  199. self.$.stage.on('touchmove.rvs', {self: self}, self.onTouchMove)
  200. .on('touchend.rvs', {self: self}, self.onTouchEnd);
  201. }
  202. };
  203.  
  204. FP.RVSliderItems.prototype.onTouchMove = function(e){
  205. var self = e.data.self, touches = e.originalEvent.touches || e.touches;
  206. if (self.touched && touches.length == self.rvs.o.swipe.touches){
  207. self.diff = [self.start[0]-touches[0].pageX,self.start[1]-touches[0].pageY];
  208. if (Math.abs(self.diff[0]) > self.rvs.o.swipe.deadzone) e.preventDefault();
  209. }
  210. };
  211.  
  212. FP.RVSliderItems.prototype.onTouchEnd = function(e){
  213. var self = e.data.self;
  214. self.$.stage.off('touchmove.rvs touchend.rvs');
  215. if (Math.abs(self.diff[0]) > self.width * self.rvs.o.swipe.items){
  216. if (self.diff[0] > 0){ // swipe left
  217. self.rvs.setActive(self.rvs.index+1);
  218. } else if (self.diff[0] < 0){ // swipe right
  219. self.rvs.setActive(self.rvs.index-1);
  220. }
  221. }
  222. self.diff = [0,0];
  223. self.start = [0,0];
  224. self.touched = false;
  225. };
  226.  
  227. })(jQuery, window.FooPlugins = window.FooPlugins || {});
  228. (function($, FP){
  229.  
  230. FP.RVSliderNav = function(rvs){
  231. if (!(this instanceof FP.RVSliderNav)) return new FP.RVSliderNav(rvs);
  232. this.rvs = rvs;
  233. var self = this;
  234. this.$ = {
  235. container: self.rvs.$.el.find('.rvs-nav-container'),
  236. stage: self.rvs.$.el.find('.rvs-nav-stage').on('touchstart.rvs', {self: self}, self.onTouchStart)
  237. .on('DOMMouseScroll.rvs mousewheel.rvs', {self: self}, self.onMouseWheel),
  238. items: self.rvs.$.el.find('.rvs-nav-item').on('click.rvs', {self: self}, self.onItemClick),
  239. prev: self.rvs.$.el.find('.rvs-nav-prev').on('click.rvs', {self: self}, self.onPrevClick),
  240. next: self.rvs.$.el.find('.rvs-nav-next').on('click.rvs', {self: self}, self.onNextClick)
  241. };
  242. this.horizontal = self.rvs.$.el.hasClass('rvs-horizontal');
  243. this.thumbPlay = self.rvs.$.el.hasClass('rvs-thumb-play');
  244. this.touchable = 'ontouchstart' in document.documentElement;
  245. this.count = self.$.items.length;
  246. this.touched = false;
  247. this.start = [0,0];
  248. this.diff = [0,0];
  249. this.height = 0;
  250. this.width = 0;
  251. this.visible = {
  252. max: 0,
  253. first: 0,
  254. last: 0
  255. };
  256. };
  257.  
  258. FP.RVSliderNav.prototype.destroy = function(){
  259. this.$.stage.off('touchstart.rvs', this.onTouchStart)
  260. .off('touchmove.rvs', this.onTouchMove)
  261. .off('touchend.rvs', this.onTouchEnd)
  262. .off('DOMMouseScroll.rvs mousewheel.rvs', this.onMouseWheel);
  263. this.$.items.off('click.rvs', this.onItemClick);
  264. this.$.prev.off('click.rvs', this.onPrevClick);
  265. this.$.next.off('click.rvs', this.onNextClick);
  266. this.$.stage.css({width: '', transform: ''});
  267. this.$.items.css({width: '', left: ''}).removeClass('rvs-active');
  268. };
  269.  
  270. FP.RVSliderNav.prototype.resize = function(){
  271. var self = this;
  272. if (self.horizontal){
  273. self.visible.max = self.rvs.breakpoint[2];
  274. self.width = Math.floor(self.rvs.items.width / self.visible.max) + 1;
  275. self.$.stage.css('width', self.width * self.count);
  276. self.$.items.each(function(i){
  277. $(this).css({
  278. 'width': self.width,
  279. 'left': i * self.width
  280. });
  281. });
  282. } else {
  283. self.height = self.$.items.first().outerHeight();
  284. self.visible.max = Math.ceil(self.rvs.items.height / self.height);
  285. }
  286. self.setVisible(self.visible.first);
  287. };
  288.  
  289. FP.RVSliderNav.prototype.setVisible = function(index, last){
  290. index = index < 0 ? 0 : (index >= this.count ? this.count - 1 : index);
  291. if (last) index = index - (this.visible.max - 1);
  292. if (index >= 0 && index + (this.visible.max - 1) < this.count){
  293. var translate = this.horizontal ? 'translateX(-'+((index * this.width) + 1)+'px) translateY(-1px)' : 'translateX(0px) translateY(-'+((index * this.height) + 1)+'px)';
  294. this.$.stage.css('transform', translate); // +1 extra to hide border
  295. this.visible.first = index;
  296. this.visible.last = index + (this.visible.max - 1);
  297. }
  298. if (this.touchable || this.visible.first == 0) this.$.prev.detach();
  299. else if (this.$.prev.parent().length == 0) this.$.container.prepend(this.$.prev);
  300.  
  301. if (this.touchable || this.visible.last == this.count - 1 || this.visible.max > this.count - 1) this.$.next.detach();
  302. else if (this.$.next.parent().length == 0) this.$.container.append(this.$.next);
  303. };
  304.  
  305. FP.RVSliderNav.prototype.setActive = function(index){
  306. if (index >= 0 && index < this.count){
  307. this.$.items.removeClass('rvs-active').eq(index).addClass('rvs-active');
  308. if (index <= this.visible.first) this.setVisible(index - 1);
  309. else if (index >= this.visible.last) this.setVisible(index + 1, true);
  310. }
  311. };
  312.  
  313. FP.RVSliderNav.prototype.onItemClick = function(e){
  314. e.preventDefault();
  315. var self = e.data.self, $this = $(this), $thumb = $this.find('.rvs-nav-item-thumb');
  316. self.rvs.setActive($this.index());
  317. if (self.thumbPlay && ($thumb.length && ($thumb.is(e.target) || $.contains($thumb[0], e.target)))){
  318. self.rvs.player.toggle();
  319. }
  320. };
  321.  
  322. FP.RVSliderNav.prototype.onPrevClick = function(e){
  323. e.preventDefault();
  324. e.data.self.setVisible(e.data.self.visible.first - Math.floor(e.data.self.visible.max / 2));
  325. };
  326.  
  327. FP.RVSliderNav.prototype.onNextClick = function(e){
  328. e.preventDefault();
  329. e.data.self.setVisible(e.data.self.visible.last + Math.floor(e.data.self.visible.max / 2), true);
  330. };
  331.  
  332. FP.RVSliderNav.prototype.onMouseWheel = function(e){
  333. var self = e.data.self, index;
  334. if (self.count > self.visible.max){
  335. if ((e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) && self.visible.first !== 0) index = self.visible.first-1;
  336. else if ((e.originalEvent.wheelDelta < 0 || e.originalEvent.detail < 0) && self.visible.last !== self.count - 1) index = self.visible.first+1;
  337. if (typeof index === 'number' && !isNaN(index)){
  338. e.preventDefault();
  339. self.setVisible(index);
  340. }
  341. }
  342. };
  343.  
  344. FP.RVSliderNav.prototype.onTouchStart = function(e){
  345. var self = e.data.self, touches = e.originalEvent.touches || e.touches;
  346. if (touches.length == self.rvs.o.swipe.touches) {
  347. self.touched = true;
  348. self.start = [touches[0].pageX,touches[0].pageY];
  349. self.$.stage.on('touchmove.rvs', {self: self}, self.onTouchMove)
  350. .on('touchend.rvs', {self: self}, self.onTouchEnd);
  351. }
  352. };
  353.  
  354. FP.RVSliderNav.prototype.onTouchMove = function(e){
  355. var self = e.data.self, touches = e.originalEvent.touches || e.touches;
  356. if (self.touched && touches.length == self.rvs.o.swipe.touches){
  357. self.diff = [self.start[0]-touches[0].pageX,self.start[1]-touches[0].pageY];
  358. if (!this.horizontal) e.preventDefault();
  359. }
  360. };
  361.  
  362. FP.RVSliderNav.prototype.onTouchEnd = function(e){
  363. var self = e.data.self, adx = Math.abs(self.diff[0]), ady = Math.abs(self.diff[1]);
  364. self.$.stage.off('touchmove.rvs touchend.rvs');
  365. if (self.horizontal){
  366. if (adx > self.width * self.rvs.o.swipe.nav){
  367. if (self.diff[0] > 0){ // swipe left
  368. self.setVisible(self.visible.last + Math.ceil(adx/self.width), true);
  369. } else if (self.diff[0] < 0){ // swipe right
  370. self.setVisible(self.visible.first - Math.ceil(adx/self.width));
  371. }
  372. }
  373. } else {
  374. if (ady >= self.height * self.rvs.o.swipe.nav){
  375. if (self.diff[1] > 0){ // swipe up
  376. self.setVisible(self.visible.last + Math.ceil(ady/self.width), true);
  377. } else if (self.diff[1] < 0){ // swipe down
  378. self.setVisible(self.visible.first - Math.ceil(ady/self.width));
  379. }
  380. }
  381. }
  382. self.diff = [0,0];
  383. self.start = [0,0];
  384. self.touched = false;
  385. };
  386.  
  387. })(jQuery, window.FooPlugins = window.FooPlugins || {});
  388. (function($, FP){
  389.  
  390. FP.RVSliderVideoUrl = function(url){
  391. if (!(this instanceof FP.RVSliderVideoUrl)) return new FP.RVSliderVideoUrl(url);
  392. var parts = url.split('#');
  393. this.hash = parts.length == 2 ? '#'+parts[1] : '';
  394. parts = parts[0].split('?');
  395. this.url = parts[0];
  396. var match = this.url.match(/.*\/(.*)$/);
  397. this.id = match && match.length >= 2 ? match[1] : null;
  398. this.protocol = window.location.protocol === 'https:' ? 'https:' : (url.substring(0,5) == 'https' ? 'https:' : 'http:');
  399. this.params = [];
  400. var params = (parts.length == 2 ? parts[1] : '').split(/[&;]/g);
  401. for (var i = 0, len = params.length, pair; i < len; i++){
  402. pair = params[i].split('=');
  403. if (pair.length != 2) continue;
  404. this.params.push({key: decodeURIComponent(pair[0]), value: decodeURIComponent(pair[1])});
  405. }
  406.  
  407. this.mimeTypes = { // list of supported mimeTypes and the regex used to test a url
  408. 'video/youtube': /(www.)?youtube|youtu\.be/i,
  409. 'video/vimeo': /(player.)?vimeo\.com/i,
  410. 'video/wistia': /(.+)?(wistia\.(com|net)|wi\.st)\/.*/i,
  411. 'video/daily': /(www.)?dailymotion\.com|dai\.ly/i,
  412. 'video/mp4': /\.mp4/i,
  413. 'video/webm': /\.webm/i,
  414. 'video/wmv': /\.wmv/i,
  415. 'video/ogg': /\.ogv/i
  416. };
  417. this.mimeType = null;
  418. for (var name in this.mimeTypes){
  419. if (this.mimeTypes.hasOwnProperty(name) && this.mimeTypes[name].test(url))
  420. this.mimeType = name;
  421. }
  422.  
  423. var ua = navigator.userAgent.toLowerCase(), ie = ua.indexOf('msie ') > -1 || ua.indexOf('trident/') > -1 || ua.indexOf('edge/') > -1, ie8orless = !document.addEventListener;
  424. this.isDirectLink = $.inArray(this.mimeType, ['video/mp4','video/wmv','video/ogg','video/webm']) !== -1;
  425. this.isBrowserSupported = this.isDirectLink ? $.inArray(this.mimeType, ie ? ie8orless ? [] : ['video/mp4','video/wmv'] : ['video/mp4','video/ogg','video/webm']) !== -1 : true;
  426.  
  427. if (this.mimeType == 'video/youtube'){
  428. this.id = /embed\//i.test(this.url)
  429. ? this.url.split(/embed\//i)[1].split(/[?&]/)[0]
  430. : url.split(/v\/|v=|youtu\.be\//i)[1].split(/[?&]/)[0];
  431. this.url = this.protocol + '//www.youtube.com/embed/' + this.id;
  432. this.param('autoplay', '1');
  433. this.param('modestbranding', '1');
  434. this.param('rel', '0');
  435. this.param('wmode', 'transparent');
  436. this.param('showinfo', '0');
  437. } else if (this.mimeType == 'video/vimeo'){
  438. this.id = this.url.substr(this.url.lastIndexOf('/')+1);
  439. this.url = this.protocol + '//player.vimeo.com/video/' + this.id;
  440. this.param('autoplay', '1');
  441. this.param('badge', '0');
  442. this.param('portrait', '0');
  443. } else if (this.mimeType == 'video/wistia'){
  444. this.id = /embed\//i.test(this.url)
  445. ? this.url.split(/embed\/.*?\//i)[1].split(/[?&]/)[0]
  446. : this.url.split(/medias\//)[1].split(/[?&]/)[0];
  447. var playlist = /playlists\//i.test(this.url);
  448. this.url = this.protocol + '//fast.wistia.net/embed/'+(playlist ? 'playlists' : 'iframe')+'/'+this.id;
  449. if (playlist) this.param('media_0_0[autoPlay]', '1');
  450. else this.param('autoPlay', '1');
  451. this.param('theme', '');
  452. } else if (this.mimeType == 'video/daily'){
  453. this.id = /\/video\//i.test(this.url)
  454. ? this.url.split(/\/video\//i)[1].split(/[?&]/)[0].split(/[_]/)[0]
  455. : url.split(/dai\.ly/i)[1].split(/[?&]/)[0];
  456. this.url = this.protocol + '//www.dailymotion.com/embed/video/' + this.id;
  457. this.param('autoplay', '1');
  458. this.param('wmode', 'opaque');
  459. this.param('info', '0');
  460. this.param('logo', '0');
  461. this.param('related', '0');
  462. }
  463. };
  464.  
  465. FP.RVSliderVideoUrl.prototype.param = function(key, value){
  466. var GET = typeof value === 'undefined', DELETE = typeof value === 'string' && value === '';
  467. for (var i = this.params.length; i-- > 0;) {
  468. if (this.params[i].key == key) {
  469. if (GET) return this.params[i].value;
  470. if (DELETE) this.params.splice(i, 1);
  471. else this.params[i].value = value;
  472. return;
  473. }
  474. }
  475. if (!GET && !DELETE) this.params.push({key: key, value: value});
  476. };
  477.  
  478. FP.RVSliderVideoUrl.prototype.toString = function(){
  479. var params = this.params.length > 0 ? '?' : '';
  480. for (var i = 0, len = this.params.length; i < len; i++){
  481. if (i != 0) params += '&';
  482. params += encodeURIComponent(this.params[i].key) + '=' + encodeURIComponent(this.params[i].value);
  483. }
  484. return this.url + params + this.hash;
  485. };
  486.  
  487. })(jQuery, window.FooPlugins = window.FooPlugins || {});
  488. (function($, FP){
  489.  
  490. FP.RVSliderPlayer = function(rvs){
  491. if (!(this instanceof FP.RVSliderPlayer)) return new FP.RVSliderPlayer(rvs);
  492. var self = this;
  493. this.rvs = rvs;
  494. this.rvs.items.$.stage.on('click.rvs', '.rvs-play-video', {self: self}, self.onPlayClick);
  495. this.$ = {
  496. container: $('<div/>', {'class': 'rvs-player'}),
  497. close: $('<a/>', {'class': 'rvs-close'}).on('click.rvs', {self: self}, self.onCloseClick),
  498. player: null
  499. };
  500. this.$.close.appendTo(self.$.container);
  501. this.continuousPlay = self.rvs.$.el.hasClass('rvs-continuous-play');
  502. this.attached = false;
  503. };
  504.  
  505. FP.RVSliderPlayer.prototype.destroy = function(){
  506. this.rvs.items.$.stage.off('click.rvs', '.rvs-play-video', self.onPlayClick);
  507. this.rvs.items.$.items.add(this.rvs.nav.$.items).removeClass('rvs-video-active');
  508. this.$.close.off('click.rvs', self.onCloseClick);
  509. this.$.container.remove();
  510. };
  511.  
  512. FP.RVSliderPlayer.prototype._parse = function(urls){
  513. if (typeof urls === 'string'){
  514. urls = urls.split(',');
  515. for (var i = 0, len = urls.length; i < len; i++){
  516. urls[i] = new FP.RVSliderVideoUrl($.trim(urls[i]));
  517. }
  518. return urls;
  519. }
  520. return [];
  521. };
  522.  
  523. FP.RVSliderPlayer.prototype._error = function(){
  524. if (this.$.player instanceof jQuery) this.$.player.remove();
  525. this.$.player = $('<div/>', {'class': 'rvs-player-error'}).append($('<span/>', {'class': 'rvs-error-icon'}));
  526. this.$.container.append(this.$.player).appendTo(this.rvs.items.$.items.filter('.rvs-active'));
  527. this.$.close.detach();
  528. this.$.container.empty().append(this.$.player);
  529. this.$.close.appendTo(this.$.container);
  530. };
  531.  
  532. FP.RVSliderPlayer.prototype._direct = function(urls){
  533. this.$.player = $('<video/>', {
  534. controls: true,
  535. preload: false
  536. }).css({ width: '100%', height: '100%' });
  537.  
  538. var self = this, player = this.$.player[0], srcs = [];
  539. function onerror(){
  540. for (var i = 0, len = srcs.length; i < len; i++){
  541. srcs[0].removeEventListener('error', onerror, false);
  542. }
  543. player.removeEventListener('error', onerror, false);
  544. player.removeEventListener('loadeddata', onloadeddata, false);
  545. self._error();
  546. }
  547.  
  548. for (var i = 0, len = urls.length, $src; i < len; i++){
  549. if (urls[i].isDirectLink){
  550. $src = $('<source/>', { type: urls[i].mimeType, src: urls[i].toString() });
  551. $src[0].addEventListener('error', onerror, false);
  552. srcs.push($src[0]);
  553. this.$.player.append($src);
  554. }
  555. }
  556.  
  557. function onloadeddata(){
  558. for (var i = 0, len = srcs.length; i < len; i++){
  559. srcs[0].removeEventListener('error', onerror, false);
  560. }
  561. player.removeEventListener('loadeddata', onloadeddata, false);
  562. player.removeEventListener('error', onerror, false);
  563. player.play();
  564. }
  565. player.addEventListener('error', onerror, false);
  566. player.addEventListener('loadeddata', onloadeddata, false);
  567.  
  568. this.$.container.append(this.$.player).appendTo(this.rvs.items.$.items.filter('.rvs-active'));
  569.  
  570. if (player.readyState < 4) player.load();
  571. else onloadeddata();
  572. };
  573.  
  574. FP.RVSliderPlayer.prototype._embed = function(url){
  575. this.$.player = $('<iframe/>', {
  576. src: url, frameborder: 'no',
  577. width: this.rvs.items.width, height: this.rvs.items.height,
  578. webkitallowfullscreen: true, mozallowfullscreen: true, allowfullscreen: true
  579. }).css({ width: '100%', height: '100%' });
  580. this.$.container.append(this.$.player).appendTo(this.rvs.items.$.items.filter('.rvs-active'));
  581. };
  582.  
  583. FP.RVSliderPlayer.prototype.setActive = function(index){
  584. if (!this.continuousPlay && this.rvs.index != index && this.attached) this.close();
  585. };
  586.  
  587. FP.RVSliderPlayer.prototype.isDirectLink = function(urls){
  588. if (!document.addEventListener) return false;
  589. for (var i = 0, len = urls.length; i < len; i++){
  590. if (urls[i].isDirectLink && urls[i].isBrowserSupported) return true;
  591. }
  592. return false;
  593. };
  594.  
  595. FP.RVSliderPlayer.prototype.play = function(urls, options){
  596. if (!urls.length) return;
  597. if (this.attached) this.close();
  598. if (this.isDirectLink(urls)){
  599. this._direct(urls, options);
  600. } else if (urls.length > 0 && !urls[0].isDirectLink) {
  601. // the iframe method used to display YouTube and Vimeo only supports a single url so we only use the url at index 0
  602. this._embed(urls[0]);
  603. } else {
  604. this._error();
  605. }
  606. this.rvs.items.$.items.add(this.rvs.nav.$.items).filter('.rvs-active').addClass('rvs-video-active');
  607. this.attached = true;
  608. };
  609.  
  610. FP.RVSliderPlayer.prototype.close = function(){
  611. if (!this.attached) return;
  612. this.$.close.detach();
  613. this.$.container.empty().detach();
  614. this.$.close.appendTo(this.$.container);
  615. this.rvs.items.$.items.add(this.rvs.nav.$.items).removeClass('rvs-video-active');
  616. this.attached = false;
  617. };
  618.  
  619. FP.RVSliderPlayer.prototype.toggle = function(){
  620. var $active = this.rvs.items.$.items.filter('.rvs-active'), $play = $active.find('.rvs-play-video');
  621. if ($active.length && !$active.hasClass('rvs-video-active')){
  622. this.play(this._parse($play.attr('href')), $play.data('options') || {});
  623. } else {
  624. this.close();
  625. }
  626. };
  627.  
  628. FP.RVSliderPlayer.prototype.onPlayClick = function(e){
  629. e.preventDefault();
  630. var $this = $(this), self = e.data.self;
  631. self.play(self._parse($this.attr('href')), $this.data('options') || {});
  632. };
  633.  
  634. FP.RVSliderPlayer.prototype.onCloseClick = function(e){
  635. e.preventDefault();
  636. e.data.self.close();
  637. };
  638.  
  639. })(jQuery, window.FooPlugins = window.FooPlugins || {});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement