From 9a4adc492a71c8f5bff1c9808ac0c3d69ad7ae26 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 28 Nov 2014 00:54:35 +0400 Subject: [PATCH] Release v0.2.3 --- bower.json | 2 +- build/vtree.js | 11 +++++++---- build/vtree.min.js | 6 +++--- package.json | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/bower.json b/bower.json index d17b2b6..9114d25 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "vtree", - "version": "0.2.2", + "version": "0.2.3", "homepage": "https://github.com/s0ber/vtree", "authors": [ "Sergey Shishkalov " diff --git a/build/vtree.js b/build/vtree.js index 38990ad..89c4e50 100644 --- a/build/vtree.js +++ b/build/vtree.js @@ -1,7 +1,7 @@ -/*! vtree (v0.2.2), +/*! vtree (v0.2.3), Simple library for creating complicated architectures, by Sergey Shishkalov - Thu Nov 20 2014 */ + Fri Nov 28 2014 */ (function() { var modules; @@ -802,11 +802,12 @@ }; Launcher.initRefreshEvent = function() { + var refreshHandler; if (this.isRefreshEventInitialized()) { return; } this.setRefreshEventAsInitialized(); - return $('body').on('refresh', '*', (function(_this) { + refreshHandler = (function(_this) { return function(e) { var $elWithNode, node, nodeId; e.stopPropagation(); @@ -822,7 +823,9 @@ node = _this.treeManager.nodesCache.getById(nodeId); return _this.treeManager.refresh(node); }; - })(this)); + })(this); + $('body').on('refresh', refreshHandler); + return $('body').on('refresh', '*', refreshHandler); }; Launcher.createViewsTree = function() { diff --git a/build/vtree.min.js b/build/vtree.min.js index 367014f..6fccc69 100644 --- a/build/vtree.min.js +++ b/build/vtree.min.js @@ -1,5 +1,5 @@ -/*! vtree (v0.2.2), +/*! vtree (v0.2.3), Simple library for creating complicated architectures, by Sergey Shishkalov - Thu Nov 20 2014 */ -(function(){var e;e={},null==window.modula&&(window.modula={"export":function(t,n){return e[t]=n},require:function(t){var n;if(n=e[t])return n;throw"Module '"+t+"' not found."}})}).call(this),function(){var e;e=function(){function e(){}return e.prototype.viewSelector="[data-view]",e.prototype.componentSelector="[data-component]",e.prototype.selector="[data-component], [data-view]",e.prototype.namespacePattern=/(.+)#(.+)/,e.prototype.isComponentIndex=function(e){return null!=e.data("component")},e.prototype.nodeUnderscoredName=function(e){return this.isComponentIndex(e)?e.data("component"):e.data("view")||""},e.prototype.isStandAlone=function(e){return!this.isComponentIndex(e)&&this.namespacePattern.test(this.nodeUnderscoredName(e))},e.prototype.extractStandAloneNodeData=function(e){var t,n,o,i;return i=this.nodeUnderscoredName(e).match(this.namespacePattern),o=i[0],t=i[1],n=i[2],[t,n]},e.prototype.extractComponentIndexNodeData=function(e){var t,n,o,i;return i=this.nodeUnderscoredName(e).match(this.namespacePattern),o=i[0],n=i[1],t=i[2],[n,t]},e}(),modula["export"]("vtree/configuration",e)}.call(this),function(){var e,t;e=modula.require("vtree/configuration"),t=function(){function t(){}return t.initNodes=function(){return this._launcher().launch(),this._launcher().createViewsTree()},t.initNodesAsync=function(){return AsyncFn.addToCallQueue(function(e){return function(){var t;return t=new $.Deferred,AsyncFn.setImmediate(function(){return e.initNodes(),t.resolve()}),t.promise()}}(this))},t.onNodeInit=function(e){return this.hooks().onInit(e)},t.getInitCallbacks=function(){return this.hooks().onInitCallbacks()},t.onNodeUnload=function(e){return this.hooks().onUnload(e)},t.getUnloadCallbacks=function(){return this.hooks().onUnloadCallbacks()},t.configure=function(e){return _.extend(this.config(),e)},t.config=function(){return null!=this._config?this._config:this._config=new e},t.hooks=function(){var e;return null!=this._hooks?this._hooks:(e=modula.require("vtree/hooks"),null!=this._hooks?this._hooks:this._hooks=new e)},t._launcher=function(){return null!=this.__launcher?this.__launcher:this.__launcher=modula.require("vtree/launcher")},t}(),modula["export"]("vtree",t),window.Vtree=t}.call(this),function(){var e,t=[].slice;e=function(){function e(){}return e.prototype.onInit=function(e){return this.onInitCallbacks().push(e)},e.prototype.onInitCallbacks=function(){return null!=this._onInitCallbacks?this._onInitCallbacks:this._onInitCallbacks=[]},e.prototype.init=function(){var e,n,o,i,r,s;for(e=1<=arguments.length?t.call(arguments,0):[],r=this.onInitCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,e));return s},e.prototype.onActivation=function(e){return this.onActivationCallbacks().push(e)},e.prototype.onActivationCallbacks=function(){return null!=this._onActivationCallbacks?this._onActivationCallbacks:this._onActivationCallbacks=[]},e.prototype.activate=function(){var e,n,o,i,r,s;for(e=1<=arguments.length?t.call(arguments,0):[],r=this.onActivationCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,e));return s},e.prototype.onUnload=function(e){return this.onUnloadCallbacks().push(e)},e.prototype.onUnloadCallbacks=function(){return null!=this._onUnloadCallbacks?this._onUnloadCallbacks:this._onUnloadCallbacks=[]},e.prototype.unload=function(){var e,n,o,i,r,s;for(e=1<=arguments.length?t.call(arguments,0):[],r=this.onUnloadCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,e));return s},e.prototype._reset=function(){return this._onInitCallbacks=[],this._onActivationCallbacks=[],this._onUnloadCallbacks=[]},e}(),modula["export"]("vtree/hooks",e)}.call(this),function(){var e;e=function(){function e(e,t){this.nodes=null!=e?e:{},this.rootNodes=null!=t?t:[]}return e.prototype.show=function(){return this.nodes},e.prototype.showRootNodes=function(){return this.rootNodes},e.prototype.add=function(e){return this.nodes[e.id]=e},e.prototype.addAsRoot=function(e){if(null==this.nodes[e.id])throw new Error("Trying to add node as root, but node is not cached previously");return this.rootNodes.push(e)},e.prototype.getById=function(e){return this.nodes[e]},e.prototype.removeById=function(e){var t;return-1!==(t=_.indexOf(this.rootNodes,this.nodes[e]))&&this.rootNodes.splice(t,1),delete this.nodes[e]},e.prototype.clear=function(){return this.nodes={},this.rootNodes=[]},e}(),modula["export"]("vtree/vtree_nodes_cache",e)}.call(this),function(){var e,t;e=modula.require("vtree/hooks"),t=function(){function t(t,o){this.$el=t,this.hooks=o||new e,this.el=this.$el[0],this.id="nodeId"+n,this.parent=null,this.children=[],n++,this.init()}var n;return n=1,t.prototype.setParent=function(e){return this.parent=e},t.prototype.prependChild=function(e){return this.children.unshift(e)},t.prototype.appendChild=function(e){return this.children.push(e)},t.prototype.removeChild=function(e){var t;if(-1!==(t=_.indexOf(this.children,e)))return this.children.splice(t,1)},t.prototype.init=function(){return this.hooks.init(this)},t.prototype.activate=function(){return this.isActivated()?void 0:(this.setAsActivated(),this.hooks.activate(this))},t.prototype.remove=function(){return this.isRemoved()?void 0:(this.setAsRemoved(),this.isActivated()?this.unload():void 0)},t.prototype.unload=function(){return this.hooks.unload(this),this.setAsNotActivated()},t.prototype.setAsActivated=function(){return this._isActivated=!0},t.prototype.setAsNotActivated=function(){return this._isActivated=!1},t.prototype.isActivated=function(){return null!=this._isActivated?this._isActivated:this._isActivated=!1},t.prototype.setAsRemoved=function(){return this._isRemoved=!0},t.prototype.isRemoved=function(){return null!=this._isRemoved?this._isRemoved:this._isRemoved=!1},t}(),modula["export"]("vtree/node",t)}.call(this),function(){var e;e=function(){function e(e){_.extend(this,e),this.data={}}return e.prototype.el=null,e.prototype.$el=null,e.prototype.isComponentIndex=null,e.prototype.isComponentPart=null,e.prototype.isStandAlone=null,e.prototype.componentId=null,e.prototype.componentIndexNode=null,e.prototype.nodeName=null,e.prototype.componentName=null,e.prototype.namespaceName=null,e.prototype.nodeNameUnderscored=null,e.prototype.componentNameUnderscored=null,e.prototype.namespaceNameUnderscored=null,e.prototype.setData=function(e,t){return this.data[e]=t},e.prototype.getData=function(e){return this.data[e]},e}(),modula["export"]("vtree/node_data",e)}.call(this),function(){var e,t,n;n=modula.require("vtree"),e=modula.require("vtree/node_data"),t=function(){function t(e){this.node=e,this.$el=this.node.$el,this.el=this.node.el,this.isComponentIndex()&&i++,this.identifyNodeAttributes(),this.initNodeDataObject()}var o,i;return i=0,o="semarf",t.prototype.identifyNodeAttributes=function(){var e;return this.isStandAlone()?(e=n.config().extractStandAloneNodeData(this.$el),this.namespaceName=e[0],this.nodeName=e[1],e):(this.namespaceName=this.component().namespace,this.nodeName=this.isComponentIndex()?"index":this.nodeUnderscoredName())},t.prototype.initNodeDataObject=function(){var e;return this.nodeData=this.initNodeData(),null!=(e=this._hooks())&&"function"==typeof e.init?e.init(this.nodeData):void 0},t.prototype.initNodeData=function(){var t,n,o,i,r,s;return i=this.namespaceName,o=this._camelize(this.namespaceName),this.isStandAlone()?(n=null,t=null):(n=this.component().name,t=this._camelize(n)),new e({el:this.el,$el:this.$el,isStandAlone:this.isStandAlone(),isComponentIndex:this.isComponentIndex(),isComponentPart:!this.isStandAlone(),componentId:this.isStandAlone()?null:this.component().id,componentIndexNode:(null!=(r=this.componentIndexNode())&&null!=(s=r.nodeWrapper)?s.nodeData:void 0)||null,nodeName:this._camelize(this.nodeName),nodeNameUnderscored:this.nodeName,componentName:t,componentNameUnderscored:n,namespaceName:o,namespaceNameUnderscored:i})},t.prototype.unload=function(){var e;return null!=(e=this._hooks())&&"function"==typeof e.unload&&e.unload(this.nodeData),delete this.nodeData,delete this.node},t.prototype.isStandAlone=function(){return null!=this._isStandAlone?this._isStandAlone:this._isStandAlone=n.config().isStandAlone(this.$el)},t.prototype.component=function(){var e,t,r;return null!=this._component?this._component:this._component=this.isComponentIndex()?(r=n.config().extractComponentIndexNodeData(this.$el),t=r[0],e=r[1],r,{namespace:t,name:e,id:i,node:this.node}):null!=this.node.parent?this.node.parent.nodeWrapper.component():{namespace:o,name:o,id:0,node:this.node}},t.prototype.componentIndexNode=function(){return null!=this._componentIndexNode?this._componentIndexNode:this._componentIndexNode=this.isStandAlone()||this.isComponentIndex()?null:this.component().node},t.prototype.isComponentIndex=function(){return null!=this._isComponentIndex?this._isComponentIndex:this._isComponentIndex=n.config().isComponentIndex(this.$el)},t.prototype.nodeUnderscoredName=function(){return null!=this._nodeUnderscoredName?this._nodeUnderscoredName:this._nodeUnderscoredName=n.config().nodeUnderscoredName(this.$el)},t.prototype._hooks=function(){return n.hooks()},t.prototype._camelize=function(e){return e.replace(/(?:^|[-_])(\w)/g,function(e,t){return t?t.toUpperCase():""})},t}(),modula["export"]("vtree/node_wrapper",t)}.call(this),function(){var e,t,n,o,i,r;r=modula.require("vtree"),o=modula.require("vtree/vtree_nodes_cache"),t=modula.require("vtree/node"),n=modula.require("vtree/node_wrapper"),e=modula.require("vtree/hooks"),i=function(){function i(){this.initNodeHooks(),this.initialNodes=[],this.nodesCache=new o}return i.prototype.initNodeHooks=function(){return this.hooks=new e,this.hooks.onInit(_.bind(this.addNodeIdToElData,this)),this.hooks.onInit(_.bind(this.addRemoveEventHandlerToEl,this)),this.hooks.onActivation(_.bind(this.addNodeWrapper,this)),this.hooks.onUnload(_.bind(this.unloadNode,this)),this.hooks.onUnload(_.bind(this.deleteNodeWrapper,this))},i.prototype.createTree=function(){return this.setInitialNodes(),this.setParentsForInitialNodes(),this.setChildrenForInitialNodes(),this.activateInitialNodes()},i.prototype.setInitialNodes=function(){var e,n,o,i,s,a;for(e=$(r.config().selector),this.initialNodes=[],a=[],n=i=0,s=e.length;s>=0?s>i:i>s;n=s>=0?++i:--i)o=new t(e.eq(n),this.hooks),this.nodesCache.add(o),a.push(this.initialNodes.push(o));return a},i.prototype.setParentsForInitialNodes=function(){return this.setParentsForNodes(this.initialNodes)},i.prototype.setChildrenForInitialNodes=function(){return this.setChildrenForNodes(this.initialNodes)},i.prototype.setParentsForNodes=function(e){var t,n,o,i,s,a;for(a=[],i=0,s=e.length;s>i;i++)n=e[i],t=n.$el.parent().closest(r.config().selector),0===t.length?a.push(this.nodesCache.addAsRoot(n)):(o=t.data("vtree-node-id"),a.push(n.parent=this.nodesCache.getById(o)));return a},i.prototype.setChildrenForNodes=function(e){var t,n,o,i,r,s;if(e.length){for(s=[],t=o=i=e.length-1;0>=i?0>=o:o>=0;t=0>=i?++o:--o)n=e[t],s.push(null!=(r=n.parent)?r.prependChild(n):void 0);return s}},i.prototype.activateInitialNodes=function(){return this.activateRootNodes(this.initialNodes)},i.prototype.activateRootNodes=function(){var e,t,n,o,i;for(t=this.nodesCache.showRootNodes(),i=[],n=0,o=t.length;o>n;n++)e=t[n],i.push(this.activateNode(e));return i},i.prototype.activateNode=function(e){var t,n,o,i,r;for(e.activate(),i=e.children,r=[],n=0,o=i.length;o>n;n++)t=i[n],r.push(this.activateNode(t));return r},i.prototype.removeNode=function(e){return e.isRemoved()?void 0:(e.parent&&e.parent.removeChild(e),this.removeChildNodes(e),e.remove(),this.nodesCache.removeById(e.id))},i.prototype.removeChildNodes=function(e){var t,n,o,i,r;for(i=e.children,r=[],n=0,o=i.length;o>n;n++)t=i[n],this.removeChildNodes(t),t.remove(),r.push(this.nodesCache.removeById(t.id));return r},i.prototype.refresh=function(e){var n,o,i,s,a,d,u,l,h,c;for(o=e.$el.find(r.config().selector),s=[e],i=u=0,c=o.length;c>=0?c>u:u>c;i=c>=0?++u:--u)n=o.eq(i),(d=n.data("vtree-node-id"))?a=this.nodesCache.getById(d):(a=new t(n,this.hooks),this.nodesCache.add(a)),s.push(a);for(l=0,h=s.length;h>l;l++)a=s[l],a.children.length=0;return this.setParentsForNodes(s),this.setChildrenForNodes(s),this.activateNode(e)},i.prototype.addNodeIdToElData=function(e){return e.$el.data("vtree-node-id",e.id)},i.prototype.addRemoveEventHandlerToEl=function(e){return e.$el.on("remove",function(t){return function(){return t.removeNode(e)}}(this))},i.prototype.addNodeWrapper=function(e){return e.nodeWrapper=new n(e)},i.prototype.unloadNode=function(e){var t;return null!=(t=e.nodeWrapper)&&"function"==typeof t.unload?t.unload():void 0},i.prototype.deleteNodeWrapper=function(e){return delete e.nodeWrapper},i}(),modula["export"]("vtree/tree_manager",i)}.call(this),function(){var e,t,n;n=modula.require("vtree"),t=modula.require("vtree/tree_manager"),e=function(){function e(){}return e.launch=function(){return this.initTreeManager(),this.initRemoveEvent(),this.initRefreshEvent()},e.initTreeManager=function(){return this.isTreeManagerInitialized()?void 0:(this.setTreeManagerAsInitialized(),this.treeManager=new t)},e.initRemoveEvent=function(){return this.isRemoveEventInitialized()?void 0:(this.setRemoveEventAsInitialized(),$.event.special.remove={remove:function(e){var t,n;return n=this,t={type:"remove",data:e.data,currentTarget:n},e.handler(t)}})},e.initRefreshEvent=function(){return this.isRefreshEventInitialized()?void 0:(this.setRefreshEventAsInitialized(),$("body").on("refresh","*",function(e){return function(t){var o,i,r;for(t.stopPropagation(),o=$(t.currentTarget).closest(n.config().selector),r=o.data("vtree-node-id");o.length&&!r;)o=o.parent().closest(n.config().selector),r=o.data("vtree-node-id");return r?(i=e.treeManager.nodesCache.getById(r),e.treeManager.refresh(i)):void 0}}(this)))},e.createViewsTree=function(){return this.treeManager.createTree()},e.isTreeManagerInitialized=function(){return null!=this._isTreeManagerInitialized?this._isTreeManagerInitialized:this._isTreeManagerInitialized=!1},e.setTreeManagerAsInitialized=function(){return this._isTreeManagerInitialized=!0},e.isRemoveEventInitialized=function(){return null!=this._isRemoveEventInitialized?this._isRemoveEventInitialized:this._isRemoveEventInitialized=!1},e.setRemoveEventAsInitialized=function(){return this._isRemoveEventInitialized=!0},e.isRefreshEventInitialized=function(){return null!=this._isRefreshEventInitialized?this._isRefreshEventInitialized:this._isRefreshEventInitialized=!1},e.setRefreshEventAsInitialized=function(){return this._isRefreshEventInitialized=!0},e}(),modula["export"]("vtree/launcher",e)}.call(this),function(){var e;e=function(){function e(){}return e.html=function(e,t){return e.html(t),e.trigger("refresh")},e.append=function(e,t){return e.append(t),e.trigger("refresh")},e.prepend=function(e,t){return e.prepend(t),e.trigger("refresh")},e.before=function(e,t){return e.before(t),e.parent().trigger("refresh")},e.after=function(e,t){return e.after(t),e.parent().trigger("refresh")},e.remove=function(e){return e.remove()},e.htmlAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.html(t),e.trigger("refresh"),n.resolve()}),n.promise()})},e.appendAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.append(t),e.trigger("refresh"),n.resolve()}),n.promise()})},e.prependAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.prepend(t),e.trigger("refresh"),n.resolve()}),n.promise()})},e.beforeAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.before(t),e.parent().trigger("refresh"),n.resolve()}),n.promise()})},e.afterAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.after(t),e.parent().trigger("refresh"),n.resolve()}),n.promise()})},e}(),modula["export"]("vtree/dom",e),window.Vtree.DOM=e}.call(this); \ No newline at end of file + Fri Nov 28 2014 */ +(function(){var e;e={},null==window.modula&&(window.modula={"export":function(t,n){return e[t]=n},require:function(t){var n;if(n=e[t])return n;throw"Module '"+t+"' not found."}})}).call(this),function(){var e;e=function(){function e(){}return e.prototype.viewSelector="[data-view]",e.prototype.componentSelector="[data-component]",e.prototype.selector="[data-component], [data-view]",e.prototype.namespacePattern=/(.+)#(.+)/,e.prototype.isComponentIndex=function(e){return null!=e.data("component")},e.prototype.nodeUnderscoredName=function(e){return this.isComponentIndex(e)?e.data("component"):e.data("view")||""},e.prototype.isStandAlone=function(e){return!this.isComponentIndex(e)&&this.namespacePattern.test(this.nodeUnderscoredName(e))},e.prototype.extractStandAloneNodeData=function(e){var t,n,o,i;return i=this.nodeUnderscoredName(e).match(this.namespacePattern),o=i[0],t=i[1],n=i[2],[t,n]},e.prototype.extractComponentIndexNodeData=function(e){var t,n,o,i;return i=this.nodeUnderscoredName(e).match(this.namespacePattern),o=i[0],n=i[1],t=i[2],[n,t]},e}(),modula["export"]("vtree/configuration",e)}.call(this),function(){var e,t;e=modula.require("vtree/configuration"),t=function(){function t(){}return t.initNodes=function(){return this._launcher().launch(),this._launcher().createViewsTree()},t.initNodesAsync=function(){return AsyncFn.addToCallQueue(function(e){return function(){var t;return t=new $.Deferred,AsyncFn.setImmediate(function(){return e.initNodes(),t.resolve()}),t.promise()}}(this))},t.onNodeInit=function(e){return this.hooks().onInit(e)},t.getInitCallbacks=function(){return this.hooks().onInitCallbacks()},t.onNodeUnload=function(e){return this.hooks().onUnload(e)},t.getUnloadCallbacks=function(){return this.hooks().onUnloadCallbacks()},t.configure=function(e){return _.extend(this.config(),e)},t.config=function(){return null!=this._config?this._config:this._config=new e},t.hooks=function(){var e;return null!=this._hooks?this._hooks:(e=modula.require("vtree/hooks"),null!=this._hooks?this._hooks:this._hooks=new e)},t._launcher=function(){return null!=this.__launcher?this.__launcher:this.__launcher=modula.require("vtree/launcher")},t}(),modula["export"]("vtree",t),window.Vtree=t}.call(this),function(){var e,t=[].slice;e=function(){function e(){}return e.prototype.onInit=function(e){return this.onInitCallbacks().push(e)},e.prototype.onInitCallbacks=function(){return null!=this._onInitCallbacks?this._onInitCallbacks:this._onInitCallbacks=[]},e.prototype.init=function(){var e,n,o,i,r,s;for(e=1<=arguments.length?t.call(arguments,0):[],r=this.onInitCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,e));return s},e.prototype.onActivation=function(e){return this.onActivationCallbacks().push(e)},e.prototype.onActivationCallbacks=function(){return null!=this._onActivationCallbacks?this._onActivationCallbacks:this._onActivationCallbacks=[]},e.prototype.activate=function(){var e,n,o,i,r,s;for(e=1<=arguments.length?t.call(arguments,0):[],r=this.onActivationCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,e));return s},e.prototype.onUnload=function(e){return this.onUnloadCallbacks().push(e)},e.prototype.onUnloadCallbacks=function(){return null!=this._onUnloadCallbacks?this._onUnloadCallbacks:this._onUnloadCallbacks=[]},e.prototype.unload=function(){var e,n,o,i,r,s;for(e=1<=arguments.length?t.call(arguments,0):[],r=this.onUnloadCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,e));return s},e.prototype._reset=function(){return this._onInitCallbacks=[],this._onActivationCallbacks=[],this._onUnloadCallbacks=[]},e}(),modula["export"]("vtree/hooks",e)}.call(this),function(){var e;e=function(){function e(e,t){this.nodes=null!=e?e:{},this.rootNodes=null!=t?t:[]}return e.prototype.show=function(){return this.nodes},e.prototype.showRootNodes=function(){return this.rootNodes},e.prototype.add=function(e){return this.nodes[e.id]=e},e.prototype.addAsRoot=function(e){if(null==this.nodes[e.id])throw new Error("Trying to add node as root, but node is not cached previously");return this.rootNodes.push(e)},e.prototype.getById=function(e){return this.nodes[e]},e.prototype.removeById=function(e){var t;return-1!==(t=_.indexOf(this.rootNodes,this.nodes[e]))&&this.rootNodes.splice(t,1),delete this.nodes[e]},e.prototype.clear=function(){return this.nodes={},this.rootNodes=[]},e}(),modula["export"]("vtree/vtree_nodes_cache",e)}.call(this),function(){var e,t;e=modula.require("vtree/hooks"),t=function(){function t(t,o){this.$el=t,this.hooks=o||new e,this.el=this.$el[0],this.id="nodeId"+n,this.parent=null,this.children=[],n++,this.init()}var n;return n=1,t.prototype.setParent=function(e){return this.parent=e},t.prototype.prependChild=function(e){return this.children.unshift(e)},t.prototype.appendChild=function(e){return this.children.push(e)},t.prototype.removeChild=function(e){var t;if(-1!==(t=_.indexOf(this.children,e)))return this.children.splice(t,1)},t.prototype.init=function(){return this.hooks.init(this)},t.prototype.activate=function(){return this.isActivated()?void 0:(this.setAsActivated(),this.hooks.activate(this))},t.prototype.remove=function(){return this.isRemoved()?void 0:(this.setAsRemoved(),this.isActivated()?this.unload():void 0)},t.prototype.unload=function(){return this.hooks.unload(this),this.setAsNotActivated()},t.prototype.setAsActivated=function(){return this._isActivated=!0},t.prototype.setAsNotActivated=function(){return this._isActivated=!1},t.prototype.isActivated=function(){return null!=this._isActivated?this._isActivated:this._isActivated=!1},t.prototype.setAsRemoved=function(){return this._isRemoved=!0},t.prototype.isRemoved=function(){return null!=this._isRemoved?this._isRemoved:this._isRemoved=!1},t}(),modula["export"]("vtree/node",t)}.call(this),function(){var e;e=function(){function e(e){_.extend(this,e),this.data={}}return e.prototype.el=null,e.prototype.$el=null,e.prototype.isComponentIndex=null,e.prototype.isComponentPart=null,e.prototype.isStandAlone=null,e.prototype.componentId=null,e.prototype.componentIndexNode=null,e.prototype.nodeName=null,e.prototype.componentName=null,e.prototype.namespaceName=null,e.prototype.nodeNameUnderscored=null,e.prototype.componentNameUnderscored=null,e.prototype.namespaceNameUnderscored=null,e.prototype.setData=function(e,t){return this.data[e]=t},e.prototype.getData=function(e){return this.data[e]},e}(),modula["export"]("vtree/node_data",e)}.call(this),function(){var e,t,n;n=modula.require("vtree"),e=modula.require("vtree/node_data"),t=function(){function t(e){this.node=e,this.$el=this.node.$el,this.el=this.node.el,this.isComponentIndex()&&i++,this.identifyNodeAttributes(),this.initNodeDataObject()}var o,i;return i=0,o="semarf",t.prototype.identifyNodeAttributes=function(){var e;return this.isStandAlone()?(e=n.config().extractStandAloneNodeData(this.$el),this.namespaceName=e[0],this.nodeName=e[1],e):(this.namespaceName=this.component().namespace,this.nodeName=this.isComponentIndex()?"index":this.nodeUnderscoredName())},t.prototype.initNodeDataObject=function(){var e;return this.nodeData=this.initNodeData(),null!=(e=this._hooks())&&"function"==typeof e.init?e.init(this.nodeData):void 0},t.prototype.initNodeData=function(){var t,n,o,i,r,s;return i=this.namespaceName,o=this._camelize(this.namespaceName),this.isStandAlone()?(n=null,t=null):(n=this.component().name,t=this._camelize(n)),new e({el:this.el,$el:this.$el,isStandAlone:this.isStandAlone(),isComponentIndex:this.isComponentIndex(),isComponentPart:!this.isStandAlone(),componentId:this.isStandAlone()?null:this.component().id,componentIndexNode:(null!=(r=this.componentIndexNode())&&null!=(s=r.nodeWrapper)?s.nodeData:void 0)||null,nodeName:this._camelize(this.nodeName),nodeNameUnderscored:this.nodeName,componentName:t,componentNameUnderscored:n,namespaceName:o,namespaceNameUnderscored:i})},t.prototype.unload=function(){var e;return null!=(e=this._hooks())&&"function"==typeof e.unload&&e.unload(this.nodeData),delete this.nodeData,delete this.node},t.prototype.isStandAlone=function(){return null!=this._isStandAlone?this._isStandAlone:this._isStandAlone=n.config().isStandAlone(this.$el)},t.prototype.component=function(){var e,t,r;return null!=this._component?this._component:this._component=this.isComponentIndex()?(r=n.config().extractComponentIndexNodeData(this.$el),t=r[0],e=r[1],r,{namespace:t,name:e,id:i,node:this.node}):null!=this.node.parent?this.node.parent.nodeWrapper.component():{namespace:o,name:o,id:0,node:this.node}},t.prototype.componentIndexNode=function(){return null!=this._componentIndexNode?this._componentIndexNode:this._componentIndexNode=this.isStandAlone()||this.isComponentIndex()?null:this.component().node},t.prototype.isComponentIndex=function(){return null!=this._isComponentIndex?this._isComponentIndex:this._isComponentIndex=n.config().isComponentIndex(this.$el)},t.prototype.nodeUnderscoredName=function(){return null!=this._nodeUnderscoredName?this._nodeUnderscoredName:this._nodeUnderscoredName=n.config().nodeUnderscoredName(this.$el)},t.prototype._hooks=function(){return n.hooks()},t.prototype._camelize=function(e){return e.replace(/(?:^|[-_])(\w)/g,function(e,t){return t?t.toUpperCase():""})},t}(),modula["export"]("vtree/node_wrapper",t)}.call(this),function(){var e,t,n,o,i,r;r=modula.require("vtree"),o=modula.require("vtree/vtree_nodes_cache"),t=modula.require("vtree/node"),n=modula.require("vtree/node_wrapper"),e=modula.require("vtree/hooks"),i=function(){function i(){this.initNodeHooks(),this.initialNodes=[],this.nodesCache=new o}return i.prototype.initNodeHooks=function(){return this.hooks=new e,this.hooks.onInit(_.bind(this.addNodeIdToElData,this)),this.hooks.onInit(_.bind(this.addRemoveEventHandlerToEl,this)),this.hooks.onActivation(_.bind(this.addNodeWrapper,this)),this.hooks.onUnload(_.bind(this.unloadNode,this)),this.hooks.onUnload(_.bind(this.deleteNodeWrapper,this))},i.prototype.createTree=function(){return this.setInitialNodes(),this.setParentsForInitialNodes(),this.setChildrenForInitialNodes(),this.activateInitialNodes()},i.prototype.setInitialNodes=function(){var e,n,o,i,s,a;for(e=$(r.config().selector),this.initialNodes=[],a=[],n=i=0,s=e.length;s>=0?s>i:i>s;n=s>=0?++i:--i)o=new t(e.eq(n),this.hooks),this.nodesCache.add(o),a.push(this.initialNodes.push(o));return a},i.prototype.setParentsForInitialNodes=function(){return this.setParentsForNodes(this.initialNodes)},i.prototype.setChildrenForInitialNodes=function(){return this.setChildrenForNodes(this.initialNodes)},i.prototype.setParentsForNodes=function(e){var t,n,o,i,s,a;for(a=[],i=0,s=e.length;s>i;i++)n=e[i],t=n.$el.parent().closest(r.config().selector),0===t.length?a.push(this.nodesCache.addAsRoot(n)):(o=t.data("vtree-node-id"),a.push(n.parent=this.nodesCache.getById(o)));return a},i.prototype.setChildrenForNodes=function(e){var t,n,o,i,r,s;if(e.length){for(s=[],t=o=i=e.length-1;0>=i?0>=o:o>=0;t=0>=i?++o:--o)n=e[t],s.push(null!=(r=n.parent)?r.prependChild(n):void 0);return s}},i.prototype.activateInitialNodes=function(){return this.activateRootNodes(this.initialNodes)},i.prototype.activateRootNodes=function(){var e,t,n,o,i;for(t=this.nodesCache.showRootNodes(),i=[],n=0,o=t.length;o>n;n++)e=t[n],i.push(this.activateNode(e));return i},i.prototype.activateNode=function(e){var t,n,o,i,r;for(e.activate(),i=e.children,r=[],n=0,o=i.length;o>n;n++)t=i[n],r.push(this.activateNode(t));return r},i.prototype.removeNode=function(e){return e.isRemoved()?void 0:(e.parent&&e.parent.removeChild(e),this.removeChildNodes(e),e.remove(),this.nodesCache.removeById(e.id))},i.prototype.removeChildNodes=function(e){var t,n,o,i,r;for(i=e.children,r=[],n=0,o=i.length;o>n;n++)t=i[n],this.removeChildNodes(t),t.remove(),r.push(this.nodesCache.removeById(t.id));return r},i.prototype.refresh=function(e){var n,o,i,s,a,d,u,l,h,c;for(o=e.$el.find(r.config().selector),s=[e],i=u=0,c=o.length;c>=0?c>u:u>c;i=c>=0?++u:--u)n=o.eq(i),(d=n.data("vtree-node-id"))?a=this.nodesCache.getById(d):(a=new t(n,this.hooks),this.nodesCache.add(a)),s.push(a);for(l=0,h=s.length;h>l;l++)a=s[l],a.children.length=0;return this.setParentsForNodes(s),this.setChildrenForNodes(s),this.activateNode(e)},i.prototype.addNodeIdToElData=function(e){return e.$el.data("vtree-node-id",e.id)},i.prototype.addRemoveEventHandlerToEl=function(e){return e.$el.on("remove",function(t){return function(){return t.removeNode(e)}}(this))},i.prototype.addNodeWrapper=function(e){return e.nodeWrapper=new n(e)},i.prototype.unloadNode=function(e){var t;return null!=(t=e.nodeWrapper)&&"function"==typeof t.unload?t.unload():void 0},i.prototype.deleteNodeWrapper=function(e){return delete e.nodeWrapper},i}(),modula["export"]("vtree/tree_manager",i)}.call(this),function(){var e,t,n;n=modula.require("vtree"),t=modula.require("vtree/tree_manager"),e=function(){function e(){}return e.launch=function(){return this.initTreeManager(),this.initRemoveEvent(),this.initRefreshEvent()},e.initTreeManager=function(){return this.isTreeManagerInitialized()?void 0:(this.setTreeManagerAsInitialized(),this.treeManager=new t)},e.initRemoveEvent=function(){return this.isRemoveEventInitialized()?void 0:(this.setRemoveEventAsInitialized(),$.event.special.remove={remove:function(e){var t,n;return n=this,t={type:"remove",data:e.data,currentTarget:n},e.handler(t)}})},e.initRefreshEvent=function(){var e;if(!this.isRefreshEventInitialized())return this.setRefreshEventAsInitialized(),e=function(e){return function(t){var o,i,r;for(t.stopPropagation(),o=$(t.currentTarget).closest(n.config().selector),r=o.data("vtree-node-id");o.length&&!r;)o=o.parent().closest(n.config().selector),r=o.data("vtree-node-id");return r?(i=e.treeManager.nodesCache.getById(r),e.treeManager.refresh(i)):void 0}}(this),$("body").on("refresh",e),$("body").on("refresh","*",e)},e.createViewsTree=function(){return this.treeManager.createTree()},e.isTreeManagerInitialized=function(){return null!=this._isTreeManagerInitialized?this._isTreeManagerInitialized:this._isTreeManagerInitialized=!1},e.setTreeManagerAsInitialized=function(){return this._isTreeManagerInitialized=!0},e.isRemoveEventInitialized=function(){return null!=this._isRemoveEventInitialized?this._isRemoveEventInitialized:this._isRemoveEventInitialized=!1},e.setRemoveEventAsInitialized=function(){return this._isRemoveEventInitialized=!0},e.isRefreshEventInitialized=function(){return null!=this._isRefreshEventInitialized?this._isRefreshEventInitialized:this._isRefreshEventInitialized=!1},e.setRefreshEventAsInitialized=function(){return this._isRefreshEventInitialized=!0},e}(),modula["export"]("vtree/launcher",e)}.call(this),function(){var e;e=function(){function e(){}return e.html=function(e,t){return e.html(t),e.trigger("refresh")},e.append=function(e,t){return e.append(t),e.trigger("refresh")},e.prepend=function(e,t){return e.prepend(t),e.trigger("refresh")},e.before=function(e,t){return e.before(t),e.parent().trigger("refresh")},e.after=function(e,t){return e.after(t),e.parent().trigger("refresh")},e.remove=function(e){return e.remove()},e.htmlAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.html(t),e.trigger("refresh"),n.resolve()}),n.promise()})},e.appendAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.append(t),e.trigger("refresh"),n.resolve()}),n.promise()})},e.prependAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.prepend(t),e.trigger("refresh"),n.resolve()}),n.promise()})},e.beforeAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.before(t),e.parent().trigger("refresh"),n.resolve()}),n.promise()})},e.afterAsync=function(e,t){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return e.after(t),e.parent().trigger("refresh"),n.resolve()}),n.promise()})},e}(),modula["export"]("vtree/dom",e),window.Vtree.DOM=e}.call(this); \ No newline at end of file diff --git a/package.json b/package.json index 5312a55..621afe9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vtree", - "version": "0.2.2", + "version": "0.2.3", "author": "Sergey Shishkalov ", "description": "Library for automated initialization of backbone views (or whatever)", "devDependencies": {