-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HypeGlobalBehavior.min.js
9 lines (9 loc) · 2.58 KB
/
HypeGlobalBehavior.min.js
1
2
3
4
5
6
7
8
9
/*
Hype GlobalBehavior 1.8
copyright (c) 2020 Max Ziebell, (https://maxziebell.de). MIT-license
*/
!1==="HypeGlobalBehavior"in window&&(window.HypeGlobalBehavior=function(){var e={},g=[],k=function(a,c,b){if("#"!=b.customBehaviorName.substr(0,1)){c=b.customBehaviorName.split("@");a=c.shift();if(window.hasOwnProperty("HYPE")&&window.HYPE.hasOwnProperty("documents")){c=0==c.length?Object.keys(window.HYPE.documents):c;for(var d in c)if(window.HYPE.documents.hasOwnProperty(c[d])){var f=window.HYPE.documents[c[d]];f.triggerCustomBehaviorNamed("#"+a);if(f.hasOwnProperty("onGlobalBehavior"))f.onGlobalBehavior("#"+
a)}}if(h.hasOwnProperty("onGlobalBehavior"))h.onGlobalBehavior("#"+a);d=!b.isBubbleDown&&!b.isBubbleUp;(b.isBubbleDown||d)&&n(a,null);if(b.isBubbleUp||d)window!=top&&window.parent.postMessage({type:"TriggerCustomBehaviorBubbleUp",customBehaviorName:a},"*"),b.childToAvoid&&n(a,b.childToAvoid)}return!0},n=function(a,c){[].forEach.call(document.querySelectorAll("iframe"),function(b){b=b.contentWindow;c!=b&&b.postMessage({type:"TriggerCustomBehaviorBubbleDown",customBehaviorName:a},"*")})},l=function(a){k(null,
null,{customBehaviorName:a})},p=function(a,c,b){if(null!=a&&null!=c&&!e.hasOwnProperty(a)){var d=c.hasOwnProperty("FPS")?1E3/c.FPS:1E3*c;b=b?b:{};b.hasOwnProperty("pattern")?(b._buf=b.pattern.slice(0),null==b.countdown&&(b.countdown=Infinity),c=function(){0==b._buf.length&&(b._buf=b.pattern.slice(0));b._buf.shift()&&l(a)}):c=function(){l(a)};e[a]=setInterval(c,d);b.omitFirst||c()}},m=function(a){e.hasOwnProperty(a)&&(clearInterval(e[a]),delete e[a])},q=function(){for(var a in e)m(a)};window.addEventListener("message",
function(a){if(g.length&&-1==g.indexOf(a.origin))console.log("Blocked behavior from "+a.origin);else if(a.data.hasOwnProperty("type")&&a.data.hasOwnProperty("customBehaviorName")){var c="TriggerCustomBehaviorBubbleUp"==a.data.type,b="TriggerCustomBehaviorBubbleDown"==a.data.type;(c||b)&&k(null,null,{customBehaviorName:a.data.customBehaviorName,isBubbleUp:c,isBubbleDown:b,childToAvoid:c?window:null})}},!1);!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeDocumentLoad",
callback:function(a,c,b){a.startCustomBehaviorTicker=function(d,f,r){p(d,f,r)};a.stopCustomBehaviorTicker=function(d){m(d)};a.stopAllCustomBehaviorTicker=function(){q()};return!0}});window.HYPE_eventListeners.push({type:"HypeTriggerCustomBehavior",callback:k});var h={version:"1.7",allowPostMessageFrom:function(a){g.push(a)},triggerCustomBehaviorNamed:l,startCustomBehaviorTicker:p,stopCustomBehaviorTicker:m,stopAllCustomBehaviorTicker:q};return h}());