@htmlguyllc/jpack
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -1,1 +0,1 @@ | ||
!function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=11)}([function(t,e,n){"use strict";n.d(e,"a",function(){return i});const i={getElement:function(t,e,n){if((t=this.getElements(t,e)).length>1&&n)throw"Too many DOM elements found in getElement for "+JSON.stringify(t);return t?t[0]:null},getElements:function(t,e){e=void 0!==e&&e;let n=[];if(void 0!==t&&t)if(t instanceof Element||t instanceof HTMLDocument)n.push(t);else if("string"==typeof t)n=(n=document.querySelectorAll(t))?Array.from(n):n;else if(t instanceof jQuery)t.length&&(n=t.toArray());else if(t instanceof NodeList||t instanceof HTMLCollection)n=Array.from(t);else{if(!Array.isArray(t))throw"Invalid value provided to getElements: "+JSON.stringify(t);t.forEach(function(t){(t=i.getElement(t))&&n.push(t)})}else;if(!n.length&&e)throw"Failed to get array of DOM elements for "+JSON.stringify(t);return n},remove:function(t){return this.getElements(t).forEach(function(t){t.parentNode.removeChild(t)}),this},replaceElWithHTML:function(t,e){if("string"!=typeof e)throw`${e} is not a string`;t=this.getElement(t);let n=(new DOMParser).parseFromString(e,"text/html");return n=t.parentNode.insertBefore(n.documentElement.querySelector("body").childNodes[0],t),t.remove(),n},isVisible(t){t=this.getElement(t,!0,!0);const e=getComputedStyle(t);if("none"===e.display)return!1;if("visible"!==e.visibility)return!1;if(0===e.opacity)return!1;if(t.offsetWidth+t.offsetHeight+t.getBoundingClientRect().height+t.getBoundingClientRect().width===0)return!1;const n=t.getBoundingClientRect(),i={"top-left":{x:n.left,y:n.top},"top-right":{x:n.right,y:n.top},"bottom-left":{x:n.left,y:n.bottom},"bottom-right":{x:n.right,y:n.bottom},center:{x:n.left+t.offsetWidth/2,y:n.top+t.offsetHeight/2}};for(key in i){var r=i[key];if(r.x<0)return!1;if(r.x>(document.documentElement.clientWidth||window.innerWidth))return!1;if(r.y<0)return!1;if(r.y>(document.documentElement.clientHeight||window.innerHeight))return!1;let e=document.elementFromPoint(r.x,r.y);if(null!==e)do{if(e===t)return!0}while(e=e.parentNode)}return!1},exists:function(t){return this.getElements(t).length},multipleExist:function(t){return this.getElements(t).length>1}}},function(t,e,n){"use strict";n.d(e,"a",function(){return u});var i=n(4),r=n.n(i),o=n(0),s=n(5),a=n(2);const u={_passthroughData:null,setPassthroughData:function(t){return this._passthroughData=t,this},clearPassthroughData:function(){return this.setPassthroughData(null),this},getPassThroughData:function(t){return this._passthroughData},_incomingElementSelector:"body",setIncomingElement:function(t){if("string"!=typeof t)throw`${t} is not a string`;this._incomingElementSelector=t},getIncomingElement:function(){return this._incomingElementSelector},_replaceElementSelector:"body",setReplaceElement:function(t){if("string"!=typeof t)throw`${t} is not a string`;this._replaceElementSelector=t},getReplaceElement:function(){return this._replaceElementSelector},load:function(t,e,n,i,s){if("string"!=typeof t)throw`Provided URL (${t}) is not a string`;if(n=void 0!==n&&n?n:this.getIncomingElement(),i=void 0!==i&&i?i:this.getReplaceElement(),s=void 0===s||s,"string"!=typeof n)throw`Provided incoming_el (${n}) is not a string`;if("string"!=typeof i)throw`Provided replace_el (${i}) is not a string`;u.showLoader(),r.a.get(t).then(function(r){u.hideLoader(),u.replacePageContent(r.data,t,n,i,s),"function"==typeof e&&window.setTimeout(function(){e(o.a.getElement(i),n,u.getPassThroughData())},105)}).catch(function(t){throw u.hideLoader(),u.triggerNavigationFailure(t),t})},loaderEnabled:!0,_loaderDelay:300,setLoaderDelay:function(t){if("number"!=typeof t)throw`${t} is not an integer`;return this._loaderDelay=t,this},getLoaderDelay:function(){return this._loaderDelay},_loaderClasses:"progress page-navigation-loader",_loaderInnerDivClasses:"progress-bar progress-bar-striped progress-bar-animated",getLoaderEl:function(){if(!this.loaderEnabled)return;if(u.navLoaderCached)return u.navLoaderCached;let t=document.createElement("div");t.classList=this._loaderClasses;let e=document.createElement("div");return e.classList=this._loaderInnerDivClasses,t.append(e),document.body.prepend(t),u.navLoaderCached=o.a.getElement(".page-navigation-loader"),u.navLoaderCached},showLoader:function(){if(this.loaderEnabled)return u.loader_timeout=window.setTimeout(function(){u.getLoaderEl().classList.add("active")},this.getLoaderDelay()),this},hideLoader:function(){if(this.loaderEnabled)return window.clearTimeout(u.loader_timeout),u.getLoaderEl().classList.remove("active"),this},parseHTML(t,e){if("string"!=typeof(e=void 0===e?null:e)&&null!==e)throw`Provided parent_el (${e}) is not a string or null`;var n=new DOMParser,i=n.parseFromString(t,"text/html"),r=i.querySelector("title");r=r?r.innerText:null;var o=i.head.getElementsByTagName("meta"),s=i.querySelectorAll('link[rel="canonical"]'),a=i.body.classList,l=t;if(e){var c=i.querySelector(e);if(!c)throw`Could not find parent selector ${e}`;l=c.outerHTML}var h=u.getRouteFromMeta(i);return n=i=null,{title:r,route:h,metas:o,links:s,body_classes:a,html:l}},getRouteFromMeta:function(t){var e=(t=void 0===t?document.head:t).querySelector('[name="current_route"]');return e=e?e.content:null},replacePageContent(t,e,n,i,r){var s=this;if(r=void 0===r||r,n=void 0!==n&&n?n:this.getIncomingElement(),i=void 0!==i&&i?i:this.getReplaceElement(),"string"!=typeof e)throw`Provided url (${e}) is not a string`;if("string"!=typeof n)throw`Provided incoming_el (${n}) is not a string`;if("string"!=typeof i)throw`Provided replace_el (${i}) is not a string`;return u.triggerUnload(o.a.getElement(i),i,this.getRouteFromMeta()),window.setTimeout(function(){var a=u.parseHTML(t,n);if(a.html.length){o.a.remove("meta"),document.head.append(a.metas),o.a.remove('[rel="canonical"]'),Array.from(a.links).forEach(function(t){document.head.append(t)}),document.body.classList=a.body_classes,r&&history.pushState({url:e},a.title,e),u.setTitle(a.title);const t=o.a.replaceElWithHTML(i,a.html);u.triggerOnLoad(t,n,i,a.route),s.getReplaceElement()!==i&&s.setReplaceElement(n)}},100),this},reload:function(t){return t="function"!=typeof t?null:t,u.load(s.a.getFullURL(),t),this},fullReload:function(){u.showLoader(),window.location.reload()},redirect:function(t){u.showLoader(),window.location.href=t},setTitle:function(t){return document.title=t,this},onLoad:function(t){return a.a.on("body","navigation.complete",t),this},onUnload:function(t){return a.a.on("body","navigation.started",t),this},onNavigationFailure:function(t){return a.a.on("body","navigation.failed",t),this},triggerOnLoad:function(t,e,n,i){return i=void 0!==i?i:u.getRouteFromMeta(),a.a.trigger("body","navigation.complete",{el:t,el_selector:e,replaced_selector:n,route:i,data:this.getPassThroughData()}),this},triggerUnload:function(t,e,n){return a.a.trigger("body","navigation.started",{el:t,el_selector:e,route:n}),this},triggerNavigationFailure:function(t){return a.a.trigger("body","navigation.failed",{error:t}),this},initHistoryHandlers:function(){return window.onpushstate=function(t){console.log(t),u.load(s.a.getURIWithQueryString())},window.onpopstate=function(t){console.log(t),u.load(s.a.getURIWithQueryString(),null,null,null,!1)},this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return r});var i=n(0);const r={setGlobal:function(t){for(var e in t="string"==typeof t?t:null,this)this.hasOwnProperty(e)&&"setGlobal"!==e&&(t?(void 0===window[t]&&(window[t]={}),window[t][e]=this[e]):window[e]=this[e])},onClick:function(t,e){return this.onEventPreventDefault(t,"click",e)},offClick(t,e){return this.offEventPreventDefault(t,"click",e)},onSubmit:function(t,e){return this.onEventPreventDefault(t,"submit",e)},offSubmit:function(t,e){return this.offEventPreventDefault(t,"submit",e)},onChange:function(t,e){return this.on(t,"change",e)},offChange:function(t,e){return this.off(t,"change",e)},onEventPreventDefault:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.addEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),r):t},offEventPreventDefault:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.removeEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),r):t},on:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.addEventListener(e,n)}),r):t},off:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.removeEventListener(e,n)}),r):t},trigger:function(t,e,n){const r=i.a.getElements(t);return r.length?(n=void 0===n?null:n,e=new CustomEvent(e,{detail:n}),r.forEach(function(t){t.dispatchEvent(e)}),r):t}}},function(t,e,n){"use strict";n.d(e,"a",function(){return i});const i={isDataObject:function(t,e,n,i,r){r=void 0!==r&&r,n=void 0!==n&&n;var o=JSON.stringify(t);const s=`${o} is not an object`;if(void 0===t){if(r)throw s;return!1}if(!("object"==typeof t)||null===t||Array.isArray(t)){if(r)throw s;return!1}if(Array.isArray(e)){let s=!1,a=[];const u=Object.keys(t);if(e.forEach(function(t){u.includes(t)?s=!0:a.push(t)}),!s){if(r)throw`${o} does not contain at least one of the following: `+e.join(", ");return!1}if(n&&a.length){if(r)throw`${o} is missing data: `+a.join(", ");return!1}if(i){let t=[];if(u.forEach(function(n){e.includes(n)||t.push(n)}),t.length){if(r)throw`${o} contains invalid data: `+t.join(", ");return!1}}}return!0}}},function(t,e){t.exports=axios},function(t,e,n){"use strict";n.d(e,"a",function(){return i}),n(13);const i={query:new URLSearchParams(window.location.search),isHttps:function(){return"https:"===window.location.protocol},getDomain:function(){return window.location.hostname||window.location.host},getDomainWithProtocol:function(){return window.location.origin},getURI:function(){return window.location.pathname},getURIWithQueryString:function(){return window.location.pathname+window.location.search},getFullURL:function(){return window.location.href},appendSlash:function(t){return"/"!==t[t.length-1]?t+"/":t}}},function(t,e,n){"use strict";n.d(e,"a",function(){return o});var i=n(3),r=n(7);class o{constructor(){}populate(t){const e=this;if(void 0===this._keys)throw"Cannot populate object if _keys property is not set";return i.a.isDataObject(t,this._keys,!1,!0,!0),this._keys.forEach(function(n){void 0!==t[n]&&e[r.a.setter(n)](t[n])}),this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return i});const i={getter:function(t){return"get"+this.ucfirst(t)},setter:function(t){return"set"+this.ucfirst(t)},ucfirst:function(t){return t&&t[0].toUpperCase()+t.slice(1)}}},function(t,e,n){"use strict";var i=n(0),r=n(1),o=n(4),s=n.n(o);n(14);const a={xhrSubmit:!0,submitURL:null,submitMethod:null,onError:function(t,e,n){alert(t)},onSuccess:function(t,e){"string"==typeof t.success?alert(t.success):alert("Your submission has been received")},validateForm:function(t){t.classList.add("was-validated");const e=!t.querySelector(":invalid");return e&&t.classList.remove("was-validated"),e}};class u{constructor(t,e){if("object"!=typeof(e=void 0===e?{}:e))throw`${e} is not an object`;e={...a,...e},this.setForm(t),this.setValidateCallback(e.validateForm),this.setXHRSubmit(e.xhrSubmit),this.setSubmitMethod(e.submitMethod),this.setSubmitURL(e.submitURL),this.onSuccess(e.onSuccess),this.onError(e.onError)}setValidateCallback(t){if("function"!=typeof t)throw`${t} is not a function`;return this._validateCallback=t,this}validate(t){return void 0===t&&(t=this.getForm()),this._validateCallback(t)}setForm(t){if(!t||void 0===t)throw"Form element is required";if(!(t=i.a.getElement(t,!0,!0)))throw"Invalid form element received";return this._form=t,this}getForm(){return this._form}setXHRSubmit(t){return this._xhrSubmit=!!t,this}setSubmitMethod(t){if("string"!=typeof t&&null!==t)throw`${t} is not a string or null`;return this._submitMethod=t,this}getSubmitMethod(){return this._submitMethod}setSubmitURL(t){if("string"!=typeof t&&"function"!=typeof t&&null!==t)throw`${t} is not a string, function, or null`;return this._submitURL=t,this}getSubmitURL(){return this._submitURL}getFinalSubmitURL(t){let e=this.getSubmitURL(t);return"function"==typeof this._submitURL?this._submitURL(t):null===e?t.action:e}attachSubmitHandler(t){if(!this._xhrSubmit)return;if(!(t=void 0===t?this.getForm():i.a.getElement(t)))throw"Form element not received, cannot attach submit handler";const e=this;return t.addEventListener("submit",function(n){return!e._xhrSubmit||(n.preventDefault(),e.submitForm(t),!1)}),this}onSuccess(t){if("function"!=typeof t)throw`${t} is not a function`;return void 0===this._onSuccess&&(this._onSuccess=[]),this._onSuccess.push(t),this}clearOnSuccessCallbacks(){return this._onSuccess=[],this}triggerOnSuccess(t,e){return void 0!==this._onSuccess&&(this._onSuccess.forEach(function(n){n(t,e)}),this)}onError(t){if("function"!=typeof t)throw`${t} is not a function`;return void 0===this._onError&&(this._onError=[]),this._onError.push(t),this}clearOnErrorCallbacks(){return this._onError=[],this}triggerOnError(t,e,n){return void 0!==this._onError&&(this._onError.forEach(function(i){i(t,e,n)}),this)}submitForm(t){if(void 0===this._processing&&(this._processing=!1),this._processing)return!1;this._processing=!0;const e=this;let n=this.getFinalSubmitURL(t),i=this.getSubmitMethod();if(null===i&&void 0!==t.attributes.method&&(i=t.method),i=i?i.toLowerCase():"post",!this.validate(t))return this._processing=!1,!1;r.a.showLoader();const o=Array.from(this.getFormValues(t),t=>t.map(encodeURIComponent).join("=")).join("&");return s()({url:n,method:i,data:o}).then(function(n){r.a.hideLoader(),e._processing=!1;let i=n.data;try{i="string"==typeof i?JSON.parse(i):i}catch(t){}if("string"==typeof i){if("string"==typeof e.getIncomingElementSelector()){const n=r.a.parseHTML(i,e.getIncomingElementSelector());return n.html.length?e.insertForm(n,i,t):e.triggerOnError(`${e.getIncomingElementSelector()} could not be found in response from the server`,i,t)}return e.insertForm({html:i},i,t)}if("object"==typeof i)return i.html?e.insertForm({html:i.html},i,t):i.error?e.triggerOnError(i.error,i,t):e.triggerOnSuccess(i,t)}).catch(function(t){throw r.a.hideLoader(),e._processing=!1,t}),this}getFormValues(t){return new FormData(t)}}const l={incomingElementSelector:null,insertIntoElement:null,onload:function(t){return this}};class c extends u{constructor(t,e){if(super(null,e),"string"!=typeof t)throw`${t} is not a string`;if("object"!=typeof(e=void 0===e?{}:e))throw`${e} is not an object`;e={...l,...e},this.setURL(t),this.setIncomingElementSelector(e.incomingElementSelector),this.setInsertIntoElement(e.insertIntoElement),this.onload(e.onload)}setForm(t){return this._form=t,this}setURL(t){if("string"!=typeof t)throw`${t} is not a string`;return this._url=t,this}getURL(){return this._url}getFinalSubmitURL(t){let e=this.getSubmitURL(t);return"function"==typeof this._submitURL?this._submitURL(t):(null===e&&t.attributes.action&&(e=t.action),null===(e=e||this.getURL())&&(e=t.action),e)}setIncomingElementSelector(t){if(null!==t&&"string"!=typeof t)throw`${t} is not a string or null value`;return this._incomingElementSelector=t,this}getIncomingElementSelector(){return this._incomingElementSelector}setInsertIntoElement(t){this._insertIntoElement=t}getInsertIntoElement(){return this._insertIntoElement}getForm(){const t=this;r.a.showLoader(),s.a.get(this.getURL()).then(function(e){r.a.hideLoader();let n=e.data;try{n="string"==typeof n?JSON.parse(n):n}catch(t){}if("string"==typeof n){if("string"==typeof t.getIncomingElementSelector()){const e=r.a.parseHTML(n,t.getIncomingElementSelector());return t.insertForm(e,n)}return t.insertForm({html:n})}if("object"==typeof n&&void 0!==n.html)return t.insertForm({html:n.html},n);throw`Unexpected server response ${n}`}).catch(function(t){throw r.a.hideLoader(),t})}insertForm(t,e,n){let r=this.getInsertIntoElement();if(null===r)throw"Cannot determine where to insert form. Overwrite insertForm() or provide insertIntoElement";return(r=i.a.getElement(r,!0)).innerHTML=t.html,n=r.querySelector("form"),this.attachSubmitHandler(n),this.triggerOnload(n),r}onload(t){if("function"!=typeof t)throw`${t} is not a function`;return void 0===this._onload&&(this._onload=[]),this._onload.push(t),this}clearOnloadCallbacks(){return this._onload=[],this}triggerOnload(t){return void 0!==this._onload&&(this._onload.forEach(function(e){e(t)}),this)}}n.d(e,"b",function(){return u}),n.d(e,"a",function(){return c})},function(t,e,n){"use strict";n.d(e,"a",function(){return s});var i=n(3),r=n(6);const o={id:null,name:null,config:{}};class s extends r.a{constructor(t){if(super(),this._keys=["id","name","config"],void 0===t)return this;t={...o,...t},this.populate(t)}getId(){return this._id}setId(t){return this._id=t,this}getName(){return this._name}setName(t){return this._name=t,this}getConfig(){return this._config}setConfig(t){return i.a.isDataObject(t,null,!1,!1,!0),this._config=t,this}getConfigItem(t){return void 0===this._config[t]?null:this._config[t]}setConfigItem(t,e){return this._config[t]=e,this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return s});var i=n(3),r=n(6);const o={id:null,isGuest:!1,isAdmin:!1,username:null,fname:null,lname:null,email:null,phone:null,permissions:[],additionalData:{}};class s extends r.a{constructor(t){if(super(),this._keys=["id","isGuest","isAdmin","username","fname","lname","email","phone","permissions","additionalData"],void 0===t)return this;t={...o,...t},this.populate(t)}setId(t){return this._id=t,this}getId(){return this._id}setIsGuest(t){return this._isGuest=t,this}getIsGuest(){return this._isGuest}setIsAdmin(t){return this._isAdmin=t,this}getIsAdmin(){return this._isAdmin}setUsername(t){return this._username=t,this}getUsername(){return this._username}getFname(){return this._fname}setFname(t){return this._fname=t,this}getLname(){return this._lname}setLname(t){return this._lname=t,this}getName(){return`${user.getFname()} ${user.getLname()}`}getEmail(){return this._email}setEmail(t){return this._email=t,this}getPhone(){return this._phone}setPhone(t){return this._phone=t,this}getPermissions(){return this._permissions}setPermissions(t){if(!Array.isArray(t))throw"setPermissions requires an array";return this._permissions=t,this}addPermission(t){return this._permissions.push(t),this}removePermission(t){return this.setPermissions(this._permissions.filter(function(e){return e!==t})),this}hasPermission(t){return this.getPermissions().includes(t)}getAdditionalData(){return this._additionalData}setAdditionalData(t){return i.a.isDataObject(t,null,!1,!1,!0),this._additionalData=t,this}getDataItem(t){return void 0===this._additionalData[t]?null:this._additionalData[t]}setDataItem(t,e){return this._additionalData[t]=e,this}}},function(t,e,n){"use strict";n.r(e),function(t){n.d(e,"jpack",function(){return d});var i=n(0),r=n(2),o=n(8),s=n(1),a=n(5),u=n(9),l=n(7),c=n(3),h=n(10);const f={dom:i.a,events:r.a,XHRForm:o.b,FormFromURL:o.a,navigation:s.a,request:a.a,Site:u.a,strings:l.a,type_checks:c.a,User:h.a},d={...f,setGlobal:function(t){t="string"==typeof t?t:null;for(const e in f)t?(void 0===window[t]&&(window[t]={}),window[t][e]=f[e]):window[e]=f[e]}};t.jpack=d}.call(this,n(12))},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e){t.exports=url-search-params-polyfill},function(t,e){t.exports=formdata-polyfill}]); | ||
!function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=11)}([function(t,e,n){"use strict";n.d(e,"a",function(){return i});const i={getElement:function(t,e,n){if((t=this.getElements(t,e)).length>1&&n)throw"Too many DOM elements found in getElement for "+JSON.stringify(t);return t?t[0]:null},getElements:function(t,e){e=void 0!==e&&e;let n=[];if(void 0!==t&&t)if(t instanceof Element||t instanceof HTMLDocument)n.push(t);else if("string"==typeof t)n=(n=document.querySelectorAll(t))?Array.from(n):n;else if(t instanceof jQuery)t.length&&(n=t.toArray());else if(t instanceof NodeList||t instanceof HTMLCollection)n=Array.from(t);else{if(!Array.isArray(t))throw"Invalid value provided to getElements: "+JSON.stringify(t);t.forEach(function(t){(t=i.getElement(t))&&n.push(t)})}else;if(!n.length&&e)throw"Failed to get array of DOM elements for "+JSON.stringify(t);return n},remove:function(t){return this.getElements(t).forEach(function(t){t.parentNode.removeChild(t)}),this},replaceElWithHTML:function(t,e){if("string"!=typeof e)throw`${e} is not a string`;t=this.getElement(t);let n=(new DOMParser).parseFromString(e,"text/html");return n=t.parentNode.insertBefore(n.documentElement.querySelector("body").childNodes[0],t),t.remove(),n},isVisible(t){t=this.getElement(t,!0,!0);const e=getComputedStyle(t);if("none"===e.display)return!1;if("visible"!==e.visibility)return!1;if(0===e.opacity)return!1;if(t.offsetWidth+t.offsetHeight+t.getBoundingClientRect().height+t.getBoundingClientRect().width===0)return!1;const n=t.getBoundingClientRect(),i={"top-left":{x:n.left,y:n.top},"top-right":{x:n.right,y:n.top},"bottom-left":{x:n.left,y:n.bottom},"bottom-right":{x:n.right,y:n.bottom},center:{x:n.left+t.offsetWidth/2,y:n.top+t.offsetHeight/2}};return Object.keys(i).forEach(function(e){var n=i[e];if(n.x<0)return!1;if(n.x>(document.documentElement.clientWidth||window.innerWidth))return!1;if(n.y<0)return!1;if(n.y>(document.documentElement.clientHeight||window.innerHeight))return!1;let r=document.elementFromPoint(n.x,n.y);if(null!==r)do{if(r===t)return!0}while(r=r.parentNode)}),!1},exists:function(t){return this.getElements(t).length},multipleExist:function(t){return this.getElements(t).length>1}}},function(t,e,n){"use strict";n.d(e,"a",function(){return u});var i=n(4),r=n.n(i),o=n(0),s=n(5),a=n(2);const u={_passthroughData:null,setPassthroughData:function(t){return this._passthroughData=t,this},clearPassthroughData:function(){return this.setPassthroughData(null),this},getPassThroughData:function(t){return this._passthroughData},_incomingElementSelector:"body",setIncomingElement:function(t){if("string"!=typeof t)throw`${t} is not a string`;this._incomingElementSelector=t},getIncomingElement:function(){return this._incomingElementSelector},_replaceElementSelector:"body",setReplaceElement:function(t){if("string"!=typeof t)throw`${t} is not a string`;this._replaceElementSelector=t},getReplaceElement:function(){return this._replaceElementSelector},load:function(t,e,n,i,s){if("string"!=typeof t)throw`Provided URL (${t}) is not a string`;if(n=void 0!==n&&n?n:this.getIncomingElement(),i=void 0!==i&&i?i:this.getReplaceElement(),s=void 0===s||s,"string"!=typeof n)throw`Provided incoming_el (${n}) is not a string`;if("string"!=typeof i)throw`Provided replace_el (${i}) is not a string`;u.showLoader(),r.a.get(t).then(function(r){u.hideLoader(),u.replacePageContent(r.data,t,n,i,s),"function"==typeof e&&window.setTimeout(function(){e(o.a.getElement(i),n,u.getPassThroughData())},105)}).catch(function(t){throw u.hideLoader(),u.triggerNavigationFailure(t),t})},loaderEnabled:!0,_loaderDelay:300,setLoaderDelay:function(t){if("number"!=typeof t)throw`${t} is not an integer`;return this._loaderDelay=t,this},getLoaderDelay:function(){return this._loaderDelay},_loaderClasses:"progress page-navigation-loader",_loaderInnerDivClasses:"progress-bar progress-bar-striped progress-bar-animated",getLoaderEl:function(){if(!this.loaderEnabled)return;if(u.navLoaderCached)return u.navLoaderCached;let t=document.createElement("div");t.classList=this._loaderClasses;let e=document.createElement("div");return e.classList=this._loaderInnerDivClasses,t.append(e),document.body.prepend(t),u.navLoaderCached=o.a.getElement(".page-navigation-loader"),u.navLoaderCached},showLoader:function(){if(this.loaderEnabled)return u.loader_timeout=window.setTimeout(function(){u.getLoaderEl().classList.add("active")},this.getLoaderDelay()),this},hideLoader:function(){if(this.loaderEnabled)return window.clearTimeout(u.loader_timeout),u.getLoaderEl().classList.remove("active"),this},parseHTML(t,e){if("string"!=typeof(e=void 0===e?null:e)&&null!==e)throw`Provided parent_el (${e}) is not a string or null`;var n=new DOMParser,i=n.parseFromString(t,"text/html"),r=i.querySelector("title");r=r?r.innerText:null;var o=i.head.getElementsByTagName("meta"),s=i.querySelectorAll('link[rel="canonical"]'),a=i.body.classList,l=t;if(e){var c=i.querySelector(e);if(!c)throw`Could not find parent selector ${e}`;l=c.outerHTML}var h=u.getRouteFromMeta(i);return n=i=null,{title:r,route:h,metas:o,links:s,body_classes:a,html:l}},getRouteFromMeta:function(t){var e=(t=void 0===t?document.head:t).querySelector('[name="current_route"]');return e=e?e.content:null},replacePageContent(t,e,n,i,r){var s=this;if(r=void 0===r||r,n=void 0!==n&&n?n:this.getIncomingElement(),i=void 0!==i&&i?i:this.getReplaceElement(),"string"!=typeof e)throw`Provided url (${e}) is not a string`;if("string"!=typeof n)throw`Provided incoming_el (${n}) is not a string`;if("string"!=typeof i)throw`Provided replace_el (${i}) is not a string`;return u.triggerUnload(o.a.getElement(i),i,this.getRouteFromMeta()),window.setTimeout(function(){var a=u.parseHTML(t,n);if(a.html.length){o.a.remove("meta"),document.head.append(a.metas),o.a.remove('[rel="canonical"]'),Array.from(a.links).forEach(function(t){document.head.append(t)}),document.body.classList=a.body_classes,r&&history.pushState({url:e},a.title,e),u.setTitle(a.title);const t=o.a.replaceElWithHTML(i,a.html);u.triggerOnLoad(t,n,i,a.route),s.getReplaceElement()!==i&&s.setReplaceElement(n)}},100),this},reload:function(t){return t="function"!=typeof t?null:t,u.load(s.a.getFullURL(),t),this},fullReload:function(){u.showLoader(),window.location.reload()},redirect:function(t){u.showLoader(),window.location.href=t},setTitle:function(t){return document.title=t,this},onLoad:function(t){return a.a.on("body","navigation.complete",t),this},onUnload:function(t){return a.a.on("body","navigation.started",t),this},onNavigationFailure:function(t){return a.a.on("body","navigation.failed",t),this},triggerOnLoad:function(t,e,n,i){return i=void 0!==i?i:u.getRouteFromMeta(),a.a.trigger("body","navigation.complete",{el:t,el_selector:e,replaced_selector:n,route:i,data:this.getPassThroughData()}),this},triggerUnload:function(t,e,n){return a.a.trigger("body","navigation.started",{el:t,el_selector:e,route:n}),this},triggerNavigationFailure:function(t){return a.a.trigger("body","navigation.failed",{error:t}),this},initHistoryHandlers:function(){return window.onpushstate=function(t){console.log(t),u.load(s.a.getURIWithQueryString())},window.onpopstate=function(t){console.log(t),u.load(s.a.getURIWithQueryString(),null,null,null,!1)},this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return r});var i=n(0);const r={setGlobal:function(t){for(var e in t="string"==typeof t?t:null,this)this.hasOwnProperty(e)&&"setGlobal"!==e&&(t?(void 0===window[t]&&(window[t]={}),window[t][e]=this[e]):window[e]=this[e])},onClick:function(t,e){return this.onEventPreventDefault(t,"click",e)},offClick(t,e){return this.offEventPreventDefault(t,"click",e)},onSubmit:function(t,e){return this.onEventPreventDefault(t,"submit",e)},offSubmit:function(t,e){return this.offEventPreventDefault(t,"submit",e)},onChange:function(t,e){return this.on(t,"change",e)},offChange:function(t,e){return this.off(t,"change",e)},onEventPreventDefault:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.addEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),r):t},offEventPreventDefault:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.removeEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),r):t},on:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.addEventListener(e,n)}),r):t},off:function(t,e,n){const r=i.a.getElements(t);return r.length?(r.forEach(function(t){t.removeEventListener(e,n)}),r):t},trigger:function(t,e,n){const r=i.a.getElements(t);return r.length?(n=void 0===n?null:n,e=new CustomEvent(e,{detail:n}),r.forEach(function(t){t.dispatchEvent(e)}),r):t}}},function(t,e,n){"use strict";n.d(e,"a",function(){return i});const i={isDataObject:function(t,e,n,i,r){r=void 0!==r&&r,n=void 0!==n&&n;var o=JSON.stringify(t);const s=`${o} is not an object`;if(void 0===t){if(r)throw s;return!1}if(!("object"==typeof t)||null===t||Array.isArray(t)){if(r)throw s;return!1}if(Array.isArray(e)){let s=!1,a=[];const u=Object.keys(t);if(e.forEach(function(t){u.includes(t)?s=!0:a.push(t)}),!s){if(r)throw`${o} does not contain at least one of the following: `+e.join(", ");return!1}if(n&&a.length){if(r)throw`${o} is missing data: `+a.join(", ");return!1}if(i){let t=[];if(u.forEach(function(n){e.includes(n)||t.push(n)}),t.length){if(r)throw`${o} contains invalid data: `+t.join(", ");return!1}}}return!0}}},function(t,e){t.exports=axios},function(t,e,n){"use strict";n.d(e,"a",function(){return i}),n(13);const i={query:new URLSearchParams(window.location.search),isHttps:function(){return"https:"===window.location.protocol},getDomain:function(){return window.location.hostname||window.location.host},getDomainWithProtocol:function(){return window.location.origin},getURI:function(){return window.location.pathname},getURIWithQueryString:function(){return window.location.pathname+window.location.search},getFullURL:function(){return window.location.href},appendSlash:function(t){return"/"!==t[t.length-1]?t+"/":t}}},function(t,e,n){"use strict";n.d(e,"a",function(){return o});var i=n(3),r=n(7);class o{constructor(){}populate(t){const e=this;if(void 0===this._keys)throw"Cannot populate object if _keys property is not set";return i.a.isDataObject(t,this._keys,!1,!0,!0),this._keys.forEach(function(n){void 0!==t[n]&&e[r.a.setter(n)](t[n])}),this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return i});const i={getter:function(t){return"get"+this.ucfirst(t)},setter:function(t){return"set"+this.ucfirst(t)},ucfirst:function(t){return t&&t[0].toUpperCase()+t.slice(1)}}},function(t,e,n){"use strict";var i=n(0),r=n(1),o=n(4),s=n.n(o);n(14);const a={xhrSubmit:!0,submitURL:null,submitMethod:null,onError:function(t,e,n){alert(t)},onSuccess:function(t,e){"string"==typeof t.success?alert(t.success):alert("Your submission has been received")},validateForm:function(t){t.classList.add("was-validated");const e=!t.querySelector(":invalid");return e&&t.classList.remove("was-validated"),e}};class u{constructor(t,e){if("object"!=typeof(e=void 0===e?{}:e))throw`${e} is not an object`;e={...a,...e},this.setForm(t),this.setValidateCallback(e.validateForm),this.setXHRSubmit(e.xhrSubmit),this.setSubmitMethod(e.submitMethod),this.setSubmitURL(e.submitURL),this.onSuccess(e.onSuccess),this.onError(e.onError)}setValidateCallback(t){if("function"!=typeof t)throw`${t} is not a function`;return this._validateCallback=t,this}validate(t){return void 0===t&&(t=this.getForm()),this._validateCallback(t)}setForm(t){if(!t||void 0===t)throw"Form element is required";if(!(t=i.a.getElement(t,!0,!0)))throw"Invalid form element received";return this._form=t,this}getForm(){return this._form}setXHRSubmit(t){return this._xhrSubmit=!!t,this}setSubmitMethod(t){if("string"!=typeof t&&null!==t)throw`${t} is not a string or null`;return this._submitMethod=t,this}getSubmitMethod(){return this._submitMethod}setSubmitURL(t){if("string"!=typeof t&&"function"!=typeof t&&null!==t)throw`${t} is not a string, function, or null`;return this._submitURL=t,this}getSubmitURL(){return this._submitURL}getFinalSubmitURL(t){let e=this.getSubmitURL(t);return"function"==typeof this._submitURL?this._submitURL(t):null===e?t.action:e}attachSubmitHandler(t){if(!this._xhrSubmit)return;if(!(t=void 0===t?this.getForm():i.a.getElement(t)))throw"Form element not received, cannot attach submit handler";const e=this;return t.addEventListener("submit",function(n){return!e._xhrSubmit||(n.preventDefault(),e.submitForm(t),!1)}),this}onSuccess(t){if("function"!=typeof t)throw`${t} is not a function`;return void 0===this._onSuccess&&(this._onSuccess=[]),this._onSuccess.push(t),this}clearOnSuccessCallbacks(){return this._onSuccess=[],this}triggerOnSuccess(t,e){return void 0!==this._onSuccess&&(this._onSuccess.forEach(function(n){n(t,e)}),this)}onError(t){if("function"!=typeof t)throw`${t} is not a function`;return void 0===this._onError&&(this._onError=[]),this._onError.push(t),this}clearOnErrorCallbacks(){return this._onError=[],this}triggerOnError(t,e,n){return void 0!==this._onError&&(this._onError.forEach(function(i){i(t,e,n)}),this)}submitForm(t){if(void 0===this._processing&&(this._processing=!1),this._processing)return!1;this._processing=!0;const e=this;let n=this.getFinalSubmitURL(t),i=this.getSubmitMethod();if(null===i&&void 0!==t.attributes.method&&(i=t.method),i=i?i.toLowerCase():"post",!this.validate(t))return this._processing=!1,!1;r.a.showLoader();const o=Array.from(this.getFormValues(t),t=>t.map(encodeURIComponent).join("=")).join("&");return s()({url:n,method:i,data:o}).then(function(n){r.a.hideLoader(),e._processing=!1;let i=n.data;try{i="string"==typeof i?JSON.parse(i):i}catch(t){}if("string"==typeof i){if("string"==typeof e.getIncomingElementSelector()){const n=r.a.parseHTML(i,e.getIncomingElementSelector());return n.html.length?e.insertForm(n,i,t):e.triggerOnError(`${e.getIncomingElementSelector()} could not be found in response from the server`,i,t)}return e.insertForm({html:i},i,t)}if("object"==typeof i)return i.html?e.insertForm({html:i.html},i,t):i.error?e.triggerOnError(i.error,i,t):e.triggerOnSuccess(i,t)}).catch(function(t){throw r.a.hideLoader(),e._processing=!1,t}),this}getFormValues(t){return new FormData(t)}}const l={incomingElementSelector:null,insertIntoElement:null,onload:function(t){return this}};class c extends u{constructor(t,e){if(super(null,e),"string"!=typeof t)throw`${t} is not a string`;if("object"!=typeof(e=void 0===e?{}:e))throw`${e} is not an object`;e={...l,...e},this.setURL(t),this.setIncomingElementSelector(e.incomingElementSelector),this.setInsertIntoElement(e.insertIntoElement),this.onload(e.onload)}setForm(t){return this._form=t,this}setURL(t){if("string"!=typeof t)throw`${t} is not a string`;return this._url=t,this}getURL(){return this._url}getFinalSubmitURL(t){let e=this.getSubmitURL(t);return"function"==typeof this._submitURL?this._submitURL(t):(null===e&&t.attributes.action&&(e=t.action),null===(e=e||this.getURL())&&(e=t.action),e)}setIncomingElementSelector(t){if(null!==t&&"string"!=typeof t)throw`${t} is not a string or null value`;return this._incomingElementSelector=t,this}getIncomingElementSelector(){return this._incomingElementSelector}setInsertIntoElement(t){this._insertIntoElement=t}getInsertIntoElement(){return this._insertIntoElement}getForm(){const t=this;r.a.showLoader(),s.a.get(this.getURL()).then(function(e){r.a.hideLoader();let n=e.data;try{n="string"==typeof n?JSON.parse(n):n}catch(t){}if("string"==typeof n){if("string"==typeof t.getIncomingElementSelector()){const e=r.a.parseHTML(n,t.getIncomingElementSelector());return t.insertForm(e,n)}return t.insertForm({html:n})}if("object"==typeof n&&void 0!==n.html)return t.insertForm({html:n.html},n);throw`Unexpected server response ${n}`}).catch(function(t){throw r.a.hideLoader(),t})}insertForm(t,e,n){let r=this.getInsertIntoElement();if(null===r)throw"Cannot determine where to insert form. Overwrite insertForm() or provide insertIntoElement";return(r=i.a.getElement(r,!0)).innerHTML=t.html,n=r.querySelector("form"),this.attachSubmitHandler(n),this.triggerOnload(n),r}onload(t){if("function"!=typeof t)throw`${t} is not a function`;return void 0===this._onload&&(this._onload=[]),this._onload.push(t),this}clearOnloadCallbacks(){return this._onload=[],this}triggerOnload(t){return void 0!==this._onload&&(this._onload.forEach(function(e){e(t)}),this)}}n.d(e,"b",function(){return u}),n.d(e,"a",function(){return c})},function(t,e,n){"use strict";n.d(e,"a",function(){return s});var i=n(3),r=n(6);const o={id:null,name:null,config:{}};class s extends r.a{constructor(t){if(super(),this._keys=["id","name","config"],void 0===t)return this;t={...o,...t},this.populate(t)}getId(){return this._id}setId(t){return this._id=t,this}getName(){return this._name}setName(t){return this._name=t,this}getConfig(){return this._config}setConfig(t){return i.a.isDataObject(t,null,!1,!1,!0),this._config=t,this}getConfigItem(t){return void 0===this._config[t]?null:this._config[t]}setConfigItem(t,e){return this._config[t]=e,this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return s});var i=n(3),r=n(6);const o={id:null,isGuest:!1,isAdmin:!1,username:null,fname:null,lname:null,email:null,phone:null,permissions:[],additionalData:{}};class s extends r.a{constructor(t){if(super(),this._keys=["id","isGuest","isAdmin","username","fname","lname","email","phone","permissions","additionalData"],void 0===t)return this;t={...o,...t},this.populate(t)}setId(t){return this._id=t,this}getId(){return this._id}setIsGuest(t){return this._isGuest=t,this}getIsGuest(){return this._isGuest}setIsAdmin(t){return this._isAdmin=t,this}getIsAdmin(){return this._isAdmin}setUsername(t){return this._username=t,this}getUsername(){return this._username}getFname(){return this._fname}setFname(t){return this._fname=t,this}getLname(){return this._lname}setLname(t){return this._lname=t,this}getName(){return`${user.getFname()} ${user.getLname()}`}getEmail(){return this._email}setEmail(t){return this._email=t,this}getPhone(){return this._phone}setPhone(t){return this._phone=t,this}getPermissions(){return this._permissions}setPermissions(t){if(!Array.isArray(t))throw"setPermissions requires an array";return this._permissions=t,this}addPermission(t){return this._permissions.push(t),this}removePermission(t){return this.setPermissions(this._permissions.filter(function(e){return e!==t})),this}hasPermission(t){return this.getPermissions().includes(t)}getAdditionalData(){return this._additionalData}setAdditionalData(t){return i.a.isDataObject(t,null,!1,!1,!0),this._additionalData=t,this}getDataItem(t){return void 0===this._additionalData[t]?null:this._additionalData[t]}setDataItem(t,e){return this._additionalData[t]=e,this}}},function(t,e,n){"use strict";n.r(e),function(t){n.d(e,"jpack",function(){return d});var i=n(0),r=n(2),o=n(8),s=n(1),a=n(5),u=n(9),l=n(7),c=n(3),h=n(10);const f={dom:i.a,events:r.a,XHRForm:o.b,FormFromURL:o.a,navigation:s.a,request:a.a,Site:u.a,strings:l.a,type_checks:c.a,User:h.a},d={...f,setGlobal:function(t){t="string"==typeof t?t:null;for(const e in f)t?(void 0===window[t]&&(window[t]={}),window[t][e]=f[e]):window[e]=f[e]}};t.jpack=d}.call(this,n(12))},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e){t.exports=url-search-params-polyfill},function(t,e){t.exports=formdata-polyfill}]); |
@@ -164,4 +164,3 @@ /** | ||
//make sure the element is inside the viewport | ||
for(key in el_bounds) { | ||
Object.keys(el_bounds).forEach(function(key){ | ||
var point = el_bounds[key]; | ||
@@ -180,3 +179,3 @@ | ||
} | ||
} | ||
}); | ||
@@ -183,0 +182,0 @@ return false; |
{ | ||
"name": "@htmlguyllc/jpack", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Core Javascript Library of Everyday Objects, Events, and Utilities", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
326217