-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrid.min.js
More file actions
5 lines (5 loc) · 14.5 KB
/
grid.min.js
File metadata and controls
5 lines (5 loc) · 14.5 KB
1
2
3
4
5
/*
GRIDDERY by @glenthemes [2021-2026]
git.new/griddery
*/
if("undefined"!=typeof $){var t=getComputedStyle(document.documentElement),e=t,i=jQuery.fn.jquery.replaceAll(".","");$(document).ready(function(){window.griddery=function(e,r){e.addClass("col-item");var n=Number(t.getPropertyValue(r));for($(".col-item").each(function(){$(this).not(".col-item + .col-item").each(function(){i>="180"?$(this).nextUntil(":not(.col-item)").addBack().wrapAll('<div class="col-tr">'):$(this).nextUntil(":not(.col-item)").andSelf().wrapAll('<div class="col-tr">')})}),smh=1;smh<n+1;smh++)$(".col-tr .col-item:nth-child("+n+"n+"+smh+")").each(function(){$(this).attr("col-id",smh)});for($(".col-tr").prepend("<div class='temp-cols'></div>"),tytn=1;tytn<n+1;tytn++)$(".temp-cols").append("<div class='col-column' col-id='"+tytn+"'></div>");$(".temp-cols").children().unwrap(),$(".col-item").each(function(){var t=$(this).attr("col-id");$(this).appendTo($(this).parents(".col-tr").find(".col-column[col-id='"+t+"']"))}),$(".col-column[col-id], .col-item[col-id]").removeAttr("col-id"),$(".col-column").each(function(){""==$.trim($(this).html())&&$(this).remove()})}})}"undefined"!=typeof $&&$(document).ready(function(){window.gridderyV2=function(t,r){t=$.trim(t),r=parseInt($.trim(e.getPropertyValue($.trim(r)))),$(t).each(function(){$(this).not(t+"+"+t).each(function(){i>="180"?$(this).nextUntil(":not("+t+")").addBack().wrapAll("<div griddery-cont cols='"+r+"'>"):$(this).nextUntil(":not("+t+")").andSelf().wrapAll("<div griddery-cont cols='"+r+"'>"),$(this).parent("[griddery-cont]").each(function(){for($(this).wrapInner("<div griddery-tr/>"),smh=1;smh<r+1;smh++)$(this).find(t+":nth-of-type("+r+"n+"+smh+")").each(function(){$(this).attr("col-id",smh)}),$(this).find("[griddery-tr]").append("<div griddery-col='"+smh+"'></div>")})})}),$("[griddery-col]").each(function(){var t=$(this).attr("griddery-col");$(this).parents("[griddery-cont]").find("[col-id]").filter(function(){return $(this).attr("col-id")==t}).appendTo($(this)).removeAttr("col-id")}),$(t).each(function(){$(this).wrap("<div griddery-item>"),$(this).parents("[griddery-cont]").attr("griddery-id",t)})}}),window.gridderyV3=t=>{if(void 0!==t&&void 0!==t.items&&void 0!==t.columns&&""!==t.items.toString().trim()&&""!==t.columns.toString().trim()){let e=t.items.toString().trim(),i=document.querySelectorAll(e),r=t.columns;if("number"!=typeof r){if(isNaN(Number(r))){if("--"==(r=r.toString().trim()).slice(0,2)||"var(--"==r.slice(0,6)){let n=getComputedStyle(document.documentElement).getPropertyValue("--"+r.split("--").slice(1).join().replaceAll(")",""));""!==(n=n.replaceAll('"',"","'",""))&&("number"==typeof n?r=n:isNaN(Number(n))?console.error("【 griddery 】 error — columns count must be a number (integer)."):r=Number(n))}}else r=Number(r)}i?.forEach((t,i)=>{if(!t.previousElementSibling?.matches(e)){let n=document.createElement("div");n.setAttribute("griddery-cont",""),n.setAttribute("griddery-id",e),t.before(n);let o=n.nextElementSibling;for(;o&&o.matches(e);)n.appendChild(o),o=n.nextElementSibling;let s=document.createElement("div");s.setAttribute("griddery-tr",""),n.prepend(s);for(let c=0;c<r;c++){let d=document.createElement("div");d.setAttribute("griddery-col",c+1),s.append(d)}}setTimeout(()=>{let e=document.createElement("div");e.setAttribute("griddery-item",""),t.before(e),e.appendChild(t);let n=(i+=1)%r;0==n&&(n=r),e.setAttribute("col",n);let o=t.closest("[griddery-cont]");if(o){let s=o.querySelector(`[griddery-col="${n}"]`);s&&s.append(e)}},0)})}else console.error("【 griddery 】 error — Please specify the items selector AND the number of columns.")},window.gridderyV4=(t,e)=>{if(!t||!t.items||!t.columns)return;let i=t.container||document.body,r=t.items,n=t.columns;function o(t,e){t&&new ResizeObserver(t=>{for(let i of t){let{top:r,left:n,width:o,height:s}=i.contentRect;e({top:r,left:n,width:o,height:s})}}).observe(t)}function s(t,e,i,r){let n=[],o=t.querySelectorAll(`${e}:not(${e} ${e})`),s=0,c=o.length;o?.forEach(t=>{if(!t.previousElementSibling?.matches(e)){let o=document.createElement(i.tag);o.setAttribute(i.attr,""),t.before(o);let d=o.nextElementSibling;for(d&&(!d||d.matches(e))||o.remove(),d&&n.push(o);d&&d.matches(e);)o.append(d),d=o.nextElementSibling}++s===c&&r?.(n)})}function c(t){let e=parseInt(t);if(!isNaN(e))return e;let i=t.trimStart().startsWith("var(")&&t.trimEnd().endsWith(")")?t.trim().slice(4,-1):t.trimStart().startsWith("--")?t.trim():null;return i&&(e=parseInt(getComputedStyle(document.documentElement).getPropertyValue(i))),isNaN(e)?1:e}function d(t,e,i){t.style.setProperty("--Griddery-Columns",e);let r=1;for(let n=0;n<e;n++)if(!t.querySelector(`[griddery-column][data-col="${r}"]`)){let o=document.createElement("div");o.dataset.col=r++,o.setAttribute("griddery-column",""),t.append(o)}i?.forEach((i,r)=>{i.matches("[griddery-item]")||i.setAttribute("griddery-item",""),i.matches("[data-id]")||(i.dataset.id=r+1);let n=r%e+1;i.dataset.col=n,t.querySelector(`[griddery-column][data-col="${n}"]`)?.append(i)})}function a(t){t.querySelector("[griddery-column] > [griddery-item]")&&t.querySelectorAll("[griddery-column]")?.forEach(t=>{t.replaceWith(...t.childNodes)})}(function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ResizeObserver=e()})(this,function(){"use strict";var t=function(){if("undefined"!=typeof Map)return Map;function t(t,e){var i=-1;return t.some(function(t,r){return t[0]===e&&(i=r,!0)}),i}return function(){function e(){this.__entries__=[]}return Object.defineProperty(e.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),e.prototype.get=function(e){var i=t(this.__entries__,e),r=this.__entries__[i];return r&&r[1]},e.prototype.set=function(e,i){var r=t(this.__entries__,e);~r?this.__entries__[r][1]=i:this.__entries__.push([e,i])},e.prototype.delete=function(e){var i=this.__entries__,r=t(i,e);~r&&i.splice(r,1)},e.prototype.has=function(e){return!!~t(this.__entries__,e)},e.prototype.clear=function(){this.__entries__.splice(0)},e.prototype.forEach=function(t,e){void 0===e&&(e=null);for(var i=0,r=this.__entries__;i<r.length;i++){var n=r[i];t.call(e,n[1],n[0])}},e}()}(),e="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,i="undefined"!=typeof global&&global.Math===Math?global:"undefined"!=typeof self&&self.Math===Math?self:"undefined"!=typeof window&&window.Math===Math?window:Function("return this")(),r="function"==typeof requestAnimationFrame?requestAnimationFrame.bind(i):function(t){return setTimeout(function(){return t(Date.now())},1e3/60)},n=["top","right","bottom","left","width","height","size","weight"],o="undefined"!=typeof MutationObserver,s=function(){function t(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=function(t,e){var i=!1,n=!1,o=0;function s(){i&&(i=!1,t()),n&&d()}function c(){r(s)}function d(){var t=Date.now();if(i){if(t-o<2)return;n=!0}else i=!0,n=!1,setTimeout(c,20);o=t}return d}(this.refresh.bind(this),20)}return t.prototype.addObserver=function(t){~this.observers_.indexOf(t)||this.observers_.push(t),this.connected_||this.connect_()},t.prototype.removeObserver=function(t){var e=this.observers_,i=e.indexOf(t);~i&&e.splice(i,1),!e.length&&this.connected_&&this.disconnect_()},t.prototype.refresh=function(){this.updateObservers_()&&this.refresh()},t.prototype.updateObservers_=function(){var t=this.observers_.filter(function(t){return t.gatherActive(),t.hasActive()});return t.forEach(function(t){return t.broadcastActive()}),t.length>0},t.prototype.connect_=function(){e&&!this.connected_&&(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),o?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},t.prototype.disconnect_=function(){e&&this.connected_&&(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},t.prototype.onTransitionEnd_=function(t){var e=t.propertyName,i=void 0===e?"":e;n.some(function(t){return!!~i.indexOf(t)})&&this.refresh()},t.getInstance=function(){return this.instance_||(this.instance_=new t),this.instance_},t.instance_=null,t}(),c=function(t,e){for(var i=0,r=Object.keys(e);i<r.length;i++){var n=r[i];Object.defineProperty(t,n,{value:e[n],enumerable:!1,writable:!1,configurable:!0})}return t},d=function(t){return t&&t.ownerDocument&&t.ownerDocument.defaultView||i},a=f(0,0,0,0);function l(t){return parseFloat(t)||0}function h(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.reduce(function(e,i){return e+l(t["border-"+i+"-width"])},0)}var u="undefined"!=typeof SVGGraphicsElement?function(t){return t instanceof d(t).SVGGraphicsElement}:function(t){return t instanceof d(t).SVGElement&&"function"==typeof t.getBBox};function f(t,e,i,r){return{x:t,y:e,width:i,height:r}}var p=function(){function t(t){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=f(0,0,0,0),this.target=t}return t.prototype.isActive=function(){var t,i,r,n=(t=this.target,e?u(t)?(r=(i=t).getBBox(),f(0,0,r.width,r.height)):function t(e){var i=e.clientWidth,r=e.clientHeight;if(!i&&!r)return a;var n,o=d(e).getComputedStyle(e),s=function(t){for(var e={},i=0,r=["top","right","bottom","left"];i<r.length;i++){var n=r[i],o=t["padding-"+n];e[n]=l(o)}return e}(o),c=s.left+s.right,u=s.top+s.bottom,p=l(o.width),m=l(o.height);if("border-box"===o.boxSizing&&(Math.round(p+c)!==i&&(p-=h(o,"left","right")+c),Math.round(m+u)!==r&&(m-=h(o,"top","bottom")+u)),(n=e)!==d(n).document.documentElement){var v=Math.round(p+c)-i,y=Math.round(m+u)-r;1!==Math.abs(v)&&(p-=v),1!==Math.abs(y)&&(m-=y)}return f(s.left,s.top,p,m)}(t):a);return this.contentRect_=n,n.width!==this.broadcastWidth||n.height!==this.broadcastHeight},t.prototype.broadcastRect=function(){var t=this.contentRect_;return this.broadcastWidth=t.width,this.broadcastHeight=t.height,t},t}(),m=function(t,e){var i,r,n,o,s,d,a,l=(r=(i=e).x,n=i.y,o=i.width,s=i.height,a=Object.create((d="undefined"!=typeof DOMRectReadOnly?DOMRectReadOnly:Object).prototype),c(a,{x:r,y:n,width:o,height:s,top:n,right:r+o,bottom:s+n,left:r}),a);c(this,{target:t,contentRect:l})},v=function(){function e(e,i,r){if(this.activeObservations_=[],this.observations_=new t,"function"!=typeof e)throw TypeError("The callback provided as parameter 1 is not a function.");this.callback_=e,this.controller_=i,this.callbackCtx_=r}return e.prototype.observe=function(t){if(!arguments.length)throw TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof d(t).Element))throw TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)||(e.set(t,new p(t)),this.controller_.addObserver(this),this.controller_.refresh())}},e.prototype.unobserve=function(t){if(!arguments.length)throw TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof d(t).Element))throw TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)&&(e.delete(t),e.size||this.controller_.removeObserver(this))}},e.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},e.prototype.gatherActive=function(){var t=this;this.clearActive(),this.observations_.forEach(function(e){e.isActive()&&t.activeObservations_.push(e)})},e.prototype.broadcastActive=function(){if(this.hasActive()){var t=this.callbackCtx_,e=this.activeObservations_.map(function(t){return new m(t.target,t.broadcastRect())});this.callback_.call(t,e,t),this.clearActive()}},e.prototype.clearActive=function(){this.activeObservations_.splice(0)},e.prototype.hasActive=function(){return this.activeObservations_.length>0},e}(),y="undefined"!=typeof WeakMap?new WeakMap:new t,g=function t(e){if(!(this instanceof t))throw TypeError("Cannot call a class as a function.");if(!arguments.length)throw TypeError("1 argument required, but only 0 present.");var i=s.getInstance(),r=new v(e,i,this);y.set(this,r)};return["observe","unobserve","disconnect"].forEach(function(t){g.prototype[t]=function(){var e;return(e=y.get(this))[t].apply(e,arguments)}}),void 0!==i.ResizeObserver?i.ResizeObserver:g}),n=c(n);let l=["top","middle","center","bot","bottom"],h=t=>{("string"==typeof i?document.querySelectorAll(i):i instanceof Element?[i]:i instanceof NodeList?i:[])?.forEach(i=>{s(i,r,{tag:"div",attr:"griddery-container"},i=>{i?.forEach(i=>{i.matches("[griddery-id]:not([griddery-id=''])")||i.setAttribute("griddery-id",r),t.gridAlign&&"string"==typeof t.gridAlign&&l.find(e=>e==t.gridAlign)&&i.setAttribute(`griddery-align-${t.gridAlign.toLowerCase()}`,""),i.querySelectorAll(`${r}:not(${r} ${r})`)?.forEach(t=>{if(!t.closest("[griddery-item]")){let e=document.createElement("div");e.setAttribute("griddery-item",""),t.before(e),e.append(t)}});let s=Array.from(i.querySelectorAll("[griddery-item]"));d(i,n,s);if(e?.(i,{destroyGriddery(){let t=[];i.querySelectorAll("[griddery-item][data-id]")?.forEach(e=>{t.push(Number(e.dataset.id))});let e=t.sort((t,e)=>t-e),r=document.createElement("div");i.after(r),e?.forEach(t=>{i.querySelectorAll(`[griddery-item][data-id="${t}"]`)?.forEach(n=>{r.append(n),n.replaceWith(...n.childNodes),t==e.length&&(r.replaceWith(...r.childNodes),i.remove())})})}}),t.responsive&&t.responsive.breakpoints){let h=0,u=!0===t.responsive.basedOnGrid||"yes"==t.responsive.basedOnGrid;u&&o(i,({width:t})=>{h=Math.round(t)});let f,p=document.querySelector("div[griddery-viewport-watcher]");if(p)f=p;else{let m=document.createElement("div");m.setAttribute("griddery-viewport-watcher",""),m.ariaHidden=!0,m.tabIndex=-1,document.body.append(m),f=m}let v=t.responsive?.breakpoints,y=!1;function g(t){if(!1===y){y=!0;let e=c(v[t]);a(i),d(i,e,s),i.style.setProperty("--Griddery-Columns",e),y=!1}}o(f,({width:t})=>{let e=t;for(let i in v)if(i.includes("width:")&&i.includes("px")){let r=i.split(":")[0].trim();r.includes("-width")&&(r=r.split("-width")[0]);let n=i.split(":")[1].trim();n.includes("px")&&(n=n.split("px")[0]),"max"==r?(u?h:e)<n&&g(i):"min"==r&&(u?h:e)>n&&g(i)}})}})})})};"loading"==document.readyState?document.addEventListener("DOMContentLoaded",()=>h(t)):h(t)};