diff --git a/.gitignore b/.gitignore
index 23b9d6b..f053b35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
node_modules
.idea
-
-
+bower_components
\ No newline at end of file
diff --git a/dist/choona.js b/dist/choona.js
index 547a16e..b77c8a5 100644
--- a/dist/choona.js
+++ b/dist/choona.js
@@ -115,6 +115,23 @@
}
}
},
+ addProperty: function(obj, prop, getCallback, setCallback) {
+ var v;
+ //var v = obj[prop]; //Initialise with Old Property Value
+ Object.defineProperty(obj, prop, {
+ enumerable: true,
+ configurable: true,
+ get: function() {
+ getCallback(v);
+ return v;
+ },
+ set: function(value) {
+ v = value;
+ setCallback(v);
+ }
+ });
+
+ },
loadHTML: function(ele, str) {
ele.innerHTML = str;
//TODO - find any submodule
@@ -192,7 +209,26 @@
"use strict";
choona.Model = choona.EventBus.extend({
initialize: function() {
- choona.EventBus.call(this);
+ choona.EventBus.apply(this, arguments);
+ this.loadDefaults();
+ },
+ loadDefaults: function() {
+ var self = this;
+ choona.Util.for(this.defaults, function(v, key) {
+ self.addProperty(key);
+ });
+ },
+ addProperty: function(key) {
+ var self = this;
+ choona.Util.addProperty(this,
+ key,
+ function() {
+ //Get Callback
+ },
+ function(val) {
+ //Set Callback
+ this.publish("change:" + key);
+ });
},
publishChange: function() {
this.publish("change");
diff --git a/dist/choona.min.js b/dist/choona.min.js
index 1d08941..3b40c95 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";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)},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.call(this)},publishChange:function(){this.publish("change")}})}(),function(){"use strict";choona.Settings.GlobalEventBus=new choona.EventBus;var a=choona.Util.log;choona.View=choona.Base.extend({initialize:function(a,b){if(choona.Base.call(this),this.config=a.config,this._viewMetadata={eventBus:choona.Settings.GlobalEventBus,topicList:{},subModuleList:{},id:a.id,eventsMap:[],mercykillFunc:null},"string"!=typeof a.id||""===a.id)throw new Error("Id provided is not String or it is a blank sting");if(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 c="";"string"==typeof this.template&&(c=this.template),"function"==typeof this.template&&(c=this.template()),this.$.innerHTML=choona.Settings.postTemplateProcessing(c),this.isolatedEventBus===!0&&(this._viewMetadata.eventBus=new choona.EventBus);var d=this;void 0!==this.globalEvents&&choona.Util.for(this.globalEvents,function(a,b){d.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!==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(){console.log("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){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";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.View=choona.Base.extend({initialize:function(a,b){if(choona.Base.call(this),this.config=a.config,this._viewMetadata={eventBus:choona.Settings.GlobalEventBus,topicList:{},subModuleList:{},id:a.id,eventsMap:[],mercykillFunc:null},"string"!=typeof a.id||""===a.id)throw new Error("Id provided is not String or it is a blank sting");if(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 c="";"string"==typeof this.template&&(c=this.template),"function"==typeof this.template&&(c=this.template()),this.$.innerHTML=choona.Settings.postTemplateProcessing(c),this.isolatedEventBus===!0&&(this._viewMetadata.eventBus=new choona.EventBus);var d=this;void 0!==this.globalEvents&&choona.Util.for(this.globalEvents,function(a,b){d.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!==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(){console.log("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){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/Todo.md b/src/Todo.md
index dbe8b27..bc819c4 100644
--- a/src/Todo.md
+++ b/src/Todo.md
@@ -9,9 +9,11 @@
* loading submodule using html syntax inside dom
+* Think for adding it to xtag
* Full Documentation, API Docs, Demos
* Create underscore template support !
* 2 way binding using underscore template
-
\ No newline at end of file
+* If Id is not given then it will append new subModule into current module !!
+* Todo video
diff --git a/src/choona.Model.js b/src/choona.Model.js
index 7fdb53d..f1e5b2c 100644
--- a/src/choona.Model.js
+++ b/src/choona.Model.js
@@ -2,7 +2,26 @@
"use strict";
choona.Model = choona.EventBus.extend({
initialize: function() {
- choona.EventBus.call(this);
+ choona.EventBus.apply(this, arguments);
+ this.loadDefaults();
+ },
+ loadDefaults: function() {
+ var self = this;
+ choona.Util.for(this.defaults, function(v, key) {
+ self.addProperty(key);
+ });
+ },
+ addProperty: function(key) {
+ var self = this;
+ choona.Util.addProperty(this,
+ key,
+ function() {
+ //Get Callback
+ },
+ function(val) {
+ //Set Callback
+ this.publish("change:" + key);
+ });
},
publishChange: function() {
this.publish("change");
diff --git a/src/choona.Util.js b/src/choona.Util.js
index 96eb7d8..33aa662 100644
--- a/src/choona.Util.js
+++ b/src/choona.Util.js
@@ -50,6 +50,23 @@
}
}
},
+ addProperty: function(obj, prop, getCallback, setCallback) {
+ var v;
+ //var v = obj[prop]; //Initialise with Old Property Value
+ Object.defineProperty(obj, prop, {
+ enumerable: true,
+ configurable: true,
+ get: function() {
+ getCallback(v);
+ return v;
+ },
+ set: function(value) {
+ v = value;
+ setCallback(v);
+ }
+ });
+
+ },
loadHTML: function(ele, str) {
ele.innerHTML = str;
//TODO - find any submodule