diff --git a/dist/terrific.js b/dist/terrific.js index e2b86fb..af86b14 100755 --- a/dist/terrific.js +++ b/dist/terrific.js @@ -1010,8 +1010,19 @@ var Utils = { Utils.extend(Constructor, spec.statics); } + // Ensure that stop is called even if the spec contains a custom stop function + if (spec.hasOwnProperty('stop')) { + proto.stop = function() { + // Call the spec stop function + spec.stop.apply(this, arguments); + // Call the original stop function + Module.prototype.stop.apply(this, arguments); + }; + } + var reservedKeys = [ - 'statics' + 'statics', + 'stop' ]; // mixin spec properties to module prototype diff --git a/dist/terrific.min.js b/dist/terrific.min.js index 519e517..244f0f6 100755 --- a/dist/terrific.min.js +++ b/dist/terrific.min.js @@ -6,5 +6,5 @@ * @license Licensed under MIT license * @version 3.0.0 */ -function t(t,r){if(t||r)if(i.isNode(r)){var o=r;r=t,t=o}else i.isNode(t)||r?i.isNode(t)&&!r&&(r={}):(r=t,t=document);else t=document,r={};var s={namespace:n};r=i.extend(s,r),this._ctx=i.getElement(t),this._config=r,this._sandbox=new e(this),this._modules={},this._id=1}function e(t){this._application=t,this._eventEmitters=[]}function n(t,e){this._ctx=t,this._sandbox=e,this._events=new r(e)}function r(t){this._listeners={},this._sandbox=t,this._connected=!1}t.prototype.registerModules=function(t){var e={};t=i.getElement(t)||this._ctx,this._sandbox.dispatch("t.register.start");var n=i.getModuleNodes(t);return n.forEach(function(t){var n=this.registerModule(t,t.getAttribute("data-t-name"),t.getAttribute("data-t-decorator"),t.getAttribute("data-t-namespace"));n&&(e[n._ctx.getAttribute("data-t-id")]=n)}.bind(this)),this._sandbox.dispatch("t.register.end"),e},t.prototype.unregisterModules=function(t){t=t||this._modules,this._sandbox.dispatch("t.unregister.start");for(var e in t)this._modules.hasOwnProperty(e)&&(i.isNode(this._modules[e]._ctx)&&this._modules[e]._ctx.removeAttribute("data-t-id"),delete this._modules[e]);this._sandbox.dispatch("t.unregister.end")},t.prototype.start=function(t){t=t||this._modules;var e=[];this._sandbox.dispatch("t.start");for(var n in t)if(t.hasOwnProperty(n)){var r=function(e){return new Promise(function(n,r){t[e].start(n,r)})}(n);e.push(r)}var i=Promise.all(e);return i.then(function(){this._sandbox.dispatch("t.sync")}.bind(this))["catch"](function(t){throw t}),i},t.prototype.stop=function(t){t=t||this._modules,this._sandbox.dispatch("t.stop");for(var e in t)t.hasOwnProperty(e)&&t[e].stop()},t.prototype.registerModule=function(t,e,n,r){var o=this._modules;if(t.hasAttribute("data-t-id"))return null;if(e=i.capitalize(i.camelize(e)),i.isString(n)?window[n]?(r=window[n],n=null):n=n.split(","):!Array.isArray(n)&&i.isObject(n)&&(r=n,n=null),n=n||[],n=n.map(function(t){return i.capitalize(i.camelize(t.trim()))}),r=r||this._config.namespace,r[e]){var s=this._id++;t.setAttribute("data-t-id",s),o[s]=new r[e](t,this._sandbox);for(var a=0,c=n.length;c>a;a++){var u=n[a];r[e][u]&&r[e][u](o[s])}return o[s]}return this._sandbox.dispatch("t.missing",t,e,n,r),null},t.prototype.getModuleById=function(t){if(this._modules[t])return this._modules[t];throw Error("The module with the id "+t+" does not exist")},e.prototype.addModules=function(t){var e={},n=this._application;return i.isNode(t)&&(e=n.registerModules(t),n.start(e)),e},e.prototype.removeModules=function(t){var e=this._application;if(i.isNode(t)){var n={},r=i.getModuleNodes(t);r.forEach(function(t){if(t.hasAttribute("data-t-id")){var e=t.getAttribute("data-t-id"),r=this.getModuleById(e);r&&(n[e]=r)}}.bind(this)),t=n}return i.isObject(t)&&(e.stop(t),e.unregisterModules(t)),this},e.prototype.getModuleById=function(t){return this._application.getModuleById(t)},e.prototype.getConfig=function(){return this._application._config},e.prototype.getConfigParam=function(t){var e=this._application._config;if(void 0!==e[t])return e[t];throw Error("The config param "+t+" does not exist")},e.prototype.addEventEmitter=function(t){return this._eventEmitters.push(t),this},e.prototype.removeEventEmitter=function(t){for(var e=this._eventEmitters,n=0,r=e.length;r>n;n++)if(e[n]===t){e.splice(n,1);break}return this},e.prototype.dispatch=function(){for(var t=this._eventEmitters,e=0,n=t.length;n>e;e++){var r=t[e];void 0!==r&&r.handle.apply(r,arguments)}return this},n.prototype.start=function(t){t()},n.prototype.stop=function(){this._events.off().disconnect()},r.prototype.on=r.prototype.addListener=function(t,e){return this.connect(),(this._listeners["$"+t]=this._listeners["$"+t]||[]).push(e),this},r.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return this.connect(),n.listener=e,this.on(t,n),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=function(t,e){if(0===arguments.length)return this._listeners={},this;var n=this._listeners["$"+t];if(!n)return this;if(1===arguments.length)return delete this._listeners["$"+t],this;for(var r,i=0,o=n.length;o>i;i++)if(r=n[i],r===e||r.listener===e){n.splice(i,1);break}return this},r.prototype.emit=function(){return this.connect(),this._sandbox.dispatch.apply(this._sandbox,arguments),this},r.prototype.handle=function(t){var e=[].slice.call(arguments,1),n=this._listeners["$"+t];if(n){n=n.slice(0);for(var r=0,i=n.length;i>r;++r)n[r].apply(this,e)}return this},r.prototype.listeners=function(t){return this._listeners["$"+t]||[]},r.prototype.hasListeners=function(t){return!!this.listeners(t).length},r.prototype.connect=function(){return this._connected||(this._sandbox.addEventEmitter(this),this._connected=!0),this},r.prototype.disconnect=function(){return this._connected&&(this._sandbox.removeEventEmitter(this),this._connected=!1),this};var i={capitalize:function(t){return t.substr(0,1).toUpperCase().concat(t.substr(1))},camelize:function(t){return t.replace(/(\-[A-Za-z])/g,function(t){return t.toUpperCase().replace("-","")})},isString:function(t){return"[object String]"===Object.prototype.toString.call(t)},isObject:function(t){var e=typeof t;return!(!t||"object"!==e&&"function"!==e||Array.isArray(t))},isFunction:function(t){var e=typeof t;return!!t&&"function"===e},isNode:function(t){return t&&t.nodeType?1===t.nodeType||9===t.nodeType:!1},matches:function(t,e){var n=Element.prototype,r=n.matches||n.webkitMatchesSelector||n.mozMatchesSelector||n.msMatchesSelector||function(t){return-1!==[].slice.call(document.querySelectorAll(t)).indexOf(this)};return r.call(t,e)},extend:function(t){if(!i.isObject(t))return t;for(var e,n,r=1,o=arguments.length;o>r;r++){e=arguments[r];for(n in e)e.hasOwnProperty(n)&&(t[n]=e[n])}return t},getElement:function(t){return this.isNode(t)?9===t.nodeType&&t.documentElement?t.documentElement:t:null},getModuleNodes:function(t){var e=[].slice.call(t.querySelectorAll("[data-t-name]"));return this.matches(t,"[data-t-name]")&&e.unshift(t),e},createModule:function(t){if(!t||!i.isObject(t))throw Error("Your module spec is not an object. Usage: T.createModule({ … })");var e=function(t,e){n.call(this,t,e)},r=e.prototype=Object.create(n.prototype);r.constructor=e,t.hasOwnProperty("statics")&&i.extend(e,t.statics);var o=["statics"];for(var s in t)if(t.hasOwnProperty(s)&&-1===o.indexOf(s)){var a=t[s];r[s]=a}return e},createDecorator:function(t){if(!t||!i.isObject(t))throw Error("Your decorator spec is not an object. Usage: T.createDecorator({ … })");return function(e){var n,r={};for(n in e)i.isFunction(e[n])&&(r[n]=e[n].bind(e));for(n in t)t.hasOwnProperty(n)&&(e[n]=i.isFunction(t[n])?function(t,e){return function(){return this._parent=r,e.apply(this,arguments)}}(n,t[n]):t[n])}}},o={Application:t,Sandbox:e,Module:n,EventEmitter:r,createModule:i.createModule,createDecorator:i.createDecorator,version:"3.0.0"};return o}); -//# sourceMappingURL=terrific.min.js.map \ No newline at end of file +function t(t,i){if(t||i)if(r.isNode(i)){var o=i;i=t,t=o}else r.isNode(t)||i?r.isNode(t)&&!i&&(i={}):(i=t,t=document);else t=document,i={};var s={namespace:n};i=r.extend(s,i),this._ctx=r.getElement(t),this._config=i,this._sandbox=new e(this),this._modules={},this._id=1}function e(t){this._application=t,this._eventEmitters=[]}function n(t,e){this._ctx=t,this._sandbox=e,this._events=new i(e)}function i(t){this._listeners={},this._sandbox=t,this._connected=!1}t.prototype.registerModules=function(t){var e={};t=r.getElement(t)||this._ctx,this._sandbox.dispatch("t.register.start");var n=r.getModuleNodes(t);return n.forEach(function(t){var n=this.registerModule(t,t.getAttribute("data-t-name"),t.getAttribute("data-t-decorator"),t.getAttribute("data-t-namespace"));n&&(e[n._ctx.getAttribute("data-t-id")]=n)}.bind(this)),this._sandbox.dispatch("t.register.end"),e},t.prototype.unregisterModules=function(t){t=t||this._modules,this._sandbox.dispatch("t.unregister.start");for(var e in t)this._modules.hasOwnProperty(e)&&(r.isNode(this._modules[e]._ctx)&&this._modules[e]._ctx.removeAttribute("data-t-id"),delete this._modules[e]);this._sandbox.dispatch("t.unregister.end")},t.prototype.start=function(t){t=t||this._modules;var e=[];this._sandbox.dispatch("t.start");for(var n in t)if(t.hasOwnProperty(n)){var i=function(e){return new Promise(function(n,i){t[e].start(n,i)})}(n);e.push(i)}var r=Promise.all(e);return r.then(function(){this._sandbox.dispatch("t.sync")}.bind(this))["catch"](function(t){throw t}),r},t.prototype.stop=function(t){t=t||this._modules,this._sandbox.dispatch("t.stop");for(var e in t)t.hasOwnProperty(e)&&t[e].stop()},t.prototype.registerModule=function(t,e,n,i){var o=this._modules;if(t.hasAttribute("data-t-id"))return null;if(e=r.capitalize(r.camelize(e)),r.isString(n)?window[n]?(i=window[n],n=null):n=n.split(","):!Array.isArray(n)&&r.isObject(n)&&(i=n,n=null),n=n||[],n=n.map(function(t){return r.capitalize(r.camelize(t.trim()))}),i=i||this._config.namespace,i[e]){var s=this._id++;t.setAttribute("data-t-id",s),o[s]=new i[e](t,this._sandbox);for(var a=0,c=n.length;a