diff --git a/bower.json b/bower.json index f0bc983..261ed66 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "vtree", - "version": "0.1.7", + "version": "0.1.8", "homepage": "https://github.com/s0ber/vtree", "authors": [ "Sergey Shishkalov " @@ -10,7 +10,7 @@ "dependencies": { "jquery": "", "underscore": "", - "async_fn": "0.1.0" + "async_fn": "~>0.1.1" }, "license": "MIT", diff --git a/build/vtree.js b/build/vtree.js index 86a51db..9706a9c 100644 --- a/build/vtree.js +++ b/build/vtree.js @@ -1,7 +1,7 @@ /*! Vtree (v0.1.2), simple library for creating complicated architectures, by Sergey Shishkalov - Sat Aug 23 2014 */ + Mon Aug 25 2014 */ (function() { var modules; diff --git a/build/vtree.min.js b/build/vtree.min.js index 6b8963e..928db9b 100644 --- a/build/vtree.min.js +++ b/build/vtree.min.js @@ -1,5 +1,5 @@ /*! Vtree (v0.1.2), simple library for creating complicated architectures, by Sergey Shishkalov - Sat Aug 23 2014 */ + Mon Aug 25 2014 */ (function(){var t;t={},null==window.modula&&(window.modula={"export":function(e,n){return t[e]=n},require:function(e){var n;if(n=t[e])return n;throw"Module '"+e+"' not found."}})}).call(this),function(){var t;t=function(){function t(){}return t.prototype.viewSelector="[data-view]",t.prototype.appPelector="[data-app]",t.prototype.selector="[data-app], [data-view]",t.prototype.componentPattern=/(.+)#(.+)/,t.prototype.isLayout=function(t){return null!=t.data("app")},t.prototype.layoutUnderscoredName=function(t){return t.data("app")},t.prototype.nodeUnderscoredName=function(t){return this.isLayout(t)?"layout":t.data("view")||""},t.prototype.hasComponent=function(t){return this.componentPattern.test(this.nodeUnderscoredName(t))},t.prototype.extractComponentData=function(t){var e,n,o,i;return i=this.nodeUnderscoredName(t).match(this.componentPattern),o=i[0],e=i[1],n=i[2],[e,n]},t}(),modula["export"]("vtree/configuration",t)}.call(this),function(){var t,e;t=modula.require("vtree/configuration"),e=function(){function e(){}return e.initNodes=function(){return this._launcher().launch(),this._launcher().createViewsTree()},e.initNodesAsync=function(){return AsyncFn.addToCallQueue(function(t){return function(){var e;return e=new $.Deferred,AsyncFn.setImmediate(function(){return t.initNodes(),e.resolve()}),e.promise()}}(this))},e.onNodeInit=function(t){return this.hooks().onInit(t)},e.getInitCallbacks=function(){return this.hooks().onInitCallbacks()},e.onNodeUnload=function(t){return this.hooks().onUnload(t)},e.getUnloadCallbacks=function(){return this.hooks().onUnloadCallbacks()},e.configure=function(t){return _.extend(this.config(),t)},e.config=function(){return null!=this._config?this._config:this._config=new t},e.hooks=function(){var t;return null!=this._hooks?this._hooks:(t=modula.require("vtree/hooks"),null!=this._hooks?this._hooks:this._hooks=new t)},e._launcher=function(){return null!=this.__launcher?this.__launcher:this.__launcher=modula.require("vtree/launcher")},e}(),modula["export"]("vtree",e),window.Vtree=e}.call(this),function(){var t,e=[].slice;t=function(){function t(){}return t.prototype.onInit=function(t){return this.onInitCallbacks().push(t)},t.prototype.onInitCallbacks=function(){return this._onInitCallbacks||(this._onInitCallbacks=[])},t.prototype.init=function(){var t,n,o,i,r,s;for(t=1<=arguments.length?e.call(arguments,0):[],r=this.onInitCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,t));return s},t.prototype.onActivation=function(t){return this.onActivationCallbacks().push(t)},t.prototype.onActivationCallbacks=function(){return this._onActivationCallbacks||(this._onActivationCallbacks=[])},t.prototype.activate=function(){var t,n,o,i,r,s;for(t=1<=arguments.length?e.call(arguments,0):[],r=this.onActivationCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,t));return s},t.prototype.onUnload=function(t){return this.onUnloadCallbacks().push(t)},t.prototype.onUnloadCallbacks=function(){return this._onUnloadCallbacks||(this._onUnloadCallbacks=[])},t.prototype.unload=function(){var t,n,o,i,r,s;for(t=1<=arguments.length?e.call(arguments,0):[],r=this.onUnloadCallbacks(),s=[],o=0,i=r.length;i>o;o++)n=r[o],s.push(n.apply(null,t));return s},t.prototype._reset=function(){return this._onInitCallbacks=[],this._onActivationCallbacks=[],this._onUnloadCallbacks=[]},t}(),modula["export"]("vtree/hooks",t)}.call(this),function(){var t;t=function(){function t(t,e){this.nodes=null!=t?t:{},this.rootNodes=null!=e?e:[]}return t.prototype.show=function(){return this.nodes},t.prototype.showRootNodes=function(){return this.rootNodes},t.prototype.add=function(t){return this.nodes[t.id]=t},t.prototype.addAsRoot=function(t){return this.rootNodes.push(t)},t.prototype.getById=function(t){return this.nodes[t]},t.prototype.removeById=function(t){return delete this.nodes[t],this.rootNodes=_.reject(this.rootNodes,function(e){return e.id===t})},t.prototype.clear=function(){return this.nodes={},this.rootNodes=[]},t}(),modula["export"]("vtree/vtree_nodes_cache",t)}.call(this),function(){var t,e;t=modula.require("vtree/hooks"),e=function(){function e(e,o){this.$el=e,this.hooks=o||new t,this.el=this.$el[0],this.id="nodeId"+n,this.parent=null,this.children=[],n++,this.init()}var n;return n=1,e.prototype.setParent=function(t){return this.parent=t},e.prototype.setChildren=function(t){return this.children=_.filter(t,function(t){return function(e){return e.parent===t}}(this))},e.prototype.removeChild=function(t){var e;if(-1!==(e=_.indexOf(this.children,t)))return this.children.splice(e,1)},e.prototype.init=function(){return this.hooks.init(this)},e.prototype.activate=function(){return this.isActivated()?void 0:(this.setAsActivated(),this.hooks.activate(this))},e.prototype.remove=function(){return this.isRemoved()?void 0:(this.setAsRemoved(),this.isActivated()?this.unload():void 0)},e.prototype.unload=function(){return this.hooks.unload(this),this.setAsNotActivated()},e.prototype.setAsActivated=function(){return this._isActivated=!0},e.prototype.setAsNotActivated=function(){return this._isActivated=!1},e.prototype.isActivated=function(){return this._isActivated||(this._isActivated=!1)},e.prototype.setAsRemoved=function(){return this._isRemoved=!0},e.prototype.isRemoved=function(){return this._isRemoved||(this._isRemoved=!1)},e}(),modula["export"]("vtree/node",e)}.call(this),function(){var t;t=function(){function t(t){_.extend(this,t),this.data={}}return t.prototype.el=null,t.prototype.$el=null,t.prototype.isApplicationLayout=null,t.prototype.isApplicationPart=null,t.prototype.isComponentPart=null,t.prototype.applicationId=null,t.prototype.nodeName=null,t.prototype.applicationName=null,t.prototype.componentName=null,t.prototype.nodeNameUnderscored=null,t.prototype.applicationNameUnderscored=null,t.prototype.componentNameUnderscored=null,t.prototype.setData=function(t,e){return this.data[t]=e},t.prototype.getData=function(t){return this.data[t]},t}(),modula["export"]("vtree/node_data",t)}.call(this),function(){var t,e,n;n=modula.require("vtree"),t=modula.require("vtree/node_data"),e=function(){function e(t){this.node=t,this.$el=this.node.$el,this.el=this.node.el,this.isLayout()&&r++,this.identifyNodeAttributes(),this.initNodeDataObject()}var o,i,r;return r=0,o=/(.+)#(.+)/,i="semarf",e.prototype.identifyNodeAttributes=function(){var t;return this.layoutName=this.layout().name,this.layoutId=this.layout().id,this.hasComponent()?(t=n.config().extractComponentData(this.$el),this.componentName=t[0],this.nodeName=t[1],t):(this.componentName=this.layoutName,this.nodeName=this.nodeUnderscoredName())},e.prototype.initNodeDataObject=function(){var t;return this.nodeData=this.initNodeData(),null!=(t=this._hooks())&&"function"==typeof t.init?t.init(this.nodeData):void 0},e.prototype.initNodeData=function(){var e,n,o,i,r,s;return this.hasComponent()?(i=this.componentName,o=this._camelize(this.componentName),n=null,e=null):(n=this.componentName,e=this._camelize(this.componentName),i=null,o=null),new t({el:this.el,$el:this.$el,isApplicationLayout:this.isLayout(),isApplicationPart:!this.hasComponent(),isComponentPart:this.hasComponent(),applicationId:this.hasComponent()?null:this.layoutId,applicationNode:(null!=(r=this.applicationNode())&&null!=(s=r.nodeWrapper)?s.nodeData:void 0)||null,nodeName:this._camelize(this.nodeName),nodeNameUnderscored:this.nodeName,applicationName:e,applicationNameUnderscored:n,componentName:o,componentNameUnderscored:i})},e.prototype.unload=function(){var t;return null!=(t=this._hooks())&&"function"==typeof t.unload&&t.unload(this.nodeData),delete this.nodeData,delete this.node},e.prototype.hasComponent=function(){return this._hasComponent||(this._hasComponent=n.config().hasComponent(this.$el))},e.prototype.layout=function(){return this._layout||(this._layout=this.isLayout()?{name:this.layoutUnderscoredName(),id:r,node:this.node}:null!=this.node.parent?this.node.parent.nodeWrapper.layout():{name:i,id:0})},e.prototype.applicationNode=function(){return null!=this._applicationNode?this._applicationNode:this._applicationNode=this.hasComponent()||this.isLayout()?null:this.layout().node},e.prototype.isLayout=function(){return null!=this._isLayout?this._isLayout:this._isLayout=n.config().isLayout(this.$el)},e.prototype.layoutUnderscoredName=function(){return null!=this._layoutUnderscoredName?this._layoutUnderscoredName:this._layoutUnderscoredName=n.config().layoutUnderscoredName(this.$el)},e.prototype.nodeUnderscoredName=function(){return null!=this._nodeUnderscoredName?this._nodeUnderscoredName:this._nodeUnderscoredName=n.config().nodeUnderscoredName(this.$el)},e.prototype._hooks=function(){return n.hooks()},e.prototype._camelize=function(t){return t.replace(/(?:^|[-_])(\w)/g,function(t,e){return e?e.toUpperCase():""})},e}(),modula["export"]("vtree/node_wrapper",e)}.call(this),function(){var t,e,n,o,i,r;r=modula.require("vtree"),o=modula.require("vtree/vtree_nodes_cache"),e=modula.require("vtree/node"),n=modula.require("vtree/node_wrapper"),t=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 t,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.unloadView,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 t,n,o,i,s,a;for(t=$(r.config().selector),this.initialNodes=[],a=[],n=i=0,s=t.length;s>=0?s>i:i>s;n=s>=0?++i:--i)o=new e(t.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(t){var e,n,o,i,s,a;for(a=[],i=0,s=t.length;s>i;i++)n=t[i],e=n.$el.parent().closest(r.config().selector),0===e.length?a.push(this.nodesCache.addAsRoot(n)):(o=e.data("vtree-node-id"),a.push(n.parent=this.nodesCache.getById(o)));return a},i.prototype.setChildrenForNodes=function(t){var e;if(t.length)return e=t.shift(),e.setChildren(t),this.setChildrenForNodes(t)},i.prototype.activateInitialNodes=function(){return this.activateRootNodes(this.initialNodes)},i.prototype.activateRootNodes=function(){var t,e,n,o,i;for(e=this.nodesCache.showRootNodes(),i=[],n=0,o=e.length;o>n;n++)t=e[n],i.push(this.activateNode(t));return i},i.prototype.activateNode=function(t){var e,n,o,i,r;for(t.activate(),i=t.children,r=[],n=0,o=i.length;o>n;n++)e=i[n],r.push(this.activateNode(e));return r},i.prototype.removeNode=function(t){return t.isRemoved()?void 0:(t.parent&&t.parent.removeChild(t),this.removeChildNodes(t),t.remove(),this.nodesCache.removeById(t.id))},i.prototype.removeChildNodes=function(t){var e,n,o,i,r;for(n=_.clone(t.children),r=[],o=0,i=n.length;i>o;o++)e=n[o],this.removeChildNodes(e),e.remove(),r.push(this.nodesCache.removeById(e.id));return r},i.prototype.refresh=function(t){var n,o,i,s,a,u,d,l;for(o=t.$el.find(r.config().selector),s=[t],i=d=0,l=o.length;l>=0?l>d:d>l;i=l>=0?++d:--d)n=o.eq(i),(u=n.data("vtree-node-id"))?a=this.nodesCache.getById(u):(a=new e(o.eq(i),this.hooks),this.nodesCache.add(a)),s.push(a);return this.setParentsForNodes(s),this.setChildrenForNodes(s),this.activateNode(t)},i.prototype.addNodeIdToElData=function(t){return t.$el.data("vtree-node-id",t.id)},i.prototype.addRemoveEventHandlerToEl=function(t){return t.$el.on("remove",function(e){return function(){return e.removeNode(t)}}(this))},i.prototype.addNodeWrapper=function(t){return t.nodeWrapper=new n(t)},i.prototype.unloadView=function(t){var e;return null!=(e=t.nodeWrapper)&&"function"==typeof e.unload?e.unload():void 0},i.prototype.deleteNodeWrapper=function(t){return delete t.nodeWrapper},i}(),modula["export"]("vtree/tree_manager",i)}.call(this),function(){var t,e,n;n=modula.require("vtree"),e=modula.require("vtree/tree_manager"),t=function(){function t(){}return t.launch=function(){return this.initTreeManager(),this.initRemoveEvent(),this.initRefreshEvent()},t.initTreeManager=function(){return this.isTreeManagerInitialized()?void 0:(this.setTreeManagerAsInitialized(),this.treeManager=new e)},t.initRemoveEvent=function(){return this.isRemoveEventInitialized()?void 0:(this.setRemoveEventAsInitialized(),$.event.special.remove={remove:function(t){var e,n;return n=this,e={type:"remove",data:t.data,currentTarget:n},t.handler(e)}})},t.initRefreshEvent=function(){return this.isRefreshEventInitialized()?void 0:(this.setRefreshEventAsInitialized(),$("body").on("refresh","*",function(t){return function(e){var o,i,r;for(e.stopPropagation(),o=$(e.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=t.treeManager.nodesCache.getById(r),t.treeManager.refresh(i)):void 0}}(this)))},t.createViewsTree=function(){return this.treeManager.createTree()},t.isTreeManagerInitialized=function(){return this._isTreeManagerInitialized||(this._isTreeManagerInitialized=!1)},t.setTreeManagerAsInitialized=function(){return this._isTreeManagerInitialized=!0},t.isRemoveEventInitialized=function(){return this._isRemoveEventInitialized||(this._isRemoveEventInitialized=!1)},t.setRemoveEventAsInitialized=function(){return this._isRemoveEventInitialized=!0},t.isRefreshEventInitialized=function(){return this._isRefreshEventInitialized||(this._isRefreshEventInitialized=!1)},t.setRefreshEventAsInitialized=function(){return this._isRefreshEventInitialized=!0},t}(),modula["export"]("vtree/launcher",t)}.call(this),function(){var t;t=function(){function t(){}return t.html=function(t,e){return t.html(e),t.trigger("refresh")},t.append=function(t,e){return t.append(e),t.trigger("refresh")},t.prepend=function(t,e){return t.prepend(e),t.trigger("refresh")},t.before=function(t,e){return t.before(e),t.parent().trigger("refresh")},t.after=function(t,e){return t.after(e),t.parent().trigger("refresh")},t.remove=function(t){return t.remove()},t.htmlAsync=function(t,e){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return t.html(e),t.trigger("refresh"),n.resolve()}),n.promise()})},t.appendAsync=function(t,e){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return t.append(e),t.trigger("refresh"),n.resolve()}),n.promise()})},t.prependAsync=function(t,e){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return t.prepend(e),t.trigger("refresh"),n.resolve()}),n.promise()})},t.beforeAsync=function(t,e){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return t.before(e),t.parent().trigger("refresh"),n.resolve()}),n.promise()})},t.afterAsync=function(t,e){return AsyncFn.addToCallQueue(function(){var n;return n=new $.Deferred,AsyncFn.setImmediate(function(){return t.after(e),t.parent().trigger("refresh"),n.resolve()}),n.promise()})},t}(),modula["export"]("vtree/dom",t),window.Vtree.DOM=t}.call(this); \ No newline at end of file diff --git a/package.json b/package.json index 77e1a85..d3afa20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vtree", - "version": "0.1.7-alpha", + "version": "0.1.8-alpha", "author": "Sergey Shishkalov ", "description": "Library for automated initialization of backbone views", "devDependencies": {