| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963 |
- AUI.add('aui-tree-view', function(A) {
- /**
- * The TreeView Utility
- *
- * @module aui-tree
- * @submodule aui-tree-view
- */
-
- var L = A.Lang,
- isBoolean = L.isBoolean,
- isString = L.isString,
-
- UA = A.UA,
-
- BOUNDING_BOX = 'boundingBox',
- CHILDREN = 'children',
- CONTAINER = 'container',
- CONTENT = 'content',
- CONTENT_BOX = 'contentBox',
- DOT = '.',
- FILE = 'file',
- HITAREA = 'hitarea',
- ICON = 'icon',
- INVALID = 'invalid',
- LABEL = 'label',
- LAST_SELECTED = 'lastSelected',
- LEAF = 'leaf',
- NODE = 'node',
- OWNER_TREE = 'ownerTree',
- ROOT = 'root',
- SELECT_ON_TOGGLE = 'selectOnToggle',
- SPACE = ' ',
- TREE = 'tree',
- TREE_NODE = 'tree-node',
- TREE_VIEW = 'tree-view',
- TYPE = 'type',
- VIEW = 'view',
-
- concat = function() {
- return Array.prototype.slice.call(arguments).join(SPACE);
- },
-
- isTreeNode = function(v) {
- return ( v instanceof A.TreeNode );
- },
-
- getCN = A.getClassName,
-
- CSS_TREE_HITAREA = getCN(TREE, HITAREA),
- CSS_TREE_ICON = getCN(TREE, ICON),
- CSS_TREE_LABEL = getCN(TREE, LABEL),
- CSS_TREE_NODE_CONTENT = getCN(TREE, NODE, CONTENT),
- CSS_TREE_NODE_CONTENT_INVALID = getCN(TREE, NODE, CONTENT, INVALID),
- CSS_TREE_ROOT_CONTAINER = getCN(TREE, ROOT, CONTAINER),
- CSS_TREE_VIEW_CONTENT = getCN(TREE, VIEW, CONTENT);
-
- /**
- * <p><img src="assets/images/aui-tree-view/main.png"/></p>
- *
- * A base class for TreeView, providing:
- * <ul>
- * <li>Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)</li>
- * </ul>
- *
- * Quick Example:<br/>
- *
- * <pre><code>var tree2 = new A.TreeView({
- * width: 200,
- * type: 'normal',
- * boundingBox: '#tree',
- * children: [
- * { label: 'Folder 1', children: [ { label: 'file' }, { label: 'file' }, { label: 'file' } ] },
- * { label: 'Folder 2', expanded: true, children: [ { label: 'file' }, { label: 'file' } ] },
- * { label: 'Folder 3', children: [ { label: 'file' } ] },
- * { label: 'Folder 4', expanded: true, children: [ { label: 'Folder 4-1', expanded: true, children: [ { label: 'file' } ] } ] }
- * ]
- * })
- * .render();
- * </code></pre>
- *
- * Check the list of <a href="TreeView.html#configattributes">Configuration Attributes</a> available for
- * TreeView.
- *
- * @param config {Object} Object literal specifying widget configuration properties.
- *
- * @class TreeView
- * @constructor
- * @extends TreeData
- */
- var TreeView = A.Component.create(
- {
- /**
- * Static property provides a string to identify the class.
- *
- * @property TreeView.NAME
- * @type String
- * @static
- */
- NAME: TREE_VIEW,
-
- /**
- * Static property used to define the default attribute
- * configuration for the TreeView.
- *
- * @property TreeView.ATTRS
- * @type Object
- * @static
- */
- ATTRS: {
- /**
- * Type of the treeview (i.e. could be 'file' or 'normal').
- *
- * @attribute type
- * @default 'file'
- * @type String
- */
- type: {
- value: FILE,
- validator: isString
- },
-
- /**
- * Last selected TreeNode.
- *
- * @attribute lastSelected
- * @default null
- * @type TreeNode
- */
- lastSelected: {
- value: null,
- validator: isTreeNode
- },
-
- lazyLoad: {
- validator: isBoolean,
- value: true
- },
-
- selectOnToggle: {
- validator: isBoolean,
- value: false
- }
- },
-
- AUGMENTS: [A.TreeData, A.TreeViewPaginator, A.TreeViewIO],
-
- prototype: {
- CONTENT_TEMPLATE: '<ul></ul>',
-
- initializer: function() {
- var instance = this;
- var boundingBox = instance.get(BOUNDING_BOX);
-
- boundingBox.setData(TREE_VIEW, instance);
-
- instance.initTreeData();
- },
-
- /**
- * Bind the events on the TreeView UI. Lifecycle.
- *
- * @method bindUI
- * @protected
- */
- bindUI: function() {
- var instance = this;
-
- instance.after('childrenChange', A.bind(instance._afterSetChildren, instance));
-
- instance._delegateDOM();
- },
-
- /**
- * Create the DOM structure for the TreeView. Lifecycle.
- *
- * @method renderUI
- * @protected
- */
- renderUI: function() {
- var instance = this;
-
- instance._renderElements();
- },
-
- /**
- * Fires after set children.
- *
- * @method _afterSetChildren
- * @param {EventFacade} event
- * @protected
- */
- _afterSetChildren: function(event) {
- var instance = this;
-
- var paginator = instance.get('paginator');
-
- if (paginator && paginator.total) {
- var increment = -1;
-
- if (event.newVal.length > event.prevVal.length) {
- increment = 1;
- }
-
- paginator.total += increment;
- }
-
- instance._syncPaginatorUI();
- },
-
- /**
- * Create TreeNode from HTML markup.
- *
- * @method _createFromHTMLMarkup
- * @param {Node} container
- * @protected
- */
- _createFromHTMLMarkup: function(container) {
- var instance = this;
-
- container.all('> li').each(function(node) {
- // use firstChild as label
- var labelEl = node.one('> *').remove();
- var label = labelEl.outerHTML();
- var deepContainer = node.one('> ul');
-
- var treeNode = new A.TreeNode({
- boundingBox: node,
- container: deepContainer,
- label: label,
- leaf: !deepContainer,
- ownerTree: instance
- });
-
- if (instance.get('lazyLoad')) {
- A.setTimeout(function() {
- treeNode.render();
- }, 50);
- }
- else {
- treeNode.render();
- }
-
- // find the parent TreeNode...
- var parentNode = node.get(PARENT_NODE).get(PARENT_NODE);
- var parentInstance = parentNode.getData(TREE_NODE);
-
- if (!A.instanceOf(parentInstance, A.TreeNode)) {
- parentInstance = parentNode.getData(TREE_VIEW);
- }
-
- // and simulate the appendChild.
- parentInstance.appendChild(treeNode);
-
- if (deepContainer) {
- // propgating markup recursion
- instance._createFromHTMLMarkup(deepContainer);
- }
- });
- },
-
- _createNodeContainer: function() {
- var instance = this;
- var contentBox = instance.get(CONTENT_BOX);
-
- instance.set(CONTAINER, contentBox);
-
- return contentBox;
- },
-
- /**
- * Render elements.
- *
- * @method _renderElements
- * @protected
- */
- _renderElements: function() {
- var instance = this;
- var contentBox = instance.get(CONTENT_BOX);
- var children = instance.get(CHILDREN);
- var type = instance.get(TYPE);
- var CSS_TREE_TYPE = getCN(TREE, type);
-
- contentBox.addClass(CSS_TREE_VIEW_CONTENT);
-
- contentBox.addClass(
- concat(CSS_TREE_TYPE, CSS_TREE_ROOT_CONTAINER)
- );
-
- if (!children.length) {
- // if children not specified try to create from markup
- instance._createFromHTMLMarkup(contentBox);
- }
- },
-
- /**
- * Delegate events.
- *
- * @method _delegateDOM
- * @protected
- */
- _delegateDOM: function() {
- var instance = this;
-
- var boundingBox = instance.get(BOUNDING_BOX);
-
- // expand/collapse delegations
- boundingBox.delegate('click', A.bind(instance._onClickNodeEl, instance), DOT+CSS_TREE_NODE_CONTENT);
- boundingBox.delegate('dblclick', A.bind(instance._onClickHitArea, instance), DOT+CSS_TREE_ICON);
- boundingBox.delegate('dblclick', A.bind(instance._onClickHitArea, instance), DOT+CSS_TREE_LABEL);
- // other delegations
- boundingBox.delegate('mouseenter', A.bind(instance._onMouseEnterNodeEl, instance), DOT+CSS_TREE_NODE_CONTENT);
- boundingBox.delegate('mouseleave', A.bind(instance._onMouseLeaveNodeEl, instance), DOT+CSS_TREE_NODE_CONTENT);
- },
-
- /**
- * Fires on click the TreeView (i.e. set the select/unselect state).
- *
- * @method _onClickNodeEl
- * @param {EventFacade} event
- * @protected
- */
- _onClickNodeEl: function(event) {
- var instance = this;
-
- var treeNode = instance.getNodeByChild( event.currentTarget );
-
- if (treeNode) {
- if (event.target.test(DOT+CSS_TREE_HITAREA)) {
- treeNode.toggle();
-
- if (!instance.get(SELECT_ON_TOGGLE)) {
- return;
- }
- }
-
- if (!treeNode.isSelected()) {
- var lastSelected = instance.get(LAST_SELECTED);
-
- // select drag node
- if (lastSelected) {
- lastSelected.unselect();
- }
-
- treeNode.select();
- }
- }
- },
-
- /**
- * Fires on <code>mouseeneter</code> the TreeNode.
- *
- * @method _onMouseEnterNodeEl
- * @param {EventFacade} event
- * @protected
- */
- _onMouseEnterNodeEl: function(event) {
- var instance = this;
- var treeNode = instance.getNodeByChild( event.currentTarget );
-
- if (treeNode) {
- treeNode.over();
- }
- },
-
- /**
- * Fires on <code>mouseleave</code> the TreeNode.
- *
- * @method _onMouseLeaveNodeEl
- * @param {EventFacade} event
- * @protected
- */
- _onMouseLeaveNodeEl: function(event) {
- var instance = this;
- var treeNode = instance.getNodeByChild( event.currentTarget );
-
- if (treeNode) {
- treeNode.out();
- }
- },
-
- /**
- * Fires on <code>click</code> the TreeNode hitarea.
- *
- * @method _onClickHitArea
- * @param {EventFacade} event
- * @protected
- */
- _onClickHitArea: function(event) {
- var instance = this;
- var treeNode = instance.getNodeByChild( event.currentTarget );
-
- if (treeNode) {
- treeNode.toggle();
- }
- }
- }
- }
- );
-
- A.TreeView = TreeView;
-
- /*
- * TreeViewDD - Drag & Drop
- */
- var isNumber = L.isNumber,
-
- ABOVE = 'above',
- APPEND = 'append',
- BELOW = 'below',
- BLOCK = 'block',
- BODY = 'body',
- CLEARFIX = 'clearfix',
- DEFAULT = 'default',
- DISPLAY = 'display',
- DOWN = 'down',
- DRAG = 'drag',
- DRAGGABLE = 'draggable',
- DRAG_CURSOR = 'dragCursor',
- DRAG_NODE = 'dragNode',
- EXPANDED = 'expanded',
- HELPER = 'helper',
- INSERT = 'insert',
- OFFSET_HEIGHT = 'offsetHeight',
- PARENT_NODE = 'parentNode',
- SCROLL_DELAY = 'scrollDelay',
- STATE = 'state',
- TREE_DRAG_DROP = 'tree-drag-drop',
- UP = 'up',
-
- DDM = A.DD.DDM,
-
- CSS_HELPER_CLEARFIX = getCN(HELPER, CLEARFIX),
- CSS_ICON = getCN(ICON),
- CSS_TREE_DRAG_HELPER = getCN(TREE, DRAG, HELPER),
- CSS_TREE_DRAG_HELPER_CONTENT = getCN(TREE, DRAG, HELPER, CONTENT),
- CSS_TREE_DRAG_HELPER_LABEL = getCN(TREE, DRAG, HELPER, LABEL),
- CSS_TREE_DRAG_INSERT_ABOVE = getCN(TREE, DRAG, INSERT, ABOVE),
- CSS_TREE_DRAG_INSERT_APPEND = getCN(TREE, DRAG, INSERT, APPEND),
- CSS_TREE_DRAG_INSERT_BELOW = getCN(TREE, DRAG, INSERT, BELOW),
- CSS_TREE_DRAG_STATE_APPEND = getCN(TREE, DRAG, STATE, APPEND),
- CSS_TREE_DRAG_STATE_INSERT_ABOVE = getCN(TREE, DRAG, STATE, INSERT, ABOVE),
- CSS_TREE_DRAG_STATE_INSERT_BELOW = getCN(TREE, DRAG, STATE, INSERT, BELOW),
-
- HELPER_TPL = '<div class="'+CSS_TREE_DRAG_HELPER+'">'+
- '<div class="'+[CSS_TREE_DRAG_HELPER_CONTENT, CSS_HELPER_CLEARFIX].join(SPACE)+'">'+
- '<span class="'+CSS_ICON+'"></span>'+
- '<span class="'+CSS_TREE_DRAG_HELPER_LABEL+'"></span>'+
- '</div>'+
- '</div>';
-
- /**
- * A base class for TreeViewDD, providing:
- * <ul>
- * <li>Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)</li>
- * <li>DragDrop support for the TreeNodes</li>
- * </ul>
- *
- * Quick Example:<br/>
- *
- * Check the list of <a href="TreeViewDD.html#configattributes">Configuration Attributes</a> available for
- * TreeViewDD.
- *
- * @param config {Object} Object literal specifying widget configuration properties.
- *
- * @class TreeViewDD
- * @constructor
- * @extends TreeView
- */
- var TreeViewDD = A.Component.create(
- {
- /**
- * Static property provides a string to identify the class.
- *
- * @property TreeViewDD.NAME
- * @type String
- * @static
- */
- NAME: TREE_DRAG_DROP,
-
- /**
- * Static property used to define the default attribute
- * configuration for the TreeViewDD.
- *
- * @property TreeViewDD.ATTRS
- * @type Object
- * @static
- */
- ATTRS: {
- /**
- * Dragdrop helper element.
- *
- * @attribute helper
- * @default null
- * @type Node | String
- */
- helper: {
- value: null
- },
-
- /**
- * Delay of the scroll while dragging the TreeNodes.
- *
- * @attribute scrollDelay
- * @default 100
- * @type Number
- */
- scrollDelay: {
- value: 100,
- validator: isNumber
- }
- },
-
- EXTENDS: A.TreeView,
-
- prototype: {
- /**
- * Direction of the drag (i.e. could be 'up' or 'down').
- *
- * @property direction
- * @type String
- * @protected
- */
- direction: BELOW,
-
- /**
- * Drop action (i.e. could be 'append', 'below' or 'above').
- *
- * @attribute dropAction
- * @default null
- * @type String
- */
- dropAction: null,
-
- /**
- * Last Y.
- *
- * @attribute lastY
- * @default 0
- * @type Number
- */
- lastY: 0,
-
- node: null,
-
- /**
- * Reference for the current drop node.
- *
- * @attribute nodeContent
- * @default null
- * @type Node
- */
- nodeContent: null,
-
- /**
- * Descructor lifecycle implementation for the TreeViewDD class.
- * Purges events attached to the node (and all child nodes).
- *
- * @method destructor
- * @protected
- */
- destructor: function() {
- var instance = this;
- var helper = instance.get(HELPER);
-
- if (helper) {
- helper.remove(true);
- }
-
- if (instance.ddDelegate) {
- instance.ddDelegate.destroy();
- }
- },
-
- /**
- * Bind the events on the TreeViewDD UI. Lifecycle.
- *
- * @method bindUI
- * @protected
- */
- bindUI: function() {
- var instance = this;
-
- A.TreeViewDD.superclass.bindUI.apply(this, arguments);
-
- instance._bindDragDrop();
- },
-
- /**
- * Create the DOM structure for the TreeViewDD. Lifecycle.
- *
- * @method renderUI
- * @protected
- */
- renderUI: function() {
- var instance = this;
-
- A.TreeViewDD.superclass.renderUI.apply(this, arguments);
-
- // creating drag helper and hiding it
- var helper = A.Node.create(HELPER_TPL).hide();
-
- // append helper to the body
- A.one(BODY).append(helper);
-
- instance.set(HELPER, helper);
-
- // set DRAG_CURSOR to the default arrow
- DDM.set(DRAG_CURSOR, DEFAULT);
- },
-
- /**
- * Bind DragDrop events.
- *
- * @method _bindDragDrop
- * @protected
- */
- _bindDragDrop: function() {
- var instance = this;
-
- var boundingBox = instance.get(BOUNDING_BOX);
-
- var dragInitHandle = null;
-
- instance._createDragInitHandler = function() {
- instance.ddDelegate = new A.DD.Delegate(
- {
- bubbleTargets: instance,
- container: boundingBox,
- invalid: DOT+CSS_TREE_NODE_CONTENT_INVALID,
- nodes: DOT+CSS_TREE_NODE_CONTENT,
- target: true
- }
- );
-
- var dd = instance.ddDelegate.dd;
-
- dd.plug(A.Plugin.DDProxy, {
- moveOnEnd: false,
- positionProxy: false,
- borderStyle: null
- })
- .plug(A.Plugin.DDNodeScroll, {
- scrollDelay: instance.get(SCROLL_DELAY),
- node: boundingBox
- });
-
- dd.removeInvalid('a');
-
- if (dragInitHandle) {
- dragInitHandle.detach();
- }
-
- };
-
- // Check for mobile devices and execute _createDragInitHandler before events
- if (!UA.touch) {
- // only create the drag on the init elements if the user mouseover the boundingBox for init performance reasons
- dragInitHandle = boundingBox.on(['focus', 'mousedown', 'mousemove'], instance._createDragInitHandler);
- }
- else {
- instance._createDragInitHandler();
- }
-
- // drag & drop listeners
- instance.on('drag:align', instance._onDragAlign);
- instance.on('drag:start', instance._onDragStart);
- instance.on('drop:exit', instance._onDropExit);
- instance.after('drop:hit', instance._afterDropHit);
- instance.on('drop:hit', instance._onDropHit);
- instance.on('drop:over', instance._onDropOver);
- },
-
- /**
- * Set the append CSS state on the passed <code>nodeContent</code>.
- *
- * @method _appendState
- * @param {Node} nodeContent
- * @protected
- */
- _appendState: function(nodeContent) {
- var instance = this;
-
- instance.dropAction = APPEND;
-
- instance.get(HELPER).addClass(CSS_TREE_DRAG_STATE_APPEND);
-
- nodeContent.addClass(CSS_TREE_DRAG_INSERT_APPEND);
- },
-
- /**
- * Set the going down CSS state on the passed <code>nodeContent</code>.
- *
- * @method _goingDownState
- * @param {Node} nodeContent
- * @protected
- */
- _goingDownState: function(nodeContent) {
- var instance = this;
-
- instance.dropAction = BELOW;
-
- instance.get(HELPER).addClass(CSS_TREE_DRAG_STATE_INSERT_BELOW);
-
- nodeContent.addClass(CSS_TREE_DRAG_INSERT_BELOW);
- },
-
- /**
- * Set the going up CSS state on the passed <code>nodeContent</code>.
- *
- * @method _goingUpState
- * @param {Node} nodeContent
- * @protected
- */
- _goingUpState: function(nodeContent) {
- var instance = this;
-
- instance.dropAction = ABOVE;
-
- instance.get(HELPER).addClass(CSS_TREE_DRAG_STATE_INSERT_ABOVE);
-
- nodeContent.addClass(CSS_TREE_DRAG_INSERT_ABOVE);
- },
-
- /**
- * Set the reset CSS state on the passed <code>nodeContent</code>.
- *
- * @method _resetState
- * @param {Node} nodeContent
- * @protected
- */
- _resetState: function(nodeContent) {
- var instance = this;
- var helper = instance.get(HELPER);
-
- helper.removeClass(CSS_TREE_DRAG_STATE_APPEND);
- helper.removeClass(CSS_TREE_DRAG_STATE_INSERT_ABOVE);
- helper.removeClass(CSS_TREE_DRAG_STATE_INSERT_BELOW);
-
- if (nodeContent) {
- nodeContent.removeClass(CSS_TREE_DRAG_INSERT_ABOVE);
- nodeContent.removeClass(CSS_TREE_DRAG_INSERT_APPEND);
- nodeContent.removeClass(CSS_TREE_DRAG_INSERT_BELOW);
- }
- },
-
- /**
- * Update the CSS node state (i.e. going down, going up, append etc).
- *
- * @method _updateNodeState
- * @param {EventFacade} event
- * @protected
- */
- _updateNodeState: function(event) {
- var instance = this;
- var drag = event.drag;
- var drop = event.drop;
- var nodeContent = drop.get(NODE);
- var dropNode = nodeContent.get(PARENT_NODE);
- var dragNode = drag.get(NODE).get(PARENT_NODE);
- var dropTreeNode = dropNode.getData(TREE_NODE);
-
- // reset the classNames from the last nodeContent
- instance._resetState(instance.nodeContent);
-
- // cannot drop the dragged element into any of its children
- // nor above an undraggable element
- // using DOM contains method for performance reason
- if (!!dropTreeNode.get(DRAGGABLE) && !dragNode.contains(dropNode)) {
- // nArea splits the height in 3 areas top/center/bottom
- // these areas are responsible for defining the state when the mouse is over any of them
- var nArea = nodeContent.get(OFFSET_HEIGHT) / 3;
- var yTop = nodeContent.getY();
- var yCenter = yTop + nArea;
- var yBottom = yTop + nArea*2;
- var mouseY = drag.mouseXY[1];
-
- // UP: mouse on the top area of the node
- if ((mouseY > yTop) && (mouseY < yCenter)) {
- instance._goingUpState(nodeContent);
- }
- // DOWN: mouse on the bottom area of the node
- else if (mouseY > yBottom) {
- instance._goingDownState(nodeContent);
- }
- // APPEND: mouse on the center area of the node
- else if ((mouseY > yCenter) && (mouseY < yBottom)) {
- // if it's a folder set the state to append
- if (dropTreeNode && !dropTreeNode.isLeaf()) {
- instance._appendState(nodeContent);
- }
- // if it's a leaf we need to set the ABOVE or BELOW state instead of append
- else {
- if (instance.direction === UP) {
- instance._goingUpState(nodeContent);
- }
- else {
- instance._goingDownState(nodeContent);
- }
- }
- }
- }
-
- instance.nodeContent = nodeContent;
- },
-
- /**
- * Fires after the drop hit event.
- *
- * @method _afterDropHit
- * @param {EventFacade} event drop hit event facade
- * @protected
- */
- _afterDropHit: function(event) {
- var instance = this;
- var dropAction = instance.dropAction;
- var dragNode = event.drag.get(NODE).get(PARENT_NODE);
- var dropNode = event.drop.get(NODE).get(PARENT_NODE);
-
- var dropTreeNode = dropNode.getData(TREE_NODE);
- var dragTreeNode = dragNode.getData(TREE_NODE);
-
- var output = instance.getEventOutputMap(instance);
-
- output.tree.dropNode = dropTreeNode;
- output.tree.dragNode = dragTreeNode;
-
- if (dropAction === ABOVE) {
- dropTreeNode.insertBefore(dragTreeNode);
-
- instance.bubbleEvent('dropInsert', output);
- }
- else if (dropAction === BELOW) {
- dropTreeNode.insertAfter(dragTreeNode);
-
- instance.bubbleEvent('dropInsert', output);
- }
- else if (dropAction === APPEND) {
- if (dropTreeNode && !dropTreeNode.isLeaf()) {
- if (!dropTreeNode.get(EXPANDED)) {
- // expand node when drop a child on it
- dropTreeNode.expand();
- }
-
- dropTreeNode.appendChild(dragTreeNode);
-
- instance.bubbleEvent('dropAppend', output);
- }
- }
-
- instance._resetState(instance.nodeContent);
-
- // bubbling drop event
- instance.bubbleEvent('drop', output);
-
- instance.dropAction = null;
- },
-
- /**
- * Fires on drag align event.
- *
- * @method _onDragAlign
- * @param {EventFacade} event append event facade
- * @protected
- */
- _onDragAlign: function(event) {
- var instance = this;
- var lastY = instance.lastY;
- var y = event.target.lastXY[1];
-
- // if the y change
- if (y !== lastY) {
- // set the drag direction
- instance.direction = (y < lastY) ? UP : DOWN;
- }
-
- instance.lastY = y;
- },
-
- /**
- * Fires on drag start event.
- *
- * @method _onDragStart
- * @param {EventFacade} event append event facade
- * @protected
- */
- _onDragStart: function(event) {
- var instance = this;
- var drag = event.target;
- var dragNode = drag.get(NODE).get(PARENT_NODE);
- var dragTreeNode = dragNode.getData(TREE_NODE);
- var lastSelected = instance.get(LAST_SELECTED);
-
- // select drag node
- if (lastSelected) {
- lastSelected.unselect();
- }
-
- dragTreeNode.select();
-
- // initialize drag helper
- var helper = instance.get(HELPER);
- var helperLabel = helper.one(DOT+CSS_TREE_DRAG_HELPER_LABEL);
-
- // show helper, we need display block here, yui dd hide it with display none
- helper.setStyle(DISPLAY, BLOCK).show();
-
- // set the CSS_TREE_DRAG_HELPER_LABEL html with the label of the dragged node
- helperLabel.html( dragTreeNode.get(LABEL) );
-
- // update the DRAG_NODE with the new helper
- drag.set(DRAG_NODE, helper);
- },
-
- /**
- * Fires on drop over event.
- *
- * @method _onDropOver
- * @param {EventFacade} event append event facade
- * @protected
- */
- _onDropOver: function(event) {
- var instance = this;
-
- instance._updateNodeState(event);
- },
-
- /**
- * Fires on drop hit event.
- *
- * @method _onDropHit
- * @param {EventFacade} event append event facade
- * @protected
- */
- _onDropHit: function(event) {
- var dropNode = event.drop.get(NODE).get(PARENT_NODE);
- var dropTreeNode = dropNode.getData(TREE_NODE);
-
- if (!isTreeNode(dropTreeNode)) {
- event.preventDefault();
- }
- },
-
- /**
- * Fires on drop exit event.
- *
- * @method _onDropExit
- * @param {EventFacade} event append event facade
- * @protected
- */
- _onDropExit: function() {
- var instance = this;
-
- instance.dropAction = null;
-
- instance._resetState(instance.nodeContent);
- }
- }
- }
- );
-
- A.TreeViewDD = TreeViewDD;
-
- }, '@VERSION@' ,{requires:['aui-tree-node','aui-tree-paginator','aui-tree-io','dd-delegate','dd-proxy'], skinnable:true});
|