From 6788d4e8ce11f5433655fa631df3c20c9b196bef Mon Sep 17 00:00:00 2001 From: Sergey Date: Sat, 23 Aug 2014 00:59:53 +0400 Subject: [PATCH] Release new version --- bower.json | 2 +- build/vtree.js | 92 +--------------------------------------------- build/vtree.min.js | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 94 deletions(-) diff --git a/bower.json b/bower.json index 926344e..f0bc983 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "vtree", - "version": "0.1.6", + "version": "0.1.7", "homepage": "https://github.com/s0ber/vtree", "authors": [ "Sergey Shishkalov " diff --git a/build/vtree.js b/build/vtree.js index c9a1f9d..86a51db 100644 --- a/build/vtree.js +++ b/build/vtree.js @@ -88,8 +88,6 @@ }; Vtree.initNodesAsync = function() { - var AsyncFn; - AsyncFn = modula.require('vtree/async_fn'); return AsyncFn.addToCallQueue((function(_this) { return function() { var dfd; @@ -150,92 +148,6 @@ }).call(this); -(function() { - var AsyncFn; - - AsyncFn = (function() { - function AsyncFn(asyncFn) { - this.fn = asyncFn; - } - - AsyncFn.prototype.done = function(callback) { - this.callback = callback; - if (this.isCalled) { - return this.callback(); - } - }; - - AsyncFn.prototype.call = function() { - if (this.isCalled) { - return; - } - return this.fn().always((function(_this) { - return function() { - _this.isCalled = true; - if (_this.callback) { - return _this.callback(); - } - }; - })(this)); - }; - - AsyncFn.addToCallQueue = function(fn) { - var asyncFn; - asyncFn = new AsyncFn(fn); - if (this.currentFn != null) { - this.currentFn.done((function(_this) { - return function() { - return asyncFn.call(); - }; - })(this)); - } else { - asyncFn.call(); - } - return this.currentFn = asyncFn; - }; - - AsyncFn.setImmediate = (function() { - var ID, head, onmessage, tail; - head = {}; - tail = head; - ID = Math.random(); - onmessage = function(e) { - var func; - if (e.data !== ID) { - return; - } - head = head.next; - func = head.func; - delete head.func; - return func(); - }; - if (window.addEventListener) { - window.addEventListener("message", onmessage, false); - } else { - window.attachEvent("onmessage", onmessage); - } - if (window.postMessage) { - return function(func) { - tail = tail.next = { - func: func - }; - return window.postMessage(ID, "*"); - }; - } else { - return function(func) { - return setTimeout(func, 0); - }; - } - })(); - - return AsyncFn; - - })(); - - modula["export"]('vtree/async_fn', AsyncFn); - -}).call(this); - (function() { var Hooks, __slice = [].slice; @@ -941,9 +853,7 @@ }).call(this); (function() { - var AsyncFn, DOM; - - AsyncFn = modula.require('vtree/async_fn'); + var DOM; DOM = (function() { function DOM() {} diff --git a/build/vtree.min.js b/build/vtree.min.js index baa98cf..6b8963e 100644 --- a/build/vtree.min.js +++ b/build/vtree.min.js @@ -2,4 +2,4 @@ simple library for creating complicated architectures, by Sergey Shishkalov Sat Aug 23 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(){var t;return t=modula.require("vtree/async_fn"),t.addToCallQueue(function(e){return function(){var n;return n=new $.Deferred,t.setImmediate(function(){return e.initNodes(),n.resolve()}),n.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;t=function(){function t(t){this.fn=t}return t.prototype.done=function(t){return this.callback=t,this.isCalled?this.callback():void 0},t.prototype.call=function(){return this.isCalled?void 0:this.fn().always(function(t){return function(){return t.isCalled=!0,t.callback?t.callback():void 0}}(this))},t.addToCallQueue=function(e){var n;return n=new t(e),null!=this.currentFn?this.currentFn.done(function(){return function(){return n.call()}}(this)):n.call(),this.currentFn=n},t.setImmediate=function(){var t,e,n,o;return e={},o=e,t=Math.random(),n=function(n){var o;if(n.data===t)return e=e.next,o=e.func,delete e.func,o()},window.addEventListener?window.addEventListener("message",n,!1):window.attachEvent("onmessage",n),window.postMessage?function(e){return o=o.next={func:e},window.postMessage(t,"*")}:function(t){return setTimeout(t,0)}}(),t}(),modula["export"]("vtree/async_fn",t)}.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,a;for(t=1<=arguments.length?e.call(arguments,0):[],r=this.onInitCallbacks(),a=[],o=0,i=r.length;i>o;o++)n=r[o],a.push(n.apply(null,t));return a},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,a;for(t=1<=arguments.length?e.call(arguments,0):[],r=this.onActivationCallbacks(),a=[],o=0,i=r.length;i>o;o++)n=r[o],a.push(n.apply(null,t));return a},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,a;for(t=1<=arguments.length?e.call(arguments,0):[],r=this.onUnloadCallbacks(),a=[],o=0,i=r.length;i>o;o++)n=r[o],a.push(n.apply(null,t));return a},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,a;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!=(a=r.nodeWrapper)?a.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,a,s;for(t=$(r.config().selector),this.initialNodes=[],s=[],n=i=0,a=t.length;a>=0?a>i:i>a;n=a>=0?++i:--i)o=new e(t.eq(n),this.hooks),this.nodesCache.add(o),s.push(this.initialNodes.push(o));return s},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,a,s;for(s=[],i=0,a=t.length;a>i;i++)n=t[i],e=n.$el.parent().closest(r.config().selector),0===e.length?s.push(this.nodesCache.addAsRoot(n)):(o=e.data("vtree-node-id"),s.push(n.parent=this.nodesCache.getById(o)));return s},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,a,s,u,d,l;for(o=t.$el.find(r.config().selector),a=[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"))?s=this.nodesCache.getById(u):(s=new e(o.eq(i),this.hooks),this.nodesCache.add(s)),a.push(s);return this.setParentsForNodes(a),this.setChildrenForNodes(a),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,e;t=modula.require("vtree/async_fn"),e=function(){function e(){}return e.html=function(t,e){return t.html(e),t.trigger("refresh")},e.append=function(t,e){return t.append(e),t.trigger("refresh")},e.prepend=function(t,e){return t.prepend(e),t.trigger("refresh")},e.before=function(t,e){return t.before(e),t.parent().trigger("refresh")},e.after=function(t,e){return t.after(e),t.parent().trigger("refresh")},e.remove=function(t){return t.remove()},e.htmlAsync=function(e,n){return t.addToCallQueue(function(){var o;return o=new $.Deferred,t.setImmediate(function(){return e.html(n),e.trigger("refresh"),o.resolve()}),o.promise()})},e.appendAsync=function(e,n){return t.addToCallQueue(function(){var o;return o=new $.Deferred,t.setImmediate(function(){return e.append(n),e.trigger("refresh"),o.resolve()}),o.promise()})},e.prependAsync=function(e,n){return t.addToCallQueue(function(){var o;return o=new $.Deferred,t.setImmediate(function(){return e.prepend(n),e.trigger("refresh"),o.resolve()}),o.promise()})},e.beforeAsync=function(e,n){return t.addToCallQueue(function(){var o;return o=new $.Deferred,t.setImmediate(function(){return e.before(n),e.parent().trigger("refresh"),o.resolve()}),o.promise()})},e.afterAsync=function(e,n){return t.addToCallQueue(function(){var o;return o=new $.Deferred,t.setImmediate(function(){return e.after(n),e.parent().trigger("refresh"),o.resolve()}),o.promise()})},e}(),modula["export"]("vtree/dom",e),window.Vtree.DOM=e}.call(this); \ No newline at end of file +(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 5eec6f2..77e1a85 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vtree", - "version": "0.1.6-alpha", + "version": "0.1.7-alpha", "author": "Sergey Shishkalov ", "description": "Library for automated initialization of backbone views", "devDependencies": {