mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-22 11:42:05 +00:00
15 lines
7.0 KiB
JavaScript
15 lines
7.0 KiB
JavaScript
(function(){'use strict';var e,k=function(a){if("function"==typeof a.gwdLoad&&"function"==typeof a.gwdIsLoaded&&!a.gwdIsLoaded()){var b=h(a),c=b&&"function"==typeof b.gwdIsLoaded;(!b||c&&b.gwdIsLoaded())&&a.gwdLoad()}},l=function(a){if(null==a.gwdActivate||"function"==typeof a.gwdActivate)if(null==a.gwdIsActive||!a.gwdIsActive()){var b=h(a),c=b&&null!=b.gwdIsActive&&"function"==typeof b.gwdIsActive;null==b&&a.gwdActivate();c&&b.gwdIsActive()&&a.gwdActivate()}},m=function(a){return"gwd-page"==a.tagName.toLowerCase()||
|
|
"gwd-page"==a.getAttribute("is")},h=function(a){if(m(a))return a;for(;a&&9!=a.nodeType;)if((a=a.parentElement)&&m(a))return a;return null},n=function(a){for(var b=[];a;a=a.parentNode)b.unshift(a);return b},p=function(a,b,c){var d=d||b;a.hasAttribute(b)?(a=a.getAttribute(b),c.setAttribute(d,a)):c.removeAttribute(d)};var q=function(a,b){setTimeout(a,b)};var r=function(a,b,c){if(c){var d=document.createEvent("CustomEvent");d.initCustomEvent(a,!0,!0,c)}else d=document.createEvent("Event"),d.initEvent(a,!0,!0);b.dispatchEvent(d)},t=function(a,b){var c=function(d){a.removeEventListener("playing",c);b(d)};a.addEventListener("playing",c)};var u={v:"fullscreenchange",A:"webkitfullscreenchange",w:"mozfullscreenchange"},v={v:"fullscreenElement",A:"webkitFullscreenElement",w:"mozFullScreenElement"},w=function(a){var b;for(b in v){var c=a[v[b]];if(void 0!==c)break}return c||null},x=function(a){var b=document;this.g="has-fullscreen-gwd-video";this.b=b;this.c=a;this.o=this.C.bind(this)};
|
|
x.prototype.C=function(){var a=w(this.b);if(a)if(this.c==a){var b=this.b;for(a=this.c;a&&a!=b;a=a.parentNode)a.classList.add(this.g)}else if(a.classList.contains(this.g)){b=n(this.c);a=n(a);for(var c=0,d=b[0],g=a[0],f=null;d&&g&&d==g;)f=d,c++,d=b[c],g=a[c];y(this,f)}else y(this);else y(this)};x.prototype.install=function(){for(var a in u)this.b.addEventListener(u[a],this.o)};var y=function(a,b){b=b||a.b;for(var c=a.c;c&&c!=b;c=c.parentNode)c.classList.remove(a.g)};var z="abort canplay canplaythrough durationchange emptied ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),A="autoplay loop muted sources controls poster".split(" "),B={".avi":1,".m4v":1,".mp4":1,".mpeg":1,".mpg":1,".ogg":1,".ogv":1,".qt":1,".webm":1,".wmv":1},C=function(){};goog.inherits(C,HTMLElement);e=C.prototype;
|
|
e.createdCallback=function(){for(var a;a=this.firstChild;)this.removeChild(a);this.a=document.createElement("video");this.u=this.B.bind(this);this.m=function(a){r(a.type,this,a.detail)}.bind(this);this.s=new x(this.a);this.h=this.i=!1;for(a=0;a<A.length;a++)p(this,A[a],this.a);this.a.setAttribute("webkit-playsinline","");this.a.setAttribute("playsinline","");this.a.setAttribute("x-webkit-airplay","allow");this.l=1;this.j=!1;a=document.createElement("div");a.classList.add("intermediate-element");a.appendChild(this.a);
|
|
this.appendChild(a);Object.defineProperty(this,"nativeElement",{enumerable:!0,get:function(){return this.a}});Object.defineProperty(this,"autoplay",{enumerable:!0,get:function(){return this.a.autoplay},set:function(a){a?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}});Object.defineProperty(this,"loop",{enumerable:!0,get:function(){return this.a.loop},set:function(a){a?this.setAttribute("loop",""):this.removeAttribute("loop")}});Object.defineProperty(this,"muted",{enumerable:!0,
|
|
get:function(){return this.hasAttribute("muted")},set:function(a){a?this.setAttribute("muted",""):this.removeAttribute("muted")}});this.a.muted=this.muted;Object.defineProperty(this,"controls",{enumerable:!0,get:function(){return this.a.controls},set:function(a){a?this.setAttribute("controls",""):this.removeAttribute("controls")}});Object.defineProperty(this,"poster",{enumerable:!0,get:function(){return this.a.poster},set:function(a){a?this.setAttribute("poster",a):this.removeAttribute("poster")}});
|
|
Object.defineProperty(this,"paused",{enumerable:!0,get:function(){return this.a.paused}});Object.defineProperty(this,"volume",{enumerable:!0,get:function(){return this.a.volume},set:function(a){this.a.volume=a}});Object.defineProperty(this,"currentTime",{enumerable:!0,get:function(){return this.a.currentTime},set:function(a){this.a.currentTime=a}});Object.defineProperty(this,"duration",{enumerable:!0,get:function(){return this.a.duration}});Object.defineProperty(this,"width",{enumerable:!0,get:function(){return this.a.width},
|
|
set:function(a){a&&(this.a.width=a)}});Object.defineProperty(this,"height",{enumerable:!0,get:function(){return this.a.height},set:function(a){a&&(this.a.height=a)}});Object.defineProperty(this,"videoWidth",{enumerable:!0,get:function(){return this.a.videoWidth}});Object.defineProperty(this,"videoHeight",{enumerable:!0,get:function(){return this.a.videoHeight}});this.f=this.muted&&-1!=(window.navigator.userAgent||"").indexOf("Android")};
|
|
e.attachedCallback=function(){k(this);l(this);this.f&&t(this.a,function(){this.f&&(this.a.volume=0)}.bind(this));this.a.addEventListener("volumechange",this.u,!1);for(var a=0;a<z.length;a++)this.a.addEventListener(z[a],this.m,!1);this.s.install()};e.detachedCallback=function(){var a=this.s,b;for(b in u)a.b.removeEventListener(u[b],a.o);a.c==w(a.b)&&y(a);this.f&&(this.a.volume=1);this.a.removeEventListener("volumechange",this.u,!1);for(a=0;a<z.length;a++)this.a.removeEventListener(z[a],this.m,!1)};
|
|
e.attributeChangedCallback=function(a){if("sources"==a){if(this.i){var b=this.a.paused,c=this.muted;D(this);this.a.load();q(function(){this.muted=c;b?this.pause():this.play()}.bind(this),0)}}else"muted"==a&&(this.a.muted=this.muted);"class"!=a&&p(this,a,this.a)};e.gwdActivate=function(){this.autoplay&&this.a.paused&&q(function(){this.play()}.bind(this),200);this.h=!0};e.gwdDeactivate=function(){this.hasAttribute("resumable")||this.seek(0);this.pause();this.h=!1};e.gwdIsActive=function(){return this.h};
|
|
e.gwdLoad=function(){D(this);this.i=!0;r("ready",this)};e.gwdIsLoaded=function(){return this.i};e.mute=function(){this.f&&(this.a.volume=1);this.f=!1;this.muted=!this.muted};e.replay=function(){this.seek(0);this.play()};e.seek=function(a){this.currentTime!=a&&(this.currentTime=a)};e.B=function(){!1===this.j&&!0===this.muted&&0===this.l&&(this.a.volume=1,this.muted=!1);this.l=this.a.volume;this.j=this.muted};
|
|
e.setVolume=function(a){this.muted=0<a?!1:!0;this.a.volume=a/100;this.l=this.a.volume;this.j=this.muted};e.setSources=function(a){this.setAttribute("sources",a)};e.play=function(){this.a.play()};e.pause=function(){this.a.pause()};
|
|
var D=function(a){var b=a.getAttribute("sources");b=E(b);for(var c;c=a.a.firstChild;)a.a.removeChild(c);for(c=0;c<b.length;++c){var d=document.createElement("source"),g=d;var f=b[c];f=f.trim();f=window.Enabler?Enabler.getUrl(f):f;g.src=f;a.a.appendChild(d)}},E=function(a){var b=[];if(!a)return b;a=a.split(",").map(function(a){return a.trim()});for(var c="",d=0;d<a.length;d++){var g=a[d];c+=g;var f=g.lastIndexOf(".");-1!=f?B[g.substring(f).toLowerCase()]?(b.push(c),c=""):c+=",":c+=","}c&&b.push(c.substring(0,
|
|
c.length-1));return b};document.registerElement("gwd-video",{prototype:C.prototype});}).call(this);
|