Skip to content

Commit

Permalink
Replace deprecated $.isFunction()
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Apr 2, 2021
1 parent 095d5cd commit 886006d
Show file tree
Hide file tree
Showing 6 changed files with 464 additions and 358 deletions.
2 changes: 1 addition & 1 deletion src/jquery.fancytree.filter.js
Expand Up @@ -267,7 +267,7 @@

if (count === 0 && opts.nodata && hideMode) {
statusNode = opts.nodata;
if ($.isFunction(statusNode)) {
if (typeof statusNode === "function") {
statusNode = statusNode();
}
if (statusNode === true) {
Expand Down
2 changes: 1 addition & 1 deletion src/jquery.fancytree.glyph.js
Expand Up @@ -174,7 +174,7 @@
setClass = baseClass + " " + (map._addClass || "");

// #871 Allow a callback
if ($.isFunction(icon)) {
if (typeof icon === "function") {
icon = icon.call(this, node, span, type);
}
// node.debug( "setIcon(" + baseClass + ", " + type + "): " + "oldIcon" + " -> " + icon );
Expand Down
34 changes: 19 additions & 15 deletions src/jquery.fancytree.js
Expand Up @@ -189,6 +189,10 @@
return Object.prototype.hasOwnProperty.call(object, property);
}

function _isFunction(obj) {
return typeof obj === "function";
}

var _isArray = Array.isArray;

_assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
Expand Down Expand Up @@ -276,7 +280,7 @@
length = arguments.length;

// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !$.isFunction(target)) {
if (typeof target !== "object" && !_isFunction(target)) {
target = {};
}
if (i === length) {
Expand Down Expand Up @@ -538,7 +542,7 @@
if (
!NODE_ATTR_MAP[name] &&
(this.tree.options.copyFunctionsToData ||
!$.isFunction(obj[name])) &&
!_isFunction(obj[name])) &&
!NONE_NODE_DATA_MAP[name]
) {
// node.data.NAME = obj.NAME
Expand Down Expand Up @@ -822,7 +826,7 @@
for (name in patch) {
if (_hasProp(patch, name)) {
v = patch[name];
if (!IGNORE_MAP[name] && !$.isFunction(v)) {
if (!IGNORE_MAP[name] && !_isFunction(v)) {
if (NODE_ATTR_MAP[name]) {
this[name] = v;
} else {
Expand Down Expand Up @@ -935,7 +939,7 @@
* @returns {FancytreeNode[]} array of nodes (may be empty)
*/
findAll: function(match) {
match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
match = _isFunction(match) ? match : _makeNodeTitleMatcher(match);
var res = [];
this.visit(function(n) {
if (match(n)) {
Expand All @@ -952,7 +956,7 @@
* @see FancytreeNode#findAll
*/
findFirst: function(match) {
match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
match = _isFunction(match) ? match : _makeNodeTitleMatcher(match);
var res = null;
this.visit(function(n) {
if (match(n)) {
Expand Down Expand Up @@ -1187,7 +1191,7 @@
// node.data += dict.data
$.extend(this.data, dict.data);
} else if (
!$.isFunction(dict[name]) &&
!_isFunction(dict[name]) &&
!NONE_NODE_DATA_MAP[name]
) {
// node.data.NAME = dict.NAME
Expand Down Expand Up @@ -1345,7 +1349,7 @@

var val,
path = [],
isFunc = $.isFunction(part);
isFunc = _isFunction(part);

this.visitParents(function(n) {
if (n.parent) {
Expand Down Expand Up @@ -2791,7 +2795,7 @@
var ctx = this._makeHookContext(contextObject),
fn = this[funcName],
args = Array.prototype.slice.call(arguments, 2);
if (!$.isFunction(fn)) {
if (!_isFunction(fn)) {
$.error("_callHook('" + funcName + "') is not a function");
}
args.unshift(ctx);
Expand Down Expand Up @@ -4287,16 +4291,16 @@
requestId = Date.now();

// `source` is a callback: use the returned result instead:
if ($.isFunction(source)) {
if (_isFunction(source)) {
source = source.call(tree, { type: "source" }, ctx);
_assert(
!$.isFunction(source),
!_isFunction(source),
"source callback must not return another function"
);
}
// `source` is already a promise:
if ($.isFunction(source.then)) {
// _assert($.isFunction(source.always), "Expected jQuery?");
if (_isFunction(source.then)) {
// _assert(_isFunction(source.always), "Expected jQuery?");
ajaxDfd = source;
} else if (source.url) {
// `source` is an Ajax options object
Expand Down Expand Up @@ -4536,7 +4540,7 @@
node._setChildren(children);

if (tree.options.nodata && children.length === 0) {
if ($.isFunction(tree.options.nodata)) {
if (_isFunction(tree.options.nodata)) {
noDataRes = tree.options.nodata.call(
tree,
{ type: "nodata" },
Expand Down Expand Up @@ -5542,7 +5546,7 @@
// See #716, #717
$(node.li).addClass(cn.animating); // #717

if ($.isFunction($(node.ul)[effect.effect])) {
if (_isFunction($(node.ul)[effect.effect])) {
// tree.debug( "use jquery." + effect.effect + " method" );
$(node.ul)[effect.effect]({
duration: effect.duration,
Expand Down Expand Up @@ -7050,7 +7054,7 @@
treeOpt = treeOptions[optionName],
nodeOpt = nodeObject[optionName];

if ($.isFunction(treeOpt)) {
if (_isFunction(treeOpt)) {
ctx = {
node: node,
tree: tree,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test-core.js
Expand Up @@ -71,7 +71,7 @@ QUnit.test("Static members", function(assert) {
tools.setup(assert);
assert.expect(5);

assert.ok($.isFunction($.ui.fancytree.debug), "ui.fancytree.debug function is defined");
assert.ok(tools.isFunction($.ui.fancytree.debug), "ui.fancytree.debug function is defined");
assert.equal($(":ui-fancytree").length, 0, "no tree instance exists");
// equal($.ui.fancytree._nextId, 1, "next tree instance counter is 1");

Expand Down
10 changes: 5 additions & 5 deletions test/unit/test-ext-filter.js
Expand Up @@ -127,11 +127,11 @@ QUnit.test("Default options (mode='dimm')", function(assert) {
var tree = data.tree;

// Class methods:
assert.ok($.isFunction(tree.isFilterActive), "Has tree.isFilterActive()");
assert.ok($.isFunction(tree.clearFilter), "Has tree.clearFilter()");
assert.ok($.isFunction(tree.filterNodes), "Has tree.filterNodes()");
assert.ok($.isFunction(tree.filterBranches), "Has tree.filterBranches()");
assert.ok($.isFunction(tree.rootNode.isMatched), "Has node.isMatched()");
assert.ok(tools.isFunction(tree.isFilterActive), "Has tree.isFilterActive()");
assert.ok(tools.isFunction(tree.clearFilter), "Has tree.clearFilter()");
assert.ok(tools.isFunction(tree.filterNodes), "Has tree.filterNodes()");
assert.ok(tools.isFunction(tree.filterBranches), "Has tree.filterBranches()");
assert.ok(tools.isFunction(tree.rootNode.isMatched), "Has node.isMatched()");
// Default options:
assert.equal(data.options.filter.autoApply, true, "opts.autoApply === true");
assert.equal(data.options.filter.counter, true, "opts.counter === true");
Expand Down

0 comments on commit 886006d

Please sign in to comment.