wtc-utility-helpers
Version:
Javascript helpers, perfect for non-jquery projects.
3 lines (2 loc) • 2.7 kB
JavaScript
function e(e,n){return Math.random()*(n-e)+e}function n(n,t){return Math.round(e(n,t))}function t(e,n,t){return(1-t)*e+t*n}function o(e,n,t){return Math.min(Math.max(t,e),n)}function r(e,n){void 0===n&&(n=!0);var t,o,r=e.length;for(!1===n&&(e=e.slice(0));0!==r;)o=Math.floor(Math.random()*r),t=e[r-=1],e[r]=e[o],e[o]=t;return e}function a(e,n,t,o){void 0===t&&(t=!0),void 0===o&&(o=!0),window.dispatchEvent(new CustomEvent(e,{bubbles:t,cancelable:o,detail:n}))}function i(e,n){void 0===n&&(n=!0);var t={top:0,left:0};if(!1===n)t.top=e.offsetTop,t.left=e.offsetLeft;else{var o=e.getBoundingClientRect(),r=window.pageYOffset,a=window.pageXOffset,i=document.body.clientTop||0,f=document.body.clientLeft||0;t.top+=Math.round(o.top+r-i),t.left+=Math.round(o.left+a-f)}return t}function f(e,n,t){void 0===t&&(t=!0);var o=!1;return e.parentNode===n&&(o=!0),!0===t&&!1===o&&e.parentNode&&(o=o(e.parentNode,n)),o}function u(e){return[].concat(e.parentNode.children).filter(function(n){return n!==e})}function l(e,n,t){return void 0===n&&(n=!0),t||(t=[]),!0===n&&e.parentNode===document.body||e.parentNode&&(t.splice(0,0,[e.parentNode]),l(e.parentNode,n,t)),t}function d(e){for(var n=[];e.parentNode;){if(e.id){n.unshift("#"+e.id);break}n.unshift(e==e.ownerDocument.documentElement?e.tagName:e.tagName+":nth-child("+c+")"),e=e.parentNode}return n.join(" > ")}function s(e){if(_els=e,e instanceof Node&&(_els=[e]),_els&&_els.length)for(var n=0;n<_els.length;n++){var t=_els[n];t instanceof Node&&(t.innerHTML=t.innerHTML.replace(/\s(?=[^\s]*$)/g," "))}}function p(e){var n=[];if("object"==typeof e&&"FORM"==e.nodeName)for(var t=0;t<e.elements.length;t++){var o=e.elements[t];if(o.name&&!o.disabled&&"file"!=o.type&&"reset"!=o.type&&"submit"!=o.type&&"button"!=o.type)if("select-multiple"==o.type)for(var r=0;r<e.elements[t].options.length;r++)o.options[r].selected&&(n[n.length]={name:o.name,value:o.options[r].value});else("checkbox"!=o.type&&"radio"!=o.type||o.checked)&&(n[n.length]={name:o.name,value:o.value})}return n}function v(e){var n=e.src,t=function(e,n){if(null==e)return{};var t,o,r={},a=Object.keys(e);for(o=0;o<a.length;o++)n.indexOf(t=a[o])>=0||(r[t]=e[t]);return r}(e,["src"]);return new Promise(function(e,o){var r=new Image;r.onload=function(){return e(r)},r.onerror=o;for(var a=0,i=Object.entries(t);a<i.length;a++){var f=i[a];r[f[0]]=f[1]}r.src=n})}export{v as asyncImageLoadfunction,o as clampfunction,a as fireCustomEvent,s as fixWidows,e as floatRandomBetween,l as getAncestors,i as getElementPosition,d as getSelectorForElement,u as getSiblings,f as isChildOf,t as lerp,n as randomBetween,p as serializeArray,r as shuffleArray};
//# sourceMappingURL=wtc-utility-helpers.module.js.map