zjquery: Add closest() method.

This commit is contained in:
Puneeth Chaganti
2019-05-22 05:19:54 +05:30
committed by Tim Abbott
parent b13add3eaf
commit be527905ca
2 changed files with 40 additions and 0 deletions

View File

@@ -163,6 +163,18 @@ exports.make_new_elem = function (selector, opts) {
event_store.generic_event('click', arg);
return self;
},
closest: function (selector) {
var elem = self;
var search = selector.startsWith('.') || selector.startsWith('#') ? selector.substring(1) : selector;
if (elem.selector.indexOf(search) > -1) {
return elem;
} else if (parents_result.get(selector)) {
return parents_result.get(selector);
} else if (!elem.parent()) {
return [];
}
return elem.parent().closest(selector);
},
data: noop,
delay: function () {
return self;