1 minplayer = minplayer || {}; 2 (function(exports) { 3 /*! 4 * screenfull 5 * v1.1.1 - 2013-11-20 6 * https://github.com/sindresorhus/screenfull.js 7 * (c) Sindre Sorhus; MIT License 8 */ 9 !function(a,b){"use strict";var c="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){for(var a,c,d=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],e=0,f=d.length,g={};f>e;e++)if(a=d[e],a&&a[1]in b){for(e=0,c=a.length;c>e;e++)g[d[0][e]]=a[e];return g}return!1}(),e={request:function(a){var e=d.requestFullscreen;a=a||b.documentElement,/5\.1[\.\d]* Safari/.test(navigator.userAgent)?a[e]():a[e](c&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){b[d.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){},onerror:function(){},raw:d};return d?(Object.defineProperties(e,{isFullscreen:{get:function(){return!!b[d.fullscreenElement]}},element:{enumerable:!0,get:function(){return b[d.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!b[d.fullscreenEnabled]}}}),b.addEventListener(d.fullscreenchange,function(a){e.onchange.call(e,a)}),b.addEventListener(d.fullscreenerror,function(a){e.onerror.call(e,a)}),a.screenfull=e,void 0):(a.screenfull=!1,void 0)}(window,document);exports.screenfull = screenfull; 10 })(minplayer); 11 /** 12 * @constructor 13 * @extends minplayer.plugin 14 * @class Base class used to provide the display and options for any component 15 * deriving from this class. Components who derive are expected to provide 16 * the elements that they define by implementing the getElements method. 17 * 18 * @param {string} name The name of this plugin. 19 * @param {object} context The jQuery context this component resides. 20 * @param {object} options The options for this component. 21 * @param {object} queue The event queue to pass events around. 22 */ 23 minplayer.display = function(name, context, options, queue) { 24 25 // Derive from plugin 26 minplayer.plugin.call(this, name, context, options, queue); 27 }; 28 29 /** Derive from minplayer.plugin. */ 30 minplayer.display.prototype = new minplayer.plugin(); 31 32 /** Reset the constructor. */ 33 minplayer.display.prototype.constructor = minplayer.display; 34 35 /** 36 * Returns the display for this component. 37 * 38 * @param {object} context The context which this display is within. 39 * @param {object} options The options to get the display. 40 * 41 * @return {object} The jQuery context for this display. 42 */ 43 minplayer.display.prototype.getDisplay = function(context, options) { 44 45 // Return the context. 46 return context; 47 }; 48 49 /** 50 * @see minplayer.plugin.initialize 51 */ 52 minplayer.display.prototype.initialize = function() { 53 54 // Only set the display if it hasn't already been set. 55 if (!this.display) { 56 57 // Set the display. 58 this.display = this.getDisplay(this.context, this.options); 59 } 60 61 // Only continue loading this plugin if there is a display. 62 if (this.display) { 63 64 // Set the plugin name within the options. 65 this.options.pluginName = 'display'; 66 67 // Get the display elements. 68 this.elements = this.getElements(); 69 70 // Call the plugin initialize method. 71 minplayer.plugin.prototype.initialize.call(this); 72 } 73 }; 74 75 /** 76 * @see minplayer.plugin.construct 77 */ 78 minplayer.display.prototype.construct = function() { 79 80 // Call the plugin constructor. 81 minplayer.plugin.prototype.construct.call(this); 82 83 // Set if this display is in autohide. 84 this.autoHide = false; 85 86 // Only do this if they allow resize for this display. 87 if (this.onResize) { 88 89 // Set the resize timeout and this pointer. 90 var resizeTimeout = 0; 91 92 // Add a handler to trigger a resize event. 93 jQuery(window).resize((function(display) { 94 return function() { 95 clearTimeout(resizeTimeout); 96 resizeTimeout = setTimeout(function() { 97 display.onResize(); 98 }, 200); 99 }; 100 })(this)); 101 } 102 }; 103 104 /** 105 * Called when the window resizes. 106 */ 107 minplayer.display.prototype.onResize = false; 108 109 /** 110 * Wrapper around hide that will always not show. 111 * 112 * @param {object} element The element you wish to hide. 113 */ 114 minplayer.display.prototype.hide = function(element) { 115 element = element || this.display; 116 if (element) { 117 element.forceHide = true; 118 element.unbind().hide(); 119 } 120 }; 121 122 /** 123 * Gets the full screen element. 124 * 125 * @return {object} The display to be used for full screen support. 126 */ 127 minplayer.display.prototype.fullScreenElement = function() { 128 return this.display; 129 }; 130 131 /** 132 * Fix for the click function in jQuery to be cross platform. 133 * 134 * @param {object} element The element that will be clicked. 135 * @param {function} fn Called when the element is clicked. 136 * @return {object} The element that is to be clicked. 137 */ 138 minplayer.click = function(element, fn) { 139 var flag = false; 140 element = jQuery(element); 141 element.bind('touchstart click', function(event) { 142 if (!flag) { 143 flag = true; 144 setTimeout(function() { 145 flag = false; 146 }, 100); 147 fn.call(this, event); 148 } 149 }); 150 return element; 151 }; 152 153 /** 154 * Determines if the player is in focus or not. 155 * 156 * @param {boolean} focus If the player is in focus. 157 */ 158 minplayer.display.prototype.onFocus = function(focus) { 159 this.hasFocus = this.focus = focus; 160 161 // If they have autoHide enabled, then show then hide this element. 162 if (this.autoHide) { 163 this.showThenHide( 164 this.autoHide.element, 165 this.autoHide.timeout, 166 this.autoHide.cb 167 ); 168 } 169 }; 170 171 /** 172 * Called if you would like for your plugin to show then hide. 173 * 174 * @param {object} element The element you would like to hide or show. 175 * @param {number} timeout The timeout to hide and show. 176 * @param {function} cb Called when something happens. 177 */ 178 minplayer.display.prototype.showThenHide = function(element, timeout, cb) { 179 180 // Get the element type. 181 var elementType = (typeof element); 182 183 // Set some interface defaults. 184 if (elementType === 'undefined') { 185 cb = null; 186 element = this.display; 187 } 188 else if (elementType === 'number') { 189 cb = timeout; 190 timeout = element; 191 element = this.display; 192 } 193 else if (elementType === 'function') { 194 cb = element; 195 element = this.display; 196 } 197 198 if (!element) { 199 return; 200 } 201 202 // Make sure we have a timeout. 203 timeout = timeout || 5000; 204 205 // Set the autohide variable. 206 this.autoHide = { 207 element: element, 208 timeout: timeout, 209 cb: cb 210 }; 211 212 // Show the element. 213 if (!element.forceHide) { 214 if (typeof element.showMe !== 'undefined') { 215 if (element.showMe) { 216 element.showMe(cb); 217 } 218 } 219 else { 220 element.show(); 221 if (cb) { 222 cb(true); 223 } 224 } 225 } 226 227 // Define the hover state for this element. 228 if (!element.hoverState) { 229 jQuery(element).bind('mouseenter', function() { 230 element.hoverState = true; 231 }); 232 jQuery(element).bind('mouseleave', function() { 233 element.hoverState = false; 234 }); 235 } 236 237 // Clear the timeout and start it over again. 238 clearTimeout(this.showTimer); 239 this.showTimer = setTimeout((function(self) { 240 return function tryAgain() { 241 242 // Check the hover state. 243 if (!element.hoverState) { 244 if (typeof element.hideMe !== 'undefined') { 245 if (element.hideMe) { 246 element.hideMe(cb); 247 } 248 } 249 else { 250 // Hide the element. 251 element.hide('slow', function() { 252 if (cb) { 253 cb(false); 254 } 255 }); 256 } 257 } 258 else { 259 260 // Try again in the timeout time. 261 self.showTimer = setTimeout(tryAgain, timeout); 262 } 263 }; 264 })(this), timeout); 265 }; 266 267 /** 268 * Make this display element go fullscreen. 269 * 270 * @param {boolean} full Tell the player to go into fullscreen or not. 271 */ 272 minplayer.display.prototype.fullscreen = function(full) { 273 var isFull = this.isFullScreen(); 274 var element = this.fullScreenElement(); 275 if (isFull && !full) { 276 element.removeClass('fullscreen'); 277 if (minplayer.screenfull) { 278 minplayer.screenfull.exit(); 279 } 280 this.trigger('fullscreen', false); 281 } 282 else if (!isFull && full) { 283 element.addClass('fullscreen'); 284 if (minplayer.screenfull) { 285 minplayer.screenfull.request(element[0]); 286 minplayer.screenfull.onchange = (function(display) { 287 return function(e) { 288 if (!minplayer.screenfull.isFullscreen) { 289 display.fullscreen(false); 290 } 291 }; 292 })(this); 293 } 294 this.trigger('fullscreen', true); 295 } 296 }; 297 298 /** 299 * Toggle fullscreen. 300 */ 301 minplayer.display.prototype.toggleFullScreen = function() { 302 this.fullscreen(!this.isFullScreen()); 303 }; 304 305 /** 306 * Checks to see if we are in fullscreen mode. 307 * 308 * @return {boolean} TRUE - fullscreen, FALSE - otherwise. 309 */ 310 minplayer.display.prototype.isFullScreen = function() { 311 return this.fullScreenElement().hasClass('fullscreen'); 312 }; 313 314 /** 315 * Returns a scaled rectangle provided a ratio and the container rect. 316 * 317 * @param {number} ratio The width/height ratio of what is being scaled. 318 * @param {object} rect The bounding rectangle for scaling. 319 * @return {object} The Rectangle object of the scaled rectangle. 320 */ 321 minplayer.display.prototype.getScaledRect = function(ratio, rect) { 322 var scaledRect = {}; 323 scaledRect.x = rect.x ? rect.x : 0; 324 scaledRect.y = rect.y ? rect.y : 0; 325 scaledRect.width = rect.width ? rect.width : 0; 326 scaledRect.height = rect.height ? rect.height : 0; 327 if (ratio) { 328 if ((rect.width / rect.height) > ratio) { 329 scaledRect.height = rect.height; 330 scaledRect.width = Math.floor(rect.height * ratio); 331 } 332 else { 333 scaledRect.height = Math.floor(rect.width / ratio); 334 scaledRect.width = rect.width; 335 } 336 scaledRect.x = Math.floor((rect.width - scaledRect.width) / 2); 337 scaledRect.y = Math.floor((rect.height - scaledRect.height) / 2); 338 } 339 return scaledRect; 340 }; 341 342 /** 343 * Returns all the jQuery elements that this component uses. 344 * 345 * @return {object} An object which defines all the jQuery elements that 346 * this component uses. 347 */ 348 minplayer.display.prototype.getElements = function() { 349 return {}; 350 }; 351