-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHypeDataDecorator.min.js
12 lines (12 loc) · 3.83 KB
/
HypeDataDecorator.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
Hype Data Decorator 1.2.8
copyright (c) 2019-2021 Max Ziebell, (https://maxziebell.de). MIT-license
*/
!1==="HypeDataDecorator"in window&&(window.HypeDataDecorator=function(){function B(a){for(var b in h)-1!=b.indexOf(a.id+"__")&&(h[b].disconnect(),h[b]=void 0,delete h[b])}function w(a,b){B(a);q.forEach(function(c){c.activateHandler(c,a,b)})}function C(a,b,c){var e=b.id+"__"+a.attributeName,r=b;h[e]||(a.observerFunction=function(l){l.forEach(function(d){if(d.attributeName==a.attributeName){var f=d.target.getAttribute(a.attributeName),g=[].slice.call(d.target.querySelectorAll(a.selector));d.target.matches(a.selector)&&
g.unshift(d.target);for(var m=0;m<g.length;m++){var t=c?c.getSymbolInstanceById(g[m].id):null,p=x(a.callback?a.callback:k.setContent);u||(r=document.getElementById(c.currentSceneId()));for(var n,v=0;v<p.length;v++)n=p[v](c,g[m],n||{value:f,mutation:d,symbolInstance:t,hypeDocumentElm:b,sceneElm:r})}}d.attributeName==a.attributeName+"-initial"&&(g=d.target.getAttribute(a.attributeName+"-initial"),f=d.target.getAttribute(a.attributeName),u?d.target.setAttribute(a.attributeName,g):null!=f?d.target.setAttribute(a.attributeName,
f):!d.target.hasAttribute(a.attributeName)&&g&&d.target.setAttribute(a.attributeName,g))})},a.observer=new MutationObserver(a.observerFunction),h[e]=a.observer,a.startObserver=function(l){this.observer.observe(l,{attributes:!0,attributeOldValue:!0,subtree:!0,attributeFilter:[this.attributeName,this.attributeName+"-initial"]})},a.startObserver(b))}function D(a,b,c){var e=b.id+"__"+a.selector,r=a.attributeFilter?a.attributeFilter[0]:"style",l=b;h[e]||(a.observerFunction=function(d){d.forEach(function(f){if(f.target.matches(a.selector)){var g=
f.target.getAttribute(r),m=c?c.getSymbolInstanceById(f.target):null,t=x(a.callback);u||(l=document.getElementById(c.currentSceneId()));for(var p,n=0;n<t.length;n++)p=t[n](c,f.target,p||{value:g,mutation:f,symbolInstance:m,hypeDocumentElm:b,sceneElm:l})}})},a.observer=new MutationObserver(a.observerFunction),h[e]=a.observer,a.observer.observe(b,{attributes:!0,attributeOldValue:!0,subtree:!0,attributeFilter:a.attributeFilter?a.attributeFilter:["style"]}))}function x(a){var b=[];switch(typeof a){case "function":b=
[a];break;case "string":b=a.split("|").map(function(c){return c.trim()}).filter(function(c){return c&&k[c]}).map(function(c){return k[c]});break;case "object":Array.isArray(a)&&(b=a.filter(function(c){return"function"==typeof c||k[c]}).map(function(c){return"function"==typeof c?c:k[c]}))}return b}function y(a,b){a&&!a.querySelector(".HYPE_element_container, .HYPE_element")&&(a.innerHTML=b)}function z(a,b,c,e){(new RegExp(/^[a-z0-9-_]+$/i)).test(a)&&b&&c&&(e=e?e:{},q.push(Object.assign(e,{attributeName:a,
selector:b,callback:c,activateHandler:C})))}var q=[],h={},k={setContent:function(a,b,c){y(b,c.value)}},u=-1!=window.location.href.indexOf("/Hype/Scratch/HypeScratch.");if(u){var E=function(){var a=Math.round((new Date).getTime()/10);A!=a&&(A=a,q.forEach(function(b){b.attributeName&&document.querySelectorAll("["+b.attributeName+"]").forEach(function(c){c.setAttribute(b.attributeName,c.getAttribute(b.attributeName))})}))},A=0;window.addEventListener("DOMContentLoaded",function(a){a=document.documentElement||
document.body;w(a);(new MutationObserver(function(){E()})).observe(a,{attributes:!0,subtree:!0,attributeFilter:["class"]})})}!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeDocumentLoad",callback:function(a,b,c){b=a.getElementById(a.documentId());w(b,a)}});return{version:"1.2.8",mapDataAttribute:function(a,b,c){z("data-"+a,"."+a,b||k[a]||k.setContent,c)},mapAttributeToSelector:z,observeBySelector:function(a,b,c){a&&b&&(c=c?c:{},q.push(Object.assign(c,
{selector:a,callback:b,activateHandler:D})))},registerElementDecorator:function(a,b){k[a]=b},setContent:y,getRunningObserver:function(){return h}}}());