DEV: Use native `element.closest()` (#17482)

This commit is contained in:
Jarek Radosz 2022-07-14 02:57:24 +02:00 committed by GitHub
parent abe9b41ddf
commit 3ada82f713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 24 deletions

View File

@ -15,10 +15,10 @@ export default Component.extend({
this._clearFlash();
}
let fixedParent = $(this.element).closest(".d-modal.fixed-modal");
if (fixedParent.length) {
let fixedParent = this.element.closest(".d-modal.fixed-modal");
if (fixedParent) {
this.set("fixed", true);
fixedParent.modal("show");
$(fixedParent).modal("show");
}
scheduleOnce("afterRender", this, this._afterFirstRender);

View File

@ -1,14 +1,14 @@
import Component from "@ember/component";
export default Component.extend({
classNameBindings: [":featured-topic"],
attributeBindings: ["topic.id:data-topic-id"],
click(e) {
const $target = $(e.target);
if ($target.closest(".last-posted-at").length) {
if (e.target.closest(".last-posted-at")) {
this.appEvents.trigger("topic-entrance:show", {
topic: this.topic,
position: $target.offset(),
position: $(e.target).offset(),
});
return false;
}

View File

@ -164,10 +164,10 @@ export default Component.extend(LoadMore, {
click(e) {
const onClick = (sel, callback) => {
let target = $(e.target).closest(sel);
let target = e.target.closest(sel);
if (target.length === 1) {
callback.apply(this, [target]);
if (target) {
callback.call(this, target);
}
};
@ -186,8 +186,8 @@ export default Component.extend(LoadMore, {
$("input.bulk-select:checked").click();
});
onClick("th.sortable", function (e2) {
this.changeSort(e2.data("sort-order"));
onClick("th.sortable", function (element) {
this.changeSort(element.dataset.sortOrder);
this.rerender();
});
@ -210,15 +210,15 @@ export default Component.extend(LoadMore, {
keyDown(e) {
if (e.key === "Enter" || e.key === " ") {
let onKeyDown = (sel, callback) => {
let target = $(e.target).closest(sel);
let target = e.target.closest(sel);
if (target.length === 1) {
callback.apply(this, [target]);
if (target) {
callback.call(this, target);
}
};
onKeyDown("th.sortable", (e2) => {
this.changeSort(e2.data("sort-order"));
onKeyDown("th.sortable", (element) => {
this.changeSort(element.dataset.sortOrder);
this.rerender();
});
}

View File

@ -345,11 +345,12 @@ export default Mixin.create({
@bind
_clickOutsideHandler(event) {
if (this.visible) {
const $target = $(event.target);
if (
$target.closest(`[data-${this.elementId}]`).data(this.elementId) ||
$target.closest(`a.${this.triggeringLinkClass}`).length > 0 ||
$target.closest(`#${this.elementId}`).length > 0
event.target
.closest(`[data-${this.elementId}]`)
?.getAttribute(`data-${this.elementId}`) ||
event.target.closest(`a.${this.triggeringLinkClass}`) ||
event.target.closest(`#${this.elementId}`)
) {
return;
}

View File

@ -136,7 +136,7 @@ export default createWidget("home-logo", {
}
e.preventDefault();
DiscourseURL.routeToTag($(e.target).closest("a")[0]);
DiscourseURL.routeToTag(e.target.closest("a"));
return false;
},
});

View File

@ -131,6 +131,6 @@ export default createWidget("link", {
this.sendWidgetEvent("linkClicked", this.attrs);
}
return DiscourseURL.routeToTag($(e.target).closest("a")[0]);
return DiscourseURL.routeToTag(e.target.closest("a"));
},
});

View File

@ -81,7 +81,7 @@ createWidget("topic-admin-menu-button", {
if (e === undefined) {
$button = $(".keyboard-target-admin-menu");
} else {
$button = $(e.target).closest("button");
$button = $(e.target.closest("button"));
}
const position = $button.position(),

View File

@ -70,7 +70,7 @@ createWidget("discourse-poll-option", {
},
click(e) {
if ($(e.target).closest("a").length === 0) {
if (!e.target.closest("a")) {
this.sendWidgetAction("toggleOption", this.attrs.option);
}
},