Skip to content

Commit

Permalink
Added new opts argument to setExpanded()
Browse files Browse the repository at this point in the history
Closed #128
Closed #129
  • Loading branch information
mar10 committed Feb 8, 2014
1 parent 029143b commit 590814a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 49 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
* [FEATURE] New method `tree._requireExtension()`
* [FEATURE] Fixed d'n'd for ext-table
* [FEATURE] New option `titlesTabbable`
* [FEATURE] New argument `opts` for setExpanded() and setActive()
* [BUGFIX] ext-edit: fixed loosing focus and made chainable
* [BUGFIX] ext-filter: fixed navigation for hidden nodes
* Added browser test matrix (saucelabs)


# 2.0.0-5 / 2013-12-23

* [BREAKING CHANGE] Refactored drag'n'drop extension.
For example `dnd.onDrop(node)` --> `dnd.dragDrop(node, data)`.
* [BREAKING CHANGE] Refactored drag'n'drop extension.
For example `dnd.onDrop(node)` --> `dnd.dragDrop(node, data)`.
See [[TutorialExtDnd]]
* [BREAKING CHANGE] Renamed `rencercolumns` event to `renderColumns`
* [BREAKING CHANGE] Renamed `fancytree-focused` class to `fancytree-treefocus` (container only)
* [FEATURE] Experimental `ext-gridnav` implents key navigation for tables.
Refactored keyboard handling. Keydown handlers are now bound to the container instead of document
Refactored keyboard handling. Keydown handlers are now bound to the container instead of document
(Co-work with Koloto)
* [FEATURE] Allow to return 'preventNav' in keydown event to prevent withput blocking keys in embedded input controls.
* [FEATURE] New method `node.navigate()` to support custom keyboard handlers
Expand All @@ -30,7 +31,7 @@
* [BUGFIX] Fixed BACKSPACE on top-level nodes
* [BUGFIX] Fixed #71, #75, #90, #104, #105
* Improved table render speed by 15%
* `grunt dev` combines `grunt server` + `grunt watch` (trigger jshint and
* `grunt dev` combines `grunt server` + `grunt watch` (trigger jshint and
less on save)


Expand All @@ -47,7 +48,7 @@

# 2.0.0-2 / 2013-09-15

* [BREAKING CHANGE] Renamed `onCustomRender` to `renderTitle`.
* [BREAKING CHANGE] Renamed `onCustomRender` to `renderTitle`.
`renderTitle`, `renderNode` and `createNode` events are only triggered as options callback (not DOM events), for performance reasons.
* [BREAKING CHANGE] Renamed `data.orgEvent` to `data.originalEvent`
* [BREAKING CHANGE] Renamed events to camelCase as suggested by the jQuery style guide (`rendernnode` -> `renderNode`, ...)
Expand Down
4 changes: 2 additions & 2 deletions src/jquery.fancytree.childcounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ $.ui.fancytree.registerExtension({
}
},
// Overload the `setExpanded` hook, so the counters are updated
nodeSetExpanded: function(ctx, flag) {
nodeSetExpanded: function(ctx, flag, opts) {
var tree = ctx.tree,
node = ctx.node;
// Let the base implementation expand/collapse the node, then redraw the title
// after the animation has finished
return this._super(ctx, flag).done(function(){
return this._super(ctx, flag, opts).always(function(){
tree.nodeRenderTitle(ctx);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/jquery.fancytree.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ $.ui.fancytree.registerExtension({
},
nodeRenderTitle: function(ctx, title) {
},
nodeSetActive: function(ctx, flag) {
nodeSetActive: function(ctx, flag, opts) {
},
nodeSetExpanded: function(ctx, flag) {
nodeSetExpanded: function(ctx, flag, opts) {
},
nodeSetFocus: function(ctx) {
},
Expand Down
45 changes: 29 additions & 16 deletions src/jquery.fancytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,16 +1240,18 @@ FancytreeNode.prototype = /** @lends FancytreeNode# */{

/**Activate this node.
* @param {boolean} [flag=true] pass false to deactivate
* @param {object} [opts] additional options. Defaults to {noEvents: false}
*/
setActive: function(flag){
return this.tree._callHook("nodeSetActive", this, flag);
setActive: function(flag, opts){
return this.tree._callHook("nodeSetActive", this, flag, opts);
},
/**Expand or collapse this node.
* @param {boolean} [flag=true] pass false to collapse
* @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
* @returns {$.Promise} resolved, when lazy loading and animations are done
*/
setExpanded: function(flag){
return this.tree._callHook("nodeSetExpanded", this, flag);
setExpanded: function(flag, opts){
return this.tree._callHook("nodeSetExpanded", this, flag, opts);
},
/**Set keyboard focus to this node.
* @param {boolean} [flag=true] pass false to blur
Expand Down Expand Up @@ -2035,7 +2037,7 @@ $.extend(Fancytree.prototype,
}
// TODO: return promise?
},
nodeCollapseSiblings: function(ctx) {
nodeCollapseSiblings: function(ctx, callOpts) {
// TODO: return promise?
var ac, i, l,
node = ctx.node;
Expand All @@ -2044,7 +2046,7 @@ $.extend(Fancytree.prototype,
ac = node.parent.children;
for (i=0, l=ac.length; i<l; i++) {
if ( ac[i] !== node && ac[i].expanded ){
this._callHook("nodeSetExpanded", ac[i], false);
this._callHook("nodeSetExpanded", ac[i], false, callOpts);
}
}
}
Expand Down Expand Up @@ -2753,15 +2755,18 @@ $.extend(Fancytree.prototype,
* If flag is false, the node is deactivated (must be a synchronous operation)
* @param {EventData} ctx
* @param {boolean} [flag=true]
* @param {object} [opts] additional options. Defaults to {}
*/
nodeSetActive: function(ctx, flag) {
nodeSetActive: function(ctx, flag, callOpts) {
// Handle user click / [space] / [enter], according to clickFolderMode.
callOpts = callOpts || {};
var subCtx,
node = ctx.node,
tree = ctx.tree,
opts = ctx.options,
// userEvent = !!ctx.originalEvent,
isActive = (node === tree.activeNode);

// flag defaults to true
flag = (flag !== false);
node.debug("nodeSetActive", flag);
Expand Down Expand Up @@ -2798,21 +2803,23 @@ $.extend(Fancytree.prototype,
*
* @param {EventData} ctx
* @param {boolean} [flag=true]
* @param {object} [opts] additional options. Defaults to {noAnimation: false}
* @returns {$.Promise} The deferred will be resolved as soon as the (lazy)
* data was retrieved, rendered, and the expand animation finshed.
*/
nodeSetExpanded: function(ctx, flag) {
nodeSetExpanded: function(ctx, flag, callOpts) {
callOpts = callOpts || {};
var _afterLoad, dfd, i, l, parents, prevAC,
node = ctx.node,
tree = ctx.tree,
opts = ctx.options;
opts = ctx.options,
noAnimation = callOpts.noAnimation === true;

// flag defaults to true
flag = (flag !== false);

node.debug("nodeSetExpanded(" + flag + ")");
// TODO: !!node.expanded is nicer, but doesn't pass jshint
// https://github.com/jshint/jshint/issues/455
// if( !!node.expanded === !!flag){

if((node.expanded && flag) || (!node.expanded && !flag)){
// Nothing to do
node.debug("nodeSetExpanded(" + flag + "): nothing to do");
Expand All @@ -2827,7 +2834,11 @@ $.extend(Fancytree.prototype,
// Callback returned false
return _getRejectedPromise(node, ["rejected"]);
}
//
// If this node inside a collpased node, no animation and scrolling is needed
if( !noAnimation && !node.isVisible() ) {
noAnimation = callOpts.noAnimation = true;
}

dfd = new $.Deferred();

// Auto-collapse mode: collapse all siblings
Expand All @@ -2838,7 +2849,7 @@ $.extend(Fancytree.prototype,
opts.autoCollapse = false;
for(i=0, l=parents.length; i<l; i++){
// TODO: should return promise?
this._callHook("nodeCollapseSiblings", parents[i]);
this._callHook("nodeCollapseSiblings", parents[i], callOpts);
}
}finally{
opts.autoCollapse = prevAC;
Expand All @@ -2847,7 +2858,7 @@ $.extend(Fancytree.prototype,
// Trigger expand/collapse after expanding
dfd.done(function(){
ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
if(opts.autoScroll){
if( opts.autoScroll && !noAnimation ) {
// Scroll down to last child, but keep current node visible
node.getLastChild().scrollIntoView(true, node);
}
Expand Down Expand Up @@ -2878,8 +2889,10 @@ $.extend(Fancytree.prototype,
isExpanded = !!node.expanded;
if ( isVisible === isExpanded ) {
node.warn("nodeSetExpanded: UL.style.display already set");
} else if ( !opts.fx ) {

} else if ( !opts.fx || noAnimation ) {
node.ul.style.display = ( node.expanded || !parent ) ? "" : "none";

} else {
duration = opts.fx.duration || 200;
easing = opts.fx.easing;
Expand Down
8 changes: 4 additions & 4 deletions src/jquery.fancytree.persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,24 @@ $.ui.fancytree.registerExtension({
// treeDestroy: function(ctx){
// this._super(ctx);
// },
nodeSetActive: function(ctx, flag) {
nodeSetActive: function(ctx, flag, opts) {
var instData = this._local,
instOpts = this.options.persist;

this._super(ctx, flag);
this._super(ctx, flag, opts);

if(instData.storeActive){
$.cookie(instData.cookiePrefix + ACTIVE,
this.activeNode ? this.activeNode.key : null,
instOpts.cookie);
}
},
nodeSetExpanded: function(ctx, flag) {
nodeSetExpanded: function(ctx, flag, opts) {
var res,
node = ctx.node,
instData = this._local;

res = this._super(ctx, flag);
res = this._super(ctx, flag, opts);

if(instData.storeExpanded){
instData._setKey(EXPANDED, node.key, flag);
Expand Down
4 changes: 2 additions & 2 deletions src/jquery.fancytree.table.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ $.ui.fancytree.registerExtension({
$(node.span).css({marginLeft: indent + "px"});
},
/* Expand node, return Deferred.promise. */
nodeSetExpanded: function(ctx, flag) {
return this._super(ctx, flag).always(function () {
nodeSetExpanded: function(ctx, flag, opts) {
return this._super(ctx, flag, opts).always(function () {
flag = (flag !== false);
setChildRowVisibility(ctx.node, flag);
});
Expand Down
19 changes: 1 addition & 18 deletions test/triage/test-issue-NNN-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,10 @@
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
autoExpandMS: 400,
dragStart: function(node, data) {
/** This function MUST be defined to enable dragging for the tree.
* Return false to cancel dragging of node.
*/
return true;
},
dragEnter: function(node, data) {
/** data.otherNode may be null for non-fancytree droppables.
* Return false to disallow dropping on node. In this case
* dragOver and dragLeave are not called.
* Return 'over', 'before, or 'after' to force a hitMode.
* Return ['before', 'after'] to restrict available hitModes.
* Any other return value will calc the hitMode from the cursor position.
*/
// Prevent dropping a parent below another parent (only sort
// nodes under the same parent)
/* if(node.parent !== data.otherNode.parent){
return false;
}
// Don't allow dropping *over* a node (would create a child)
return ["before", "after"];
*/
// return ["before", "after"];
return true;
},
dragDrop: function(node, data) {
Expand Down

0 comments on commit 590814a

Please sign in to comment.