diff --git a/CHANGE.md b/CHANGE.md index c8b7821..7ebfd6b 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -9,6 +9,14 @@ Latest Release Older releases ============= +* 1.3.9 - on 8 Feb, 2015 + +Fixed bug on event binding and Live events + +* 1.3.8 - on 4 Jan, 2015 + +Fixed bug : multiple subViews was not loading ! + * 1.3.4 - on 1 Jan 2015 Now, Id will be generated automatically. You need now to pass id when loading any AppView or subView diff --git a/bower.json b/bower.json index 376a1a9..f66431b 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "choona.js", "repo": "nsisodiya/choona.js", - "version": "1.3.8", + "version": "1.3.9", "main": "dist/choona.js", "keywords": [ "scalable", diff --git a/dist/choona.js b/dist/choona.js index 8c8278c..45c1f05 100644 --- a/dist/choona.js +++ b/dist/choona.js @@ -1,8 +1,8 @@ /** - * Copyright 2013-14 Narendra Sisodiya, + * Copyright 2013-15 Narendra Sisodiya, * Licensed under "The MIT License". visit http://nsisodiya.mit-license.org/ to read the License. * @author Narendra Sisodiya - * + * Version - 1.3.9 */ ;var choona = {}; (function() { @@ -22,7 +22,7 @@ Child.prototype = Object.create(Parent.prototype); Child.prototype.constructor = Child; for (var i in ChildProto) { - if (ChildProto.hasOwnProperty(i)) { + if (ChildProto.hasOwnProperty(i) === true) { Child.prototype[i] = ChildProto[i]; } } @@ -136,7 +136,7 @@ //Replacement for _.each over Objects for: function(Obj, callback) { for (var i in Obj) { - if (Obj.hasOwnProperty(i)) { + if (Obj.hasOwnProperty(i) === true) { callback(Obj[i], i); } } @@ -291,7 +291,7 @@ topicList: {}, subModuleList: {}, id: moduleConf.id, - eventsMap: [], + eventsMap: {}, mercykillFunc: null }; @@ -308,7 +308,7 @@ } //setup this.$el & this.$$ if jQuery present. - if (window.jQuery) { + if (window.jQuery !== undefined && typeof window.jQuery === "function") { this.$el = this.$$ = window.jQuery(this.$); } @@ -328,7 +328,8 @@ * because, you need to get event bus for * */ - //Start Isolated EventBus , this will be useful for creating third party widget who do not want to create conflicts in naming + //Start Isolated EventBus , this will be useful for creating third party widget who do not want to create + // conflicts in naming if (this.isolatedEventBus === true) { this._viewMetadata.eventBus = new choona.EventBus(); } @@ -434,10 +435,16 @@ var callback = function(e) { if (hash === "") { - self[handler].call(self, e, e.target, e.target.dataset); + self[handler].call(self, e, e.currentTarget, e.currentTarget.dataset); } else { - if (e.target.matches(hash)) { - self[handler].call(self, e, e.target, e.target.dataset); + var currNode; + currNode = e.target; + while (currNode !== e.currentTarget && currNode !== document) { + if (currNode.matches(hash) === true) { + self[handler].call(self, e, currNode, currNode.dataset); + break; + } + currNode = currNode.parentNode; } } }; @@ -478,7 +485,7 @@ } //unSubscribing All DOM events - this._viewMetadata.eventsMap.map(function(v, key) { + choona.Util.for(this._viewMetadata.eventsMap, function(v, key) { self.off(key); }); @@ -501,6 +508,9 @@ delete this._viewMetadata.topicList; delete this._viewMetadata.eventsMap; delete this._viewMetadata; + choona.Util.for(this, function(v, key) { + delete self[key]; + }); } }); diff --git a/dist/choona.min.js b/dist/choona.min.js index 3071f36..27c2c40 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===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 +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";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)===!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";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=function(c){if(""===f)b[a].call(b,c,c.currentTarget,c.currentTarget.dataset);else{var d;for(d=c.target;d!==c.currentTarget&&d!==document;){if(d.matches(f)===!0){b[a].call(b,c,d,d.dataset);break}d=d.parentNode}}};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(),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)},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.Klass.js b/src/choona.Klass.js index 1749a52..c7a753b 100644 --- a/src/choona.Klass.js +++ b/src/choona.Klass.js @@ -16,7 +16,7 @@ var choona = {}; Child.prototype = Object.create(Parent.prototype); Child.prototype.constructor = Child; for (var i in ChildProto) { - if (ChildProto.hasOwnProperty(i)) { + if (ChildProto.hasOwnProperty(i) === true) { Child.prototype[i] = ChildProto[i]; } } diff --git a/src/choona.Util.js b/src/choona.Util.js index 33aa662..6cfde41 100644 --- a/src/choona.Util.js +++ b/src/choona.Util.js @@ -45,7 +45,7 @@ //Replacement for _.each over Objects for: function(Obj, callback) { for (var i in Obj) { - if (Obj.hasOwnProperty(i)) { + if (Obj.hasOwnProperty(i) === true) { callback(Obj[i], i); } } diff --git a/src/choona.View.js b/src/choona.View.js index 0c907c7..3cec25b 100644 --- a/src/choona.View.js +++ b/src/choona.View.js @@ -28,7 +28,7 @@ topicList: {}, subModuleList: {}, id: moduleConf.id, - eventsMap: [], + eventsMap: {}, mercykillFunc: null }; @@ -45,7 +45,7 @@ } //setup this.$el & this.$$ if jQuery present. - if (window.jQuery) { + if (window.jQuery !== undefined && typeof window.jQuery === "function") { this.$el = this.$$ = window.jQuery(this.$); } @@ -65,7 +65,8 @@ * because, you need to get event bus for * */ - //Start Isolated EventBus , this will be useful for creating third party widget who do not want to create conflicts in naming + //Start Isolated EventBus , this will be useful for creating third party widget who do not want to create + // conflicts in naming if (this.isolatedEventBus === true) { this._viewMetadata.eventBus = new choona.EventBus(); } @@ -171,10 +172,16 @@ var callback = function(e) { if (hash === "") { - self[handler].call(self, e, e.target, e.target.dataset); + self[handler].call(self, e, e.currentTarget, e.currentTarget.dataset); } else { - if (e.target.matches(hash)) { - self[handler].call(self, e, e.target, e.target.dataset); + var currNode; + currNode = e.target; + while (currNode !== e.currentTarget && currNode !== document) { + if (currNode.matches(hash) === true) { + self[handler].call(self, e, currNode, currNode.dataset); + break; + } + currNode = currNode.parentNode; } } }; @@ -215,7 +222,7 @@ } //unSubscribing All DOM events - this._viewMetadata.eventsMap.map(function(v, key) { + choona.Util.for(this._viewMetadata.eventsMap, function(v, key) { self.off(key); }); @@ -238,6 +245,9 @@ delete this._viewMetadata.topicList; delete this._viewMetadata.eventsMap; delete this._viewMetadata; + choona.Util.for(this, function(v, key) { + delete self[key]; + }); } }); diff --git a/src/headerNotice.md b/src/headerNotice.md index e511c48..26c7ea3 100644 --- a/src/headerNotice.md +++ b/src/headerNotice.md @@ -1,7 +1,7 @@ /** - * Copyright 2013-14 Narendra Sisodiya, + * Copyright 2013-15 Narendra Sisodiya, * Licensed under "The MIT License". visit http://nsisodiya.mit-license.org/ to read the License. * @author Narendra Sisodiya - * + * Version - 1.3.9 */ \ No newline at end of file