text: var choona={};!function(){"use strict";var a=function(b){var c,d=function(){"function"==typeof b.initialize&&b.initialize.apply(this,arguments)};c=void 0!==this&&this.extend===a?this:Object,d.prototype=Object.create(c.prototype),d.prototype.constructor=d;for(var e in b)b.hasOwnProperty(e)===!0&&(d.prototype[e]=b[e]);return d.extend=a,d.parent=c,d.super=c.prototype,d};choona.klass=a}(),choona.Base=choona.klass({}),function(){"use strict";function a(){var a=(new Date).getTime(),b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==b?c:7&c|8).toString(16)});return"id_"+b}var b=choona.Base.extend({initialize:function(){choona.Base.apply(this,arguments),this.collection=[]},getId:function(){for(var b=a();-1!==this.collection.indexOf(b);)b=a();return this.collection.push(b),b}});choona.uniqueIdManager=new b}(),function(){"use strict";choona.Settings={preStart:function(){},postEnd:function(){},postTemplateProcessing:function(a){return a},moduleResolver:function(a){return a},debug:!1,isConsoleAvailable:!1}}(),function(){"use strict";choona.Util={log:function(){choona.Settings.debug===!0&&choona.Settings.isConsoleAvailable===!0&&console.log.apply(console,arguments)},logError:function(){choona.Settings.debug===!0&&choona.Settings.isConsoleAvailable===!0&&console.error.apply(console,arguments)},"for":function(a,b){for(var c in a)a.hasOwnProperty(c)===!0&&b(a[c],c)},addProperty:function(a,b,c,d){var e;Object.defineProperty(a,b,{enumerable:!0,configurable:!0,get:function(){return c(e),e},set:function(a){e=a,d(e)}})},loadHTML:function(a,b){a.innerHTML=b}}}(),function(){"use strict";var a=choona.Util.log;choona.EventBus=choona.Base.extend({initialize:function(){this._NewsPaperList={},this._OrderList=[]},on:function(){return this.subscribe.apply(this,arguments)},subscribe:function(b,c){if(a("subscribed ",b),"string"!=typeof b||"function"!=typeof c)return-1;var d=this._NewsPaperList[b];"object"!=typeof d&&(d=this._NewsPaperList[b]=[]);var e=d.push(c)-1;return this._OrderList.push({newsPaper:b,customer:e})-1},off:function(){return this.unsubscribe.apply(this,arguments)},unsubscribe:function(b){var c=this._OrderList[b];void 0!==c&&(a("unsubscribe ",c.newsPaper),delete this._NewsPaperList[c.newsPaper][c.customer])},trigger:function(){this.publish.apply(this,arguments)},publish:function(){a.apply(null,arguments);var b=Array.prototype.slice.call(arguments),c=b.slice(0,1)[0];b.shift();var d=this._NewsPaperList[c];if("undefined"!=typeof d)for(var e=d.length,f=0;e>f;f++)"function"==typeof d[f]&&d[f].apply(this,b)}})}(),function(){"use strict";var a=Element.prototype;a.matchesSelector=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector,a.matches||(a.matches=a.matchesSelector),choona.DomEvents={addLiveEventListener:function(a,b,c,d,e){var f=function(a){var b=a.target;if(""===c)d.call(e,a,a.currentTarget,a.currentTarget.dataset);else for(;b!==a.currentTarget&&b!==document&&null!==b;){if(b.matches(c)===!0){d.call(e,a,b,b.dataset);break}b=b.parentNode}};return a.addEventListener(b,f,!1),f},trigger:function(a,b,c){void 0===c&&(c={});var d=document.createEvent("CustomEvent");d.initCustomEvent(b,c.bubbles!==!1,c.cancelable!==!1),a.dispatchEvent(d)}}}(),function(){"use strict";choona.Model=choona.EventBus.extend({initialize:function(){choona.EventBus.apply(this,arguments),this.loadDefaults()},loadDefaults:function(){var a=this;choona.Util.for(this.defaults,function(b,c){a.addProperty(c)})},addProperty:function(a){choona.Util.addProperty(this,a,function(){},function(){this.publish("change:"+a)})},publishChange:function(){this.publish("change")}})}(),function(){"use strict";choona.Settings.GlobalEventBus=new choona.EventBus;{var a=choona.Util.log;choona.Util.logError}choona.View=choona.Base.extend({initialize:function(a,b){if(choona.Base.call(this),void 0===a.id){a.id=choona.uniqueIdManager.getId();var c=document.createElement("div");c.setAttribute("id",a.id),void 0!==b?b.parentNode.appendChild(c):document.body.appendChild(c)}if(this.config=a.config,this._viewMetadata={eventBus:choona.Settings.GlobalEventBus,topicList:{},subModuleList:{},id:a.id,eventsMap:{},mercykillFunc:null},void 0!==b?(this._viewMetadata.mercykillFunc=b.mercykillFunc,this._viewMetadata.eventBus=b.parentEventBus,this.$=b.parentNode.querySelector("#"+a.id)):this.$=document.querySelector("#"+a.id),null===this.$)throw new Error('Unable to Load Module, as I am unable to find id="'+a.id+'" inside Root DOM');void 0!==window.jQuery&&"function"==typeof window.jQuery&&(this.$el=this.$$=window.jQuery(this.$));var d="";"string"==typeof this.template&&(d=this.template),"function"==typeof this.template&&(d=this.template()),this.$.innerHTML=choona.Settings.postTemplateProcessing(d),this.isolatedEventBus===!0&&(this._viewMetadata.eventBus=new choona.EventBus);var e=this;void 0!==this.globalEvents&&choona.Util.for(this.globalEvents,function(a,b){e.subscribeGlobalEvent(b,a)}),void 0!==this.events&&this.on(this.events),"function"==typeof choona.Settings.preStart&&choona.Settings.preStart.call(this)},_getEventBus:function(){return this._viewMetadata.eventBus},subscribeGlobalEvent:function(a,b){var c=this,d=function(){c[b].apply(c,arguments)};void 0===this._viewMetadata.topicList[a]&&(this._viewMetadata.topicList[a]=[]);var e=this._getEventBus();this._viewMetadata.topicList[a].push(e.subscribe(a,d))},unsubscribeGlobalEvent:function(a){var b=this._getEventBus();void 0!==this._viewMetadata.topicList[a]&&(this._viewMetadata.topicList[a].map(function(a){b.unsubscribe(a)}),delete this._viewMetadata.topicList[a])},publishGlobalEvent:function(){var a=this._getEventBus();a.publish.apply(a,arguments)},loadSubView:function(a){var b=this;if(void 0===a)throw new Error("loadSubView : argument received is undefined");if(void 0===a.module)throw new Error("loadSubView : module cannot be undefined");if(void 0===a.id){a.id=choona.uniqueIdManager.getId();var c=document.createElement("div");c.setAttribute("id",a.id),this.$.appendChild(c)}if(void 0!==this._viewMetadata.subModuleList[a.id])throw new Error("data.id::"+a.id+" is already contains a module.  Please provide separate id new module");this._viewMetadata.subModuleList[a.id]=new a.module(a,{parentNode:this.$,parentEventBus:this._getEventBus(),mercykillFunc:function(){b.removeSubView(a.id)}})},killme:function(){"function"==typeof this._viewMetadata.mercykillFunc&&this._viewMetadata.mercykillFunc()},removeSubView:function(a){void 0!==this._viewMetadata.subModuleList[a]&&(this._viewMetadata.subModuleList[a]._endModule(),delete this._viewMetadata.subModuleList[a])},on:function(a){var b=this;choona.Util.for(a,function(a,c){c=c.trim().replace(/ +/g," ");var d=c.split(" "),e=d.shift(),f=d.join(" "),g=choona.DomEvents.addLiveEventListener(b.$,e,f,b[a],b);b._viewMetadata.eventsMap[c]={eventName:e,callback:g}})},off:function(a){var b=this._viewMetadata.eventsMap[a];void 0!==b&&"object"==typeof b&&(this.$.removeEventListener(b.eventName,b.callback),delete this._viewMetadata.eventsMap[a])},end:function(){a("Ending base View")},_endModule:function(){"function"==typeof choona.Settings.postEnd&&choona.Settings.postEnd.call(this);var b=this;choona.Util.for(this._viewMetadata.subModuleList,function(a,c){b.removeSubView(c)}),"function"==typeof this.end&&this.end(),choona.Util.for(this._viewMetadata.eventsMap,function(a,c){b.off(c)}),this.$.innerHTML="",choona.Util.for(this._viewMetadata.topicList,function(a,c){b.unsubscribeGlobalEvent(c)}),delete this.$,delete this.$el,delete this.$$,delete this.config,a("ended module -> "+this._viewMetadata.id),delete this._viewMetadata.id,delete this._viewMetadata.subModuleList,delete this._viewMetadata.eventBus,delete this._viewMetadata.topicList,delete this._viewMetadata.eventsMap,delete this._viewMetadata,choona.Util.for(this,function(a,c){delete b[c]})}}),choona.loadView=function(a){if(void 0===a)throw new Error("choona.loadView received undefined, expecting object");if(void 0===a.module)throw new Error("choona.loadView : module is undefined, expecting Function constructor");return new a.module(a)}}(),function(){"use strict";choona.Router=choona.View.extend({initialize:function(){choona.View.apply(this,arguments),this.router=[];var a=this;choona.Util.for(this.config.routes,function(b,c){a.router.push({path:c,callback:function(){a.removeSubView("router"),a.loadSubView({id:"router",module:b})}})}),this.onDocumentClick=function(b){var c=b.target.getAttribute("href"),d=a.loadPath(c,!1);d===!1&&(b.stopPropagation(),b.stopImmediatePropagation(),b.preventDefault())},this.onPopstate=function(){var b=document.location.pathname;a.loadPath(b,!0)},document.addEventListener("click",this.onDocumentClick,!1),window.addEventListener("popstate",this.onPopstate,!1)},template:"<router id='router'></router>",loadPath:function(a,b){var c=this,d=!1;return this.router.map(function(e){if(e.path===a){d=!0,b===!1&&history.pushState({},"",a);var f=!0;"function"==typeof c.config.before&&(f=c.config.before(a)),f===!0&&e.callback()}}),!d},end:function(){document.removeEventListener("click",this.onDocumentClick),window.removeEventListener("popstate",this.onPopstate),delete this.onDocumentClick,delete this.onPopstate}})}(),function(){"use strict";"function"==typeof define&&define.amd&&define("choona",[],function(){return choona})}();