diff --git a/CHANGELOG.md b/CHANGELOG.md index f4c8cd0..7c27d9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +v2.2.0 - March 14, 2016 + +* 2.2.0 (Jeff Tan) +* Use recommended wording (Justin Bennett) +* Remove bind, reword test (Justin Bennett) +* Remove unnecessary `bind` call. (Zephraph) +* Support cleaner onmessage handler (Zephraph) +* Add malformed JSON error message (Zephraph) + v2.1.0 - January 31, 2016 * 2.1.0 (Jeff Tan) diff --git a/README.md b/README.md index 8984fbf..f3cf100 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,16 @@ The last published release: ``` - + - + - + - + ``` ## Upgrade from 1.5.1 to 2.0.0 diff --git a/dist/t3-jquery-2.1.0.min.js b/dist/t3-jquery-2.1.0.min.js deleted file mode 100644 index 9bf7508..0000000 --- a/dist/t3-jquery-2.1.0.min.js +++ /dev/null @@ -1,18 +0,0 @@ -/*! t3-jquery v2.1.0 */ -/*! -Copyright 2015 Box, Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -!function(e){var t={};if(t.EventTarget=function(){"use strict";function e(){this._handlers={}}return e.prototype={constructor:e,on:function(e,t){var n,r,i=this._handlers[e];for("undefined"==typeof i&&(i=this._handlers[e]=[]),n=0,r=i.length;r>n;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.JQueryDOM=function(){"use strict";return{type:"jquery",query:function(e,t){return jQuery(e).find(t)[0]||null},queryAll:function(e,t){return jQuery.makeArray(jQuery(e).find(t))},on:function(e,t,n){jQuery(e).on(t,n)},off:function(e,t,n){jQuery(e).off(t,n)}}}(),t.DOM=t.JQueryDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function o(){m={},b={},E={},w=[],D={},_={},A=!1}function a(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function u(e){if(m.debug)throw e;M.fire("error",{exception:e})}function s(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,u(i)}}}(n,r))}function c(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function f(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function l(e){var t=E[e];if(t){if(!t.instance){if(a(e))return u(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return u(new Error('Service "'+e+'" not found')),null}function h(e){var t,n,r,i,o,a=[],s={};for(n=e.instance.behaviors||[],t=0;tg;g++)l=d[g],f(l,"init");f(n.instance,"init"),p(n)}return this},stop:function(e){var t=v(e);if(t){g(t);for(var n,r=h(t),i=r.length-1;i>=0;i--)n=r[i],f(n,"destroy");f(t.instance,"destroy"),delete _[e.id]}else if(m.debug)return u(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(u(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=v(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');o&&(i=JSON.parse(o.text)),r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(u(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:l,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(u(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,o,a,u,s,c;for(o in _)if(_.hasOwnProperty(o)){for(c=[],a=_[o],-1!==i(a.instance.messages||[],e)&&c.push(r(a.instance.onmessage,a.instance)),s=h(a),n=0;n tag supports .text property if (configElement) { - moduleConfig = JSON.parse(configElement.text); + try { + moduleConfig = JSON.parse(configElement.text); + } catch (exception) { + error(new Error('Module with id ' + element.id + ' has a malformed config.')); + } } // Cache the configurations for performance, if the module instance has been created @@ -1223,32 +1233,21 @@ Box.Application = (function() { id, instanceData, behaviorInstance, - moduleBehaviors, - messageHandlers; + moduleBehaviors; for (id in instances) { if (instances.hasOwnProperty(id)) { - messageHandlers = []; instanceData = instances[id]; // Module message handler is called first - if (indexOf(instanceData.instance.messages || [], name) !== -1) { - messageHandlers.push(bind(instanceData.instance.onmessage, instanceData.instance)); - } + callMessageHandler(instanceData.instance, name, data); // And then any message handlers defined in module's behaviors moduleBehaviors = getBehaviors(instanceData); for (i = 0; i < moduleBehaviors.length; i++) { behaviorInstance = moduleBehaviors[i]; - - if (indexOf(behaviorInstance.messages || [], name) !== -1) { - messageHandlers.push(bind(behaviorInstance.onmessage, behaviorInstance)); - } - } - - for (i = 0; i < messageHandlers.length; i++) { - messageHandlers[i](name, data); + callMessageHandler(behaviorInstance, name, data); } } diff --git a/dist/t3-jquery-2.2.0.min.js b/dist/t3-jquery-2.2.0.min.js new file mode 100644 index 0000000..05e14c2 --- /dev/null +++ b/dist/t3-jquery-2.2.0.min.js @@ -0,0 +1,18 @@ +/*! t3-jquery v2.2.0 */ +/*! +Copyright 2015 Box, Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +!function(e){var t={};if(t.EventTarget=function(){"use strict";function e(){this._handlers={}}return e.prototype={constructor:e,on:function(e,t){var n,r,i=this._handlers[e];for("undefined"==typeof i&&(i=this._handlers[e]=[]),n=0,r=i.length;r>n;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.JQueryDOM=function(){"use strict";return{type:"jquery",query:function(e,t){return jQuery(e).find(t)[0]||null},queryAll:function(e,t){return jQuery.makeArray(jQuery(e).find(t))},on:function(e,t,n){jQuery(e).on(t,n)},off:function(e,t,n){jQuery(e).off(t,n)}}}(),t.DOM=t.JQueryDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function i(){m={},b={},E={},w=[],D={},_={},A=!1}function o(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function a(e){if(m.debug)throw e;M.fire("error",{exception:e})}function u(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,a(i)}}}(n,r))}function s(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function c(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function f(e){var t=E[e];if(t){if(!t.instance){if(o(e))return a(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return a(new Error('Service "'+e+'" not found')),null}function l(e){var t,n,r,i,o,u=[],s={};for(n=e.instance.behaviors||[],t=0;tg;g++)h=p[g],c(h,"init");c(n.instance,"init"),d(n)}return this},stop:function(e){var t=g(e);if(t){p(t);for(var n,r=l(t),i=r.length-1;i>=0;i--)n=r[i],c(n,"destroy");c(t.instance,"destroy"),delete _[e.id]}else if(m.debug)return a(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(a(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=g(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');if(o)try{i=JSON.parse(o.text)}catch(u){a(new Error("Module with id "+e.id+" has a malformed config."))}r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(a(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:f,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(a(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,r,i,o,a;for(r in _)if(_.hasOwnProperty(r))for(i=_[r],v(i.instance,e,t),a=l(i),n=0;n tag supports .text property if (configElement) { - moduleConfig = JSON.parse(configElement.text); + try { + moduleConfig = JSON.parse(configElement.text); + } catch (exception) { + error(new Error('Module with id ' + element.id + ' has a malformed config.')); + } } // Cache the configurations for performance, if the module instance has been created @@ -1223,32 +1233,21 @@ Box.Application = (function() { id, instanceData, behaviorInstance, - moduleBehaviors, - messageHandlers; + moduleBehaviors; for (id in instances) { if (instances.hasOwnProperty(id)) { - messageHandlers = []; instanceData = instances[id]; // Module message handler is called first - if (indexOf(instanceData.instance.messages || [], name) !== -1) { - messageHandlers.push(bind(instanceData.instance.onmessage, instanceData.instance)); - } + callMessageHandler(instanceData.instance, name, data); // And then any message handlers defined in module's behaviors moduleBehaviors = getBehaviors(instanceData); for (i = 0; i < moduleBehaviors.length; i++) { behaviorInstance = moduleBehaviors[i]; - - if (indexOf(behaviorInstance.messages || [], name) !== -1) { - messageHandlers.push(bind(behaviorInstance.onmessage, behaviorInstance)); - } - } - - for (i = 0; i < messageHandlers.length; i++) { - messageHandlers[i](name, data); + callMessageHandler(behaviorInstance, name, data); } } diff --git a/dist/t3-jquery.min.js b/dist/t3-jquery.min.js index 9bf7508..05e14c2 100644 --- a/dist/t3-jquery.min.js +++ b/dist/t3-jquery.min.js @@ -1,4 +1,4 @@ -/*! t3-jquery v2.1.0 */ +/*! t3-jquery v2.2.0 */ /*! Copyright 2015 Box, Inc. All rights reserved. @@ -14,5 +14,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -!function(e){var t={};if(t.EventTarget=function(){"use strict";function e(){this._handlers={}}return e.prototype={constructor:e,on:function(e,t){var n,r,i=this._handlers[e];for("undefined"==typeof i&&(i=this._handlers[e]=[]),n=0,r=i.length;r>n;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.JQueryDOM=function(){"use strict";return{type:"jquery",query:function(e,t){return jQuery(e).find(t)[0]||null},queryAll:function(e,t){return jQuery.makeArray(jQuery(e).find(t))},on:function(e,t,n){jQuery(e).on(t,n)},off:function(e,t,n){jQuery(e).off(t,n)}}}(),t.DOM=t.JQueryDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function o(){m={},b={},E={},w=[],D={},_={},A=!1}function a(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function u(e){if(m.debug)throw e;M.fire("error",{exception:e})}function s(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,u(i)}}}(n,r))}function c(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function f(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function l(e){var t=E[e];if(t){if(!t.instance){if(a(e))return u(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return u(new Error('Service "'+e+'" not found')),null}function h(e){var t,n,r,i,o,a=[],s={};for(n=e.instance.behaviors||[],t=0;tg;g++)l=d[g],f(l,"init");f(n.instance,"init"),p(n)}return this},stop:function(e){var t=v(e);if(t){g(t);for(var n,r=h(t),i=r.length-1;i>=0;i--)n=r[i],f(n,"destroy");f(t.instance,"destroy"),delete _[e.id]}else if(m.debug)return u(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(u(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=v(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');o&&(i=JSON.parse(o.text)),r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(u(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:l,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(u(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,o,a,u,s,c;for(o in _)if(_.hasOwnProperty(o)){for(c=[],a=_[o],-1!==i(a.instance.messages||[],e)&&c.push(r(a.instance.onmessage,a.instance)),s=h(a),n=0;nn;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.JQueryDOM=function(){"use strict";return{type:"jquery",query:function(e,t){return jQuery(e).find(t)[0]||null},queryAll:function(e,t){return jQuery.makeArray(jQuery(e).find(t))},on:function(e,t,n){jQuery(e).on(t,n)},off:function(e,t,n){jQuery(e).off(t,n)}}}(),t.DOM=t.JQueryDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function i(){m={},b={},E={},w=[],D={},_={},A=!1}function o(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function a(e){if(m.debug)throw e;M.fire("error",{exception:e})}function u(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,a(i)}}}(n,r))}function s(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function c(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function f(e){var t=E[e];if(t){if(!t.instance){if(o(e))return a(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return a(new Error('Service "'+e+'" not found')),null}function l(e){var t,n,r,i,o,u=[],s={};for(n=e.instance.behaviors||[],t=0;tg;g++)h=p[g],c(h,"init");c(n.instance,"init"),d(n)}return this},stop:function(e){var t=g(e);if(t){p(t);for(var n,r=l(t),i=r.length-1;i>=0;i--)n=r[i],c(n,"destroy");c(t.instance,"destroy"),delete _[e.id]}else if(m.debug)return a(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,y),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(a(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=g(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');if(o)try{i=JSON.parse(o.text)}catch(u){a(new Error("Module with id "+e.id+" has a malformed config."))}r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(a(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:f,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(a(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,r,i,o,a;for(r in _)if(_.hasOwnProperty(r))for(i=_[r],v(i.instance,e,t),a=l(i),n=0;nn;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.NativeDOM=function(){"use strict";return{type:"native",query:function(e,t){return e.querySelector(t)},queryAll:function(e,t){return e.querySelectorAll(t)},on:function(e,t,n){e.addEventListener(t,n,!1)},off:function(e,t,n){e.removeEventListener(t,n,!1)}}}(),t.DOM=t.NativeDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function o(){y={},b={},w={},E=[],D={},_={},A=!1}function a(e){for(var t=0,n=E.length;n>t;t++)if(E[t]===e)return!0;return!1}function u(e){if(y.debug)throw e;M.fire("error",{exception:e})}function s(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,u(i)}}}(n,r))}function c(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function f(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function l(e){var t=w[e];if(t){if(!t.instance){if(a(e))return u(new ReferenceError("Circular service dependency: "+E.join(" -> ")+" -> "+e)),null;E.push(e),t.instance=t.creator(M),E.pop()}return t.instance}return u(new Error('Service "'+e+'" not found')),null}function h(e){var t,n,r,i,o,a=[],s={};for(n=e.instance.behaviors||[],t=0;tv;v++)l=d[v],f(l,"init");f(n.instance,"init"),p(n)}return this},stop:function(e){var t=g(e);if(t){v(t);for(var n,r=h(t),i=r.length-1;i>=0;i--)n=r[i],f(n,"destroy");f(t.instance,"destroy"),delete _[e.id]}else if(y.debug)return u(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(u(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=g(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');o&&(i=JSON.parse(o.text)),r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof w[e]?(u(new Error("Service "+e+" has already been added.")),this):(w[e]={creator:t,instance:null},this)},getService:l,hasService:function(e){return w.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(u(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,o,a,u,s,c;for(o in _)if(_.hasOwnProperty(o)){for(c=[],a=_[o],-1!==i(a.instance.messages||[],e)&&c.push(r(a.instance.onmessage,a.instance)),s=h(a),n=0;n tag supports .text property if (configElement) { - moduleConfig = JSON.parse(configElement.text); + try { + moduleConfig = JSON.parse(configElement.text); + } catch (exception) { + error(new Error('Module with id ' + element.id + ' has a malformed config.')); + } } // Cache the configurations for performance, if the module instance has been created @@ -1221,32 +1231,21 @@ Box.Application = (function() { id, instanceData, behaviorInstance, - moduleBehaviors, - messageHandlers; + moduleBehaviors; for (id in instances) { if (instances.hasOwnProperty(id)) { - messageHandlers = []; instanceData = instances[id]; // Module message handler is called first - if (indexOf(instanceData.instance.messages || [], name) !== -1) { - messageHandlers.push(bind(instanceData.instance.onmessage, instanceData.instance)); - } + callMessageHandler(instanceData.instance, name, data); // And then any message handlers defined in module's behaviors moduleBehaviors = getBehaviors(instanceData); for (i = 0; i < moduleBehaviors.length; i++) { behaviorInstance = moduleBehaviors[i]; - - if (indexOf(behaviorInstance.messages || [], name) !== -1) { - messageHandlers.push(bind(behaviorInstance.onmessage, behaviorInstance)); - } - } - - for (i = 0; i < messageHandlers.length; i++) { - messageHandlers[i](name, data); + callMessageHandler(behaviorInstance, name, data); } } diff --git a/dist/t3-native-2.2.0.min.js b/dist/t3-native-2.2.0.min.js new file mode 100644 index 0000000..ea8fdab --- /dev/null +++ b/dist/t3-native-2.2.0.min.js @@ -0,0 +1,18 @@ +/*! t3-native v2.2.0 */ +/*! +Copyright 2015 Box, Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +!function(e){var t={};if(t.EventTarget=function(){"use strict";function e(){this._handlers={}}return e.prototype={constructor:e,on:function(e,t){var n,r,i=this._handlers[e];for("undefined"==typeof i&&(i=this._handlers[e]=[]),n=0,r=i.length;r>n;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.NativeDOM=function(){"use strict";return{type:"native",query:function(e,t){return e.querySelector(t)},queryAll:function(e,t){return e.querySelectorAll(t)},on:function(e,t,n){e.addEventListener(t,n,!1)},off:function(e,t,n){e.removeEventListener(t,n,!1)}}}(),t.DOM=t.NativeDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function i(){y={},b={},E={},w=[],D={},_={},A=!1}function o(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function a(e){if(y.debug)throw e;M.fire("error",{exception:e})}function u(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,a(i)}}}(n,r))}function s(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function c(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function f(e){var t=E[e];if(t){if(!t.instance){if(o(e))return a(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return a(new Error('Service "'+e+'" not found')),null}function l(e){var t,n,r,i,o,u=[],s={};for(n=e.instance.behaviors||[],t=0;tv;v++)h=p[v],c(h,"init");c(n.instance,"init"),d(n)}return this},stop:function(e){var t=v(e);if(t){p(t);for(var n,r=l(t),i=r.length-1;i>=0;i--)n=r[i],c(n,"destroy");c(t.instance,"destroy"),delete _[e.id]}else if(y.debug)return a(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(a(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=v(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');if(o)try{i=JSON.parse(o.text)}catch(u){a(new Error("Module with id "+e.id+" has a malformed config."))}r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(a(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:f,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(a(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,r,i,o,a;for(r in _)if(_.hasOwnProperty(r))for(i=_[r],g(i.instance,e,t),a=l(i),n=0;n tag supports .text property if (configElement) { - moduleConfig = JSON.parse(configElement.text); + try { + moduleConfig = JSON.parse(configElement.text); + } catch (exception) { + error(new Error('Module with id ' + element.id + ' has a malformed config.')); + } } // Cache the configurations for performance, if the module instance has been created @@ -1221,32 +1231,21 @@ Box.Application = (function() { id, instanceData, behaviorInstance, - moduleBehaviors, - messageHandlers; + moduleBehaviors; for (id in instances) { if (instances.hasOwnProperty(id)) { - messageHandlers = []; instanceData = instances[id]; // Module message handler is called first - if (indexOf(instanceData.instance.messages || [], name) !== -1) { - messageHandlers.push(bind(instanceData.instance.onmessage, instanceData.instance)); - } + callMessageHandler(instanceData.instance, name, data); // And then any message handlers defined in module's behaviors moduleBehaviors = getBehaviors(instanceData); for (i = 0; i < moduleBehaviors.length; i++) { behaviorInstance = moduleBehaviors[i]; - - if (indexOf(behaviorInstance.messages || [], name) !== -1) { - messageHandlers.push(bind(behaviorInstance.onmessage, behaviorInstance)); - } - } - - for (i = 0; i < messageHandlers.length; i++) { - messageHandlers[i](name, data); + callMessageHandler(behaviorInstance, name, data); } } diff --git a/dist/t3-native.min.js b/dist/t3-native.min.js index 2bd6c8d..ea8fdab 100644 --- a/dist/t3-native.min.js +++ b/dist/t3-native.min.js @@ -1,4 +1,4 @@ -/*! t3-native v2.1.0 */ +/*! t3-native v2.2.0 */ /*! Copyright 2015 Box, Inc. All rights reserved. @@ -14,5 +14,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -!function(e){var t={};if(t.EventTarget=function(){"use strict";function e(){this._handlers={}}return e.prototype={constructor:e,on:function(e,t){var n,r,i=this._handlers[e];for("undefined"==typeof i&&(i=this._handlers[e]=[]),n=0,r=i.length;r>n;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.NativeDOM=function(){"use strict";return{type:"native",query:function(e,t){return e.querySelector(t)},queryAll:function(e,t){return e.querySelectorAll(t)},on:function(e,t,n){e.addEventListener(t,n,!1)},off:function(e,t,n){e.removeEventListener(t,n,!1)}}}(),t.DOM=t.NativeDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function o(){y={},b={},w={},E=[],D={},_={},A=!1}function a(e){for(var t=0,n=E.length;n>t;t++)if(E[t]===e)return!0;return!1}function u(e){if(y.debug)throw e;M.fire("error",{exception:e})}function s(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,u(i)}}}(n,r))}function c(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function f(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function l(e){var t=w[e];if(t){if(!t.instance){if(a(e))return u(new ReferenceError("Circular service dependency: "+E.join(" -> ")+" -> "+e)),null;E.push(e),t.instance=t.creator(M),E.pop()}return t.instance}return u(new Error('Service "'+e+'" not found')),null}function h(e){var t,n,r,i,o,a=[],s={};for(n=e.instance.behaviors||[],t=0;tv;v++)l=d[v],f(l,"init");f(n.instance,"init"),p(n)}return this},stop:function(e){var t=g(e);if(t){v(t);for(var n,r=h(t),i=r.length-1;i>=0;i--)n=r[i],f(n,"destroy");f(t.instance,"destroy"),delete _[e.id]}else if(y.debug)return u(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(u(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=g(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');o&&(i=JSON.parse(o.text)),r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof w[e]?(u(new Error("Service "+e+" has already been added.")),this):(w[e]={creator:t,instance:null},this)},getService:l,hasService:function(e){return w.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(u(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,o,a,u,s,c;for(o in _)if(_.hasOwnProperty(o)){for(c=[],a=_[o],-1!==i(a.instance.messages||[],e)&&c.push(r(a.instance.onmessage,a.instance)),s=h(a),n=0;nn;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.NativeDOM=function(){"use strict";return{type:"native",query:function(e,t){return e.querySelector(t)},queryAll:function(e,t){return e.querySelectorAll(t)},on:function(e,t,n){e.addEventListener(t,n,!1)},off:function(e,t,n){e.removeEventListener(t,n,!1)}}}(),t.DOM=t.NativeDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function i(){y={},b={},E={},w=[],D={},_={},A=!1}function o(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function a(e){if(y.debug)throw e;M.fire("error",{exception:e})}function u(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,a(i)}}}(n,r))}function s(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function c(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function f(e){var t=E[e];if(t){if(!t.instance){if(o(e))return a(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return a(new Error('Service "'+e+'" not found')),null}function l(e){var t,n,r,i,o,u=[],s={};for(n=e.instance.behaviors||[],t=0;tv;v++)h=p[v],c(h,"init");c(n.instance,"init"),d(n)}return this},stop:function(e){var t=v(e);if(t){p(t);for(var n,r=l(t),i=r.length-1;i>=0;i--)n=r[i],c(n,"destroy");c(t.instance,"destroy"),delete _[e.id]}else if(y.debug)return a(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(a(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=v(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');if(o)try{i=JSON.parse(o.text)}catch(u){a(new Error("Module with id "+e.id+" has a malformed config."))}r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(a(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:f,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(a(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,r,i,o,a;for(r in _)if(_.hasOwnProperty(r))for(i=_[r],g(i.instance,e,t),a=l(i),n=0;n tag supports .text property if (configElement) { - moduleConfig = JSON.parse(configElement.text); + try { + moduleConfig = JSON.parse(configElement.text); + } catch (exception) { + error(new Error('Module with id ' + element.id + ' has a malformed config.')); + } } // Cache the configurations for performance, if the module instance has been created @@ -1221,32 +1231,21 @@ Box.Application = (function() { id, instanceData, behaviorInstance, - moduleBehaviors, - messageHandlers; + moduleBehaviors; for (id in instances) { if (instances.hasOwnProperty(id)) { - messageHandlers = []; instanceData = instances[id]; // Module message handler is called first - if (indexOf(instanceData.instance.messages || [], name) !== -1) { - messageHandlers.push(bind(instanceData.instance.onmessage, instanceData.instance)); - } + callMessageHandler(instanceData.instance, name, data); // And then any message handlers defined in module's behaviors moduleBehaviors = getBehaviors(instanceData); for (i = 0; i < moduleBehaviors.length; i++) { behaviorInstance = moduleBehaviors[i]; - - if (indexOf(behaviorInstance.messages || [], name) !== -1) { - messageHandlers.push(bind(behaviorInstance.onmessage, behaviorInstance)); - } - } - - for (i = 0; i < messageHandlers.length; i++) { - messageHandlers[i](name, data); + callMessageHandler(behaviorInstance, name, data); } } diff --git a/dist/t3.min.js b/dist/t3.min.js index 9493935..d83c766 100644 --- a/dist/t3.min.js +++ b/dist/t3.min.js @@ -1,4 +1,4 @@ -/*! t3 v2.1.0 */ +/*! t3 v2.2.0 */ /*! Copyright 2015 Box, Inc. All rights reserved. @@ -14,5 +14,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -!function(e){var t={};if(t.EventTarget=function(){"use strict";function e(){this._handlers={}}return e.prototype={constructor:e,on:function(e,t){var n,r,i=this._handlers[e];for("undefined"==typeof i&&(i=this._handlers[e]=[]),n=0,r=i.length;r>n;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.NativeDOM=function(){"use strict";return{type:"native",query:function(e,t){return e.querySelector(t)},queryAll:function(e,t){return e.querySelectorAll(t)},on:function(e,t,n){e.addEventListener(t,n,!1)},off:function(e,t,n){e.removeEventListener(t,n,!1)}}}(),t.DOM=t.NativeDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function o(){y={},b={},w={},E=[],D={},_={},A=!1}function a(e){for(var t=0,n=E.length;n>t;t++)if(E[t]===e)return!0;return!1}function u(e){if(y.debug)throw e;M.fire("error",{exception:e})}function s(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,u(i)}}}(n,r))}function c(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function f(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function l(e){var t=w[e];if(t){if(!t.instance){if(a(e))return u(new ReferenceError("Circular service dependency: "+E.join(" -> ")+" -> "+e)),null;E.push(e),t.instance=t.creator(M),E.pop()}return t.instance}return u(new Error('Service "'+e+'" not found')),null}function h(e){var t,n,r,i,o,a=[],s={};for(n=e.instance.behaviors||[],t=0;tv;v++)l=d[v],f(l,"init");f(n.instance,"init"),p(n)}return this},stop:function(e){var t=g(e);if(t){v(t);for(var n,r=h(t),i=r.length-1;i>=0;i--)n=r[i],f(n,"destroy");f(t.instance,"destroy"),delete _[e.id]}else if(y.debug)return u(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(u(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=g(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');o&&(i=JSON.parse(o.text)),r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof w[e]?(u(new Error("Service "+e+" has already been added.")),this):(w[e]={creator:t,instance:null},this)},getService:l,hasService:function(e){return w.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(u(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,o,a,u,s,c;for(o in _)if(_.hasOwnProperty(o)){for(c=[],a=_[o],-1!==i(a.instance.messages||[],e)&&c.push(r(a.instance.onmessage,a.instance)),s=h(a),n=0;nn;n++)if(i[n]===t)return;i.push(t)},fire:function(e,t){var n,r,i,o={type:e,data:t};if(n=this._handlers[o.type],n instanceof Array)for(n=n.concat(),r=0,i=n.length;i>r;r++)n[r].call(this,o)},off:function(e,t){var n,r,i=this._handlers[e];if(i instanceof Array)for(n=0,r=i.length;r>n;n++)if(i[n]===t){i.splice(n,1);break}}},e}(),t.NativeDOM=function(){"use strict";return{type:"native",query:function(e,t){return e.querySelector(t)},queryAll:function(e,t){return e.querySelectorAll(t)},on:function(e,t,n){e.addEventListener(t,n,!1)},off:function(e,t,n){e.removeEventListener(t,n,!1)}}}(),t.DOM=t.NativeDOM,t.DOMEventDelegate=function(){"use strict";function e(e){return e&&e.hasAttribute("data-module")}function n(e){return e&&e.hasAttribute("data-type")}function r(t){for(var r=!1;!r&&t&&t.parentNode&&!e(t);)r=n(t),r||(t=t.parentNode);return r?t:null}function i(e,t,n){var r,i;for(r=0;rn;n++)if(e[n]===t)return n;return-1}function i(){y={},b={},E={},w=[],D={},_={},A=!1}function o(e){for(var t=0,n=w.length;n>t;t++)if(w[t]===e)return!0;return!1}function a(e){if(y.debug)throw e;M.fire("error",{exception:e})}function u(e,t){var n,r;for(n in e)r=e[n],"function"==typeof r&&(e[n]=function(e,n){return function(){var r=t+"."+e+"() - ";try{return n.apply(this,arguments)}catch(i){i.methodName=e,i.objectName=t,i.name=r+i.name,i.message=r+i.message,a(i)}}}(n,r))}function s(e){var t=e.getAttribute("data-module");return t?t.split(" ")[0]:""}function c(e,t){"function"==typeof e[t]&&e[t].apply(e,Array.prototype.slice.call(arguments,2))}function f(e){var t=E[e];if(t){if(!t.instance){if(o(e))return a(new ReferenceError("Circular service dependency: "+w.join(" -> ")+" -> "+e)),null;w.push(e),t.instance=t.creator(M),w.pop()}return t.instance}return a(new Error('Service "'+e+'" not found')),null}function l(e){var t,n,r,i,o,u=[],s={};for(n=e.instance.behaviors||[],t=0;tv;v++)h=p[v],c(h,"init");c(n.instance,"init"),d(n)}return this},stop:function(e){var t=v(e);if(t){p(t);for(var n,r=l(t),i=r.length-1;i>=0;i--)n=r[i],c(n,"destroy");c(t.instance,"destroy"),delete _[e.id]}else if(y.debug)return a(new Error("Unable to stop module associated with element: "+e.id)),this;return this},startAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.start(n[r]);return this},stopAll:function(e){for(var n=t.DOM.queryAll(e,m),r=0,i=n.length;i>r;r++)this.stop(n[r]);return this},addModule:function(e,t){return"undefined"!=typeof b[e]?(a(new Error("Module "+e+" has already been added.")),this):(b[e]={creator:t,counter:1},this)},getModuleConfig:function(e,n){var r=v(e),i=null;if(r&&r.config)i=r.config;else{var o=t.DOM.query(e,'script[type="text/x-config"]');if(o)try{i=JSON.parse(o.text)}catch(u){a(new Error("Module with id "+e.id+" has a malformed config."))}r&&(r.config=i)}return i?"undefined"==typeof n?i:n in i?i[n]:null:null},addService:function(e,t){return"undefined"!=typeof E[e]?(a(new Error("Service "+e+" has already been added.")),this):(E[e]={creator:t,instance:null},this)},getService:f,hasService:function(e){return E.hasOwnProperty(e)},addBehavior:function(e,t){return"undefined"!=typeof D[e]?(a(new Error("Behavior "+e+" has already been added.")),this):(D[e]={creator:t,instance:null},this)},broadcast:function(e,t){var n,r,i,o,a;for(r in _)if(_.hasOwnProperty(r))for(i=_[r],g(i.instance,e,t),a=l(i),n=0;n