UNPKG

jquery-toad

Version:

jQuery TOAD - O velho e querido jQuery

7 lines 9.84 kB
/*! * jquery-toad v1.0.35 * jQuery TOAD - O velho e querido jQuery (https://e5r.github.io/jquery-toad) * Copyright (c) Erlimar Silva Campos. All rights reserved. * Licensed under the Apache-2.0 License. More license information in LICENSE. */ !function(r,e){"use strict";if("object"==typeof module&&"object"==typeof module.exports&&"function"==typeof require)module.exports=function(t){if("object"!=typeof t||"object"!=typeof t.document)throw new Error("jQuery TOAD's requires a DOM (Document Object Model)!");var r=require("jquery")(t);return e(t,r,"CommonJS")};else if("function"==typeof define&&"object"==typeof define.amd)define("jquery-toad",["jquery"],function(t){return e(r,t,"AMD")});else{if("string"!=typeof r.__TOAD__)throw new Error("You have not set a value for __TOAD__!");r[r.__TOAD__]=e(r,r.jQuery,"Browser")}}("undefined"!=typeof window?window:this,function(t,j,r){!function(){"use strict";if("function"!=typeof j)throw new Error("jQuery TOAD's requires jQuery!");var t=j.fn.jquery.split(" ")[0].split("."),r=t[0],e=t[1],n=t[2];if(!(1<r||1==r&&12<e||1==r&&12==e&&4<=n))throw new Error("jQuery TOAD's requires jQuery version 1.12.4 or higher!")}();var i={$jq:j,$toad:{version:"1.0.35",author:"Erlimar Silva Campos",license:"Apache-2.0",homepage:"https://e5r.github.io/jquery-toad",moduleLoader:r}},n=t.document,o=[],a=i._app_namespace_={},b=function(t){return i[t]=i[t]||{}},e=function(t,r,e){o.push({idx:t,cb:function(){e(i[r]=i[r]||{})}})};for(var c in i.namespace=function(t,r){if("string"!=typeof t)throw new Error("Invalid namespace.");r(a[t]=a[t]||{})},i.require=function(t){if("string"!=typeof t||j.trim(t).length<1)throw new Error("Invalid namespace to import.");var r={};if("@"===t.charAt(0)){var e=t.split("@");if(2!==e.length||0<=j.inArray(e[1],["__internals__"]))return;return i["@"][e[1]]}if(-1<j.inArray(t,["core","utils"]))for(var n in i[t])r[n]=i[t][n];for(var n in a[t])r[n]=a[t][n];return r},i.constant=function(t,r){return b("@").__internals__.setConstant(t,r)},e(9,"core",function(t){var s=b("utils"),u=b("@").__internals__,f="controller",l="data-"+f,r="["+l+"]",p="$ctrl",h="__view__",g="$options",d="$jqSelector",y="$name",v="data-events",_="["+v+"]",m=",",w="=>";function e(){j(r,n).each(function(){var t=j(this),r=t.attr(l),e=u.getController(r),n={},i=t.data();for(var o in i)o!==f&&(n[o]=i[o]);var c,a=new e(t,n);t.data(p,a),a[h]=t,a[g]=n,c=a,j(_,t).each(function(){var t=j(this),r=t.attr(v);if(s.isString(r)&&!(r.indexOf(w)<0)&&(r=r.split(m),s.isArray(r)&&!(r.length<1)))for(var e in r){var n=j.trim(r[e]),i=n.split(w);if(s.isArray(i)&&!(i.length<2)){var o=i[0],a=c[i[1]];if(!s.isString(o)||!s.isFunction(a))return;t.on(o,a),t.data(p,c)}}}),function(t,r){var e=u.listComponents();for(var n in e){var i=e[n];if(!s.isString(i.id))return;if(!s.isFunction(i.component))return;if(!s.isString(i.component[d]))return;if(!s.isString(i.component[y]))return;var o=i.component[d],a=i.component[y];j(o,t)[a](r)}}(t,a),u.callLazyTriggers(a)})}j(n).ready(function(){e()})}),e(1,"@",function(t){var e={},n=b("utils");t.config={get:function(t,r){if(n.isString(t))return n.getObjectItemByPath(e,t)||r},set:function(t,r){if(n.isString(t))return n.setObjectItemByPath(e,t,r)}}}),e(1,"@",function(t){var e={};(t.__internals__=t.__internals__||{}).setConstant=function(t,r){if("string"!=typeof t)throw new Error('Invalid constName "'+t+'"');if(!r)throw new Error("constValue is required!");if(void 0!==e[t])throw new Error('Constant "'+t+'" already exists!');if("function"!=typeof Object.defineProperties)return console.warn("WARNING!","Object.defineProperty is not supported!"),e[t]=r;return Object.defineProperty(e,t,{enumerable:!0,configurable:!1,writable:!1,value:r})[t]},t.constants=e}),e(2,"core",function(t){t.ControllerComponent=j.fn.controller=function(){return j(this).data("$ctrl")}}),e(1,"@",function(t){var o=b("utils");function r(t){this.target=t,this.cloning=[],this.validTypes=[typeof!0,"number","string",typeof{}]}((t.__internals__=t.__internals__||{}).PlainObjectCloner=r).prototype.isValidProp=function(t){return 0<=this.validTypes.indexOf(typeof t)},r.prototype.cloneArray=function(t){if(o.isArray(t)){var r=[];for(var e in t){var n=t[e];if(this.isValidProp(n)){if(0<=this.cloning.indexOf(n))throw new Error("Circular reference detected!");this.cloning.push(n),o.isArray(n)?r.push(this.cloneArray(n)):o.isObject(n)?r.push(this.cloneObject(n)):r.push(n);var i=this.cloning.indexOf(n);this.cloning.splice(i,1)}}return r}},r.prototype.cloneObject=function(){var t=arguments[0]||this.target;if(o.isArray(t))return this.cloneArray(t);if(o.isObject(t)){var r={};for(var e in t){var n=t[e];if(this.isValidProp(n)){if(0<=this.cloning.indexOf(n))throw new Error("Circular reference detected!");this.cloning.push(n),o.isArray(n)?r[e]=this.cloneArray(n):o.isObject(n)?r[e]=this.cloneObject(n):r[e]=n;var i=this.cloning.indexOf(n);this.cloning.splice(i,1)}}return r}}}),e(3,"@",function(t){var c="name",s="ctor",u=[],r=t.__internals__=t.__internals__||{};function f(t,r){return"Invalid @component.{name}. Must be a {type}.".replace("{name}",t).replace("{type}",r)}r.getComponent=function(t){if("string"!=typeof t||""==t)throw new Error("Parameter componentName is required.");if(!u[t])throw new Error("Controller "+t+" not registered!");return u[t]},r.listComponents=function(){var t=[];for(var r in u)t.push({id:r,component:u[r]});return t},t.registerComponent=function(t,r){var a=function(t){if("string"!=typeof(t=t||{})[c])throw f(c,"string");if("function"!=typeof t[s])throw f(s,"function");return t}({name:t,ctor:r}),e=a[c],n="gui-{name}".replace("{name}",e),i='[data-gui="{name}"]'.replace("{name}",e);if(u[e])throw new Error("Component "+e+" already registered!");var o=function(o){return this.each(function(t,r){var e={},n=j(r).data();for(var i in n)"gui"!==i&&(e[i]=n[i]);return a[s].apply(this,[o,e])})};return o.$name=n,o.$jqSelector=i,u[e]=o,j.fn[n]=o}}),e(3,"@",function(t){var h=b("utils"),o="name",a="ctor",g="__view__",i="__model__",d="__triggers__",c="$onUpdateModel",y=[],s=[],u=t.__internals__=t.__internals__||{};function f(t,r){return"Invalid @controller.{name}. Must be a {type}.".replace("{name}",t).replace("{type}",r)}function l(t,r){var e=this[g],n=b("@").constants.VIEW_BY_ID;if(e instanceof j){if("string"==typeof t&&1===arguments.length)r=t;else{if("string"!=typeof r)throw new Error("Invalid view selector.");switch(t){case n:r='[data-id="{id}"]'.replace("{id}",r);break;default:throw new Error('Invalid view type "'+t+'".')}}return j(r,e)}}function p(){var t=new u.PlainObjectCloner(this[i]);if(!arguments.length)return t.cloneObject();if(1===arguments.length&&h.isObject(arguments[0])){var r=new u.PlainObjectCloner(arguments[0]).cloneObject();return this[i]=r,void _(t.cloneObject(),r,null,this)}if(1===arguments.length&&h.isString(arguments[0])){var e=j.trim(arguments[0]),n=t.cloneObject();return 0===e.length?n:h.getObjectItemByPath(n,e)}if(2===arguments.length&&h.isString(arguments[0])&&h.isObject(arguments[1])){e=arguments[0],n=t.cloneObject(),r=new u.PlainObjectCloner(arguments[1]).cloneObject();return h.setObjectItemByPath(n,e,r),this[i]=n,void _(t.cloneObject(),n,e,this)}throw new Error("Call with invalid parameters for $model!")}function r(t,r,e){h.isArray(t[d])||(t[d]=[]);var n=t[d];for(var i in n){var o=n[i];if(o.path===r&&o.trigger===e)return}n.push({path:r,trigger:e})}function v(){if(1===arguments.length&&h.isFunction(arguments[0]))return r(this,null,arguments[0]);if(2===arguments.length&&h.isString(arguments[0])&&h.isFunction(arguments[1]))return r(this,arguments[0],arguments[1]);throw new Error("Call with invalid parameters for "+c+"!")}function _(i,o,a,c){if(!c[g])return n=-1,t={controller:e=c,trigger:{oldState:i,newState:o,modelPath:a}},j.each(y,function(t,r){r.controller===e&&(n=t)}),void(0<=n?y[n]=t:y.push(t));for(var e,n,t,r=[],s=a||"",u=""===s?[]:s.split("."),f=u.length-1;0<=f;f--){var l=u.splice(0,f+1);u=l.concat(u),r.push(l.join("."))}r.push("");var p=c[d]||[];j.each(r,function(t,r){var e;j.each((e=r,j.grep(p,function(t){return(t.path||"")===e})),function(t,r){if(h.isFunction(r.trigger)){var e=i,n=o;r.path&&(e=h.getObjectItemByPath(e,r.path),n=h.getObjectItemByPath(n,r.path)),r.trigger.call(null,e,n,a,c)}})})}u.getController=function(t){if("string"!=typeof t||""==t)throw new Error("Parameter controllerName is required.");if(!s[t])throw new Error("Controller "+t+" not registered!");return s[t]},u.callLazyTriggers=function(e){var n,i=-1;if(j.each(y,function(t,r){r.controller===e&&(i=t,n=r)}),n)try{_(n.trigger.oldState,n.trigger.newState,n.trigger.modelPath,n.controller)}catch(t){}0<=i&&y.splice(i,1)},u.setConstant("VIEW_BY_ID",1),t.registerController=function(t,r){var e=function(t){if("string"!=typeof(t=t||{})[o])throw f(o,"string");if("function"!=typeof t[a])throw f(a,"function");return t}({name:t,ctor:r}),n=e[o];if(s[n])throw new Error("Controller "+n+" already registered!");var i=e[a];return i.$name=e[o],(s[n]=i).prototype.$view=l,i.prototype.$model=p,i.prototype[c]=v,i}}),e(0,"utils",function(t){t.getObjectItemByPath=function(t,r){for(var e=t,n=r.split("."),i=0;e&&i<n.length;)e=e[n[i]],i++;return e},t.setObjectItemByPath=function(t,r,e){for(var n=t,i=r.split("."),o=0;n&&o<i.length;)"object"!=typeof n[i[o]]&&(n[i[o]]={}),o+1!==i.length&&(n=n[i[o]]),o++;return n[i[--o]]=e},t.isString=function(t){return"string"==typeof t},t.isFunction=function(t){return"function"==typeof t},t.isUndefined=function(t){return void 0===t},t.isObject=function(t){return null!==t&&"object"==typeof t},t.isNumber=function(t){return"number"==typeof t},t.isArray=function(t){return t instanceof Array||"[object Array]"===Object.prototype.toString.call(t)},t.getPageTitle=function(t){return j(n).attr("title")},t.setPageTitle=function(t){j(n).attr("title",t)}}),o.sort(function(t,r){return t.idx-r.idx}),o)o[c].cb();return i});