1/* 2 * blueimp Gallery Video Factory JS 1.1.1 3 * https://github.com/blueimp/Gallery 4 * 5 * Copyright 2013, Sebastian Tschan 6 * https://blueimp.net 7 * 8 * Licensed under the MIT license: 9 * http://www.opensource.org/licenses/MIT 10 */ 11 12/* global define, window, document */ 13 14(function (factory) { 15 'use strict'; 16 if (typeof define === 'function' && define.amd) { 17 // Register as an anonymous AMD module: 18 define([ 19 './blueimp-helper', 20 './blueimp-gallery' 21 ], factory); 22 } else { 23 // Browser globals: 24 factory( 25 window.blueimp.helper || window.jQuery, 26 window.blueimp.Gallery 27 ); 28 } 29}(function ($, Gallery) { 30 'use strict'; 31 32 $.extend(Gallery.prototype.options, { 33 // The class for video content elements: 34 videoContentClass: 'video-content', 35 // The class for video when it is loading: 36 videoLoadingClass: 'video-loading', 37 // The class for video when it is playing: 38 videoPlayingClass: 'video-playing', 39 // The list object property (or data attribute) for the video poster URL: 40 videoPosterProperty: 'poster', 41 // The list object property (or data attribute) for the video sources array: 42 videoSourcesProperty: 'sources' 43 }); 44 45 var handleSlide = Gallery.prototype.handleSlide; 46 47 $.extend(Gallery.prototype, { 48 49 handleSlide: function (index) { 50 handleSlide.call(this, index); 51 if (this.playingVideo) { 52 this.playingVideo.pause(); 53 } 54 }, 55 56 videoFactory: function (obj, callback, videoInterface) { 57 var that = this, 58 options = this.options, 59 videoContainerNode = this.elementPrototype.cloneNode(false), 60 videoContainer = $(videoContainerNode), 61 errorArgs = [{ 62 type: 'error', 63 target: videoContainerNode 64 }], 65 video = videoInterface || document.createElement('video'), 66 url = this.getItemProperty(obj, options.urlProperty), 67 type = this.getItemProperty(obj, options.typeProperty), 68 title = this.getItemProperty(obj, options.titleProperty), 69 posterUrl = this.getItemProperty(obj, options.videoPosterProperty), 70 posterImage, 71 sources = this.getItemProperty( 72 obj, 73 options.videoSourcesProperty 74 ), 75 source, 76 playMediaControl, 77 isLoading, 78 hasControls; 79 videoContainer.addClass(options.videoContentClass); 80 if (title) { 81 videoContainerNode.title = title; 82 } 83 if (video.canPlayType) { 84 if (url && type && video.canPlayType(type)) { 85 video.src = url; 86 } else { 87 while (sources && sources.length) { 88 source = sources.shift(); 89 url = this.getItemProperty(source, options.urlProperty); 90 type = this.getItemProperty(source, options.typeProperty); 91 if (url && type && video.canPlayType(type)) { 92 video.src = url; 93 break; 94 } 95 } 96 } 97 } 98 if (posterUrl) { 99 video.poster = posterUrl; 100 posterImage = this.imagePrototype.cloneNode(false); 101 $(posterImage).addClass(options.toggleClass); 102 posterImage.src = posterUrl; 103 posterImage.draggable = false; 104 videoContainerNode.appendChild(posterImage); 105 } 106 playMediaControl = document.createElement('a'); 107 playMediaControl.setAttribute('target', '_blank'); 108 if (!videoInterface) { 109 playMediaControl.setAttribute('download', title); 110 } 111 playMediaControl.href = url; 112 if (video.src) { 113 video.controls = true; 114 (videoInterface || $(video)) 115 .on('error', function () { 116 that.setTimeout(callback, errorArgs); 117 }) 118 .on('pause', function () { 119 isLoading = false;
120 videoContainer 121 .removeClass(that.options.videoLoadingClass) 122 .removeClass(that.options.videoPlayingClass); 123 if (hasControls) { 124 that.container.addClass(that.options.controlsClass); 125 } 126 delete that.playingVideo; 127 if (that.interval) { 128 that.play(); 129 } 130 }) 131 .on('playing', function () { 132 isLoading = false; 133 videoContainer 134 .removeClass(that.options.videoLoadingClass) 135 .addClass(that.options.videoPlayingClass); 136 if (that.container.hasClass(that.options.controlsClass)) { 137 hasControls = true; 138 that.container.removeClass(that.options.controlsClass); 139 } else { 140 hasControls = false; 141 } 142 }) 143 .on('play', function () { 144 window.clearTimeout(that.timeout); 145 isLoading = true; 146 videoContainer.addClass(that.options.videoLoadingClass); 147 that.playingVideo = video; 148 }); 149 $(playMediaControl).on('click', function (event) { 150 that.preventDefault(event); 151 if (isLoading) { 152 video.pause(); 153 } else { 154 video.play(); 155 } 156 }); 157 videoContainerNode.appendChild( 158 (videoInterface && videoInterface.element) || video 159 ); 160 } 161 videoContainerNode.appendChild(playMediaControl); 162 this.setTimeout(callback, [{ 163 type: 'load', 164 target: videoContainerNode 165 }]); 166 return videoContainerNode; 167 } 168 }); 169 170 return Gallery; 171}));
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.