-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwddatabinder_min.js
21 lines (19 loc) · 5.44 KB
/
gwddatabinder_min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(function(){/*
Copyright The Closure Library Authors.
SPDX-License-Identifier: Apache-2.0
*/
'use strict';var h,k="function"==typeof Object.create?Object.create:function(a){function b(){}b.prototype=a;return new b},m;if("function"==typeof Object.setPrototypeOf)m=Object.setPrototypeOf;else{var n;a:{var p={a:!0},q={};try{q.__proto__=p;n=q.a;break a}catch(a){}n=!1}m=n?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var r=m;function t(a,b){if(a&&Array.isArray(a)){var c=b?b.split("."):[""];return a.map(function(e){if(1==c.length)return e[c[0]];var d=e;c.forEach(function(f){d&&(d=d[f])});return d})}return[]}function u(a,b){return a&&Array.isArray(a)?a.join(b||","):""}
var v={hex:function(a){return a?a.replace(/0x/,"#"):a},limit:function(a,b){return b?a&&Array.isArray(a)&&("string"==typeof b&&(b=parseInt(b,10)),!isNaN(b))?a.slice(0,b):a:a},lowercase:function(a){return a?a.toLowerCase():a},join:u,pixelvalue:function(a){if("undefined"!=typeof a)return a+"px"},pluck:t,pluckandjoin:function(a,b){return u(t(a,b))},uppercase:function(a){return a?a.toUpperCase():a}};function w(a,b,c){if("undefined"!=typeof c){var e=document.querySelector("gwd-text-helper");e&&e.saveStyleOverride(a,b,c);a.style[b]=c}}function x(a,b,c){c?a.classList.add(b):a.classList.remove(b)}function y(a,b){if("undefined"!=typeof b){var c=document.querySelector("gwd-text-helper");c&&c.saveInitialText(a);a.textContent=b;c&&c.applyStylePreservation(a)}}function z(a,b){a.style.display=!b||"string"==typeof b&&"false"==b.toLowerCase()?"none":""}
function A(a,b,c){"undefined"!==typeof c&&c!==a.getAttribute(b)&&a.setAttribute(b,c)};var B=RegExp("^bind-"),C=RegExp("^style-"),D=RegExp("^class-"),E=RegExp("^each-"),F=RegExp("-([a-z])","g");function G(a,b,c){c=void 0===c?null:c;var e=document.createEvent("CustomEvent");e.initCustomEvent(a,!0,!0,c);b.dispatchEvent(e)};function H(a){return String(a).replace(F,function(b,c){return c.toUpperCase()})}function I(a){return!(!a||!B.test(a.name))}function J(a){return!(!a||0!=a.name.indexOf("bind-each"))}function K(){var a=HTMLElement.call(this)||this;a.v=null;a.l=!1;a.g=null;a.j=a.u.bind(a);return a}var L=HTMLElement;K.prototype=k(L.prototype);K.prototype.constructor=K;
if(r)r(K,L);else for(var M in L)if("prototype"!=M)if(Object.defineProperties){var N=Object.getOwnPropertyDescriptor(L,M);N&&Object.defineProperty(K,M,N)}else K[M]=L[M];h=K.prototype;h.disconnectedCallback=function(){O(this)};
h.bindData=function(a,b){b=b||Array.prototype.slice.call(this.ownerDocument.querySelectorAll("*"));var c=(c=this.ownerDocument.querySelector("meta[name=environment]"))?c.getAttribute("content"):"";this.l="gwd-adwords"==c||"gwd-googleads"==c;this.v=a;O(this);(this.g=this.ownerDocument.querySelector("gwd-font-loader"))&&this.g.startDynamicFontLoading();b.forEach(this.h.bind(this,a));a=!0;this.g&&((a=this.g.endDynamicFontLoading())||this.g.addEventListener("gwdfontsloaded",this.j));return a};
h.h=function(a,b){if(!b.hasAttribute("gwd-bind-each-template")){for(var c,e=Array.prototype.slice.call(b.attributes),d=0;d<e.length;d++)if(J(e[d])){c=e[d];break}a=this.o.bind(this,b,a);c?a(c):e.filter(I).forEach(a)}};
h.o=function(a,b,c){var e=c.name,d=e.replace(B,"");if(C.test(d)){var f=d.replace(C,"");f=w.bind(null,a,H(f))}else D.test(d)?(f=d.replace(D,""),f=x.bind(null,a,f)):E.test(d)?(f=d.replace(E,""),f=this.m.bind(this,a,f,b)):f="text"===d?y.bind(null,a):"show"===d?z.bind(null,a):window.gwd&&window.gwd.binders&&"function"==typeof window.gwd.binders[d]?window.gwd.binders[d].bind(null,a):A.bind(null,a,d);e=a.getAttribute(e);b=(-1!==e.indexOf("|")?this.s.bind(this,b,e):this.i.bind(this,b,e)).call(a);"style-font-family"==
d&&this.g&&(b=this.g.parseFontList(b));"exit-override-url"==d&&(d=(d=c.value)&&d.match(/product\.\d+/i)?(d=d.match(/product\.(\d+)/i))&&d[1]?parseInt(d[1],10):null:null,null!=d&&a.setAttribute("product-index",d),this.l&&a.setAttribute("exit-id",c.value.replace(/\./g,"_")));f.apply(a,[b])};
h.m=function(a,b,c,e){var d=a.parentNode;if(d){for(var f=a.cloneNode(!0),l=Array.prototype.slice.call(f.attributes).filter(J),g=0;g<l.length;g++)f.removeAttribute(l[g].name);l=[];for(g=0;e&&g<e.length;g++)l.push(f.cloneNode(!0));G("gwdbindeachcloned",a,{instances:l});f=this.ownerDocument.createComment("gwd-bind-each-placeholder");d.insertBefore(f,a);d.removeChild(a);P(a);if(e&&0!=e.length){for(a=0;a<e.length;a++)c[b]=e[a],g=l[a],g.setAttribute("gwd-repeat-index",a),c.$index=a,Array.prototype.slice.call(g.querySelectorAll("*")).concat(g).forEach(this.h.bind(this,
c)),d.insertBefore(g,f);delete c[b]}}};function P(a){a.setAttribute("gwd-bind-each-template","");Array.prototype.slice.call(a.querySelectorAll("*")).forEach(function(b){b.setAttribute("gwd-bind-each-template","")})}h.i=function(a,b){if(a){if(b){b=b.replace("[",".");b=b.replace("]","");var c=a;b.split(".").forEach(function(e){c&&(c=c[e])});return c}return a}};
h.s=function(a,b){if(!b)return a;b=b.split("|");var c=b.shift().trim();a=this.i(a,c);if("undefined"!=typeof a){for(c=0;c<b.length;c++)a=Q(this,a,b[c].trim());return a}};function Q(a,b,c){c=c.split(" ").map(function(f){return f.trim()});var e=c.shift(),d=v[e];c.unshift(b);return d?d.apply(null,c):window.gwd&&window.gwd.formatters&&"function"==typeof window.gwd.formatters[e]?window.gwd.formatters[e].apply(a,c):b}h.u=function(){O(this);G("bindingfinished",this)};
function O(a){a.g&&(a.g.removeEventListener("gwdfontsloaded",a.j),a.g=null)}customElements.define("gwd-data-binder",K);/*
SPDX-License-Identifier: Apache-2.0
*/
}).call(this);