Skip to content

Commit

Permalink
Tagging the 2.1.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed May 29, 2014
1 parent 8271e9a commit eab115c
Show file tree
Hide file tree
Showing 39 changed files with 1,018 additions and 567 deletions.
486 changes: 299 additions & 187 deletions dist/jquery.fancytree-all.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/jquery.fancytree-custom.min.js

Large diffs are not rendered by default.

175 changes: 109 additions & 66 deletions dist/jquery.fancytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Released under the MIT license
* https://github.com/mar10/fancytree/wiki/LicenseInfo
*
* @version 2.0.0
* @date 2014-05-01T21:48
* @version 2.1.0
* @date 2014-05-29T16:44
*/

/** Core Fancytree module.
Expand Down Expand Up @@ -61,6 +61,11 @@ function consoleApply(method, args){
}
}

/*Return true if x is a FancytreeNode.*/
function _isNode(x){
return !!(x.tree && x.statusNodeType !== undefined);
}

/** Return true if dotted version string is equal or higher than requested version.
*
* See http://jsfiddle.net/mar10/FjSAN/
Expand Down Expand Up @@ -275,6 +280,8 @@ function FancytreeNode(parent, obj){
} else {
this.key = "_" + (FT._nextNodeKey++);
}
} else {
this.key = "" + this.key; // Convert to string (#217)
}

// Fix tree.activeNode
Expand Down Expand Up @@ -683,9 +690,8 @@ FancytreeNode.prototype = /** @lends FancytreeNode# */{
// recursively set children and render
this.removeChildren();
this.addChildren(dict.children);
}else{
this.renderTitle();
}
this.renderTitle();
/*
var children = dict.children;
if(children === undefined){
Expand Down Expand Up @@ -1350,79 +1356,93 @@ FancytreeNode.prototype = /** @lends FancytreeNode# */{
/**
*
* @param {boolean | PlainObject} [effects=false] animation options.
* @param {FancytreeNode} [topNode=null] this node will remain visible in
* @param {object} [options=null] {topNode: null, effects: ..., parent: ...} this node will remain visible in
* any case, even if `this` is outside the scroll pane.
* @returns {$.Promise}
*/
scrollIntoView: function(effects, topNode) {
effects = (effects === true) ? {duration: 200, queue: false} : effects;
var topNodeY,
scrollIntoView: function(effects, options) {
if( options !== undefined && _isNode(options) ) {
this.warn("scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead.");
options = {topNode: options};
}
// this.$scrollParent = (this.options.scrollParent === "auto") ? $ul.scrollParent() : $(this.options.scrollParent);
// this.$scrollParent = this.$scrollParent.length ? this.$scrollParent || this.$container;

var topNodeY, nodeY, horzScrollbarHeight, containerOffsetTop,
opts = $.extend({
effects: (effects === true) ? {duration: 200, queue: false} : effects,
scrollOfs: this.tree.options.scrollOfs,
scrollParent: this.tree.options.scrollParent || this.tree.$container,
topNode: null
}, options),
dfd = new $.Deferred(),
that = this,
nodeY = $(this.span).position().top,
nodeHeight = $(this.span).height(),
$container = this.tree.$container,
scrollTop = $container[0].scrollTop,
horzScrollHeight = Math.max(0, ($container.innerHeight() - $container[0].clientHeight)),
// containerHeight = $container.height(),
containerHeight = $container.height() - horzScrollHeight,
$container = $(opts.scrollParent),
topOfs = opts.scrollOfs.top || 0,
bottomOfs = opts.scrollOfs.bottom || 0,
containerHeight = $container.height(),// - topOfs - bottomOfs,
scrollTop = $container.scrollTop(),
$animateTarget = $container,
isParentWindow = $container[0] === window,
topNode = opts.topNode || null,
newScrollTop = null;

// console.log("horzScrollHeight: " + horzScrollHeight);
// console.log("$container[0].scrollTop: " + $container[0].scrollTop);
// console.log("$container[0].scrollHeight: " + $container[0].scrollHeight);
// console.log("$container[0].clientHeight: " + $container[0].clientHeight);
// console.log("$container.innerHeight(): " + $container.innerHeight());
// console.log("$container.height(): " + $container.height());

if(nodeY < 0){
newScrollTop = scrollTop + nodeY;
}else if((nodeY + nodeHeight) > containerHeight){
newScrollTop = scrollTop + nodeY - containerHeight + nodeHeight;
// this.debug("scrollIntoView(), scrollTop=", scrollTop, opts.scrollOfs);
_assert($(this.span).is(":visible"), "scrollIntoView node is invisible"); // otherwise we cannot calc offsets

if( isParentWindow ) {
nodeY = $(this.span).offset().top;
topNodeY = topNode ? $(topNode.span).offset().top : 0;
$animateTarget = $("html,body");

} else {
_assert($container[0] !== document && $container[0] !== document.body, "scrollParent should be an simple element or `window`, not document or body.");

containerOffsetTop = $container.offset().top,
nodeY = $(this.span).offset().top - containerOffsetTop + scrollTop; // relative to scroll parent
topNodeY = topNode ? $(topNode.span).offset().top - containerOffsetTop + scrollTop : 0;
horzScrollbarHeight = Math.max(0, ($container.innerHeight() - $container[0].clientHeight));
containerHeight -= horzScrollbarHeight;
}

// this.debug(" scrollIntoView(), nodeY=", nodeY, "containerHeight=", containerHeight);
if( nodeY < (scrollTop + topOfs) ){
// Node is above visible container area
newScrollTop = nodeY - topOfs;
// this.debug(" scrollIntoView(), UPPER newScrollTop=", newScrollTop);

}else if((nodeY + nodeHeight) > (scrollTop + containerHeight - bottomOfs)){
newScrollTop = nodeY + nodeHeight - containerHeight + bottomOfs;
// this.debug(" scrollIntoView(), LOWER newScrollTop=", newScrollTop);
// If a topNode was passed, make sure that it is never scrolled
// outside the upper border
if(topNode){
topNodeY = topNode ? $(topNode.span).position().top : 0;
if((nodeY - topNodeY) > containerHeight){
newScrollTop = scrollTop + topNodeY;
_assert($(topNode.span).is(":visible"));
if( topNodeY < newScrollTop ){
newScrollTop = topNodeY - topOfs;
// this.debug(" scrollIntoView(), TOP newScrollTop=", newScrollTop);
}
}
}

if(newScrollTop !== null){
if(effects){
// TODO: resolve dfd after animation
// var that = this;
effects.complete = function(){
// this.debug(" scrollIntoView(), SET newScrollTop=", newScrollTop);
if(opts.effects){
opts.effects.complete = function(){
dfd.resolveWith(that);
};
$container.animate({
$animateTarget.stop(true).animate({
scrollTop: newScrollTop
}, effects);
}, opts.effects);
}else{
$container[0].scrollTop = newScrollTop;
$animateTarget[0].scrollTop = newScrollTop;
dfd.resolveWith(this);
}
}else{
dfd.resolveWith(this);
}
return dfd.promise();
/* from jQuery.menu:
var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
if ( this._hasScroll() ) {
borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
scroll = this.activeMenu.scrollTop();
elementHeight = this.activeMenu.height();
itemHeight = item.height();
if ( offset < 0 ) {
this.activeMenu.scrollTop( scroll + offset );
} else if ( offset + itemHeight > elementHeight ) {
this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
}
}
*/
},

/**Activate this node.
Expand Down Expand Up @@ -2817,8 +2837,8 @@ $.extend(Fancytree.prototype,
// folder or doctype icon
role = aria ? " role='img'" : "";
if ( icon && typeof icon === "string" ) {
imageSrc = (icon.charAt(0) === "/") ? icon : (opts.imagePath + icon);
ares.push("<img src='" + imageSrc + "' alt='' />");
imageSrc = (icon.charAt(0) === "/") ? icon : ((opts.imagePath || "") + icon);
ares.push("<img src='" + imageSrc + "' class='fancytree-icon' alt='' />");
} else if ( node.data.iconclass ) {
// TODO: review and test and document
ares.push("<span " + role + " class='fancytree-custom-icon" + " " + node.data.iconclass + "'></span>");
Expand All @@ -2834,7 +2854,6 @@ $.extend(Fancytree.prototype,
nodeTitle = opts.renderTitle.call(tree, {type: "renderTitle"}, ctx) || "";
}
if(!nodeTitle){
// TODO: escape tooltip string
tooltip = node.tooltip ? " title='" + FT.escapeHtml(node.tooltip) + "'" : "";
id = aria ? " id='ftal_" + node.key + "'" : "";
role = aria ? " role='treeitem'" : "";
Expand Down Expand Up @@ -2979,7 +2998,6 @@ $.extend(Fancytree.prototype,
node = ctx.node,
tree = ctx.tree,
opts = ctx.options,
// userEvent = !!ctx.originalEvent,
noEvents = (callOpts.noEvents === true),
isActive = (node === tree.activeNode);

Expand All @@ -3003,7 +3021,7 @@ $.extend(Fancytree.prototype,
}
if(opts.activeVisible){
// tree.nodeMakeVisible(ctx);
node.makeVisible();
node.makeVisible({scrollIntoView: false}); // nodeSetFocus will scroll
}
tree.activeNode = node;
tree.nodeRenderStatus(ctx);
Expand Down Expand Up @@ -3080,9 +3098,9 @@ $.extend(Fancytree.prototype,
}
// Trigger expand/collapse after expanding
dfd.done(function(){
if( opts.autoScroll && !noAnimation ) {
if( flag && opts.autoScroll && !noAnimation ) {
// Scroll down to last child, but keep current node visible
node.getLastChild().scrollIntoView(true, node).always(function(){
node.getLastChild().scrollIntoView(true, {topNode: node}).always(function(){
if( !noEvents ) {
ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
}
Expand All @@ -3093,7 +3111,6 @@ $.extend(Fancytree.prototype,
}
}
});

// vvv Code below is executed after loading finished:
_afterLoad = function(callback){
var duration, easing, isVisible, isExpanded;
Expand Down Expand Up @@ -3201,7 +3218,7 @@ $.extend(Fancytree.prototype,
this._callHook("treeSetFocus", ctx, true, true);
}
// this.nodeMakeVisible(ctx);
node.makeVisible();
node.makeVisible({scrollIntoView: false});
tree.focusNode = node;
// node.debug("FOCUS...");
// $(node.span).find(".fancytree-title").focus();
Expand Down Expand Up @@ -3512,6 +3529,8 @@ $.widget("ui.fancytree",
keyboard: true,
keyPathSeparator: "/",
minExpandLevel: 1,
scrollOfs: {top: 0, bottom: 0},
scrollParent: null,
selectMode: 2,
strings: {
loading: "Loading&#8230;",
Expand Down Expand Up @@ -3772,7 +3791,7 @@ $.extend($.ui.fancytree,
/** @lends Fancytree_Static# */
{
/** @type {string} */
version: "2.0.0", // Set to semver by 'grunt release'
version: "2.1.0", // Set to semver by 'grunt release'
/** @type {string} */
buildType: "production", // Set to 'production' by 'grunt build'
/** @type {int} */
Expand Down Expand Up @@ -3800,6 +3819,29 @@ $.extend($.ui.fancytree,
assert: function(cond, msg){
return _assert(cond, msg);
},
/** Return a function that executes *fn* at most every *timeout* ms.
* @param {integer} timeout
* @param {function} fn
* @param {boolean} [invokeAsap=false]
* @param {any} [ctx]
*/
debounce : function(timeout, fn, invokeAsap, ctx) {
var timer;
if(arguments.length === 3 && typeof invokeAsap !== "boolean") {
ctx = invokeAsap;
invokeAsap = false;
}
return function() {
var args = arguments;
ctx = ctx || this;
invokeAsap && !timer && fn.apply(ctx, args);
clearTimeout(timer);
timer = setTimeout(function() {
invokeAsap || fn.apply(ctx, args);
timer = null;
}, timeout);
};
},
/** Write message to console if debugLevel >= 2
* @param {string} msg
*/
Expand Down Expand Up @@ -3850,8 +3892,7 @@ $.extend($.ui.fancytree,
getEventTarget: function(event){
var tcn = event && event.target ? event.target.className : "",
res = {node: this.getNode(event.target), type: undefined};
// tcn may contains UI themeroller or Font Awesome classes, so we use
// a fast version of $(res.node).hasClass()
// We use a fast version of $(res.node).hasClass()
// See http://jsperf.com/test-for-classname/2
if( /\bfancytree-title\b/.test(tcn) ){
res.type = "title";
Expand All @@ -3862,8 +3903,10 @@ $.extend($.ui.fancytree,
}else if( /\bfancytree-icon\b/.test(tcn) ){
res.type = "icon";
}else if( /\bfancytree-node\b/.test(tcn) ){
// TODO: (http://code.google.com/p/dynatree/issues/detail?id=93)
// res.type = this._getTypeForOuterNodeEvent(event);
// Somewhere near the title
res.type = "title";
}else if( event && event.target && $(event.target).closest(".fancytree-title").length ) {
// #228: clicking an embedded element inside a title
res.type = "title";
}
return res;
Expand Down
8 changes: 4 additions & 4 deletions dist/jquery.fancytree.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit eab115c

Please sign in to comment.