@htmlguyllc/jpack
Advanced tools
Comparing version 3.0.3 to 4.0.1
@@ -1,1 +0,1 @@ | ||
!function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},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=9)}([function(t,e,n){"use strict";n.d(e,"a",function(){return r});const r={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[0]},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))throw"Invalid value provided to getElements: "+JSON.stringify(t);t.length&&(n=t.toArray())}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},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 i});var r=n(0);const i={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 i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.addEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),i):t},offEventPreventDefault:function(t,e,n){const i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.removeEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),i):t},on:function(t,e,n){const i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.addEventListener(e,n)}),i):t},off:function(t,e,n){const i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.removeEventListener(e,n)}),i):t},trigger:function(t,e,n){const i=r.a.getElements(t);return i.length?(n=void 0===n?null:n,e=new CustomEvent(e,{detail:n}),i.forEach(function(t){t.dispatchEvent(e)}),i):t}}},function(t,e,n){"use strict";n.d(e,"a",function(){return r});const r={isDataObject:function(t,e,n,r,i){i=void 0!==i&&i,n=void 0!==n&&n;var o=JSON.stringify(t);const s=`${o} is not an object`;if(void 0===t){if(i)throw s;return!1}if(!("object"==typeof t)||null===t||Array.isArray(t)){if(i)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(i)throw`${o} does not contain at least one of the following: `+e.join(", ");return!1}if(n&&a.length){if(i)throw`${o} is missing data: `+a.join(", ");return!1}if(r){let t=[];if(u.forEach(function(n){e.includes(n)||t.push(n)}),t.length){if(i)throw`${o} contains invalid data: `+t.join(", ");return!1}}}return!0}}},function(t,e,n){"use strict";n.d(e,"a",function(){return r}),n(11);const r={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.r(e);var r=n(2);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)}};var o=n(0),s=n(1);n.d(e,"type_checks",function(){return r.a}),n.d(e,"strings",function(){return i}),n.d(e,"dom",function(){return o.a}),n.d(e,"events",function(){return s.a})},function(t,e){t.exports=axios},function(t,e,n){"use strict";n.r(e)},function(t,e,n){"use strict";n.r(e);var r=n(3),i=n(2),o=n(4);class s{constructor(){}populate(t){const e=this;if(void 0===this._keys)throw"Cannot populate object if _keys property is not set";return o.type_checks.isDataObject(t,this._keys,!1,!0,!0),this._keys.forEach(function(n){void 0!==t[n]&&e[o.strings.setter(n)](t[n])}),this}}const a={id:null,name:null,config:{}};class u extends s{constructor(t){if(super(),this._keys=["id","name","config"],void 0===t)return this;t={...a,...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}}const l={id:null,isGuest:!1,isAdmin:!1,username:null,fname:null,lname:null,email:null,phone:null,permissions:[],additionalData:{}};class c extends s{constructor(t){if(super(),this._keys=["id","isGuest","isAdmin","username","fname","lname","email","phone","permissions","additionalData"],void 0===t)return this;t={...l,...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}}n.d(e,"request",function(){return r.a}),n.d(e,"User",function(){return c}),n.d(e,"Site",function(){return u})},function(t,e,n){"use strict";n.r(e);var r=n(5),i=n.n(r),o=n(0),s=n(3),a=n(1);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,r,s){if("string"!=typeof t)throw`Provided URL (${t}) is not a string`;if(n=void 0!==n&&n?n:this.getIncomingElement(),r=void 0!==r&&r?r:this.getReplaceElement(),s=void 0===s||s,"string"!=typeof n)throw`Provided incoming_el (${n}) is not a string`;if("string"!=typeof r)throw`Provided replace_el (${r}) is not a string`;u.showLoader(),i.a.get(t).then(function(i){u.hideLoader(),u.replacePageContent(i.data,t,n,r,s),"function"==typeof e&&window.setTimeout(function(){e(o.a.getElement(r),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,r=n.parseFromString(t,"text/html"),i=r.querySelector("title");i=i?i.innerText:null;var o=r.head.getElementsByTagName("meta"),s=r.querySelectorAll('link[rel="canonical"]'),a=r.body.classList,l=t;if(e){var c=r.querySelector(e);if(!c)throw`Could not find parent selector ${e}`;l=c.outerHTML}var h=u.getRouteFromMeta(r);return n=r=null,{title:i,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,r,i){if(i=void 0===i||i,n=void 0!==n&&n?n:this.getIncomingElement(),r=void 0!==r&&r?r: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 r)throw`Provided replace_el (${r}) is not a string`;return u.triggerUnload(o.a.getElement(r),r,this.getRouteFromMeta()),window.setTimeout(function(){var s=u.parseHTML(t,n);if(s.html.length){o.a.remove("meta"),document.head.append(s.metas),o.a.remove('[rel="canonical"]'),Array.from(s.links).forEach(function(t){document.head.append(t)}),document.body.classList=s.body_classes,i&&history.pushState({url:e},s.title,e),u.setTitle(s.title);const t=o.a.replaceElWithHTML(r,s.html);u.triggerOnLoad(t,n,s.route)}},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){return n=void 0!==n?n:u.getRouteFromMeta(),a.a.trigger("body","navigation.complete",{el:t,el_selector:e,route:n,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}};n(2);n(12);const l={xhrSubmit:!0,submitURL:null,submitMethod:null,onError:function(t,e,n){},onSuccess:function(t,e){},validateForm:function(t){t.classList.add("was-validated");const e=!t.querySelector(":invalid");return e&&t.classList.remove("was-validated"),e}},c={incomingElementSelector:null,insertIntoElement:null,onload:function(t){return this}};class h{constructor(t,e){if("object"!=typeof(e=void 0===e?{}:e))throw`${e} is not an object`;e={...l,...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=o.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(t){return"function"==typeof this._submitURL?this._submitURL(t):this._submitURL}attachSubmitHandler(t){if(this._xhrSubmit){if(!(t=void 0===t?this.getForm():o.a.getElement(t)))throw"Form element not received, cannot attach submit handler";var 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(r){r(t,e,n)}),this)}submitForm(t){var e=this;let n=this.getSubmitURL(t);null===n&&t.attributes.action&&(n=t.action),n=n||this.getURL();let r=this.getSubmitMethod();if(null===r&&void 0!==t.attributes.method&&(r=t.method),r=r?r.toLowerCase():"post",!this.validate(t))return!1;u.showLoader();const o=Array.from(this.getFormValues(t),t=>t.map(encodeURIComponent).join("=")).join("&");return i()({url:n,method:r,data:o}).then(function(n){u.hideLoader();let r=n.data;try{r="string"==typeof r?JSON.parse(r):r}catch(t){}if("string"==typeof r){if("string"==typeof e.getIncomingElementSelector()){const n=u.parseHTML(r,e.getIncomingElementSelector());return n.html.length?e.insertForm(n,r,t):e.triggerOnError(`${e.getIncomingElementSelector()} could not be found in response from the server`,r,t)}return e.insertForm({html:r},r,t)}if("object"==typeof r)return r.html?e.insertForm({html:r.html},r,t):r.error?e.triggerOnError(r.error,r,t):e.triggerOnSuccess(r,t)}).catch(function(t){throw u.hideLoader(),t}),this}getFormValues(t){return new FormData(t)}}class f extends h{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={...c,...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}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(){var t=this;u.showLoader(),i.a.get(this.getURL()).then(function(e){u.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=u.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 u.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=o.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,"navigation",function(){return u}),n.d(e,"XHRForm",function(){return h}),n.d(e,"FormFromURL",function(){return f})},function(t,e,n){"use strict";n.r(e),function(t){n.d(e,"jpack",function(){return a});var r=n(8),i=n(7),o=n(6),s=n(4);const a={components:r,objects:i,plugin_wrappers:o,utilities:s,goGlobal:function(t){t="string"==typeof t?t+".":null,[r,i,o,s].forEach(function(e){for(var n in e)e.hasOwnProperty(n)&&(window[t+n]=e[n])})}};t.jpack=a}.call(this,n(10))},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(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},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 r});const r={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[0]},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))throw"Invalid value provided to getElements: "+JSON.stringify(t);t.length&&(n=t.toArray())}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},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 r=n(4),i=n.n(r),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,r,s){if("string"!=typeof t)throw`Provided URL (${t}) is not a string`;if(n=void 0!==n&&n?n:this.getIncomingElement(),r=void 0!==r&&r?r:this.getReplaceElement(),s=void 0===s||s,"string"!=typeof n)throw`Provided incoming_el (${n}) is not a string`;if("string"!=typeof r)throw`Provided replace_el (${r}) is not a string`;u.showLoader(),i.a.get(t).then(function(i){u.hideLoader(),u.replacePageContent(i.data,t,n,r,s),"function"==typeof e&&window.setTimeout(function(){e(o.a.getElement(r),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,r=n.parseFromString(t,"text/html"),i=r.querySelector("title");i=i?i.innerText:null;var o=r.head.getElementsByTagName("meta"),s=r.querySelectorAll('link[rel="canonical"]'),a=r.body.classList,l=t;if(e){var c=r.querySelector(e);if(!c)throw`Could not find parent selector ${e}`;l=c.outerHTML}var h=u.getRouteFromMeta(r);return n=r=null,{title:i,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,r,i){if(i=void 0===i||i,n=void 0!==n&&n?n:this.getIncomingElement(),r=void 0!==r&&r?r: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 r)throw`Provided replace_el (${r}) is not a string`;return u.triggerUnload(o.a.getElement(r),r,this.getRouteFromMeta()),window.setTimeout(function(){var s=u.parseHTML(t,n);if(s.html.length){o.a.remove("meta"),document.head.append(s.metas),o.a.remove('[rel="canonical"]'),Array.from(s.links).forEach(function(t){document.head.append(t)}),document.body.classList=s.body_classes,i&&history.pushState({url:e},s.title,e),u.setTitle(s.title);const t=o.a.replaceElWithHTML(r,s.html);u.triggerOnLoad(t,n,s.route)}},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){return n=void 0!==n?n:u.getRouteFromMeta(),a.a.trigger("body","navigation.complete",{el:t,el_selector:e,route:n,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 i});var r=n(0);const i={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 i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.addEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),i):t},offEventPreventDefault:function(t,e,n){const i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.removeEventListener(e,function(t){return t.preventDefault(),n.call(this,[t]),!1})}),i):t},on:function(t,e,n){const i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.addEventListener(e,n)}),i):t},off:function(t,e,n){const i=r.a.getElements(t);return i.length?(i.forEach(function(t){t.removeEventListener(e,n)}),i):t},trigger:function(t,e,n){const i=r.a.getElements(t);return i.length?(n=void 0===n?null:n,e=new CustomEvent(e,{detail:n}),i.forEach(function(t){t.dispatchEvent(e)}),i):t}}},function(t,e,n){"use strict";n.d(e,"a",function(){return r});const r={isDataObject:function(t,e,n,r,i){i=void 0!==i&&i,n=void 0!==n&&n;var o=JSON.stringify(t);const s=`${o} is not an object`;if(void 0===t){if(i)throw s;return!1}if(!("object"==typeof t)||null===t||Array.isArray(t)){if(i)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(i)throw`${o} does not contain at least one of the following: `+e.join(", ");return!1}if(n&&a.length){if(i)throw`${o} is missing data: `+a.join(", ");return!1}if(r){let t=[];if(u.forEach(function(n){e.includes(n)||t.push(n)}),t.length){if(i)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 r}),n(13);const r={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 r=n(3),i=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 r.a.isDataObject(t,this._keys,!1,!0,!0),this._keys.forEach(function(n){void 0!==t[n]&&e[i.a.setter(n)](t[n])}),this}}},function(t,e,n){"use strict";n.d(e,"a",function(){return r});const r={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 r=n(0),i=n(1),o=n(4),s=n.n(o);n(14);const a={xhrSubmit:!0,submitURL:null,submitMethod:null,onError:function(t,e,n){},onSuccess:function(t,e){},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=r.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(t){return"function"==typeof this._submitURL?this._submitURL(t):this._submitURL}attachSubmitHandler(t){if(!this._xhrSubmit)return;if(!(t=void 0===t?this.getForm():r.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(r){r(t,e,n)}),this)}submitForm(t){const e=this;let n=this.getSubmitURL(t);null===n&&t.attributes.action&&(n=t.action),n=n||this.getURL();let r=this.getSubmitMethod();if(null===r&&void 0!==t.attributes.method&&(r=t.method),r=r?r.toLowerCase():"post",!this.validate(t))return!1;i.a.showLoader();const o=Array.from(this.getFormValues(t),t=>t.map(encodeURIComponent).join("=")).join("&");return s()({url:n,method:r,data:o}).then(function(n){i.a.hideLoader();let r=n.data;try{r="string"==typeof r?JSON.parse(r):r}catch(t){}if("string"==typeof r){if("string"==typeof e.getIncomingElementSelector()){const n=i.a.parseHTML(r,e.getIncomingElementSelector());return n.html.length?e.insertForm(n,r,t):e.triggerOnError(`${e.getIncomingElementSelector()} could not be found in response from the server`,r,t)}return e.insertForm({html:r},r,t)}if("object"==typeof r)return r.html?e.insertForm({html:r.html},r,t):r.error?e.triggerOnError(r.error,r,t):e.triggerOnSuccess(r,t)}).catch(function(t){throw i.a.hideLoader(),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}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;i.a.showLoader(),s.a.get(this.getURL()).then(function(e){i.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=i.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 i.a.hideLoader(),t})}insertForm(t,e,n){let i=this.getInsertIntoElement();if(null===i)throw"Cannot determine where to insert form. Overwrite insertForm() or provide insertIntoElement";return(i=r.a.getElement(i,!0)).innerHTML=t.html,n=i.querySelector("form"),this.attachSubmitHandler(n),this.triggerOnload(n),i}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 r=n(3),i=n(6);const o={id:null,name:null,config:{}};class s extends i.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 r.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 r=n(3),i=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 i.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 r.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 f});var r=n(0),i=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:r.a,events:i.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,setGlobal:function(t){t="string"==typeof t?t+".":null,[components,objects,plugin_wrappers,utilities].forEach(function(e){for(var n in e)e.hasOwnProperty(n)&&(window[t+n]=e[n])})}};t.jpack=f}.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}]); |
@@ -1,4 +0,4 @@ | ||
import {CurUser} from "./CurrentUser"; | ||
import {CurSite} from "./CurrentSite"; | ||
//now you have access to the current user and their data anywhere | ||
CurUser.getId(); | ||
//now you have access to the current site and their data anywhere | ||
CurSite.getId(); |
@@ -1,2 +0,2 @@ | ||
import {Site} from "@htmlguyllc/jpack/es/objects/site"; | ||
import {Site} from "../../es/site"; | ||
@@ -3,0 +3,0 @@ //grab $user data set in HTML using variables from your server |
@@ -1,2 +0,2 @@ | ||
import {User} from "@htmlguyllc/jpack/es/objects/user"; | ||
import {User} from "../../es/user"; | ||
@@ -3,0 +3,0 @@ //grab $user data set in HTML using variables from your server |
@@ -1,3 +0,3 @@ | ||
import {FormFromURL} from "@htmlguyllc/jpack/es/components/form"; | ||
import {type_checks} from "../../es/utilities/type_checks"; | ||
import {FormFromURL} from "../../es/forms"; | ||
import {type_checks} from "../../es/type_checks"; | ||
@@ -99,3 +99,3 @@ //defaults for the FormModalFromURL class | ||
insertForm(parsed_content, response, form){ | ||
var self = this; | ||
const self = this; | ||
@@ -102,0 +102,0 @@ //if form is already defined, it was submitted and the response contained HTML, so we need to just replace it ourselves |
{ | ||
"name": "@htmlguyllc/jpack", | ||
"version": "3.0.3", | ||
"version": "4.0.1", | ||
"description": "Core Javascript Library of Everyday Objects, Events, and Utilities", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# jPack | ||
jPack is a library of components, objects, plugin wrappers, and utilities designed to make building custom websites simpler. | ||
jPack is a library of components, classes, plugin wrappers, and utilities designed to make building custom websites simpler. | ||
With jPack, you can easily upgrade your server-side rendered application to a pseudo-SPA using XHR requests for page-loads, get values from the querystring, store and interact with user/multi-tenant website data, and more. | ||
# What's Included | ||
Four categories of functionality are provided in this library. | ||
Each one is detailed further in the documentation below. | ||
Component | Data Type | Singleton? | What it does | ||
--- | --- | --- | --- | ||
navigation | object | yes | Grabs HTML from a URL and replaces content on the current page. Handles browser history, meta title swaps, and offers several callbacks | ||
XHRForm | class | no | Adds an on-submit listener and sends the form values using XHR with callbacks for success/failure | ||
FormFromURL (extends XHRForm) | class | no | Grabs a form from a URL and places it on the current page (examples/FormModalFromURL shows how to put the form in a modal) and then uses an XHR request to submit the form | ||
request | object | yes | Provides a wrapper for window.location and easy querystring interaction | ||
Site | class | no | A generic website class with properties for id, name, and config - useful for multi-tenant applications where you need to know which site is being viewed | ||
User | class | no | A generic user class with properties for id, name, email, phone, etc - also allows for front-end permission checks | ||
strings | object | yes | Contains methods for semi-common string manipulation like creating a getter from a string ('hi' = 'getHi') | ||
data_types | object | yes | Validate the value of a variable with higher specificity than built-in functions. For instance, you can validate an object contains specific keys and throw errors if not, or if it contains keys that you didn't define | ||
dom | object | yes | Has methods for converting just about anything into a native DOM Element or array of them (you can provide a string selector, jQuery object, native DOM object, etc). Also has some shortcuts for common DOM checks/manipulation (like removing an element, verifying an element exists in the DOM, or replacing an element with HTML) | ||
events | object | yes | Includes shorthand methods for preventing the browser's default action onsubmit, onclick. Other methods are included for consistency like onchange (which does not prevent default since that is generally not preferred) | ||
Type | Namespace | Object/Function/Class | ||
--- | --- | --- | ||
Components | components | navigation, XHRForm, FormFromURL | ||
Objects | objects | request, Site, User | ||
Plugin Wrappers | plugin_wrappers | None Yet. | ||
Utilities | utilities | strings, data_types, dom, events | ||
# Installation | ||
@@ -33,12 +34,11 @@ | ||
//now you can take advantage of the jpack library | ||
var fname = jpack.utilities.strings.ucfirst('bob'); //Bob | ||
jpack.strings.ucfirst('bob'); //Bob | ||
//or if you're feeling lazy, you can tie all jpack components to window for shorter use. | ||
jpack.goGlobal("jp"); | ||
//if you want to change the namespace | ||
jpack.setGlobal("$"); | ||
jp.strings.ucfirst('bob'); | ||
$.strings.ucfirst('bob'); | ||
//or if you're insanely lazy and want to cross your fingers that nothing conflicts, you can tie | ||
// everything to window WITHOUT a namespace | ||
jpack.goGlobal(); | ||
//if you want to make all global without a namespace - do so at your own risk! Things may conflict! | ||
jpack.setGlobal(); | ||
@@ -60,21 +60,13 @@ strings.ucfirst('bob'); | ||
//a single component from it's own file | ||
import {strings} from '@htmlguyllc/jpack/es/utilities/strings'; | ||
import {strings} from '@htmlguyllc/jpack/es/strings'; | ||
strings.ucfirst('bob'); | ||
//or a single component from the collection file | ||
import {strings} from '@htmlguyllc/jpack/es/utilities'; | ||
//or multiple components from jpack | ||
import {strings, dom} from '@htmlguyllc/jpack'; | ||
strings.ucfirst('bob'); | ||
//or multiple components from the collection file | ||
import {strings, dom} from '@htmlguyllc/jpack/es/utilities'; | ||
strings.ucfirst('bob'); | ||
dom.exists('a.my-link'); | ||
//or a namespaced object containing all components | ||
import * as utilities from '@htmlguyllc/jpack/es/utilities'; | ||
utilities.strings.ucfirst('bob'); | ||
//or a namespaced object containing all | ||
import {jpack} from '@htmlguyllc/jpack'; | ||
jpack.utilities.strings.ucfirst('bob'); | ||
import * as j from '@htmlguyllc/jpack'; | ||
j.strings.ucfirst('bob'); | ||
``` | ||
@@ -87,3 +79,3 @@ | ||
//now use it | ||
jpack.utilities.strings.ucfirst('bob'); | ||
jpack.strings.ucfirst('bob'); | ||
``` | ||
@@ -101,4 +93,2 @@ | ||
## - Components - | ||
### -Navigation | ||
@@ -140,3 +130,3 @@ _Grabs content from a URL and replaces it on the current page (along with browser history button handling, onload/unload handlers, and much more_ | ||
```javascript | ||
import {navigation} from '@htmlguyllc/jpack/es/components'; | ||
import {navigation} from '@htmlguyllc/jpack/es/navigation'; | ||
@@ -206,3 +196,3 @@ //handles browser back/forward buttons | ||
//and then attach a handler like this: | ||
import {events} from '@htmlguyllc/jpack/es/utilities'; | ||
import {events} from '@htmlguyllc/jpack/es/events'; | ||
events.onClick('[data-href]', function(){ | ||
@@ -264,3 +254,3 @@ navigation.load(this.href); | ||
```javascript | ||
import {XHRForm} from '@htmlguyllc/jpack/es/components'; | ||
import {XHRForm} from '@htmlguyllc/jpack/es/forms'; | ||
@@ -315,3 +305,3 @@ //shown with defaults | ||
```javascript | ||
import {FormFromURL} from '@htmlguyllc/jpack/es/components'; | ||
import {FormFromURL} from '@htmlguyllc/jpack/es/forms'; | ||
@@ -353,4 +343,2 @@ //shown with defaults | ||
## - Objects - | ||
### -Request | ||
@@ -372,3 +360,3 @@ _Provides a wrapper for window.location and query string access_ | ||
```javascript | ||
import {request} from '@htmlguyllc/jpack/es/objects'; | ||
import {request} from '@htmlguyllc/jpack/es/request'; | ||
@@ -426,3 +414,3 @@ //get product_id from the querystring | ||
```javascript | ||
import {Site} from '@htmlguyllc/jpack/es/objects'; | ||
import {Site} from '@htmlguyllc/jpack/es/site'; | ||
@@ -504,3 +492,3 @@ //this example uses jQuery's shorthand AJAX call, you can use axios or any request you want | ||
```javascript | ||
import {User} from '@htmlguyllc/jpack/es/objects'; | ||
import {User} from '@htmlguyllc/jpack/es/user'; | ||
@@ -515,7 +503,2 @@ $.get('/my-user-info-endpoint.php', function(data){ | ||
## - Plugin Wrappers - | ||
None yet. | ||
## - Utilities - | ||
### -Strings | ||
@@ -533,3 +516,3 @@ _Common string manipulations_ | ||
```javascript | ||
import {strings} from '@htmlguyllc/jpack/es/utilities'; | ||
import {strings} from '@htmlguyllc/jpack/es/strings'; | ||
@@ -557,3 +540,3 @@ strings.ucfirst('bob'); //returns 'Bob' | ||
```javascript | ||
import {dom} from '@htmlguyllc/jpack/es/utilities'; | ||
import {dom} from '@htmlguyllc/jpack/es/dom'; | ||
@@ -583,3 +566,3 @@ //Dont do this. Most of these are dumb examples. | ||
```javascript | ||
import {type_checks} from '@htmlguyllc/jpack/es/utilities'; | ||
import {type_checks} from '@htmlguyllc/jpack/es/type_checks'; | ||
@@ -616,3 +599,3 @@ var my_obj = {id:null, name:'John Doe', email:'john@doe.com'}; | ||
```javascript | ||
import {events} from '@htmlguyllc/jpack/es/utilities'; | ||
import {events} from '@htmlguyllc/jpack/es/events'; | ||
@@ -619,0 +602,0 @@ events.onClick('a.my-link', function(){ |
@@ -1,17 +0,28 @@ | ||
import * as components from '../es/components'; | ||
import * as objects from '../es/objects'; | ||
import * as plugin_wrappers from '../es/plugin_wrappers'; | ||
import * as utilities from '../es/utilities'; | ||
import {dom} from "../es/dom"; | ||
import {events} from "../es/events"; | ||
import {XHRForm, FormFromURL} from "../es/forms"; | ||
import {navigation} from "../es/navigation"; | ||
import {request} from "../es/request"; | ||
import {Site} from "../es/site"; | ||
import {strings} from "../es/strings"; | ||
import {type_checks} from "../es/type_checks"; | ||
import {User} from "../es/user"; | ||
/** | ||
* All jpack components are flattened out of their namespaces and set on window | ||
* Call this function to tie all jpack components directly to the window for global use | ||
* | ||
* This means instead of calling jpack.objects.user.getId(), you can just call user.getId() | ||
* This means instead of calling jpack.strings.ucfirst(), you can just call strings.ucfirst() | ||
* | ||
* Or let's say you pass a namespace like "jp", then you can call: jp.user.getId() | ||
* This is not recommended because jpack's names may be too generic and conflict. | ||
* | ||
* Not recommended (atleast not without a namespace) | ||
* If you want to set a different namespace than jpack, that's fine, but not using a namespace at all can be risky | ||
* | ||
* For example: | ||
* | ||
* setGlobal("$") - then you can call: $.strings.ucfirst() | ||
* setGlobal("_") - then you can call: _.strings.ucfirst() | ||
* setGlobal("PeasAreGross") - then you can call: PeasAreGross.strings.ucfirst() | ||
* | ||
*/ | ||
const goGlobal = function(namespace){ | ||
const setGlobal = function(namespace){ | ||
namespace = typeof namespace === 'string' ? namespace+'.' : null; | ||
@@ -34,5 +45,5 @@ | ||
export const jpack = {components, objects, plugin_wrappers, utilities, goGlobal: goGlobal}; | ||
export const jpack = {dom, events, XHRForm, FormFromURL, navigation, request, Site, strings, type_checks, User, setGlobal: setGlobal}; | ||
//set jpack globally so that it can be used anywhere | ||
global.jpack = jpack; |
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
300480
26
4026
595