From 7e817662b386166d15fc254f8f09aeaca4a50c8a Mon Sep 17 00:00:00 2001 From: Niels Dequeker Date: Thu, 28 Jan 2016 21:56:45 +0100 Subject: [PATCH] Build v2.15.0 --- CHANGELOG.md | 4 + bower.json | 2 +- dist/angular-ui-tree.js | 161 ++++++++++++++++++++++++++---------- dist/angular-ui-tree.min.js | 6 +- package.json | 2 +- source/main.js | 2 +- 6 files changed, 126 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1eef667..3341f745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.15.0 + +* Remove scope dependency [#648](https://github.com/angular-ui-tree/angular-ui-tree/pull/648) + # 2.14.0 * Include the CSS source files in the build [#685](https://github.com/angular-ui-tree/angular-ui-tree/pull/685) diff --git a/bower.json b/bower.json index abc29ce8..2dc2af07 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-ui-tree", - "version": "2.14.0", + "version": "2.15.0", "homepage": "https://github.com/angular-ui-tree/angular-ui-tree", "authors": [ "Jim Liu ", diff --git a/dist/angular-ui-tree.js b/dist/angular-ui-tree.js index 3d1c43d5..66e01a1f 100644 --- a/dist/angular-ui-tree.js +++ b/dist/angular-ui-tree.js @@ -1,6 +1,6 @@ /** - * @license Angular UI Tree v2.14.0 - * (c) 2010-2015. https://github.com/angular-ui-tree/angular-ui-tree + * @license Angular UI Tree v2.15.0 + * (c) 2010-2016. https://github.com/angular-ui-tree/angular-ui-tree * License: MIT */ (function () { @@ -330,27 +330,6 @@ }; $scope.resetEmptyElement = this.resetEmptyElement; - - var collapseOrExpand = function (scope, collapsed) { - var i, subScope, - nodes = scope.childNodes(); - for (i = 0; i < nodes.length; i++) { - collapsed ? nodes[i].collapse() : nodes[i].expand(); - subScope = nodes[i].$childNodesScope; - if (subScope) { - collapseOrExpand(subScope, collapsed); - } - } - }; - - $scope.collapseAll = function () { - collapseOrExpand($scope.$nodesScope, true); - }; - - $scope.expandAll = function () { - collapseOrExpand($scope.$nodesScope, false); - }; - } ]); })(); @@ -601,7 +580,10 @@ bindDragMoveEvents, unbindDragMoveEvents, keydownHandler, - outOfBounds; + outOfBounds, + isHandleChild, + el; + angular.extend(config, treeConfig); if (config.nodeClass) { element.addClass(config.nodeClass); @@ -622,34 +604,52 @@ attrs.$set('collapsed', val); }); + scope.$on('angular-ui-tree:collapse-all', function () { + scope.collapsed = true; + }); + + scope.$on('angular-ui-tree:expand-all', function () { + scope.collapsed = false; + }); + /** * Called when the user has grabbed a node and started dragging it * @param e */ dragStart = function (e) { - if (!hasTouch && (e.button == 2 || e.which == 3)) { - // disable right click + // disable right click + if (!hasTouch && (e.button === 2 || e.which === 3)) { return; } - if (e.uiTreeDragging || (e.originalEvent && e.originalEvent.uiTreeDragging)) { // event has already fired in other scope. + + // event has already fired in other scope + if (e.uiTreeDragging || (e.originalEvent && e.originalEvent.uiTreeDragging)) { return; } // the node being dragged var eventElm = angular.element(e.target), - eventScope = eventElm.scope(), - cloneElm = element.clone(), - eventElmTagName, tagName, - eventObj, tdElm, hStyle; - if (!eventScope || !eventScope.$type) { - return; + isHandleChild, cloneElm, eventElmTagName, tagName, + eventObj, tdElm, hStyle, + isTreeNode, + isTreeNodeHandle; + + // if the target element is a child element of a ui-tree-handle, + // use the containing handle element as target element + isHandleChild = UiTreeHelper.treeNodeHandlerContainerOfElement(eventElm); + if (isHandleChild) { + eventElm = angular.element(isHandleChild); } - if (eventScope.$type != 'uiTreeNode' - && eventScope.$type != 'uiTreeHandle') { // Check if it is a node or a handle + + cloneElm = element.clone(); + isTreeNode = UiTreeHelper.elementIsTreeNode(eventElm); + isTreeNodeHandle = UiTreeHelper.elementIsTreeNodeHandle(eventElm); + + if (!isTreeNode && !isTreeNodeHandle) { return; } - if (eventScope.$type == 'uiTreeNode' - && eventScope.$handleScope) { // If the node has a handle, then it should be clicked by the handle + + if (isTreeNode && UiTreeHelper.elementContainsTreeNodeHandler(eventElm)) { return; } @@ -662,11 +662,12 @@ } // check if it or it's parents has a 'data-nodrag' attribute - while (eventElm && eventElm[0] && eventElm[0] != element) { - if (UiTreeHelper.nodrag(eventElm)) { // if the node mark as `nodrag`, DONOT drag it. + el = angular.element(e.target); + while (el && el[0] && el[0] !== element) { + if (UiTreeHelper.nodrag(el)) { // if the node mark as `nodrag`, DONOT drag it. return; } - eventElm = eventElm.parent(); + el = el.parent(); } if (!scope.beforeDrag(scope)) { @@ -852,13 +853,24 @@ targetElm = angular.element($window.document.elementFromPoint(targetX, targetY)); + // if the target element is a child element of a ui-tree-handle, + // use the containing handle element as target element + isHandleChild = UiTreeHelper.treeNodeHandlerContainerOfElement(targetElm); + if (isHandleChild) { + targetElm = angular.element(isHandleChild); + } + if (angular.isFunction(dragElm.show)) { dragElm.show(); } else { dragElm[0].style.display = displayElm; } - outOfBounds = !targetElm.scope() || !(targetElm.scope().$type); + outOfBounds = !UiTreeHelper.elementIsTreeNodeHandle(targetElm) && + !UiTreeHelper.elementIsTreeNode(targetElm) && + !UiTreeHelper.elementIsTreeNodes(targetElm) && + !UiTreeHelper.elementIsTree(targetElm) && + !UiTreeHelper.elementIsPlaceholder(targetElm); // Detect out of bounds condition, update drop target display, and prevent drop if (outOfBounds) { @@ -904,8 +916,22 @@ // move vertical if (!pos.dirAx) { + if (UiTreeHelper.elementIsTree(targetElm)) { + targetNode = targetElm.controller('uiTree').scope; + } else if (UiTreeHelper.elementIsTreeNodeHandle(targetElm)) { + targetNode = targetElm.controller('uiTreeHandle').scope; + } else if (UiTreeHelper.elementIsTreeNode(targetElm)) { + targetNode = targetElm.controller('uiTreeNode').scope; + } else if (UiTreeHelper.elementIsTreeNodes(targetElm)) { + targetNode = targetElm.controller('uiTreeNodes').scope; + } else if (UiTreeHelper.elementIsPlaceholder(targetElm)) { + targetNode = targetElm.controller('uiTreeNodes').scope; + } else if (targetElm.controller('uiTreeNode')) { + // is a child element of a node + targetNode = targetElm.controller('uiTreeNode').scope; + } + // check it's new position - targetNode = targetElm.scope(); isEmpty = false; if (!targetNode) { return; @@ -1186,8 +1212,8 @@ * @description * angular-ui-tree. */ - .factory('UiTreeHelper', ['$document', '$window', - function ($document, $window) { + .factory('UiTreeHelper', ['$document', '$window', 'treeConfig', + function ($document, $window, treeConfig) { return { /** @@ -1489,10 +1515,55 @@ } pos.dirAx = newAx; + }, + + elementIsTreeNode: function (element) { + return typeof element.attr('ui-tree-node') !== 'undefined'; + }, + + elementIsTreeNodeHandle: function (element) { + return typeof element.attr('ui-tree-handle') !== 'undefined'; + }, + elementIsTree: function (element) { + return typeof element.attr('ui-tree') !== 'undefined'; + }, + elementIsTreeNodes: function (element) { + return typeof element.attr('ui-tree-nodes') !== 'undefined'; + }, + elementIsPlaceholder: function (element) { + return element.hasClass(treeConfig.placeholderClass); + }, + elementContainsTreeNodeHandler: function (element) { + return element[0].querySelectorAll('[ui-tree-handle]').length >= 1; + }, + treeNodeHandlerContainerOfElement: function (element) { + return findFirstParentElementWithAttribute('ui-tree-handle', element[0]); } }; } - ]); + // TODO: optimize this loop + function findFirstParentElementWithAttribute(attributeName, childObj) { + // undefined if the mouse leaves the browser window + if (childObj === undefined) { + return null; + } + var testObj = childObj.parentNode, + count = 1, + // check for setAttribute due to exception thrown by Firefox when a node is dragged outside the browser window + res = (typeof testObj.setAttribute === 'function' && testObj.hasAttribute(attributeName)) ? testObj : null; + while (testObj && typeof testObj.setAttribute === 'function' && !testObj.hasAttribute(attributeName)) { + testObj = testObj.parentNode; + res = testObj; + if (testObj === document.documentElement) { + res = null; + break; + } + count++; + } + + return res; + } + })(); diff --git a/dist/angular-ui-tree.min.js b/dist/angular-ui-tree.min.js index 97e49890..1e3daab3 100644 --- a/dist/angular-ui-tree.min.js +++ b/dist/angular-ui-tree.min.js @@ -1,6 +1,6 @@ /** - * @license Angular UI Tree v2.14.0 - * (c) 2010-2015. https://github.com/angular-ui-tree/angular-ui-tree + * @license Angular UI Tree v2.15.0 + * (c) 2010-2016. https://github.com/angular-ui-tree/angular-ui-tree * License: MIT */ -!function(){"use strict";angular.module("ui.tree",[]).constant("treeConfig",{treeClass:"angular-ui-tree",emptyTreeClass:"angular-ui-tree-empty",hiddenClass:"angular-ui-tree-hidden",nodesClass:"angular-ui-tree-nodes",nodeClass:"angular-ui-tree-node",handleClass:"angular-ui-tree-handle",placeholderClass:"angular-ui-tree-placeholder",dragClass:"angular-ui-tree-drag",dragThreshold:3,levelThreshold:30,defaultCollapsed:!1})}(),function(){"use strict";angular.module("ui.tree").controller("TreeHandleController",["$scope","$element",function(e,n){this.scope=e,e.$element=n,e.$nodeScope=null,e.$type="uiTreeHandle"}])}(),function(){"use strict";angular.module("ui.tree").controller("TreeNodeController",["$scope","$element",function(e,n){function t(e){var n,o,l,r=0,i=e.childNodes();if(!i||0===i.length)return 0;for(l=i.length-1;l>=0;l--)n=i[l],o=1+t(n),r=Math.max(r,o);return r}this.scope=e,e.$element=n,e.$modelValue=null,e.$parentNodeScope=null,e.$childNodesScope=null,e.$parentNodesScope=null,e.$treeScope=null,e.$handleScope=null,e.$type="uiTreeNode",e.$$allowNodeDrop=!1,e.collapsed=!1,e.init=function(t){var o=t[0];e.$treeScope=t[1]?t[1].scope:null,e.$parentNodeScope=o.scope.$nodeScope,e.$modelValue=o.scope.$modelValue[e.$index],e.$parentNodesScope=o.scope,o.scope.initSubNode(e),n.on("$destroy",function(){o.scope.destroySubNode(e)})},e.index=function(){return e.$parentNodesScope.$modelValue.indexOf(e.$modelValue)},e.dragEnabled=function(){return!(e.$treeScope&&!e.$treeScope.dragEnabled)},e.isSibling=function(n){return e.$parentNodesScope==n.$parentNodesScope},e.isChild=function(n){var t=e.childNodes();return t&&t.indexOf(n)>-1},e.prev=function(){var n=e.index();return n>0?e.siblings()[n-1]:null},e.siblings=function(){return e.$parentNodesScope.childNodes()},e.childNodesCount=function(){return e.childNodes()?e.childNodes().length:0},e.hasChild=function(){return e.childNodesCount()>0},e.childNodes=function(){return e.$childNodesScope&&e.$childNodesScope.$modelValue?e.$childNodesScope.childNodes():null},e.accept=function(n,t){return e.$childNodesScope&&e.$childNodesScope.$modelValue&&e.$childNodesScope.accept(n,t)},e.remove=function(){return e.$parentNodesScope.removeNode(e)},e.toggle=function(){e.collapsed=!e.collapsed},e.collapse=function(){e.collapsed=!0},e.expand=function(){e.collapsed=!1},e.depth=function(){var n=e.$parentNodeScope;return n?n.depth()+1:1},e.maxSubDepth=function(){return e.$childNodesScope?t(e.$childNodesScope):0}}])}(),function(){"use strict";angular.module("ui.tree").controller("TreeNodesController",["$scope","$element",function(e,n){this.scope=e,e.$element=n,e.$modelValue=null,e.$nodeScope=null,e.$treeScope=null,e.$type="uiTreeNodes",e.$nodesMap={},e.nodropEnabled=!1,e.maxDepth=0,e.cloneEnabled=!1,e.initSubNode=function(n){return n.$modelValue?void(e.$nodesMap[n.$modelValue.$$hashKey]=n):null},e.destroySubNode=function(n){return n.$modelValue?void(e.$nodesMap[n.$modelValue.$$hashKey]=null):null},e.accept=function(n,t){return e.$treeScope.$callbacks.accept(n,e,t)},e.beforeDrag=function(n){return e.$treeScope.$callbacks.beforeDrag(n)},e.isParent=function(n){return n.$parentNodesScope==e},e.hasChild=function(){return e.$modelValue.length>0},e.safeApply=function(e){var n=this.$root.$$phase;"$apply"==n||"$digest"==n?e&&"function"==typeof e&&e():this.$apply(e)},e.removeNode=function(n){var t=e.$modelValue.indexOf(n.$modelValue);return t>-1?(e.safeApply(function(){e.$modelValue.splice(t,1)[0]}),e.$treeScope.$callbacks.removed(n)):null},e.insertNode=function(n,t){e.safeApply(function(){e.$modelValue.splice(n,0,t)})},e.childNodes=function(){var n,t=[];if(e.$modelValue)for(n=0;n0?e.depth()+n.maxSubDepth()+1>t:!1}}])}(),function(){"use strict";angular.module("ui.tree").controller("TreeController",["$scope","$element",function(e,n){this.scope=e,e.$element=n,e.$nodesScope=null,e.$type="uiTree",e.$emptyElm=null,e.$callbacks=null,e.dragEnabled=!0,e.emptyPlaceholderEnabled=!0,e.maxDepth=0,e.dragDelay=0,e.cloneEnabled=!1,e.nodropEnabled=!1,e.isEmpty=function(){return e.$nodesScope&&e.$nodesScope.$modelValue&&0===e.$nodesScope.$modelValue.length},e.place=function(n){e.$nodesScope.$element.append(n),e.$emptyElm.remove()},this.resetEmptyElement=function(){e.$nodesScope.$modelValue&&0!==e.$nodesScope.$modelValue.length||!e.emptyPlaceholderEnabled?e.$emptyElm.remove():n.append(e.$emptyElm)},e.resetEmptyElement=this.resetEmptyElement;var t=function(e,n){var o,l,r=e.childNodes();for(o=0;o0?angular.element(a).children().length:1e6,i=angular.element(n.document.createElement("td")).attr("colspan",d),t.$emptyElm.append(i)):t.$emptyElm=angular.element(n.document.createElement("div")),s.emptyTreeClass&&t.$emptyElm.addClass(s.emptyTreeClass),t.$watch("$nodesScope.$modelValue.length",function(e){angular.isNumber(e)&&r.resetEmptyElement()},!0),t.$watch(l.dragEnabled,function(e){"boolean"==typeof e&&(t.dragEnabled=e)}),t.$watch(l.emptyPlaceholderEnabled,function(e){"boolean"==typeof e&&(t.emptyPlaceholderEnabled=e,r.resetEmptyElement())}),t.$watch(l.nodropEnabled,function(e){"boolean"==typeof e&&(t.nodropEnabled=e)}),t.$watch(l.cloneEnabled,function(e){"boolean"==typeof e&&(t.cloneEnabled=e)}),t.$watch(l.maxDepth,function(e){"number"==typeof e&&(t.maxDepth=e)}),t.$watch(l.dragDelay,function(e){"number"==typeof e&&(t.dragDelay=e)}),c.accept=function(e,n){return!(n.nodropEnabled||n.$treeScope.nodropEnabled||n.outOfDepth(e))},c.beforeDrag=function(){return!0},c.removed=function(){},c.dropped=function(){},c.dragStart=function(){},c.dragMove=function(){},c.dragStop=function(){},c.beforeDrop=function(){},t.$watch(l.uiTree,function(e){angular.forEach(e,function(e,n){c[n]&&"function"==typeof e&&(c[n]=e)}),t.$callbacks=c},!0)}}}])}(),function(){"use strict";angular.module("ui.tree").directive("uiTreeHandle",["treeConfig",function(e){return{require:"^uiTreeNode",restrict:"A",scope:!0,controller:"TreeHandleController",link:function(n,t,o,l){var r={};angular.extend(r,e),r.handleClass&&t.addClass(r.handleClass),n!=l.scope&&(n.$nodeScope=l.scope,l.scope.$handleScope=n)}}}])}(),function(){"use strict";angular.module("ui.tree").directive("uiTreeNode",["treeConfig","UiTreeHelper","$window","$document","$timeout","$q","$rootElement",function(e,n,t,o,l,r,i){return{require:["^uiTreeNodes","^uiTree"],restrict:"A",controller:"TreeNodeController",link:function(a,d,c,s){var u,p,f,h,m,$,g,b,y,S,v,N,E,x,C,w,T,D,X,Y,A,V,H={},M="ontouchstart"in window,k=null,O=document.body,L=document.documentElement;angular.extend(H,e),H.nodeClass&&d.addClass(H.nodeClass),a.init(s),a.collapsed=!!n.getNodeAttribute(a,"collapsed")||e.defaultCollapsed,a.sourceOnly=a.nodropEnabled||a.$treeScope.nodropEnabled,a.$watch(c.collapsed,function(e){"boolean"==typeof e&&(a.collapsed=e)}),a.$watch("collapsed",function(e){n.setNodeAttribute(a,"collapsed",e),c.$set("collapsed",e)}),S=function(e){if((M||2!=e.button&&3!=e.which)&&!(e.uiTreeDragging||e.originalEvent&&e.originalEvent.uiTreeDragging)){var l,r,c,s,S,v=angular.element(e.target),N=v.scope(),E=d.clone();if(N&&N.$type&&!("uiTreeNode"!=N.$type&&"uiTreeHandle"!=N.$type||"uiTreeNode"==N.$type&&N.$handleScope||(l=v.prop("tagName").toLowerCase(),"input"==l||"textarea"==l||"button"==l||"select"==l))){for(;v&&v[0]&&v[0]!=d;){if(n.nodrag(v))return;v=v.parent()}a.beforeDrag(a)&&(e.uiTreeDragging=!0,e.originalEvent&&(e.originalEvent.uiTreeDragging=!0),e.preventDefault(),c=n.eventObj(e),u=!0,p=n.dragInfo(a),r=d.prop("tagName"),"tr"===r.toLowerCase()?(h=angular.element(t.document.createElement(r)),s=angular.element(t.document.createElement("td")).addClass(H.placeholderClass).attr("colspan",d[0].children.length),h.append(s)):h=angular.element(t.document.createElement(r)).addClass(H.placeholderClass),m=angular.element(t.document.createElement(r)),H.hiddenClass&&m.addClass(H.hiddenClass),f=n.positionStarted(c,d),h.css("height",n.height(d)+"px"),$=angular.element(t.document.createElement(a.$parentNodesScope.$element.prop("tagName"))).addClass(a.$parentNodesScope.$element.attr("class")).addClass(H.dragClass),$.css("width",n.width(d)+"px"),$.css("z-index",9999),S=(d[0].querySelector(".angular-ui-tree-handle")||d[0]).currentStyle,S&&(document.body.setAttribute("ui-tree-cursor",o.find("body").css("cursor")||""),o.find("body").css({cursor:S.cursor+"!important"})),a.sourceOnly&&h.css("display","none"),d.after(h),d.after(m),$.append(p.isClone()&&a.sourceOnly?E:d),i.append($),$.css({left:c.pageX-f.offsetX+"px",top:c.pageY-f.offsetY+"px"}),g={placeholder:h,dragging:$},X(),a.$apply(function(){a.$treeScope.$callbacks.dragStart(p.eventArgs(g,f))}),b=Math.max(O.scrollHeight,O.offsetHeight,L.clientHeight,L.scrollHeight,L.offsetHeight),y=Math.max(O.scrollWidth,O.offsetWidth,L.clientWidth,L.scrollWidth,L.offsetWidth))}}},v=function(e){var o,l,r,i,d,c,s,m,S,v,N,E,x,C,w,T,D=n.eventObj(e);if($){if(e.preventDefault(),t.getSelection?t.getSelection().removeAllRanges():t.document.selection&&t.document.selection.empty(),r=D.pageX-f.offsetX,i=D.pageY-f.offsetY,0>r&&(r=0),0>i&&(i=0),i+10>b&&(i=b-10),r+10>y&&(r=y-10),$.css({left:r+"px",top:i+"px"}),d=window.pageYOffset||t.document.documentElement.scrollTop,c=d+(window.innerHeight||t.document.clientHeight||t.document.clientHeight),c=c&&window.scrollBy(0,10),d>D.pageY&&window.scrollBy(0,-10),n.positionMoved(e,f,u),u)return void(u=!1);if(m=n.offset($).left-n.offset(h).left>=H.threshold,S=D.pageX-(t.pageXOffset||t.document.body.scrollLeft||t.document.documentElement.scrollLeft)-(t.document.documentElement.clientLeft||0),v=D.pageY-(t.pageYOffset||t.document.body.scrollTop||t.document.documentElement.scrollTop)-(t.document.documentElement.clientTop||0),angular.isFunction($.hide)?$.hide():(N=$[0].style.display,$[0].style.display="none"),t.document.elementFromPoint(S,v),x=angular.element(t.document.elementFromPoint(S,v)),angular.isFunction($.show)?$.show():$[0].style.display=N,V=!x.scope()||!x.scope().$type,V&&(h.remove(),k&&(k.resetEmptyElement(),k=null)),f.dirAx&&f.distAxX>=H.levelThreshold&&(f.distAxX=0,f.distX>0&&(o=p.prev(),o&&!o.collapsed&&o.accept(a,o.childNodesCount())&&(o.$childNodesScope.$element.append(h),p.moveTo(o.$childNodesScope,o.childNodes(),o.childNodesCount()))),f.distX<0&&(l=p.next(),l||(s=p.parentNode(),s&&s.$parentNodesScope.accept(a,s.index()+1)&&(s.$element.after(h),p.moveTo(s.$parentNodesScope,s.siblings(),s.index()+1))))),!f.dirAx){if(E=x.scope(),C=!1,!E)return;if(!E.$treeScope||E.$parent.nodropEnabled||E.$treeScope.nodropEnabled||h.css("display",""),"uiTree"==E.$type&&E.dragEnabled&&(C=E.isEmpty()),"uiTreeHandle"==E.$type&&(E=E.$nodeScope),"uiTreeNode"!=E.$type&&!C)return;k&&h.parent()[0]!=k.$element[0]&&(k.resetEmptyElement(),k=null),C?(k=E,E.$nodesScope.accept(a,0)&&(E.place(h),p.moveTo(E.$nodesScope,E.$nodesScope.childNodes(),0))):E.dragEnabled()&&(x=E.$element,w=n.offset(x),T=E.horizontal?D.pageX-1&&(this.siblings.splice(o,1),this.source.index()0?this.siblings[this.index-1]:null},next:function(){return this.index0&&(o=e.originalEvent.touches[0].pageX,l=e.originalEvent.touches[0].pageY),t.offsetX=o-this.offset(n).left,t.offsetY=l-this.offset(n).top,t.startX=t.lastX=o,t.startY=t.lastY=l,t.nowX=t.nowY=t.distX=t.distY=t.dirAx=0,t.dirX=t.dirY=t.lastDirX=t.lastDirY=t.distAxX=t.distAxY=0,t},positionMoved:function(e,n,t){var o,l=e.pageX,r=e.pageY;return e.originalEvent&&e.originalEvent.touches&&e.originalEvent.touches.length>0&&(l=e.originalEvent.touches[0].pageX,r=e.originalEvent.touches[0].pageY),n.lastX=n.nowX,n.lastY=n.nowY,n.nowX=l,n.nowY=r,n.distX=n.nowX-n.lastX,n.distY=n.nowY-n.lastY,n.lastDirX=n.dirX,n.lastDirY=n.dirY,n.dirX=0===n.distX?0:n.distX>0?1:-1,n.dirY=0===n.distY?0:n.distY>0?1:-1,o=Math.abs(n.distX)>Math.abs(n.distY)?1:0,t?(n.dirAx=o,void(n.moving=!0)):(n.dirAx!==o?(n.distAxX=0,n.distAxY=0):(n.distAxX+=Math.abs(n.distX),0!==n.dirX&&n.dirX!==n.lastDirX&&(n.distAxX=0),n.distAxY+=Math.abs(n.distY),0!==n.dirY&&n.dirY!==n.lastDirY&&(n.distAxY=0)),void(n.dirAx=o))}}}])}(); \ No newline at end of file +!function(){"use strict";angular.module("ui.tree",[]).constant("treeConfig",{treeClass:"angular-ui-tree",emptyTreeClass:"angular-ui-tree-empty",hiddenClass:"angular-ui-tree-hidden",nodesClass:"angular-ui-tree-nodes",nodeClass:"angular-ui-tree-node",handleClass:"angular-ui-tree-handle",placeholderClass:"angular-ui-tree-placeholder",dragClass:"angular-ui-tree-drag",dragThreshold:3,levelThreshold:30,defaultCollapsed:!1})}(),function(){"use strict";angular.module("ui.tree").controller("TreeHandleController",["$scope","$element",function(e,n){this.scope=e,e.$element=n,e.$nodeScope=null,e.$type="uiTreeHandle"}])}(),function(){"use strict";angular.module("ui.tree").controller("TreeNodeController",["$scope","$element",function(e,n){function t(e){var n,o,l,r=0,a=e.childNodes();if(!a||0===a.length)return 0;for(l=a.length-1;l>=0;l--)n=a[l],o=1+t(n),r=Math.max(r,o);return r}this.scope=e,e.$element=n,e.$modelValue=null,e.$parentNodeScope=null,e.$childNodesScope=null,e.$parentNodesScope=null,e.$treeScope=null,e.$handleScope=null,e.$type="uiTreeNode",e.$$allowNodeDrop=!1,e.collapsed=!1,e.init=function(t){var o=t[0];e.$treeScope=t[1]?t[1].scope:null,e.$parentNodeScope=o.scope.$nodeScope,e.$modelValue=o.scope.$modelValue[e.$index],e.$parentNodesScope=o.scope,o.scope.initSubNode(e),n.on("$destroy",function(){o.scope.destroySubNode(e)})},e.index=function(){return e.$parentNodesScope.$modelValue.indexOf(e.$modelValue)},e.dragEnabled=function(){return!(e.$treeScope&&!e.$treeScope.dragEnabled)},e.isSibling=function(n){return e.$parentNodesScope==n.$parentNodesScope},e.isChild=function(n){var t=e.childNodes();return t&&t.indexOf(n)>-1},e.prev=function(){var n=e.index();return n>0?e.siblings()[n-1]:null},e.siblings=function(){return e.$parentNodesScope.childNodes()},e.childNodesCount=function(){return e.childNodes()?e.childNodes().length:0},e.hasChild=function(){return e.childNodesCount()>0},e.childNodes=function(){return e.$childNodesScope&&e.$childNodesScope.$modelValue?e.$childNodesScope.childNodes():null},e.accept=function(n,t){return e.$childNodesScope&&e.$childNodesScope.$modelValue&&e.$childNodesScope.accept(n,t)},e.remove=function(){return e.$parentNodesScope.removeNode(e)},e.toggle=function(){e.collapsed=!e.collapsed},e.collapse=function(){e.collapsed=!0},e.expand=function(){e.collapsed=!1},e.depth=function(){var n=e.$parentNodeScope;return n?n.depth()+1:1},e.maxSubDepth=function(){return e.$childNodesScope?t(e.$childNodesScope):0}}])}(),function(){"use strict";angular.module("ui.tree").controller("TreeNodesController",["$scope","$element",function(e,n){this.scope=e,e.$element=n,e.$modelValue=null,e.$nodeScope=null,e.$treeScope=null,e.$type="uiTreeNodes",e.$nodesMap={},e.nodropEnabled=!1,e.maxDepth=0,e.cloneEnabled=!1,e.initSubNode=function(n){return n.$modelValue?void(e.$nodesMap[n.$modelValue.$$hashKey]=n):null},e.destroySubNode=function(n){return n.$modelValue?void(e.$nodesMap[n.$modelValue.$$hashKey]=null):null},e.accept=function(n,t){return e.$treeScope.$callbacks.accept(n,e,t)},e.beforeDrag=function(n){return e.$treeScope.$callbacks.beforeDrag(n)},e.isParent=function(n){return n.$parentNodesScope==e},e.hasChild=function(){return e.$modelValue.length>0},e.safeApply=function(e){var n=this.$root.$$phase;"$apply"==n||"$digest"==n?e&&"function"==typeof e&&e():this.$apply(e)},e.removeNode=function(n){var t=e.$modelValue.indexOf(n.$modelValue);return t>-1?(e.safeApply(function(){e.$modelValue.splice(t,1)[0]}),e.$treeScope.$callbacks.removed(n)):null},e.insertNode=function(n,t){e.safeApply(function(){e.$modelValue.splice(n,0,t)})},e.childNodes=function(){var n,t=[];if(e.$modelValue)for(n=0;n0?e.depth()+n.maxSubDepth()+1>t:!1}}])}(),function(){"use strict";angular.module("ui.tree").controller("TreeController",["$scope","$element",function(e,n){this.scope=e,e.$element=n,e.$nodesScope=null,e.$type="uiTree",e.$emptyElm=null,e.$callbacks=null,e.dragEnabled=!0,e.emptyPlaceholderEnabled=!0,e.maxDepth=0,e.dragDelay=0,e.cloneEnabled=!1,e.nodropEnabled=!1,e.isEmpty=function(){return e.$nodesScope&&e.$nodesScope.$modelValue&&0===e.$nodesScope.$modelValue.length},e.place=function(n){e.$nodesScope.$element.append(n),e.$emptyElm.remove()},this.resetEmptyElement=function(){e.$nodesScope.$modelValue&&0!==e.$nodesScope.$modelValue.length||!e.emptyPlaceholderEnabled?e.$emptyElm.remove():n.append(e.$emptyElm)},e.resetEmptyElement=this.resetEmptyElement}])}(),function(){"use strict";angular.module("ui.tree").directive("uiTree",["treeConfig","$window",function(e,n){return{restrict:"A",scope:!0,controller:"TreeController",link:function(t,o,l,r){var a,i,d,c={accept:null,beforeDrag:null},s={};angular.extend(s,e),s.treeClass&&o.addClass(s.treeClass),"table"===o.prop("tagName").toLowerCase()?(t.$emptyElm=angular.element(n.document.createElement("tr")),i=o.find("tr"),d=i.length>0?angular.element(i).children().length:1e6,a=angular.element(n.document.createElement("td")).attr("colspan",d),t.$emptyElm.append(a)):t.$emptyElm=angular.element(n.document.createElement("div")),s.emptyTreeClass&&t.$emptyElm.addClass(s.emptyTreeClass),t.$watch("$nodesScope.$modelValue.length",function(e){angular.isNumber(e)&&r.resetEmptyElement()},!0),t.$watch(l.dragEnabled,function(e){"boolean"==typeof e&&(t.dragEnabled=e)}),t.$watch(l.emptyPlaceholderEnabled,function(e){"boolean"==typeof e&&(t.emptyPlaceholderEnabled=e,r.resetEmptyElement())}),t.$watch(l.nodropEnabled,function(e){"boolean"==typeof e&&(t.nodropEnabled=e)}),t.$watch(l.cloneEnabled,function(e){"boolean"==typeof e&&(t.cloneEnabled=e)}),t.$watch(l.maxDepth,function(e){"number"==typeof e&&(t.maxDepth=e)}),t.$watch(l.dragDelay,function(e){"number"==typeof e&&(t.dragDelay=e)}),c.accept=function(e,n){return!(n.nodropEnabled||n.$treeScope.nodropEnabled||n.outOfDepth(e))},c.beforeDrag=function(){return!0},c.removed=function(){},c.dropped=function(){},c.dragStart=function(){},c.dragMove=function(){},c.dragStop=function(){},c.beforeDrop=function(){},t.$watch(l.uiTree,function(e){angular.forEach(e,function(e,n){c[n]&&"function"==typeof e&&(c[n]=e)}),t.$callbacks=c},!0)}}}])}(),function(){"use strict";angular.module("ui.tree").directive("uiTreeHandle",["treeConfig",function(e){return{require:"^uiTreeNode",restrict:"A",scope:!0,controller:"TreeHandleController",link:function(n,t,o,l){var r={};angular.extend(r,e),r.handleClass&&t.addClass(r.handleClass),n!=l.scope&&(n.$nodeScope=l.scope,l.scope.$handleScope=n)}}}])}(),function(){"use strict";angular.module("ui.tree").directive("uiTreeNode",["treeConfig","UiTreeHelper","$window","$document","$timeout","$q","$rootElement",function(e,n,t,o,l,r,a){return{require:["^uiTreeNodes","^uiTree"],restrict:"A",controller:"TreeNodeController",link:function(i,d,c,s){var u,p,f,m,h,$,g,b,N,y,v,S,E,T,x,C,w,D,X,Y,A,V,H,I,O={},k="ontouchstart"in window,M=null,P=document.body,L=document.documentElement;angular.extend(O,e),O.nodeClass&&d.addClass(O.nodeClass),i.init(s),i.collapsed=!!n.getNodeAttribute(i,"collapsed")||e.defaultCollapsed,i.sourceOnly=i.nodropEnabled||i.$treeScope.nodropEnabled,i.$watch(c.collapsed,function(e){"boolean"==typeof e&&(i.collapsed=e)}),i.$watch("collapsed",function(e){n.setNodeAttribute(i,"collapsed",e),c.$set("collapsed",e)}),i.$on("angular-ui-tree:collapse-all",function(){i.collapsed=!0}),i.$on("angular-ui-tree:expand-all",function(){i.collapsed=!1}),y=function(e){if((k||2!==e.button&&3!==e.which)&&!(e.uiTreeDragging||e.originalEvent&&e.originalEvent.uiTreeDragging)){var l,r,c,s,y,v,S,E,T,x=angular.element(e.target);if(l=n.treeNodeHandlerContainerOfElement(x),l&&(x=angular.element(l)),r=d.clone(),E=n.elementIsTreeNode(x),T=n.elementIsTreeNodeHandle(x),(E||T)&&!(E&&n.elementContainsTreeNodeHandler(x)||(c=x.prop("tagName").toLowerCase(),"input"==c||"textarea"==c||"button"==c||"select"==c))){for(I=angular.element(e.target);I&&I[0]&&I[0]!==d;){if(n.nodrag(I))return;I=I.parent()}i.beforeDrag(i)&&(e.uiTreeDragging=!0,e.originalEvent&&(e.originalEvent.uiTreeDragging=!0),e.preventDefault(),y=n.eventObj(e),u=!0,p=n.dragInfo(i),s=d.prop("tagName"),"tr"===s.toLowerCase()?(m=angular.element(t.document.createElement(s)),v=angular.element(t.document.createElement("td")).addClass(O.placeholderClass).attr("colspan",d[0].children.length),m.append(v)):m=angular.element(t.document.createElement(s)).addClass(O.placeholderClass),h=angular.element(t.document.createElement(s)),O.hiddenClass&&h.addClass(O.hiddenClass),f=n.positionStarted(y,d),m.css("height",n.height(d)+"px"),$=angular.element(t.document.createElement(i.$parentNodesScope.$element.prop("tagName"))).addClass(i.$parentNodesScope.$element.attr("class")).addClass(O.dragClass),$.css("width",n.width(d)+"px"),$.css("z-index",9999),S=(d[0].querySelector(".angular-ui-tree-handle")||d[0]).currentStyle,S&&(document.body.setAttribute("ui-tree-cursor",o.find("body").css("cursor")||""),o.find("body").css({cursor:S.cursor+"!important"})),i.sourceOnly&&m.css("display","none"),d.after(m),d.after(h),$.append(p.isClone()&&i.sourceOnly?r:d),a.append($),$.css({left:y.pageX-f.offsetX+"px",top:y.pageY-f.offsetY+"px"}),g={placeholder:m,dragging:$},X(),i.$apply(function(){i.$treeScope.$callbacks.dragStart(p.eventArgs(g,f))}),b=Math.max(P.scrollHeight,P.offsetHeight,L.clientHeight,L.scrollHeight,L.offsetHeight),N=Math.max(P.scrollWidth,P.offsetWidth,L.clientWidth,L.scrollWidth,L.offsetWidth))}}},v=function(e){var o,l,r,a,d,c,s,h,y,v,S,E,T,x,C,w,D=n.eventObj(e);if($){if(e.preventDefault(),t.getSelection?t.getSelection().removeAllRanges():t.document.selection&&t.document.selection.empty(),r=D.pageX-f.offsetX,a=D.pageY-f.offsetY,0>r&&(r=0),0>a&&(a=0),a+10>b&&(a=b-10),r+10>N&&(r=N-10),$.css({left:r+"px",top:a+"px"}),d=window.pageYOffset||t.document.documentElement.scrollTop,c=d+(window.innerHeight||t.document.clientHeight||t.document.clientHeight),c=c&&window.scrollBy(0,10),d>D.pageY&&window.scrollBy(0,-10),n.positionMoved(e,f,u),u)return void(u=!1);if(h=n.offset($).left-n.offset(m).left>=O.threshold,y=D.pageX-(t.pageXOffset||t.document.body.scrollLeft||t.document.documentElement.scrollLeft)-(t.document.documentElement.clientLeft||0),v=D.pageY-(t.pageYOffset||t.document.body.scrollTop||t.document.documentElement.scrollTop)-(t.document.documentElement.clientTop||0),angular.isFunction($.hide)?$.hide():(S=$[0].style.display,$[0].style.display="none"),t.document.elementFromPoint(y,v),T=angular.element(t.document.elementFromPoint(y,v)),H=n.treeNodeHandlerContainerOfElement(T),H&&(T=angular.element(H)),angular.isFunction($.show)?$.show():$[0].style.display=S,V=!(n.elementIsTreeNodeHandle(T)||n.elementIsTreeNode(T)||n.elementIsTreeNodes(T)||n.elementIsTree(T)||n.elementIsPlaceholder(T)),V&&(m.remove(),M&&(M.resetEmptyElement(),M=null)),f.dirAx&&f.distAxX>=O.levelThreshold&&(f.distAxX=0,f.distX>0&&(o=p.prev(),o&&!o.collapsed&&o.accept(i,o.childNodesCount())&&(o.$childNodesScope.$element.append(m),p.moveTo(o.$childNodesScope,o.childNodes(),o.childNodesCount()))),f.distX<0&&(l=p.next(),l||(s=p.parentNode(),s&&s.$parentNodesScope.accept(i,s.index()+1)&&(s.$element.after(m),p.moveTo(s.$parentNodesScope,s.siblings(),s.index()+1))))),!f.dirAx){if(n.elementIsTree(T)?E=T.controller("uiTree").scope:n.elementIsTreeNodeHandle(T)?E=T.controller("uiTreeHandle").scope:n.elementIsTreeNode(T)?E=T.controller("uiTreeNode").scope:n.elementIsTreeNodes(T)?E=T.controller("uiTreeNodes").scope:n.elementIsPlaceholder(T)?E=T.controller("uiTreeNodes").scope:T.controller("uiTreeNode")&&(E=T.controller("uiTreeNode").scope),x=!1,!E)return;if(!E.$treeScope||E.$parent.nodropEnabled||E.$treeScope.nodropEnabled||m.css("display",""),"uiTree"==E.$type&&E.dragEnabled&&(x=E.isEmpty()),"uiTreeHandle"==E.$type&&(E=E.$nodeScope),"uiTreeNode"!=E.$type&&!x)return;M&&m.parent()[0]!=M.$element[0]&&(M.resetEmptyElement(),M=null),x?(M=E,E.$nodesScope.accept(i,0)&&(E.place(m),p.moveTo(E.$nodesScope,E.$nodesScope.childNodes(),0))):E.dragEnabled()&&(T=E.$element,C=n.offset(T),w=E.horizontal?D.pageX-1&&(this.siblings.splice(o,1),this.source.index()0?this.siblings[this.index-1]:null},next:function(){return this.index0&&(o=e.originalEvent.touches[0].pageX,l=e.originalEvent.touches[0].pageY),t.offsetX=o-this.offset(n).left,t.offsetY=l-this.offset(n).top,t.startX=t.lastX=o,t.startY=t.lastY=l,t.nowX=t.nowY=t.distX=t.distY=t.dirAx=0,t.dirX=t.dirY=t.lastDirX=t.lastDirY=t.distAxX=t.distAxY=0,t},positionMoved:function(e,n,t){var o,l=e.pageX,r=e.pageY;return e.originalEvent&&e.originalEvent.touches&&e.originalEvent.touches.length>0&&(l=e.originalEvent.touches[0].pageX,r=e.originalEvent.touches[0].pageY),n.lastX=n.nowX,n.lastY=n.nowY,n.nowX=l,n.nowY=r,n.distX=n.nowX-n.lastX,n.distY=n.nowY-n.lastY,n.lastDirX=n.dirX,n.lastDirY=n.dirY,n.dirX=0===n.distX?0:n.distX>0?1:-1,n.dirY=0===n.distY?0:n.distY>0?1:-1,o=Math.abs(n.distX)>Math.abs(n.distY)?1:0,t?(n.dirAx=o,void(n.moving=!0)):(n.dirAx!==o?(n.distAxX=0,n.distAxY=0):(n.distAxX+=Math.abs(n.distX),0!==n.dirX&&n.dirX!==n.lastDirX&&(n.distAxX=0),n.distAxY+=Math.abs(n.distY),0!==n.dirY&&n.dirY!==n.lastDirY&&(n.distAxY=0)),void(n.dirAx=o))},elementIsTreeNode:function(e){return"undefined"!=typeof e.attr("ui-tree-node")},elementIsTreeNodeHandle:function(e){return"undefined"!=typeof e.attr("ui-tree-handle")},elementIsTree:function(e){return"undefined"!=typeof e.attr("ui-tree")},elementIsTreeNodes:function(e){return"undefined"!=typeof e.attr("ui-tree-nodes")},elementIsPlaceholder:function(e){return e.hasClass(o.placeholderClass)},elementContainsTreeNodeHandler:function(e){return e[0].querySelectorAll("[ui-tree-handle]").length>=1},treeNodeHandlerContainerOfElement:function(n){return e("ui-tree-handle",n[0])}}}])}(); \ No newline at end of file diff --git a/package.json b/package.json index 5a54d3e1..9d4b941f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-ui-tree", - "version": "2.14.0", + "version": "2.15.0", "description": "An AngularJS UI component that can sort nested lists, provides drag & drop support and doesn't depend on jQuery", "license": "MIT", "repository": { diff --git a/source/main.js b/source/main.js index ea2b564d..14d69fb5 100644 --- a/source/main.js +++ b/source/main.js @@ -1,5 +1,5 @@ /** - * @license Angular UI Tree v2.14.0 + * @license Angular UI Tree v2.15.0 * (c) 2010-2016. https://github.com/angular-ui-tree/angular-ui-tree * License: MIT */