From d66e10ec2d96b252ffe4ad755f0c3af7c419c487 Mon Sep 17 00:00:00 2001 From: Martin Wendt Date: Mon, 11 Nov 2019 22:18:17 +0100 Subject: [PATCH] Fix too much output in prodcution mode Close #974 --- CHANGELOG.md | 2 ++ src/jquery.fancytree.grid.js | 8 ++++---- src/jquery.fancytree.js | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5c07a3..98009c4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # 2.33.1-0 / Unreleased * TODO: tree.hasFocus() more reliable. + * [Added] `tree.time()`, `tree.timeEnd()` for debugging. + * [Fixed] #974 too much output in prodcution mode. * [Fixed] #973 when use ext-grid in one tree, other tree not use ext-grid has error on click. # 2.33.0 / 2019-10-29 diff --git a/src/jquery.fancytree.grid.js b/src/jquery.fancytree.grid.js index 7c83f779..f62c6592 100644 --- a/src/jquery.fancytree.grid.js +++ b/src/jquery.fancytree.grid.js @@ -403,7 +403,7 @@ // this.debug("_renumberVisibleNodes() ignored."); return false; } - window.console.time("_renumberVisibleNodes()"); + this.time("_renumberVisibleNodes()"); var i = 0, prevLength = this.visibleNodeList ? this.visibleNodeList.length : 0, visibleNodeList = (this.visibleNodeList = []); @@ -422,7 +422,7 @@ node._rowIdx = i++; visibleNodeList.push(node); }); - window.console.timeEnd("_renumberVisibleNodes()"); + this.timeEnd("_renumberVisibleNodes()"); if (i !== prevLength) { this._triggerTreeEvent("updateViewport", null, { reason: "renumber", @@ -446,7 +446,7 @@ // tree.debug("no render", tree._enableUpdate); return; } - window.console.time("redrawViewport()"); + this.time("redrawViewport()"); this._renumberVisibleNodes(force); // Adjust vp.start value to assure the current content is inside: this._fixStart(null, true); @@ -500,7 +500,7 @@ trIdx++; } this.isVpUpdating = prevPhase; - window.console.timeEnd("redrawViewport()"); + this.timeEnd("redrawViewport()"); }; $.ui.fancytree.registerExtension({ diff --git a/src/jquery.fancytree.js b/src/jquery.fancytree.js index 96424ee2..52335db7 100644 --- a/src/jquery.fancytree.js +++ b/src/jquery.fancytree.js @@ -3783,6 +3783,26 @@ setOption: function(optionName, value) { return this.widget.option(optionName, value); }, + /** + * Call console.time() when in debug mode (verbose >= 4). + * + * @param {string} label + */ + time: function(label) { + if (this.options.debugLevel >= 4) { + window.console.time(this + " - " + label); + } + }, + /** + * Call console.timeEnd() when in debug mode (verbose >= 4). + * + * @param {string} label + */ + timeEnd: function(label) { + if (this.options.debugLevel >= 4) { + window.console.timeEnd(this + " - " + label); + } + }, /** * Return all nodes as nested list of {@link NodeData}. *