Skip to content

Commit daf11c2

Browse files
committed
New option dnd.focusOnClick
1 parent 75214de commit daf11c2

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# 2.2.0 / Unreleased
22
* [Improved] #245 tree.generateInput() now returns data using PHPs array
33
convention, i.e. by appending brackets to the name: 'ft_1[]'.
4-
* [Fixed] #250: Children lazy empty nodes remain checked when parent is unchecked with hierarchical multi-selection
5-
4+
* [Fixed] #250: Children lazy empty nodes remain checked when parent is
5+
unchecked with hierarchical multi-selection
6+
* [Added] Option dnd.focusOnClick sets focus to tree widget, even when dragging
7+
is enabled
8+
* [Added] node.info()
69

710
# 2.1.0 / 2014-05-29
811
* [Added] #210: [ext-persist] optionally store information in sessionStorage or localStorage

demo/sample-ext-dnd.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
// and pass the tree options as an argument to the fancytree() function:
4343
$("#tree").fancytree({
4444
extensions: ["dnd"],
45+
// titlesTabbable: true,
4546
source: {
4647
url: "ajax-tree-fs.json"
4748
},
4849
dnd: {
50+
autoExpandMS: 400,
51+
focusOnClick: true,
4952
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
5053
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
51-
autoExpandMS: 400,
5254
dragStart: function(node, data) {
5355
/** This function MUST be defined to enable dragging for the tree.
5456
* Return false to cancel dragging of node.

src/jquery.fancytree.dnd.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ $.ui.fancytree.registerExtension({
204204
autoExpandMS: 1000, // Expand nodes after n milliseconds of hovering.
205205
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
206206
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
207+
focusOnClick: false, // Focus, although draggable cancels mousedown event (#270)
207208
dragEnter: null, // Callback(targetNode, data)
208209
dragOver: null, // Callback(targetNode, data)
209210
dragDrop: null, // Callback(targetNode, data)
@@ -216,6 +217,20 @@ $.ui.fancytree.registerExtension({
216217
treeInit: function(ctx){
217218
var tree = ctx.tree;
218219
this._super(ctx);
220+
// issue #270: draggable eats mousedown events
221+
if( tree.options.dnd.dragStart ){
222+
tree.$container.on("mousedown", function(event){
223+
if( !tree.hasFocus() && ctx.options.dnd.focusOnClick ) {
224+
var node = $.ui.fancytree.getNode(event);
225+
node.debug("Re-enable focus that was prevented by jQuery UI draggable.");
226+
// node.setFocus();
227+
// $(node.span).closest(":tabbable").focus();
228+
// $(event.target).trigger("focus");
229+
// $(event.target).closest(":tabbable").trigger("focus");
230+
$(event.target).closest(":tabbable").focus();
231+
}
232+
});
233+
}
219234
_initDragAndDrop(tree);
220235
},
221236
/* Override key handler in order to cancel dnd on escape.*/
@@ -226,6 +241,12 @@ $.ui.fancytree.registerExtension({
226241
}
227242
return this._super(ctx);
228243
},
244+
nodeClick: function(ctx) {
245+
// if( ctx.options.dnd.dragStart ){
246+
// ctx.tree.$container.focus();
247+
// }
248+
return this._super(ctx);
249+
},
229250
/* Display drop marker according to hitMode ('after', 'before', 'over', 'out', 'start', 'stop'). */
230251
_setDndStatus: function(sourceNode, targetNode, helper, hitMode, accept) {
231252
var posOpts,

0 commit comments

Comments
 (0)