Skip to content

Commit

Permalink
Replace deprecated $.trim()
Browse files Browse the repository at this point in the history
Close #1066
  • Loading branch information
mar10 committed Apr 2, 2021
1 parent a8e46c1 commit 13b5c63
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,8 @@
# 2.38.1-0 / Unreleased
* Replace deprecated jQuery functions: `$.isArray()`, `$.isFunction()`,
`$.trim()`, `$().click()`
* Update to jQuery 3.6

# 2.38.0 / 2021-02-09
* [Added] #1041 Make assertions more debuggable
* [Added] #1051 ext-filter Fuzzy matched title segment is not highlighted
Expand Down
3 changes: 2 additions & 1 deletion src/jquery.fancytree.edit.js
Expand Up @@ -34,6 +34,7 @@

var isMac = /Mac/.test(navigator.platform),
escapeHtml = $.ui.fancytree.escapeHtml,
trim = $.ui.fancytree.trim,
unescapeHtml = $.ui.fancytree.unescapeHtml;

/**
Expand Down Expand Up @@ -152,7 +153,7 @@
$input = $title.find("input.fancytree-edit-input");

if (instOpts.trim) {
$input.val($.trim($input.val()));
$input.val(trim($input.val()));
}
newVal = $input.val();

Expand Down
18 changes: 15 additions & 3 deletions src/jquery.fancytree.js
Expand Up @@ -189,10 +189,17 @@
return Object.prototype.hasOwnProperty.call(object, property);
}

/* Replacement for the deprecated `jQuery.isFunction()`. */
function _isFunction(obj) {
return typeof obj === "function";
}

/* Replacement for the deprecated `jQuery.trim()`. */
function _trim(text) {
return text == null ? "" : text.trim();
}

/* Replacement for the deprecated `jQuery.isArray()`. */
var _isArray = Array.isArray;

_assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
Expand Down Expand Up @@ -236,7 +243,7 @@
var i,
v,
t,
verParts = $.map($.trim(dottedVersion).split("."), function(e) {
verParts = $.map(_trim(dottedVersion).split("."), function(e) {
return parseInt(e, 10);
}),
testParts = $.map(
Expand Down Expand Up @@ -2421,7 +2428,7 @@
}
}
}
this.extraClasses = $.trim(curClasses);
this.extraClasses = _trim(curClasses);
// this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
return wasAdded;
},
Expand Down Expand Up @@ -7249,7 +7256,7 @@
d.title = d.title.substring(0, iPos);
}
}
d.title = $.trim(d.title);
d.title = _trim(d.title);

// Make sure all fields exist
for (i = 0, l = CLASS_ATTRS.length; i < l; i++) {
Expand Down Expand Up @@ -7332,6 +7339,11 @@
);
$.ui.fancytree._extensions[definition.name] = definition;
},
/** Replacement for the deprecated `jQuery.trim()`.
*
* @param {string} text
*/
trim: _trim,
/** Inverse of escapeHtml().
*
* @param {string} s
Expand Down
2 changes: 1 addition & 1 deletion test/test-ext-grid.html
Expand Up @@ -243,7 +243,7 @@
}
var n,
tree = $.ui.fancytree.getTree(),
match = $.trim($(this).val());
match = tools.trim($(this).val());

// Pass a string to perform case insensitive matching
n = tree.filterNodes(match, { mode: "hide" });
Expand Down
2 changes: 1 addition & 1 deletion test/test-ext-table.html
Expand Up @@ -119,7 +119,7 @@
*/
$("input[name=search]").on("keyup", function(e){
var match = $(this).val();
if(e && e.which === $.ui.keyCode.ESCAPE || $.trim(match) === ""){
if(e && e.which === $.ui.keyCode.ESCAPE || tools.trim(match) === ""){
$("#btnResetSearch").trigger("click");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/text-ext-filter.html
Expand Up @@ -79,7 +79,7 @@
});
opts.mode = $('#hideMode').is(':checked') ? 'hide' : 'dimm';

if ((e && e.which === $.ui.keyCode.ESCAPE) || $.trim(match) === '') {
if ((e && e.which === $.ui.keyCode.ESCAPE) || tools.trim(match) === '') {
$('button#btnResetSearch').trigger("click");
return;
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit/test-tools.js
Expand Up @@ -153,6 +153,11 @@
return typeof obj === "function";
};

/** Replacement for deprecated `$.trim`. */
TOOLS.trim = function(text) {
return text == null ? "" : text.trim();
};

/** Helper to reset environment for asynchronous Fancytree tests. */
TOOLS.setup = function(assert) {
if (!assert) {
Expand Down

0 comments on commit 13b5c63

Please sign in to comment.