From a322f8c5f75ac5cda42c6cd784062b790beae992 Mon Sep 17 00:00:00 2001 From: brunschgi Date: Mon, 23 May 2016 11:15:01 +0200 Subject: [PATCH] update version to 3.0.0 --- bower.json | 2 +- dist/docs/classes/T.Application.html | 26 +++++++++++++------------- dist/terrific.js | 8 ++++---- dist/terrific.min.js | 6 +++--- dist/terrific.min.js.map | 2 +- package.json | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bower.json b/bower.json index b79a897..20d1f49 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "terrific", - "version": "3.0.0-beta.9", + "version": "3.0.0", "description": "TerrificJS modularizes your frontend code by solely relying on naming conventions.", "homepage": "https://github.com/brunschgi/terrificjs", "main": "dist/terrific.js", diff --git a/dist/docs/classes/T.Application.html b/dist/docs/classes/T.Application.html index ab6759e..c3ed72d 100644 --- a/dist/docs/classes/T.Application.html +++ b/dist/docs/classes/T.Application.html @@ -100,7 +100,7 @@

T.Application Class

- Defined in: /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:23 + Defined in: /Users/me/Documents/github/terrificjs/dist/terrific.js:23
@@ -171,7 +171,7 @@

T.Application

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:23 + /Users/me/Documents/github/terrificjs/dist/terrific.js:23

@@ -406,7 +406,7 @@

getModuleById

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:327 + /Users/me/Documents/github/terrificjs/dist/terrific.js:327

@@ -531,7 +531,7 @@

registerModule

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:253 + /Users/me/Documents/github/terrificjs/dist/terrific.js:253

@@ -686,7 +686,7 @@

registerModules

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:108 + /Users/me/Documents/github/terrificjs/dist/terrific.js:108

@@ -795,7 +795,7 @@

start

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:193 + /Users/me/Documents/github/terrificjs/dist/terrific.js:193

@@ -898,7 +898,7 @@

stop

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:233 + /Users/me/Documents/github/terrificjs/dist/terrific.js:233

@@ -987,7 +987,7 @@

unregisterModules

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:168 + /Users/me/Documents/github/terrificjs/dist/terrific.js:168

@@ -1065,7 +1065,7 @@

_ctx

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:66 + /Users/me/Documents/github/terrificjs/dist/terrific.js:66

@@ -1110,7 +1110,7 @@

_modules

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:91 + /Users/me/Documents/github/terrificjs/dist/terrific.js:91

@@ -1155,7 +1155,7 @@

_sandbox

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:82 + /Users/me/Documents/github/terrificjs/dist/terrific.js:82

@@ -1201,7 +1201,7 @@

config

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:74 + /Users/me/Documents/github/terrificjs/dist/terrific.js:74

@@ -1246,7 +1246,7 @@

id

- /Users/rbrunschwiler/Documents/github/terrificjs/dist/terrific.js:99 + /Users/me/Documents/github/terrificjs/dist/terrific.js:99

