-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHypeAutoLayout.min.js
More file actions
8 lines (8 loc) · 1.84 KB
/
HypeAutoLayout.min.js
File metadata and controls
8 lines (8 loc) · 1.84 KB
1
2
3
4
5
6
7
8
/*
Hype AutoLayout 1.0
copyright (c) 2019 Max Ziebell, (https://maxziebell.de). MIT-license
*/
!1==="HypeAutoLayout"in window&&(window.HypeAutoLayout=function(){function p(c,a){var b=a.getAttribute("data-auto-layout").toLowerCase().trim(),f=parseInt(a.getAttribute("data-auto-layout-margin")),e=a.getAttribute("data-auto-layout-size-selector"),g={selector:e?e:h,margin:f?f:0,sortBy:"horizontal"==b?"left":"top",property:"horizontal"==b?"width":"height",borders:"horizontal"==b?["borderLeftWidth","borderRightWidth"]:["borderTopWidth","borderBottomWidth"]},d=[].slice.call(document.querySelectorAll("#"+
a.id+"> .HYPE_element_container > .HYPE_element"));b&&d.forEach(function(b){var a=b.querySelector(g.selector);c.startMutationObserver(a?a:b,function(b){k(c,d,g);l(c,d,g)},{id:b.id,attributes:!0,attributeFilter:["style"]})});k(c,d,g);l(c,d,g)}function k(c,a,b){a.sort(function(a,e){return c.getElementProperty(a,b.sortBy)>c.getElementProperty(e,b.sortBy)})}function m(c){return(c=parseInt(c))?c:0}function n(c,a,b){return c.getElementProperty(a,b.property)+m(a.style[b.borders[0]])+m(a.style[b.borders[1]])}
function l(c,a,b){var f=c.getElementProperty(a[0],b.sortBy),e=b.margin;a.forEach(function(a){var d=a.querySelector(b.selector);d?(d=n(c,d,b),c.setElementProperty(a,b.property,d)):d=n(c,a,b);.1<d?(a.classList.remove("hiddenCard"),c.setElementProperty(a,b.sortBy,f),f+=d,e&&(f+=d<e?d:e)):a.classList.add("hiddenCard")})}var h=".hypeAutoLayoutSize";!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeSceneLoad",callback:function(c,a,b){a=[].slice.call(a.querySelectorAll("[data-auto-layout]"));
console.log(a);a.forEach(function(a,b){a.childNodes.length&&p(c,a)})}});window.HYPE_eventListeners.push({type:"HypeDocumentLoad",callback:function(c,a,b){}});return{version:"1.0",setDefaultSizeSelector:function(c){h=c}}}());