-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwdimage_min.js
5 lines (5 loc) · 2.32 KB
/
gwdimage_min.js
1
2
3
4
5
(function(){'use strict';var c=function(a){return"gwd-page"==a.tagName.toLowerCase()||"gwd-page"==a.getAttribute("is")},e=function(a){if(c(a))return a;for(;a&&9!=a.nodeType;)if((a=a.parentElement)&&c(a))return a;return null};var f=function(a,b){var d=document.createEvent("Event");d.initEvent(a,!0,!0);b.dispatchEvent(d)};var g=function(){};goog.inherits(g,HTMLImageElement);g.prototype.createdCallback=function(){this.f=this.g.bind(this);this.a=0;this.b=this.c=-1;Object.defineProperty(this,"assetWidth",{enumerable:!0,get:function(){return this.c}});Object.defineProperty(this,"assetHeight",{enumerable:!0,get:function(){return this.b}});var a=this.getAttribute("src");a&&(this.setAttribute("source",a),this.removeAttribute("src"));this.addEventListener("load",this.f,!1);this.addEventListener("error",this.f,!1)};
g.prototype.attachedCallback=function(){if("function"==typeof this.gwdLoad&&"function"==typeof this.gwdIsLoaded&&!this.gwdIsLoaded()){var a=e(this),b=a&&"function"==typeof a.gwdIsLoaded;(!a||b&&a.gwdIsLoaded())&&this.gwdLoad()}};g.prototype.gwdIsLoaded=function(){return 2==this.a||3==this.a};g.prototype.gwdLoad=function(){var a=this.getAttribute("source");a?(this.a=1,this.setAttribute("src",a)):f("load",this)};
g.prototype.g=function(a){a&&"error"==a.type?(this.a=3,this.b=this.c=-1):(-1!=this.c&&-1!=this.b||!this.getAttribute("source")||(this.c=this.naturalWidth,this.b=this.naturalHeight),this.a=2);h(this);k(this);f("ready",this)};
var k=function(a){if(2==a.a){var b=a.getAttribute("source"),d=a.getAttribute("scaling")||"stretch";b&&("stretch"!=d?(a.classList.add("scaled-proportionally"),a.style.backgroundImage="url("+JSON.stringify(b)+")",a.style.backgroundSize="none"!=d?d:"auto","data:image/gif;base64,R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="!=a.getAttribute("src")&&a.setAttribute("src","data:image/gif;base64,R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")):(a.classList.remove("scaled-proportionally"),
a.style.backgroundImage="",b!=a.getAttribute("src")&&a.setAttribute("src",b)))}},h=function(a){var b=a.getAttribute("alignment")||"center";a.style.backgroundPosition=b};g.prototype.attributeChangedCallback=function(a){"source"==a&&0!==this.a&&this.gwdLoad();"scaling"==a&&k(this);"alignment"==a&&h(this)};document.registerElement("gwd-image",{prototype:g.prototype,"extends":"img"});}).call(this);