-
Notifications
You must be signed in to change notification settings - Fork 76
/
bigscreen.min.js
2 lines (2 loc) · 4.33 KB
/
bigscreen.min.js
1
2
// BigScreen v2.0.5 - 2015-05-02 - MIT License
!function(a,b,c){"use strict";function d(a){var b=null;if("VIDEO"===a.tagName)b=a;else{var c=a.getElementsByTagName("video");c[0]&&(b=c[0])}return b}function e(a){var b=d(a);if(b&&b.webkitEnterFullscreen){try{b.readyState<b.HAVE_METADATA?(b.addEventListener("loadedmetadata",function e(){b.removeEventListener("loadedmetadata",e,!1),b.webkitEnterFullscreen(),l=!!b.getAttribute("controls")},!1),b.load()):(b.webkitEnterFullscreen(),l=!!b.getAttribute("controls")),k=b}catch(c){return r("not_supported",a)}return!0}return r(void 0===j.request?"not_supported":"not_enabled",a)}function f(){s.element||(q(),h())}function g(){c&&"webkitfullscreenchange"===j.change&&window.addEventListener("resize",f,!1)}function h(){c&&"webkitfullscreenchange"===j.change&&window.removeEventListener("resize",f,!1)}var i=/i(Pad|Phone|Pod)/.test(navigator.userAgent)&&parseInt(navigator.userAgent.replace(/^.*OS (\d+)_(\d+).*$/,"$1.$2"),10)>=7,j=function(){var a=b.createElement("video"),c={request:["requestFullscreen","webkitRequestFullscreen","webkitRequestFullScreen","mozRequestFullScreen","msRequestFullscreen"],exit:["exitFullscreen","webkitCancelFullScreen","webkitExitFullscreen","mozCancelFullScreen","msExitFullscreen"],enabled:["fullscreenEnabled","webkitFullscreenEnabled","mozFullScreenEnabled","msFullscreenEnabled"],element:["fullscreenElement","webkitFullscreenElement","webkitCurrentFullScreenElement","mozFullScreenElement","msFullscreenElement"],change:["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange"],error:["fullscreenerror","webkitfullscreenerror","mozfullscreenerror","MSFullscreenError"]},d={};for(var e in c)for(var f=0,g=c[e].length;g>f;f++)if(c[e][f]in a||c[e][f]in b||"on"+c[e][f].toLowerCase()in b){d[e]=c[e][f];break}return d}(),k=null,l=null,m=function(){},n=[],o=!1;navigator.userAgent.indexOf("Android")>-1&&navigator.userAgent.indexOf("Chrome")>-1&&(o=parseInt(navigator.userAgent.replace(/^.*Chrome\/(\d+).*$/,"$1"),10)||!0);var p=function(a){var b=n[n.length-1];b&&(a!==b.element&&a!==k||!b.hasEntered)&&("VIDEO"===a.tagName&&(k=a),1===n.length&&s.onenter(s.element),b.enter.call(b.element,a||b.element),b.hasEntered=!0)},q=function(){!k||l||i||(k.setAttribute("controls","controls"),k.removeAttribute("controls")),k=null,l=null;var a=n.pop();a&&(a.exit.call(a.element),s.element||(n.forEach(function(a){a.exit.call(a.element)}),n=[],s.onexit()))},r=function(a,b){if(n.length>0){var c=n.pop();b=b||c.element,c.error.call(b,a),s.onerror(b,a)}},s={request:function(a,d,f,g){if(a=a||b.body,n.push({element:a,enter:d||m,exit:f||m,error:g||m}),void 0===j.request)return void e(a);if(c&&b[j.enabled]===!1)return void e(a);if(o!==!1&&32>o)return void e(a);if(c&&void 0===j.enabled)return j.enabled="webkitFullscreenEnabled",a[j.request](),void setTimeout(function(){b[j.element]?b[j.enabled]=!0:(b[j.enabled]=!1,e(a))},250);try{a[j.request](),setTimeout(function(){b[j.element]||r(c?"not_enabled":"not_allowed",a)},100)}catch(h){r("not_enabled",a)}},exit:function(){h(),b[j.exit]()},toggle:function(a,b,c,d){s.element?s.exit():s.request(a,b,c,d)},videoEnabled:function(a){if(s.enabled)return!0;a=a||b.body;var c=d(a);return c&&void 0!==c.webkitSupportsFullscreen?c.readyState<c.HAVE_METADATA?"maybe":c.webkitSupportsFullscreen:!1},onenter:m,onexit:m,onchange:m,onerror:m};try{Object.defineProperties(s,{element:{enumerable:!0,get:function(){return k&&k.webkitDisplayingFullscreen?k:b[j.element]||null}},enabled:{enumerable:!0,get:function(){return"webkitCancelFullScreen"!==j.exit||c?o!==!1&&32>o?!1:b[j.enabled]||!1:!0}}}),j.change&&b.addEventListener(j.change,function(a){if(s.onchange(s.element),s.element){var b=n[n.length-2];b&&b.element===s.element?q():(p(s.element),g())}else q()},!1),b.addEventListener("webkitbeginfullscreen",function(a){var b=!0;if(n.length>0)for(var c=0,e=n.length;e>c;c++){var f=d(n[c].element);if(f===a.srcElement){b=!1;break}}b&&n.push({element:a.srcElement,enter:m,exit:m,error:m}),s.onchange(a.srcElement),p(a.srcElement)},!0),b.addEventListener("webkitendfullscreen",function(a){s.onchange(a.srcElement),q(a.srcElement)},!0),j.error&&b.addEventListener(j.error,function(a){r("not_allowed")},!1)}catch(t){s.element=null,s.enabled=!1}"function"==typeof define&&define.amd?define(function(){return s}):"undefined"!=typeof module&&module.exports?module.exports=s:a.BigScreen=s}(this,document,self!==top);