wtc-utility-helpers
Version:
Javascript helpers, perfect for non-jquery projects.
3 lines (2 loc) • 2.83 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).wtcUtilityHelpers={})}(this,function(e){function n(e,n){return Math.random()*(n-e)+e}e.asyncImageLoadfunction=function(e){var n=e.src,t=function(e,n){if(null==e)return{};var t,o,r={},i=Object.keys(e);for(o=0;o<i.length;o++)n.indexOf(t=i[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 i=0,a=Object.entries(t);i<a.length;i++){var f=a[i];r[f[0]]=f[1]}r.src=n})},e.clampfunction=function(e,n,t){return Math.min(Math.max(t,e),n)},e.fireCustomEvent=function(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}))},e.fixWidows=function(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," "))}},e.floatRandomBetween=n,e.getAncestors=function e(n,t,o){return void 0===t&&(t=!0),o||(o=[]),!0===t&&n.parentNode===document.body||n.parentNode&&(o.splice(0,0,[n.parentNode]),e(n.parentNode,t,o)),o},e.getElementPosition=function(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,i=window.pageXOffset,a=document.body.clientTop||0,f=document.body.clientLeft||0;t.top+=Math.round(o.top+r-a),t.left+=Math.round(o.left+i-f)}return t},e.getSelectorForElement=function(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(" > ")},e.getSiblings=function(e){return[].concat(e.parentNode.children).filter(function(n){return n!==e})},e.isChildOf=function(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},e.lerp=function(e,n,t){return(1-t)*e+t*n},e.randomBetween=function(e,t){return Math.round(n(e,t))},e.serializeArray=function(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},e.shuffleArray=function(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}});
//# sourceMappingURL=wtc-utility-helpers.umd.js.map