diff --git a/dist/terrific.js b/dist/terrific.js index bc015ef..e2b86fb 100755 --- a/dist/terrific.js +++ b/dist/terrific.js @@ -11,9 +11,9 @@ * TerrificJS modularizes your frontend code by solely relying on naming conventions. * http://terrifically.org * - * @copyright Copyright (c) 2015 Remo Brunschwiler + * @copyright Copyright (c) 2016 Remo Brunschwiler * @license Licensed under MIT license - * @version 3.0.0-beta.9 + * @version 3.0.0 */ /** @@ -224,7 +224,7 @@ Application.prototype.start = function (modules) { all.then(function () { this._sandbox.dispatch('t.sync'); }.bind(this)).catch(function (err) { - throw Error('Starting or synchronizing the modules failed: ' + err); + throw err; }); return all; @@ -1087,7 +1087,7 @@ var T = { EventEmitter: EventEmitter, createModule: Utils.createModule, createDecorator: Utils.createDecorator, - version: '3.0.0-beta.9' + version: '3.0.0' }; return T; })); diff --git a/dist/terrific.min.js b/dist/terrific.min.js index fa2a371..519e517 100755 --- a/dist/terrific.min.js +++ b/dist/terrific.min.js @@ -2,9 +2,9 @@ * TerrificJS modularizes your frontend code by solely relying on naming conventions. * http://terrifically.org * - * @copyright Copyright (c) 2015 Remo Brunschwiler + * @copyright Copyright (c) 2016 Remo Brunschwiler * @license Licensed under MIT license - * @version 3.0.0-beta.9 + * @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 Error("Starting or synchronizing the modules failed: "+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-beta.9"};return o}); +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 diff --git a/dist/terrific.min.js.map b/dist/terrific.min.js.map index ddbba5d..35b4a7d 100644 --- a/dist/terrific.min.js.map +++ b/dist/terrific.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["terrific.js"],"names":["root","factory","define","amd","exports","module","T","this","Application","ctx","config","Utils","isNode","tmpConfig","document","defaults","namespace","Module","extend","_ctx","getElement","_config","_sandbox","Sandbox","_modules","_id","application","_application","_eventEmitters","sandbox","_events","EventEmitter","_listeners","_connected","prototype","registerModules","modules","dispatch","nodes","getModuleNodes","forEach","registerModule","getAttribute","bind","unregisterModules","id","hasOwnProperty","removeAttribute","start","promises","promise","Promise","resolve","reject","push","all","then","err","Error","stop","mod","decorators","hasAttribute","capitalize","camelize","isString","window","split","Array","isArray","isObject","map","decorator","trim","setAttribute","i","len","length","getModuleById","addModules","removeModules","tmpModules","getConfig","getConfigParam","name","undefined","addEventEmitter","eventEmitter","removeEventEmitter","eventEmitters","splice","handle","apply","arguments","off","disconnect","on","addListener","event","listener","connect","once","removeListener","removeAllListeners","listeners","cb","emit","args","slice","call","hasListeners","str","substr","toUpperCase","concat","replace","$1","obj","Object","toString","type","isFunction","node","nodeType","matches","el","selector","p","Element","f","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","s","querySelectorAll","indexOf","source","prop","documentElement","unshift","createModule","spec","Constructor","proto","create","constructor","statics","reservedKeys","property","createDecorator","orig","parent","fn","_parent","version"],"mappings":"CAAA,SAAAA,EAAAC,GACA,kBAAAC,SAAAA,OAAAC,IACAD,UAAAD,GACA,gBAAAG,SACAC,OAAAD,QAAAH,IAEAD,EAAAM,EAAAL,KAEAM,KAAA;;;;;;;;AA4BA,QAAAC,GAAAC,EAAAC,GAEA,GAAAD,GAAAC,EAKA,GAAAC,EAAAC,OAAAF,GAAA,CAEA,GAAAG,GAAAH,CACAA,GAAAD,EACAA,EAAAI,MAEAF,GAAAC,OAAAH,IAAAC,EAKAC,EAAAC,OAAAH,KAAAC,IAEAA,OALAA,EAAAD,EACAA,EAAAK,cAZAL,GAAAK,SACAJ,IAkBA,IAAAK,IACAC,UAAAC,EAGAP,GAAAC,EAAAO,OAAAH,EAAAL,GAQAH,KAAAY,KAAAR,EAAAS,WAAAX,GAQAF,KAAAc,QAAAX,EASAH,KAAAe,SAAA,GAAAC,GAAAhB,MAQAA,KAAAiB,YAQAjB,KAAAkB,IAAA,EA8PA,QAAAF,GAAAG,GAOAnB,KAAAoB,aAAAD,EAQAnB,KAAAqB,kBAm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D,GACA,GAAAA,EAAA/F,eAAAsC,IAKA,KAAA+D,EAAAZ,QAAAnD,GAAA,CAIA,GAAAgE,GAAAP,EAAAzD,EACA2D,GAAA3D,GAAAgE,EAGA,MAAAN,IAUAO,gBAAA,SAAAR,GAEA,IAAAA,IAAAlI,EAAA2D,SAAAuE,GACA,KAAAnF,OAAA,wEAGA,OAAA,UAAA4F,GACA,GACAlE,GADAmE,IAIA,KAAAnE,IAAAkE,GACA3I,EAAA8G,WAAA6B,EAAAlE,MACAmE,EAAAnE,GAAAkE,EAAAlE,GAAAzC,KAAA2G,GAKA,KAAAlE,IAAAyD,GACAA,EAAA/F,eAAAsC,KAEAkE,EAAAlE,GADAzE,EAAA8G,WAAAoB,EAAAzD,IACA,SAAAA,EAAAoE,GACA,MAAA,YAEA,MADAjJ,MAAAkJ,QAAAF,EACAC,EAAA5D,MAAArF,KAAAsF,aAEAT,EAAAyD,EAAAzD,IAIAyD,EAAAzD,OAWA9E,GACAE,YAAAA,EACAe,QAAAA,EACAN,OAAAA,EACAc,aAAAA,EACA6G,aAAAjI,EAAAiI,aACAS,gBAAA1I,EAAA0I,gBACAK,QAAA,eAEA,OAAApJ","file":"terrific.min.js","sourcesContent":["(function(root, factory) {\n if (typeof define === 'function' && define.amd) {\n define([], factory);\n } else if (typeof exports === 'object') {\n module.exports = factory();\n } else {\n root.T = factory();\n }\n}(this, function() {\n/*!\n * TerrificJS modularizes your frontend code by solely relying on naming conventions.\n * http://terrifically.org\n *\n * @copyright Copyright (c) 2015 Remo Brunschwiler\n * @license Licensed under MIT license\n * @version 3.0.0-beta.9\n */\n\n/**\n * @module T\n */\n\n/**\n * Responsible for application-wide issues such as the creation of modules.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Application\n *\n * @constructor\n * @param {Node} ctx\n * The context node\n * @param {Object} config\n * The configuration\n */\n/* global Sandbox, Utils, Module */\nfunction Application(ctx, config) {\n\t// validate params\n\tif (!ctx && !config) {\n\t\t// both empty\n\t\tctx = document;\n\t\tconfig = {};\n\t}\n\telse if (Utils.isNode(config)) {\n\t\t// reverse order of arguments\n\t\tvar tmpConfig = config;\n\t\tconfig = ctx;\n\t\tctx = tmpConfig;\n\t}\n\telse if (!Utils.isNode(ctx) && !config) {\n\t\t// only config is given\n\t\tconfig = ctx;\n\t\tctx = document;\n\t}\n\telse if (Utils.isNode(ctx) && !config) {\n\t\t// only ctx is given\n\t\tconfig = {};\n\t}\n\n\tvar defaults = {\n\t\tnamespace: Module\n\t};\n\n\tconfig = Utils.extend(defaults, config);\n\n\t/**\n\t * The context node.\n\t *\n\t * @property _ctx\n\t * @type Node\n\t */\n\tthis._ctx = Utils.getElement(ctx);\n\n\t/**\n\t * The configuration.\n\t *\n\t * @property config\n\t * @type Object\n\t */\n\tthis._config = config;\n\n\t/**\n\t * The sandbox to get the resources from.\n\t * The singleton is shared between all modules.\n\t *\n\t * @property _sandbox\n\t * @type Sandbox\n\t */\n\tthis._sandbox = new Sandbox(this);\n\n\t/**\n\t * Contains references to all modules on the page.\n\t *\n\t * @property _modules\n\t * @type Object\n\t */\n\tthis._modules = {};\n\n\t/**\n\t * The next unique module id to use.\n\t *\n\t * @property id\n\t * @type Number\n\t */\n\tthis._id = 1;\n}\n\n/**\n * Register modules within the context\n * Automatically registers all modules within the context,\n * as long as the modules use the naming conventions.\n *\n * @method registerModules\n * @param {Node} ctx\n * The context node\n * @return {Object}\n * A collection containing the registered modules\n */\nApplication.prototype.registerModules = function (ctx) {\n\tvar modules = {};\n\n\tctx = Utils.getElement(ctx) || this._ctx;\n\n\tthis._sandbox.dispatch('t.register.start');\n\n\t// get module nodes\n\tvar nodes = Utils.getModuleNodes(ctx);\n\tnodes.forEach(function (ctx) {\n\n\t\t/*\n\t\t * A module can have different data attributes.\n\t\t * See below for possible values.\n\t\t */\n\n\t\t/*\n\t\t * @config data-t-name=\"{mod-name}\"\n\t\t *\n\t\t * Example: data-t-name=\"foo\"\n\t\t * Indicates that the module Foo should be bound.\n\t\t */\n\n\t\t/*\n\t\t * @config data-t-namespace=\"{namespace}\"\n\t\t *\n\t\t * Example: data-t-namespace=\"App.Components\"\n\t\t * The namespace of the module. Optional.\n\t\t */\n\n\t\t/*\n\t\t * @config data-t-decorator=\"{decorator-name}\"\n\t\t *\n\t\t * Example: data-t-decorator=\"bar\"\n\t\t * Indicates that the module Foo should be decorated with the Bar decorator.\n\t\t * Multiple decorators should be comma-separated. Optional.\n\t\t */\n\t\tvar module = this.registerModule(ctx, ctx.getAttribute('data-t-name'), ctx.getAttribute('data-t-decorator'), ctx.getAttribute('data-t-namespace'));\n\n\t\tif (module) {\n\t\t\tmodules[module._ctx.getAttribute('data-t-id')] = module;\n\t\t}\n\t}.bind(this));\n\n\tthis._sandbox.dispatch('t.register.end');\n\n\treturn modules;\n};\n\n/**\n * Unregisters the modules given by the module instances.\n *\n * @method unregisterModules\n * @param {Object} modules\n * A collection containing the modules to unregister\n */\nApplication.prototype.unregisterModules = function (modules) {\n\tmodules = modules || this._modules;\n\n\tthis._sandbox.dispatch('t.unregister.start');\n\n\t// unregister the given modules\n\tfor (var id in modules) {\n\t\tif (this._modules.hasOwnProperty(id)) {\n\t\t\tif(Utils.isNode(this._modules[id]._ctx)) {\n\t\t\t\tthis._modules[id]._ctx.removeAttribute('data-t-id');\n\t\t\t}\n\t\t\tdelete this._modules[id];\n\t\t}\n\t}\n\n\tthis._sandbox.dispatch('t.unregister.end');\n};\n\n/**\n * Starts (intializes) the registered modules.\n *\n * @method start\n * @param {Object} modules\n * A collection of modules to start\n * @return {Promise}\n * The synchronize Promise\n */\nApplication.prototype.start = function (modules) {\n\tmodules = modules || this._modules;\n\n\tvar promises = [];\n\n\tthis._sandbox.dispatch('t.start');\n\n\t// start the modules\n\tfor (var id in modules) {\n\t\tif (modules.hasOwnProperty(id)) {\n\t\t\tvar promise = (function (id) {\n\t\t\t\treturn new Promise(function (resolve, reject) {\n modules[id].start(resolve, reject);\n\t\t\t\t});\n\t\t\t}(id));\n\n\t\t\tpromises.push(promise);\n\t\t}\n\t}\n\n\t// synchronize modules\n\tvar all = Promise.all(promises);\n\tall.then(function () {\n\t\tthis._sandbox.dispatch('t.sync');\n\t}.bind(this)).catch(function (err) {\n\t\tthrow Error('Starting or synchronizing the modules failed: ' + err);\n\t});\n\n\treturn all;\n};\n\n/**\n * Stops the registered modules.\n *\n * @method stop\n * @param {Object} modules\n * A collection of modules to stop\n */\nApplication.prototype.stop = function (modules) {\n\tmodules = modules || this._modules;\n\n\tthis._sandbox.dispatch('t.stop');\n\n\t// stop the modules\n\tfor (var id in modules) {\n\t\tif (modules.hasOwnProperty(id)) {\n\t\t\tmodules[id].stop();\n\t\t}\n\t}\n};\n\n/**\n * Registers a module.\n *\n * @method registerModule\n * @param {Node} ctx\n * The context node\n * @param {String} mod\n * The module name. It must match the class name of the module\n * @param {Array} decorators\n * A list of decorator names. Each entry must match a class name of a decorator\n * @param {String} namespace\n * The module namespace\n * @return {Module}\n * The reference to the registered module\n */\nApplication.prototype.registerModule = function (ctx, mod, decorators, namespace) {\n\tvar modules = this._modules;\n\n\t// validate params\n\tif(ctx.hasAttribute('data-t-id')) {\n\t\treturn null; // prevent from registering twice\n\t}\n\n\tmod = Utils.capitalize(Utils.camelize(mod));\n\n\tif (Utils.isString(decorators)) {\n\t\tif (window[decorators]) {\n\t\t\t// decorators param is the namespace\n\t\t\tnamespace = window[decorators];\n\t\t\tdecorators = null;\n\t\t}\n\t\telse {\n\t\t\t// convert string to array\n\t\t\tdecorators = decorators.split(',');\n\t\t}\n\t}\n\telse if (!Array.isArray(decorators) && Utils.isObject(decorators)) {\n\t\t// decorators is the namespace object\n\t\tnamespace = decorators;\n\t\tdecorators = null;\n\t}\n\n\tdecorators = decorators || [];\n\tdecorators = decorators.map(function (decorator) {\n\t\treturn Utils.capitalize(Utils.camelize(decorator.trim()));\n\t});\n\n\tnamespace = namespace || this._config.namespace;\n\n\tif (namespace[mod]) {\n\t\t// assign the module a unique id\n\t\tvar id = this._id++;\n\t\tctx.setAttribute('data-t-id', id);\n\n\t\t// instantiate module\n\t\tmodules[id] = new namespace[mod](ctx, this._sandbox);\n\n\t\t// decorate it\n\t\tfor (var i = 0, len = decorators.length; i < len; i++) {\n\t\t\tvar decorator = decorators[i];\n\n\t\t\tif (namespace[mod][decorator]) {\n\t\t\t\tnamespace[mod][decorator](modules[id]);\n\t\t\t}\n\t\t}\n\n\t\treturn modules[id];\n\t}\n\n\tthis._sandbox.dispatch('t.missing', ctx, mod, decorators, namespace);\n\n\treturn null;\n};\n\n/**\n * Gets the appropriate module for the given ID.\n *\n * @method getModuleById\n * @param {int} id\n * The module ID\n * @return {Module}\n * The appropriate module\n */\nApplication.prototype.getModuleById = function (id) {\n\tif (this._modules[id]) {\n\t\treturn this._modules[id];\n\t}\n\telse {\n\t\tthrow Error('The module with the id ' + id +\n\t\t' does not exist');\n\t}\n};\n\n/**\n * The sandbox is used as a central point to get resources from, add modules etc.\n * It is shared between all modules.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Sandbox\n *\n * @constructor\n * @param {Application} application\n * The application reference\n */\n/* global Utils */\nfunction Sandbox(application) {\n\t/**\n\t * The application.\n\t *\n\t * @property _application\n\t * @type Application\n\t */\n\tthis._application = application;\n\n\t/**\n\t * Contains references to all module event emitters.\n\t *\n\t * @property _eventEmitters\n\t * @type Array\n\t */\n\tthis._eventEmitters = [];\n}\n\n/**\n * Adds (register and start) all modules in the given context scope.\n *\n * @method addModules\n * @param {Node} ctx\n * The context node\n * @return {Object}\n * A collection containing the registered modules\n */\nSandbox.prototype.addModules = function (ctx) {\n\tvar modules = {},\n\t\tapplication = this._application;\n\n\tif (Utils.isNode(ctx)) {\n\t\t// register modules\n\t\tmodules = application.registerModules(ctx);\n\n\t\t// start modules\n\t\tapplication.start(modules);\n\t}\n\n\treturn modules;\n};\n\n/**\n * Removes a module by module instances.\n * This stops and unregisters a module through a module instance.\n *\n * @method removeModules\n * @param {any} modules\n * A collection of module to remove | Node context to look for registered modules in.\n * @return {Sandbox}\n */\nSandbox.prototype.removeModules = function (modules) {\n\tvar application = this._application;\n\n\tif (Utils.isNode(modules)) {\n\t\t// get modules\n\t\tvar tmpModules = {};\n\n\t\tvar nodes = Utils.getModuleNodes(modules);\n\t\tnodes.forEach(function (ctx) {\n\t\t\t// check for instance\n\t\t\tif (ctx.hasAttribute('data-t-id')) {\n\t\t\t\tvar id = ctx.getAttribute('data-t-id');\n\t\t\t\tvar module = this.getModuleById(id);\n\n\t\t\t\tif (module) {\n\t\t\t\t\ttmpModules[id] = module;\n\t\t\t\t}\n\t\t\t}\n\t\t}.bind(this));\n\n\t\tmodules = tmpModules;\n\t}\n\n\tif(Utils.isObject(modules)) {\n\t\t// stop modules – let the module clean itself\n\t\tapplication.stop(modules);\n\n\t\t// unregister modules – clean up the application\n\t\tapplication.unregisterModules(modules);\n\t}\n\n\treturn this;\n};\n\n/**\n * Gets the appropriate module for the given ID.\n *\n * @method getModuleById\n * @param {int} id\n * The module ID\n * @return {Module}\n * The appropriate module\n */\nSandbox.prototype.getModuleById = function (id) {\n\treturn this._application.getModuleById(id);\n};\n\n/**\n * Gets the application config.\n *\n * @method getConfig\n * @return {Object}\n * The configuration object\n */\nSandbox.prototype.getConfig = function () {\n\treturn this._application._config;\n};\n\n/**\n * Gets an application config param.\n *\n * @method getConfigParam\n * @param {String} name\n * The param name\n * @return {any}\n * The appropriate configuration param\n */\nSandbox.prototype.getConfigParam = function (name) {\n\tvar config = this._application._config;\n\n\tif (config[name] !== undefined) {\n\t\treturn config[name];\n\t}\n\telse {\n\t\tthrow Error('The config param ' + name + ' does not exist');\n\t}\n};\n\n/**\n * Adds an event emitter instance.\n *\n * @method addEventEmitter\n * @param {EventEmitter} eventEmitter\n * The event emitter\n * @return {Sandbox}\n */\nSandbox.prototype.addEventEmitter = function (eventEmitter) {\n\tthis._eventEmitters.push(eventEmitter);\n\treturn this;\n};\n\n/**\n * Removes an event emitter instance.\n *\n * @method addEventEmitter\n * @param {EventEmitter} eventEmitter\n * The event emitter\n * @return {Sandbox}\n */\nSandbox.prototype.removeEventEmitter = function (eventEmitter) {\n\tvar eventEmitters = this._eventEmitters;\n\tfor (var i = 0, len = eventEmitters.length; i < len; i++) {\n\t\tif (eventEmitters[i] === eventEmitter) {\n\t\t\teventEmitters.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn this;\n};\n\n/**\n * Dispatches the event with the given arguments to the attached event emitters.\n *\n * @method dispatch\n * @param {Mixed} ...\n * @return {Sandbox}\n */\nSandbox.prototype.dispatch = function () {\n\tvar eventEmitters = this._eventEmitters;\n\n\tfor(var i = 0, len = eventEmitters.length; i < len; i++) {\n\t\tvar eventEmitter = eventEmitters[i];\n\t\tif(eventEmitter !== undefined) {\n\t\t\teventEmitter.handle.apply(eventEmitter, arguments);\n\t\t}\n\t}\n\n\treturn this;\n};\n/**\n * Base class for the different modules.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Module\n *\n * @constructor\n * @param {Node} ctx\n * The context node\n * @param {Sandbox} sandbox\n * The sandbox to get the resources from\n */\n/* global EventEmitter */\nfunction Module(ctx, sandbox) {\n\t/**\n\t * Contains the context node.\n\t *\n\t * @property ctx\n\t * @type Node\n\t */\n\tthis._ctx = ctx;\n\n\t/**\n\t * The sandbox to get the resources from.\n\t *\n\t * @property _sandbox\n\t * @type Sandbox\n\t */\n\tthis._sandbox = sandbox;\n\n\t/**\n\t * The emitter.\n\t *\n\t * @property _events\n\t * @type EventEmitter\n\t */\n\tthis._events = new EventEmitter(sandbox);\n}\n\n/**\n * Template method to start the module.\n *\n * @method start\n * @param {Function} resolve\n * The resolve promise function\n * @param {Function} reject\n * \t\tThe reject promise function\n */\n/*jshint unused: true */\nModule.prototype.start = function (resolve) {\n\tresolve();\n};\n\n/**\n * Template method to stop the module.\n *\n * @method stop\n */\nModule.prototype.stop = function () {\n\tthis._events.off().disconnect();\n};\n\n/**\n * Responsible for inter-module communication.\n * Classic EventEmitter Api. Heavily inspired by https://github.com/component/emitter\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class EventEmitter\n *\n * @constructor\n *\n * @param {Sandbox} sandbox\n * The sandbox instance\n */\nfunction EventEmitter(sandbox) {\n\t/**\n\t * The listeners.\n\t *\n\t * @property _listeners\n\t * @type Object\n\t */\n\tthis._listeners = {};\n\n\t/**\n\t * The sandbox instance.\n\t *\n\t * @property _sandbox\n\t * @type Sandbox\n\t */\n\tthis._sandbox = sandbox;\n\n\t/**\n\t * Indicates whether the instance is connected to the sandbox.\n\t *\n\t * @property _connected\n\t * @type Boolean\n\t */\n\tthis._connected = false;\n}\n\n/**\n * Adds a listener for the given event.\n *\n * @method on\n * @param {String} event\n * @param {Function} listener\n * @return {EventEmitter}\n */\nEventEmitter.prototype.on = EventEmitter.prototype.addListener = function (event, listener) {\n\tthis.connect();\n\n\t(this._listeners['$' + event] = this._listeners['$' + event] || []).push(listener);\n\treturn this;\n};\n\n/**\n * Adds a listener that will be invoked a single\n * time and automatically removed afterwards.\n *\n * @method once\n * @param {String} event\n * @param {Function} listener\n * @return {EventEmitter}\n */\nEventEmitter.prototype.once = function (event, listener) {\n\tthis.connect();\n\n\tfunction on() {\n\t\tthis.off(event, on);\n\t\tlistener.apply(this, arguments);\n\t}\n\n\ton.listener = listener;\n\tthis.on(event, on);\n\treturn this;\n};\n\n/**\n * Remove the given listener for the given event or all\n * registered listeners.\n *\n * @method off\n * @param {String} event\n * @param {Function} listener\n * @return {EventEmitter}\n */\nEventEmitter.prototype.off = EventEmitter.prototype.removeListener = EventEmitter.prototype.removeAllListeners = function (event, listener) {\n\t// all\n\tif (arguments.length === 0) {\n\t\tthis._listeners = {};\n\t\treturn this;\n\t}\n\n\t// specific event\n\tvar listeners = this._listeners['$' + event];\n\tif (!listeners) {\n\t\treturn this;\n\t}\n\n\t// remove all listeners\n\tif (arguments.length === 1) {\n\t\tdelete this._listeners['$' + event];\n\t\treturn this;\n\t}\n\n\t// remove specific listener\n\tvar cb;\n\tfor (var i = 0, len = listeners.length; i < len; i++) {\n\t\tcb = listeners[i];\n\t\tif (cb === listener || cb.listener === listener) {\n\t\t\tlisteners.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn this;\n};\n\n/**\n * Dispatches event to the sandbox.\n *\n * @method emit\n * @param {Mixed} ...\n * @return {EventEmitter}\n */\nEventEmitter.prototype.emit = function () {\n\tthis.connect();\n\n\t// dispatches event to the sandbox\n\tthis._sandbox.dispatch.apply(this._sandbox, arguments);\n\n\treturn this;\n};\n\n/**\n * Handles dispatched event from sandbox.\n *\n * @method handle\n * @param {String} event\n * @param {Mixed} ...\n * @return {EventEmitter}\n */\nEventEmitter.prototype.handle = function (event) {\n\tvar args = [].slice.call(arguments, 1),\n\t\tlisteners = this._listeners['$' + event];\n\n\tif (listeners) {\n\t\tlisteners = listeners.slice(0);\n\t\tfor (var i = 0, len = listeners.length; i < len; ++i) {\n\t\t\tlisteners[i].apply(this, args);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Return array of listeners for the given event.\n *\n * @method listeners\n * @param {String} event\n * @return {Array}\n */\nEventEmitter.prototype.listeners = function (event) {\n\treturn this._listeners['$' + event] || [];\n};\n\n/**\n * Check if this event emitter has listeners.\n *\n * @method hasListeners\n * @param {String} event\n * @return {Boolean}\n */\nEventEmitter.prototype.hasListeners = function (event) {\n\treturn !!this.listeners(event).length;\n};\n\n/**\n * Connect instance to the sandbox.\n *\n * @method connect\n * @return {EventEmitter}\n */\nEventEmitter.prototype.connect = function () {\n\tif (!this._connected) {\n\t\tthis._sandbox.addEventEmitter(this);\n\t\tthis._connected = true;\n\t}\n\n\treturn this;\n};\n\n/**\n * Disconnect instance from the sandbox.\n *\n * @method disconnect\n * @return {EventEmitter}\n */\nEventEmitter.prototype.disconnect = function () {\n\tif (this._connected) {\n\t\tthis._sandbox.removeEventEmitter(this);\n\t\tthis._connected = false;\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Utility functions.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Utils\n * @static\n */\n/* global Module */\n/* jshint unused: false */\nvar Utils = {\n\t/**\n\t * Capitalizes the first letter of the given string.\n\t *\n\t * @method capitalize\n\t * @param {String} str\n\t * The original string\n\t * @return {String}\n\t * The capitalized string\n\t */\n\tcapitalize: function (str) {\n\t\treturn str.substr(0, 1).toUpperCase().concat(str.substr(1));\n\t},\n\n\t/**\n\t * Camelizes the given string.\n\t *\n\t * @method camelize\n\t * @param {String} str\n\t * The original string\n\t * @return {String}\n\t * The camelized string\n\t */\n\tcamelize: function (str) {\n\t\treturn str.replace(/(\\-[A-Za-z])/g, function ($1) {\n\t\t\treturn $1.toUpperCase().replace('-', '');\n\t\t});\n\t},\n\n\t/**\n\t * Check whether the given object is a string.\n\t *\n\t * @method isString\n\t * @param {Object} obj\n\t * The object to check\n\t * @return {Boolean}\n\t */\n\tisString: function (obj) {\n\t\treturn Object.prototype.toString.call(obj) === '[object String]';\n\t},\n\n\t/**\n\t * Check whether the given param is an object.\n\t *\n\t * @method isObject\n\t * @param {Object} obj\n\t * The object to check\n\t * @return {Boolean}\n\t */\n\tisObject: function (obj) {\n\t\tvar type = typeof obj;\n\t\treturn !!obj && (type === 'object' || type === 'function') && !Array.isArray(obj);\n\t},\n\n\t/**\n\t * Check whether the given param is a function.\n\t *\n\t * @method isFunction\n\t * @param {Object} obj\n\t * The object to check\n\t * @return {Boolean}\n\t */\n\tisFunction: function (obj) {\n\t\tvar type = typeof obj;\n\t\treturn !!obj && type === 'function';\n\t},\n\n\t/**\n\t * Check whether the given param is a valid node.\n\t *\n\t * @method isNode\n\t * @param {Node} node\n\t * The node to check\n\t * @return {Boolean}\n\t */\n\tisNode: function (node) {\n\t\tif (!node || !node.nodeType) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn node.nodeType === 1 || node.nodeType === 9;\n\t},\n\n\t/**\n\t * Check whether the element matches the given selector.\n\t *\n\t * @method matches\n\t * @param {Element} el\n\t * The element to check\n\t * @param {String} selector\n\t * The selector to check against\n\t * @return {Boolean}\n\t */\n\tmatches: function (el, selector) {\n\t\tvar p = Element.prototype;\n\t\tvar f = p.matches || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || function (s) {\n\t\t\t\treturn [].slice.call(document.querySelectorAll(s)).indexOf(this) !== -1;\n\t\t\t};\n\t\treturn f.call(el, selector);\n\t},\n\n\t/**\n\t * Extends an object with the given objects.\n\t *\n\t * @method extend\n\t * @param {Object} obj\n\t * The object to extend\n\t * @param {Object} ...\n\t * @return {Object} the extended object\n\t */\n\textend: function (obj) {\n\t\tif (!Utils.isObject(obj)) {\n\t\t\treturn obj;\n\t\t}\n\t\tvar source, prop;\n\t\tfor (var i = 1, length = arguments.length; i < length; i++) {\n\t\t\tsource = arguments[i];\n\n\t\t\tfor (prop in source) {\n\t\t\t\tif (source.hasOwnProperty(prop)) {\n\t\t\t\t\tobj[prop] = source[prop];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn obj;\n\t},\n\n\t/**\n\t * Get the element from a given node.\n\t *\n\t * @method getElement\n\t * @param {Node} node\n\t * The node to check\n\t * @return {Element}\n\t */\n\tgetElement: function (node) {\n\t\tif (!this.isNode(node)) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (node.nodeType === 9 && node.documentElement) {\n\t\t\treturn node.documentElement;\n\t\t}\n\t\telse {\n\t\t\treturn node;\n\t\t}\n\t},\n\n\t/**\n\t * Get the module nodes.\n\t *\n\t * @method getModuleNodes\n\t * @param {Node} ctx\n\t * The ctx to check\n\t * @return {Array}\n\t */\n\tgetModuleNodes: function (ctx) {\n\t\tvar nodes = [].slice.call(ctx.querySelectorAll('[data-t-name]'));\n\n\t\t// check context itself\n\t\tif (this.matches(ctx, '[data-t-name]')) {\n\t\t\tnodes.unshift(ctx);\n\t\t}\n\n\t\treturn nodes;\n\t},\n\n\t/**\n\t * Creates a module class given a class specification.\n\t *\n\t * @method createModule\n\t * @param {object} spec Class specification.\n\t * @return {function} Module constructor function\n\t */\n\tcreateModule: function (spec) {\n\t\t// validate params\n\t\tif (!spec || !Utils.isObject(spec)) {\n\t\t\tthrow Error('Your module spec is not an object. Usage: T.createModule({ … })');\n\t\t}\n\n\t\tvar Constructor = function (ctx, sandbox) {\n\t\t\tModule.call(this, ctx, sandbox);\n\t\t};\n\n\t\tvar proto = Constructor.prototype = Object.create(Module.prototype);\n\t\tproto.constructor = Constructor;\n\n\t\t// apply statics\n\t\tif (spec.hasOwnProperty('statics')) {\n\t\t\tUtils.extend(Constructor, spec.statics);\n\t\t}\n\n\t\tvar reservedKeys = [\n\t\t\t'statics'\n\t\t];\n\n\t\t// mixin spec properties to module prototype\n\t\tfor (var name in spec) {\n\t\t\tif (!spec.hasOwnProperty(name)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// check for reserved keys\n\t\t\tif (reservedKeys.indexOf(name) !== -1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvar property = spec[name];\n\t\t\tproto[name] = property;\n\t\t}\n\n\t\treturn Constructor;\n\t},\n\n\t/**\n\t * Creates a decorator given a decorator specification.\n\t *\n\t * @method createDecorator\n\t * @param {object} spec Decorator specification.\n\t * @return {function} Decorator function\n\t */\n\tcreateDecorator: function (spec) {\n\t\t// validate params\n\t\tif (!spec || !Utils.isObject(spec)) {\n\t\t\tthrow Error('Your decorator spec is not an object. Usage: T.createDecorator({ … })');\n\t\t}\n\n\t\treturn function (orig) {\n\t\t\tvar parent = {},\n\t\t\t\tname;\n\n\t\t\t// save references to original super properties\n\t\t\tfor (name in orig) {\n\t\t\t\tif (Utils.isFunction(orig[name])) {\n\t\t\t\t\tparent[name] = orig[name].bind(orig);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// override original properties and provide _parent property\n\t\t\tfor (name in spec) {\n\t\t\t\tif (spec.hasOwnProperty(name)) {\n\t\t\t\t\tif(Utils.isFunction(spec[name])) {\n\t\t\t\t\t\torig[name] = (function (name, fn) {\n\t\t\t\t\t\t\treturn function () {\n\t\t\t\t\t\t\t\tthis._parent = parent;\n\t\t\t\t\t\t\t\treturn fn.apply(this, arguments);\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}(name, spec[name]));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// simple property\n\t\t\t\t\t\torig[name] = spec[name];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n};\n\n\n/* global Application, Sandbox, Module, EventEmitter, Utils */\n/* jshint unused: false */\nvar T = {\n\tApplication: Application,\n\tSandbox: Sandbox,\n\tModule: Module,\n\tEventEmitter: EventEmitter,\n\tcreateModule: Utils.createModule,\n\tcreateDecorator: Utils.createDecorator,\n\tversion: '3.0.0-beta.9'\n};\nreturn T;\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["terrific.js"],"names":["root","factory","define","amd","exports","module","T","this","Application","ctx","config","Utils","isNode","tmpConfig","document","defaults","namespace","Module","extend","_ctx","getElement","_config","_sandbox","Sandbox","_modules","_id","application","_application","_eventEmitters","sandbox","_events","EventEmitter","_listeners","_connected","prototype","registerModules","modules","dispatch","nodes","getModuleNodes","forEach","registerModule","getAttribute","bind","unregisterModules","id","hasOwnProperty","removeAttribute","start","promises","promise","Promise","resolve","reject","push","all","then","err","stop","mod","decorators","hasAttribute","capitalize","camelize","isString","window","split","Array","isArray","isObject","map","decorator","trim","setAttribute","i","len","length","getModuleById","Error","addModules","removeModules","tmpModules","getConfig","getConfigParam","name","undefined","addEventEmitter","eventEmitter","removeEventEmitter","eventEmitters","splice","handle","apply","arguments","off","disconnect","on","addListener","event","listener","connect","once","removeListener","removeAllListeners","listeners","cb","emit","args","slice","call","hasListeners","str","substr","toUpperCase","concat","replace","$1","obj","Object","toString","type","isFunction","node","nodeType","matches","el","selector","p","Element","f","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","s","querySelectorAll","indexOf","source","prop","documentElement","unshift","createModule","spec","Constructor","proto","create","constructor","statics","reservedK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AAAyD,EAAAzD,IAIAyD,EAAAzD,OAWA9E,GACAE,YAAAA,EACAe,QAAAA,EACAN,OAAAA,EACAc,aAAAA,EACA6G,aAAAjI,EAAAiI,aACAS,gBAAA1I,EAAA0I,gBACAK,QAAA,QAEA,OAAApJ","file":"terrific.min.js","sourcesContent":["(function(root, factory) {\n if (typeof define === 'function' && define.amd) {\n define([], factory);\n } else if (typeof exports === 'object') {\n module.exports = factory();\n } else {\n root.T = factory();\n }\n}(this, function() {\n/*!\n * TerrificJS modularizes your frontend code by solely relying on naming conventions.\n * http://terrifically.org\n *\n * @copyright Copyright (c) 2016 Remo Brunschwiler\n * @license Licensed under MIT license\n * @version 3.0.0\n */\n\n/**\n * @module T\n */\n\n/**\n * Responsible for application-wide issues such as the creation of modules.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Application\n *\n * @constructor\n * @param {Node} ctx\n * The context node\n * @param {Object} config\n * The configuration\n */\n/* global Sandbox, Utils, Module */\nfunction Application(ctx, config) {\n\t// validate params\n\tif (!ctx && !config) {\n\t\t// both empty\n\t\tctx = document;\n\t\tconfig = {};\n\t}\n\telse if (Utils.isNode(config)) {\n\t\t// reverse order of arguments\n\t\tvar tmpConfig = config;\n\t\tconfig = ctx;\n\t\tctx = tmpConfig;\n\t}\n\telse if (!Utils.isNode(ctx) && !config) {\n\t\t// only config is given\n\t\tconfig = ctx;\n\t\tctx = document;\n\t}\n\telse if (Utils.isNode(ctx) && !config) {\n\t\t// only ctx is given\n\t\tconfig = {};\n\t}\n\n\tvar defaults = {\n\t\tnamespace: Module\n\t};\n\n\tconfig = Utils.extend(defaults, config);\n\n\t/**\n\t * The context node.\n\t *\n\t * @property _ctx\n\t * @type Node\n\t */\n\tthis._ctx = Utils.getElement(ctx);\n\n\t/**\n\t * The configuration.\n\t *\n\t * @property config\n\t * @type Object\n\t */\n\tthis._config = config;\n\n\t/**\n\t * The sandbox to get the resources from.\n\t * The singleton is shared between all modules.\n\t *\n\t * @property _sandbox\n\t * @type Sandbox\n\t */\n\tthis._sandbox = new Sandbox(this);\n\n\t/**\n\t * Contains references to all modules on the page.\n\t *\n\t * @property _modules\n\t * @type Object\n\t */\n\tthis._modules = {};\n\n\t/**\n\t * The next unique module id to use.\n\t *\n\t * @property id\n\t * @type Number\n\t */\n\tthis._id = 1;\n}\n\n/**\n * Register modules within the context\n * Automatically registers all modules within the context,\n * as long as the modules use the naming conventions.\n *\n * @method registerModules\n * @param {Node} ctx\n * The context node\n * @return {Object}\n * A collection containing the registered modules\n */\nApplication.prototype.registerModules = function (ctx) {\n\tvar modules = {};\n\n\tctx = Utils.getElement(ctx) || this._ctx;\n\n\tthis._sandbox.dispatch('t.register.start');\n\n\t// get module nodes\n\tvar nodes = Utils.getModuleNodes(ctx);\n\tnodes.forEach(function (ctx) {\n\n\t\t/*\n\t\t * A module can have different data attributes.\n\t\t * See below for possible values.\n\t\t */\n\n\t\t/*\n\t\t * @config data-t-name=\"{mod-name}\"\n\t\t *\n\t\t * Example: data-t-name=\"foo\"\n\t\t * Indicates that the module Foo should be bound.\n\t\t */\n\n\t\t/*\n\t\t * @config data-t-namespace=\"{namespace}\"\n\t\t *\n\t\t * Example: data-t-namespace=\"App.Components\"\n\t\t * The namespace of the module. Optional.\n\t\t */\n\n\t\t/*\n\t\t * @config data-t-decorator=\"{decorator-name}\"\n\t\t *\n\t\t * Example: data-t-decorator=\"bar\"\n\t\t * Indicates that the module Foo should be decorated with the Bar decorator.\n\t\t * Multiple decorators should be comma-separated. Optional.\n\t\t */\n\t\tvar module = this.registerModule(ctx, ctx.getAttribute('data-t-name'), ctx.getAttribute('data-t-decorator'), ctx.getAttribute('data-t-namespace'));\n\n\t\tif (module) {\n\t\t\tmodules[module._ctx.getAttribute('data-t-id')] = module;\n\t\t}\n\t}.bind(this));\n\n\tthis._sandbox.dispatch('t.register.end');\n\n\treturn modules;\n};\n\n/**\n * Unregisters the modules given by the module instances.\n *\n * @method unregisterModules\n * @param {Object} modules\n * A collection containing the modules to unregister\n */\nApplication.prototype.unregisterModules = function (modules) {\n\tmodules = modules || this._modules;\n\n\tthis._sandbox.dispatch('t.unregister.start');\n\n\t// unregister the given modules\n\tfor (var id in modules) {\n\t\tif (this._modules.hasOwnProperty(id)) {\n\t\t\tif(Utils.isNode(this._modules[id]._ctx)) {\n\t\t\t\tthis._modules[id]._ctx.removeAttribute('data-t-id');\n\t\t\t}\n\t\t\tdelete this._modules[id];\n\t\t}\n\t}\n\n\tthis._sandbox.dispatch('t.unregister.end');\n};\n\n/**\n * Starts (intializes) the registered modules.\n *\n * @method start\n * @param {Object} modules\n * A collection of modules to start\n * @return {Promise}\n * The synchronize Promise\n */\nApplication.prototype.start = function (modules) {\n\tmodules = modules || this._modules;\n\n\tvar promises = [];\n\n\tthis._sandbox.dispatch('t.start');\n\n\t// start the modules\n\tfor (var id in modules) {\n\t\tif (modules.hasOwnProperty(id)) {\n\t\t\tvar promise = (function (id) {\n\t\t\t\treturn new Promise(function (resolve, reject) {\n modules[id].start(resolve, reject);\n\t\t\t\t});\n\t\t\t}(id));\n\n\t\t\tpromises.push(promise);\n\t\t}\n\t}\n\n\t// synchronize modules\n\tvar all = Promise.all(promises);\n\tall.then(function () {\n\t\tthis._sandbox.dispatch('t.sync');\n\t}.bind(this)).catch(function (err) {\n\t\tthrow err;\n\t});\n\n\treturn all;\n};\n\n/**\n * Stops the registered modules.\n *\n * @method stop\n * @param {Object} modules\n * A collection of modules to stop\n */\nApplication.prototype.stop = function (modules) {\n\tmodules = modules || this._modules;\n\n\tthis._sandbox.dispatch('t.stop');\n\n\t// stop the modules\n\tfor (var id in modules) {\n\t\tif (modules.hasOwnProperty(id)) {\n\t\t\tmodules[id].stop();\n\t\t}\n\t}\n};\n\n/**\n * Registers a module.\n *\n * @method registerModule\n * @param {Node} ctx\n * The context node\n * @param {String} mod\n * The module name. It must match the class name of the module\n * @param {Array} decorators\n * A list of decorator names. Each entry must match a class name of a decorator\n * @param {String} namespace\n * The module namespace\n * @return {Module}\n * The reference to the registered module\n */\nApplication.prototype.registerModule = function (ctx, mod, decorators, namespace) {\n\tvar modules = this._modules;\n\n\t// validate params\n\tif(ctx.hasAttribute('data-t-id')) {\n\t\treturn null; // prevent from registering twice\n\t}\n\n\tmod = Utils.capitalize(Utils.camelize(mod));\n\n\tif (Utils.isString(decorators)) {\n\t\tif (window[decorators]) {\n\t\t\t// decorators param is the namespace\n\t\t\tnamespace = window[decorators];\n\t\t\tdecorators = null;\n\t\t}\n\t\telse {\n\t\t\t// convert string to array\n\t\t\tdecorators = decorators.split(',');\n\t\t}\n\t}\n\telse if (!Array.isArray(decorators) && Utils.isObject(decorators)) {\n\t\t// decorators is the namespace object\n\t\tnamespace = decorators;\n\t\tdecorators = null;\n\t}\n\n\tdecorators = decorators || [];\n\tdecorators = decorators.map(function (decorator) {\n\t\treturn Utils.capitalize(Utils.camelize(decorator.trim()));\n\t});\n\n\tnamespace = namespace || this._config.namespace;\n\n\tif (namespace[mod]) {\n\t\t// assign the module a unique id\n\t\tvar id = this._id++;\n\t\tctx.setAttribute('data-t-id', id);\n\n\t\t// instantiate module\n\t\tmodules[id] = new namespace[mod](ctx, this._sandbox);\n\n\t\t// decorate it\n\t\tfor (var i = 0, len = decorators.length; i < len; i++) {\n\t\t\tvar decorator = decorators[i];\n\n\t\t\tif (namespace[mod][decorator]) {\n\t\t\t\tnamespace[mod][decorator](modules[id]);\n\t\t\t}\n\t\t}\n\n\t\treturn modules[id];\n\t}\n\n\tthis._sandbox.dispatch('t.missing', ctx, mod, decorators, namespace);\n\n\treturn null;\n};\n\n/**\n * Gets the appropriate module for the given ID.\n *\n * @method getModuleById\n * @param {int} id\n * The module ID\n * @return {Module}\n * The appropriate module\n */\nApplication.prototype.getModuleById = function (id) {\n\tif (this._modules[id]) {\n\t\treturn this._modules[id];\n\t}\n\telse {\n\t\tthrow Error('The module with the id ' + id +\n\t\t' does not exist');\n\t}\n};\n\n/**\n * The sandbox is used as a central point to get resources from, add modules etc.\n * It is shared between all modules.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Sandbox\n *\n * @constructor\n * @param {Application} application\n * The application reference\n */\n/* global Utils */\nfunction Sandbox(application) {\n\t/**\n\t * The application.\n\t *\n\t * @property _application\n\t * @type Application\n\t */\n\tthis._application = application;\n\n\t/**\n\t * Contains references to all module event emitters.\n\t *\n\t * @property _eventEmitters\n\t * @type Array\n\t */\n\tthis._eventEmitters = [];\n}\n\n/**\n * Adds (register and start) all modules in the given context scope.\n *\n * @method addModules\n * @param {Node} ctx\n * The context node\n * @return {Object}\n * A collection containing the registered modules\n */\nSandbox.prototype.addModules = function (ctx) {\n\tvar modules = {},\n\t\tapplication = this._application;\n\n\tif (Utils.isNode(ctx)) {\n\t\t// register modules\n\t\tmodules = application.registerModules(ctx);\n\n\t\t// start modules\n\t\tapplication.start(modules);\n\t}\n\n\treturn modules;\n};\n\n/**\n * Removes a module by module instances.\n * This stops and unregisters a module through a module instance.\n *\n * @method removeModules\n * @param {any} modules\n * A collection of module to remove | Node context to look for registered modules in.\n * @return {Sandbox}\n */\nSandbox.prototype.removeModules = function (modules) {\n\tvar application = this._application;\n\n\tif (Utils.isNode(modules)) {\n\t\t// get modules\n\t\tvar tmpModules = {};\n\n\t\tvar nodes = Utils.getModuleNodes(modules);\n\t\tnodes.forEach(function (ctx) {\n\t\t\t// check for instance\n\t\t\tif (ctx.hasAttribute('data-t-id')) {\n\t\t\t\tvar id = ctx.getAttribute('data-t-id');\n\t\t\t\tvar module = this.getModuleById(id);\n\n\t\t\t\tif (module) {\n\t\t\t\t\ttmpModules[id] = module;\n\t\t\t\t}\n\t\t\t}\n\t\t}.bind(this));\n\n\t\tmodules = tmpModules;\n\t}\n\n\tif(Utils.isObject(modules)) {\n\t\t// stop modules – let the module clean itself\n\t\tapplication.stop(modules);\n\n\t\t// unregister modules – clean up the application\n\t\tapplication.unregisterModules(modules);\n\t}\n\n\treturn this;\n};\n\n/**\n * Gets the appropriate module for the given ID.\n *\n * @method getModuleById\n * @param {int} id\n * The module ID\n * @return {Module}\n * The appropriate module\n */\nSandbox.prototype.getModuleById = function (id) {\n\treturn this._application.getModuleById(id);\n};\n\n/**\n * Gets the application config.\n *\n * @method getConfig\n * @return {Object}\n * The configuration object\n */\nSandbox.prototype.getConfig = function () {\n\treturn this._application._config;\n};\n\n/**\n * Gets an application config param.\n *\n * @method getConfigParam\n * @param {String} name\n * The param name\n * @return {any}\n * The appropriate configuration param\n */\nSandbox.prototype.getConfigParam = function (name) {\n\tvar config = this._application._config;\n\n\tif (config[name] !== undefined) {\n\t\treturn config[name];\n\t}\n\telse {\n\t\tthrow Error('The config param ' + name + ' does not exist');\n\t}\n};\n\n/**\n * Adds an event emitter instance.\n *\n * @method addEventEmitter\n * @param {EventEmitter} eventEmitter\n * The event emitter\n * @return {Sandbox}\n */\nSandbox.prototype.addEventEmitter = function (eventEmitter) {\n\tthis._eventEmitters.push(eventEmitter);\n\treturn this;\n};\n\n/**\n * Removes an event emitter instance.\n *\n * @method addEventEmitter\n * @param {EventEmitter} eventEmitter\n * The event emitter\n * @return {Sandbox}\n */\nSandbox.prototype.removeEventEmitter = function (eventEmitter) {\n\tvar eventEmitters = this._eventEmitters;\n\tfor (var i = 0, len = eventEmitters.length; i < len; i++) {\n\t\tif (eventEmitters[i] === eventEmitter) {\n\t\t\teventEmitters.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn this;\n};\n\n/**\n * Dispatches the event with the given arguments to the attached event emitters.\n *\n * @method dispatch\n * @param {Mixed} ...\n * @return {Sandbox}\n */\nSandbox.prototype.dispatch = function () {\n\tvar eventEmitters = this._eventEmitters;\n\n\tfor(var i = 0, len = eventEmitters.length; i < len; i++) {\n\t\tvar eventEmitter = eventEmitters[i];\n\t\tif(eventEmitter !== undefined) {\n\t\t\teventEmitter.handle.apply(eventEmitter, arguments);\n\t\t}\n\t}\n\n\treturn this;\n};\n/**\n * Base class for the different modules.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Module\n *\n * @constructor\n * @param {Node} ctx\n * The context node\n * @param {Sandbox} sandbox\n * The sandbox to get the resources from\n */\n/* global EventEmitter */\nfunction Module(ctx, sandbox) {\n\t/**\n\t * Contains the context node.\n\t *\n\t * @property ctx\n\t * @type Node\n\t */\n\tthis._ctx = ctx;\n\n\t/**\n\t * The sandbox to get the resources from.\n\t *\n\t * @property _sandbox\n\t * @type Sandbox\n\t */\n\tthis._sandbox = sandbox;\n\n\t/**\n\t * The emitter.\n\t *\n\t * @property _events\n\t * @type EventEmitter\n\t */\n\tthis._events = new EventEmitter(sandbox);\n}\n\n/**\n * Template method to start the module.\n *\n * @method start\n * @param {Function} resolve\n * The resolve promise function\n * @param {Function} reject\n * \t\tThe reject promise function\n */\n/*jshint unused: true */\nModule.prototype.start = function (resolve) {\n\tresolve();\n};\n\n/**\n * Template method to stop the module.\n *\n * @method stop\n */\nModule.prototype.stop = function () {\n\tthis._events.off().disconnect();\n};\n\n/**\n * Responsible for inter-module communication.\n * Classic EventEmitter Api. Heavily inspired by https://github.com/component/emitter\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class EventEmitter\n *\n * @constructor\n *\n * @param {Sandbox} sandbox\n * The sandbox instance\n */\nfunction EventEmitter(sandbox) {\n\t/**\n\t * The listeners.\n\t *\n\t * @property _listeners\n\t * @type Object\n\t */\n\tthis._listeners = {};\n\n\t/**\n\t * The sandbox instance.\n\t *\n\t * @property _sandbox\n\t * @type Sandbox\n\t */\n\tthis._sandbox = sandbox;\n\n\t/**\n\t * Indicates whether the instance is connected to the sandbox.\n\t *\n\t * @property _connected\n\t * @type Boolean\n\t */\n\tthis._connected = false;\n}\n\n/**\n * Adds a listener for the given event.\n *\n * @method on\n * @param {String} event\n * @param {Function} listener\n * @return {EventEmitter}\n */\nEventEmitter.prototype.on = EventEmitter.prototype.addListener = function (event, listener) {\n\tthis.connect();\n\n\t(this._listeners['$' + event] = this._listeners['$' + event] || []).push(listener);\n\treturn this;\n};\n\n/**\n * Adds a listener that will be invoked a single\n * time and automatically removed afterwards.\n *\n * @method once\n * @param {String} event\n * @param {Function} listener\n * @return {EventEmitter}\n */\nEventEmitter.prototype.once = function (event, listener) {\n\tthis.connect();\n\n\tfunction on() {\n\t\tthis.off(event, on);\n\t\tlistener.apply(this, arguments);\n\t}\n\n\ton.listener = listener;\n\tthis.on(event, on);\n\treturn this;\n};\n\n/**\n * Remove the given listener for the given event or all\n * registered listeners.\n *\n * @method off\n * @param {String} event\n * @param {Function} listener\n * @return {EventEmitter}\n */\nEventEmitter.prototype.off = EventEmitter.prototype.removeListener = EventEmitter.prototype.removeAllListeners = function (event, listener) {\n\t// all\n\tif (arguments.length === 0) {\n\t\tthis._listeners = {};\n\t\treturn this;\n\t}\n\n\t// specific event\n\tvar listeners = this._listeners['$' + event];\n\tif (!listeners) {\n\t\treturn this;\n\t}\n\n\t// remove all listeners\n\tif (arguments.length === 1) {\n\t\tdelete this._listeners['$' + event];\n\t\treturn this;\n\t}\n\n\t// remove specific listener\n\tvar cb;\n\tfor (var i = 0, len = listeners.length; i < len; i++) {\n\t\tcb = listeners[i];\n\t\tif (cb === listener || cb.listener === listener) {\n\t\t\tlisteners.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn this;\n};\n\n/**\n * Dispatches event to the sandbox.\n *\n * @method emit\n * @param {Mixed} ...\n * @return {EventEmitter}\n */\nEventEmitter.prototype.emit = function () {\n\tthis.connect();\n\n\t// dispatches event to the sandbox\n\tthis._sandbox.dispatch.apply(this._sandbox, arguments);\n\n\treturn this;\n};\n\n/**\n * Handles dispatched event from sandbox.\n *\n * @method handle\n * @param {String} event\n * @param {Mixed} ...\n * @return {EventEmitter}\n */\nEventEmitter.prototype.handle = function (event) {\n\tvar args = [].slice.call(arguments, 1),\n\t\tlisteners = this._listeners['$' + event];\n\n\tif (listeners) {\n\t\tlisteners = listeners.slice(0);\n\t\tfor (var i = 0, len = listeners.length; i < len; ++i) {\n\t\t\tlisteners[i].apply(this, args);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Return array of listeners for the given event.\n *\n * @method listeners\n * @param {String} event\n * @return {Array}\n */\nEventEmitter.prototype.listeners = function (event) {\n\treturn this._listeners['$' + event] || [];\n};\n\n/**\n * Check if this event emitter has listeners.\n *\n * @method hasListeners\n * @param {String} event\n * @return {Boolean}\n */\nEventEmitter.prototype.hasListeners = function (event) {\n\treturn !!this.listeners(event).length;\n};\n\n/**\n * Connect instance to the sandbox.\n *\n * @method connect\n * @return {EventEmitter}\n */\nEventEmitter.prototype.connect = function () {\n\tif (!this._connected) {\n\t\tthis._sandbox.addEventEmitter(this);\n\t\tthis._connected = true;\n\t}\n\n\treturn this;\n};\n\n/**\n * Disconnect instance from the sandbox.\n *\n * @method disconnect\n * @return {EventEmitter}\n */\nEventEmitter.prototype.disconnect = function () {\n\tif (this._connected) {\n\t\tthis._sandbox.removeEventEmitter(this);\n\t\tthis._connected = false;\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Utility functions.\n *\n * @author Remo Brunschwiler\n * @namespace T\n * @class Utils\n * @static\n */\n/* global Module */\n/* jshint unused: false */\nvar Utils = {\n\t/**\n\t * Capitalizes the first letter of the given string.\n\t *\n\t * @method capitalize\n\t * @param {String} str\n\t * The original string\n\t * @return {String}\n\t * The capitalized string\n\t */\n\tcapitalize: function (str) {\n\t\treturn str.substr(0, 1).toUpperCase().concat(str.substr(1));\n\t},\n\n\t/**\n\t * Camelizes the given string.\n\t *\n\t * @method camelize\n\t * @param {String} str\n\t * The original string\n\t * @return {String}\n\t * The camelized string\n\t */\n\tcamelize: function (str) {\n\t\treturn str.replace(/(\\-[A-Za-z])/g, function ($1) {\n\t\t\treturn $1.toUpperCase().replace('-', '');\n\t\t});\n\t},\n\n\t/**\n\t * Check whether the given object is a string.\n\t *\n\t * @method isString\n\t * @param {Object} obj\n\t * The object to check\n\t * @return {Boolean}\n\t */\n\tisString: function (obj) {\n\t\treturn Object.prototype.toString.call(obj) === '[object String]';\n\t},\n\n\t/**\n\t * Check whether the given param is an object.\n\t *\n\t * @method isObject\n\t * @param {Object} obj\n\t * The object to check\n\t * @return {Boolean}\n\t */\n\tisObject: function (obj) {\n\t\tvar type = typeof obj;\n\t\treturn !!obj && (type === 'object' || type === 'function') && !Array.isArray(obj);\n\t},\n\n\t/**\n\t * Check whether the given param is a function.\n\t *\n\t * @method isFunction\n\t * @param {Object} obj\n\t * The object to check\n\t * @return {Boolean}\n\t */\n\tisFunction: function (obj) {\n\t\tvar type = typeof obj;\n\t\treturn !!obj && type === 'function';\n\t},\n\n\t/**\n\t * Check whether the given param is a valid node.\n\t *\n\t * @method isNode\n\t * @param {Node} node\n\t * The node to check\n\t * @return {Boolean}\n\t */\n\tisNode: function (node) {\n\t\tif (!node || !node.nodeType) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn node.nodeType === 1 || node.nodeType === 9;\n\t},\n\n\t/**\n\t * Check whether the element matches the given selector.\n\t *\n\t * @method matches\n\t * @param {Element} el\n\t * The element to check\n\t * @param {String} selector\n\t * The selector to check against\n\t * @return {Boolean}\n\t */\n\tmatches: function (el, selector) {\n\t\tvar p = Element.prototype;\n\t\tvar f = p.matches || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || function (s) {\n\t\t\t\treturn [].slice.call(document.querySelectorAll(s)).indexOf(this) !== -1;\n\t\t\t};\n\t\treturn f.call(el, selector);\n\t},\n\n\t/**\n\t * Extends an object with the given objects.\n\t *\n\t * @method extend\n\t * @param {Object} obj\n\t * The object to extend\n\t * @param {Object} ...\n\t * @return {Object} the extended object\n\t */\n\textend: function (obj) {\n\t\tif (!Utils.isObject(obj)) {\n\t\t\treturn obj;\n\t\t}\n\t\tvar source, prop;\n\t\tfor (var i = 1, length = arguments.length; i < length; i++) {\n\t\t\tsource = arguments[i];\n\n\t\t\tfor (prop in source) {\n\t\t\t\tif (source.hasOwnProperty(prop)) {\n\t\t\t\t\tobj[prop] = source[prop];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn obj;\n\t},\n\n\t/**\n\t * Get the element from a given node.\n\t *\n\t * @method getElement\n\t * @param {Node} node\n\t * The node to check\n\t * @return {Element}\n\t */\n\tgetElement: function (node) {\n\t\tif (!this.isNode(node)) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (node.nodeType === 9 && node.documentElement) {\n\t\t\treturn node.documentElement;\n\t\t}\n\t\telse {\n\t\t\treturn node;\n\t\t}\n\t},\n\n\t/**\n\t * Get the module nodes.\n\t *\n\t * @method getModuleNodes\n\t * @param {Node} ctx\n\t * The ctx to check\n\t * @return {Array}\n\t */\n\tgetModuleNodes: function (ctx) {\n\t\tvar nodes = [].slice.call(ctx.querySelectorAll('[data-t-name]'));\n\n\t\t// check context itself\n\t\tif (this.matches(ctx, '[data-t-name]')) {\n\t\t\tnodes.unshift(ctx);\n\t\t}\n\n\t\treturn nodes;\n\t},\n\n\t/**\n\t * Creates a module class given a class specification.\n\t *\n\t * @method createModule\n\t * @param {object} spec Class specification.\n\t * @return {function} Module constructor function\n\t */\n\tcreateModule: function (spec) {\n\t\t// validate params\n\t\tif (!spec || !Utils.isObject(spec)) {\n\t\t\tthrow Error('Your module spec is not an object. Usage: T.createModule({ … })');\n\t\t}\n\n\t\tvar Constructor = function (ctx, sandbox) {\n\t\t\tModule.call(this, ctx, sandbox);\n\t\t};\n\n\t\tvar proto = Constructor.prototype = Object.create(Module.prototype);\n\t\tproto.constructor = Constructor;\n\n\t\t// apply statics\n\t\tif (spec.hasOwnProperty('statics')) {\n\t\t\tUtils.extend(Constructor, spec.statics);\n\t\t}\n\n\t\tvar reservedKeys = [\n\t\t\t'statics'\n\t\t];\n\n\t\t// mixin spec properties to module prototype\n\t\tfor (var name in spec) {\n\t\t\tif (!spec.hasOwnProperty(name)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// check for reserved keys\n\t\t\tif (reservedKeys.indexOf(name) !== -1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvar property = spec[name];\n\t\t\tproto[name] = property;\n\t\t}\n\n\t\treturn Constructor;\n\t},\n\n\t/**\n\t * Creates a decorator given a decorator specification.\n\t *\n\t * @method createDecorator\n\t * @param {object} spec Decorator specification.\n\t * @return {function} Decorator function\n\t */\n\tcreateDecorator: function (spec) {\n\t\t// validate params\n\t\tif (!spec || !Utils.isObject(spec)) {\n\t\t\tthrow Error('Your decorator spec is not an object. Usage: T.createDecorator({ … })');\n\t\t}\n\n\t\treturn function (orig) {\n\t\t\tvar parent = {},\n\t\t\t\tname;\n\n\t\t\t// save references to original super properties\n\t\t\tfor (name in orig) {\n\t\t\t\tif (Utils.isFunction(orig[name])) {\n\t\t\t\t\tparent[name] = orig[name].bind(orig);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// override original properties and provide _parent property\n\t\t\tfor (name in spec) {\n\t\t\t\tif (spec.hasOwnProperty(name)) {\n\t\t\t\t\tif(Utils.isFunction(spec[name])) {\n\t\t\t\t\t\torig[name] = (function (name, fn) {\n\t\t\t\t\t\t\treturn function () {\n\t\t\t\t\t\t\t\tthis._parent = parent;\n\t\t\t\t\t\t\t\treturn fn.apply(this, arguments);\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}(name, spec[name]));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// simple property\n\t\t\t\t\t\torig[name] = spec[name];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n};\n\n\n/* global Application, Sandbox, Module, EventEmitter, Utils */\n/* jshint unused: false */\nvar T = {\n\tApplication: Application,\n\tSandbox: Sandbox,\n\tModule: Module,\n\tEventEmitter: EventEmitter,\n\tcreateModule: Utils.createModule,\n\tcreateDecorator: Utils.createDecorator,\n\tversion: '3.0.0'\n};\nreturn T;\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/package.json b/package.json index 4886cd7..2d89b77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "terrific", - "version": "3.0.0-beta.9", + "version": "3.0.0", "description": "TerrificJS modularizes your frontend code by solely relying on naming conventions.", "main": "dist/terrific.js", "license": "MIT",