diff --git a/bower.json b/bower.json index 9303e6a..376a1a9 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "choona.js", "repo": "nsisodiya/choona.js", - "version": "1.3.7", + "version": "1.3.8", "main": "dist/choona.js", "keywords": [ "scalable", diff --git a/dist/choona.js b/dist/choona.js index e653ace..8c8278c 100644 --- a/dist/choona.js +++ b/dist/choona.js @@ -391,6 +391,12 @@ throw new Error("loadSubView : module cannot be undefined"); } } + if (data.id === undefined) { + data.id = choona.uniqueIdManager.getId(); + var d = document.createElement("div"); + d.setAttribute("id", data.id); + this.$.appendChild(d); + } if (this._viewMetadata.subModuleList[data.id] === undefined) { this._viewMetadata.subModuleList[data.id] = new data.module(data, { diff --git a/dist/choona.min.js b/dist/choona.min.js index fee2dc5..3071f36 100644 --- a/dist/choona.min.js +++ b/dist/choona.min.js @@ -1 +1 @@ -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)&&(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";var a="undefined"!=typeof Element&&Element.prototype||{},b=a.addEventListener||function(a,b){return this.attachEvent("on"+a,b)},c=a.removeEventListener||function(a,b){return this.detachEvent("on"+a,b)};a.matchesSelector=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector,a.matches||(a.matches=a.matchesSelector),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)},bindEvent:function(a,c,d){b.call(a,c,d,!1)},unbindEvent:function(a,b,d){c.call(a,b,d)},"for":function(a,b){for(var c in a)a.hasOwnProperty(c)&&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";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');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!==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=function(c){""===f?b[a].call(b,c,c.target,c.target.dataset):c.target.matches(f)&&b[a].call(b,c,c.target,c.target.dataset)};choona.Util.bindEvent(b.$,e,g),b._viewMetadata.eventsMap[c]={eventName:e,callback:g}})},off:function(a){var b=this._viewMetadata.eventsMap[a];void 0!==b&&"object"==typeof b&&(choona.Util.unbindEvent(this.$,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(),this._viewMetadata.eventsMap.map(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.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)},choona.Util.bindEvent(document,"click",this.onDocumentClick),choona.Util.bindEvent(window,"popstate",this.onPopstate)},template:"",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(){choona.Util.unbindEvent(document,"click",this.onDocumentClick),choona.Util.unbindEvent(window,"popstate",this.onPopstate),delete this.onDocumentClick,delete this.onPopstate}})}(),function(){"use strict";"function"==typeof define&&define.amd&&define("choona",[],function(){return choona})}(); \ No newline at end of file +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)&&(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";var a="undefined"!=typeof Element&&Element.prototype||{},b=a.addEventListener||function(a,b){return this.attachEvent("on"+a,b)},c=a.removeEventListener||function(a,b){return this.detachEvent("on"+a,b)};a.matchesSelector=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector,a.matches||(a.matches=a.matchesSelector),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)},bindEvent:function(a,c,d){b.call(a,c,d,!1)},unbindEvent:function(a,b,d){c.call(a,b,d)},"for":function(a,b){for(var c in a)a.hasOwnProperty(c)&&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";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');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=function(c){""===f?b[a].call(b,c,c.target,c.target.dataset):c.target.matches(f)&&b[a].call(b,c,c.target,c.target.dataset)};choona.Util.bindEvent(b.$,e,g),b._viewMetadata.eventsMap[c]={eventName:e,callback:g}})},off:function(a){var b=this._viewMetadata.eventsMap[a];void 0!==b&&"object"==typeof b&&(choona.Util.unbindEvent(this.$,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(),this._viewMetadata.eventsMap.map(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.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)},choona.Util.bindEvent(document,"click",this.onDocumentClick),choona.Util.bindEvent(window,"popstate",this.onPopstate)},template:"",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(){choona.Util.unbindEvent(document,"click",this.onDocumentClick),choona.Util.unbindEvent(window,"popstate",this.onPopstate),delete this.onDocumentClick,delete this.onPopstate}})}(),function(){"use strict";"function"==typeof define&&define.amd&&define("choona",[],function(){return choona})}(); \ No newline at end of file diff --git a/src/choona.View.js b/src/choona.View.js index c026fff..0c907c7 100644 --- a/src/choona.View.js +++ b/src/choona.View.js @@ -128,6 +128,12 @@ throw new Error("loadSubView : module cannot be undefined"); } } + if (data.id === undefined) { + data.id = choona.uniqueIdManager.getId(); + var d = document.createElement("div"); + d.setAttribute("id", data.id); + this.$.appendChild(d); + } if (this._viewMetadata.subModuleList[data.id] === undefined) { this._viewMetadata.subModuleList[data.id] = new data.module(data, {