Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove a batch of simple JQuery uses (#40986)

David Taylor728a43dd7cd5
diff --git a/frontend/discourse/app/components/featured-topic.gjs b/frontend/discourse/app/components/featured-topic.gjs
index 0be081d3506..1015b2dff50 100644
--- a/frontend/discourse/app/components/featured-topic.gjs
+++ b/frontend/discourse/app/components/featured-topic.gjs
@@ -1,12 +1,12 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/require-tagless-components */
+/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
import Component from "@ember/component";
import { trustHTML } from "@ember/template";
import {
attributeBindings,
classNameBindings,
} from "@ember-decorators/component";
-import $ from "jquery";
import TopicPostBadges from "discourse/components/topic-post-badges";
+import domUtils from "discourse/lib/dom-utils";
import dAgeWithTooltip from "discourse/ui-kit/helpers/d-age-with-tooltip";
import TopicStatus from "./topic-status";
@@ -17,7 +17,7 @@ export default class FeaturedTopic extends Component {
if (e.target.closest(".last-posted-at")) {
this.appEvents.trigger("topic-entrance:show", {
topic: this.topic,
- position: $(e.target).offset(),
+ position: domUtils.offset(e.target),
});
return false;
}
diff --git a/frontend/discourse/app/components/group-flair-inputs.gjs b/frontend/discourse/app/components/group-flair-inputs.gjs
index 72f09a53b8b..31496ddac87 100644
--- a/frontend/discourse/app/components/group-flair-inputs.gjs
+++ b/frontend/discourse/app/components/group-flair-inputs.gjs
@@ -1,10 +1,9 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/no-observers */
+/* eslint-disable ember/no-classic-components, ember/no-observers */
import Component from "@ember/component";
import { fn } from "@ember/helper";
import { action, computed } from "@ember/object";
import { tagName } from "@ember-decorators/component";
import { observes, on } from "@ember-decorators/object";
-import $ from "jquery";
import UppyImageUploader from "discourse/components/uppy-image-uploader";
import { ajax } from "discourse/lib/ajax";
import discourseDebounce from "discourse/lib/debounce";
@@ -58,15 +57,16 @@ export default class GroupFlairInputs extends Component {
return;
}
- if (!$(`${c} symbol#${icon}`).length) {
- ajax(`/svg-sprite/search/${icon}`).then(function (data) {
- if ($(singleIconEl).length === 0) {
- $(c).append(`<div class="${h}">`);
+ if (!document.querySelector(`${c} symbol#${icon}`)) {
+ ajax(`/svg-sprite/search/${icon}`).then((data) => {
+ if (!document.querySelector(singleIconEl)) {
+ document
+ .querySelector(c)
+ .insertAdjacentHTML("beforeend", `<div class="${h}"></div>`);
}
- $(singleIconEl).html(
- `<svg xmlns='http://www.w3.org/2000/svg' style='display: none;'>${data}</svg>`
- );
+ document.querySelector(singleIconEl).innerHTML =
+ `<svg xmlns='http://www.w3.org/2000/svg' style='display: none;'>${data}</svg>`;
});
}
}
diff --git a/frontend/discourse/app/components/link-to-input.gjs b/frontend/discourse/app/components/link-to-input.gjs
index f1bf9a34499..95fef00f631 100644
--- a/frontend/discourse/app/components/link-to-input.gjs
+++ b/frontend/discourse/app/components/link-to-input.gjs
@@ -1,7 +1,6 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/require-tagless-components */
+/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
import Component from "@ember/component";
import { schedule } from "@ember/runloop";
-import $ from "jquery";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
@@ -12,7 +11,7 @@ export default class LinkToInput extends Component {
this.onClick();
schedule("afterRender", () => {
- $(this.element).find("input").focus();
+ this.element.querySelector("input").focus();
});
return false;
diff --git a/frontend/discourse/app/components/mobile-category-topic.gjs b/frontend/discourse/app/components/mobile-category-topic.gjs
index 6066c7518ad..80665379871 100644
--- a/frontend/discourse/app/components/mobile-category-topic.gjs
+++ b/frontend/discourse/app/components/mobile-category-topic.gjs
@@ -1,27 +1,24 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/require-tagless-components */
+/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
import Component from "@ember/component";
import { classNameBindings, tagName } from "@ember-decorators/component";
-import $ from "jquery";
import PostCountOrBadges from "discourse/components/topic-list/post-count-or-badges";
import TopicStatus from "discourse/components/topic-status";
import coldAgeClass from "discourse/helpers/cold-age-class";
+import domUtils from "discourse/lib/dom-utils";
import dAgeWithTooltip from "discourse/ui-kit/helpers/d-age-with-tooltip";
import dTopicLink from "discourse/ui-kit/helpers/d-topic-link";
export function showEntrance(e) {
- let target = $(e.target);
+ let target = e.target;
- if (target.hasClass("posts-map") || target.parents(".posts-map").length > 0) {
- if (target.prop("tagName") !== "A") {
- target = target.find("a");
- if (target.length === 0) {
- target = target.end();
- }
+ if (target.closest(".posts-map")) {
+ if (target.tagName !== "A") {
+ target = target.querySelector("a") || target;
}
this.appEvents.trigger("topic-entrance:show", {
topic: this.topic,
- position: target.offset(),
+ position: domUtils.offset(target),
});
return false;
}
diff --git a/frontend/discourse/app/components/search-text-field.js b/frontend/discourse/app/components/search-text-field.js
index 8b5fc3d6991..0e0fdc6c6f5 100644
--- a/frontend/discourse/app/components/search-text-field.js
+++ b/frontend/discourse/app/components/search-text-field.js
@@ -1,8 +1,6 @@
-/* eslint-disable ember/no-jquery */
import { computed } from "@ember/object";
import { getOwner } from "@ember/owner";
import { on } from "@ember-decorators/object";
-import $ from "jquery";
import { applySearchAutocomplete } from "discourse/lib/search";
import DTextField from "discourse/ui-kit/d-text-field";
import { i18n } from "discourse-i18n";
@@ -28,14 +26,13 @@ export default class SearchTextField extends DTextField {
getOwner(this)
);
- const $searchInput = $(this.element);
if (!this.hasAutofocus) {
return;
}
// iOS is crazy, without this we will not be
// at the top of the page
- $(window).scrollTop(0);
- $searchInput.focus();
+ window.scrollTo(0, 0);
+ this.element.focus();
}
@on("willDestroyElement")
diff --git a/frontend/discourse/app/lib/ajax-error.js b/frontend/discourse/app/lib/ajax-error.js
index 4932aaeaf9e..4ef76c9d64a 100644
--- a/frontend/discourse/app/lib/ajax-error.js
+++ b/frontend/discourse/app/lib/ajax-error.js
@@ -1,6 +1,4 @@
-/* eslint-disable ember/no-jquery */
import { trustHTML } from "@ember/template";
-import $ from "jquery";
import { getOwnerWithFallback } from "discourse/lib/get-owner";
import { i18n } from "discourse-i18n";
@@ -39,7 +37,7 @@ export function extractErrorInfo(
if (!parsedJSON && error.responseText) {
try {
- parsedJSON = $.parseJSON(error.responseText);
+ parsedJSON = JSON.parse(error.responseText);
} catch (ex) {
// in case the JSON doesn't parse
// eslint-disable-next-line no-console
diff --git a/frontend/discourse/app/routes/user-activity/bookmarks.js b/frontend/discourse/app/routes/user-activity/bookmarks.js
index b8575462d31..f4dbb48285b 100644
--- a/frontend/discourse/app/routes/user-activity/bookmarks.js
+++ b/frontend/discourse/app/routes/user-activity/bookmarks.js
@@ -1,8 +1,6 @@
-/* eslint-disable ember/no-jquery */
import { action } from "@ember/object";
import { trackedArray } from "@ember/reactive/collections";
import { service } from "@ember/service";
-import $ from "jquery";
import { Promise } from "rsvp";
import { ajax } from "discourse/lib/ajax";
import Bookmark from "discourse/models/bookmark";
@@ -74,7 +72,11 @@ export default class UserActivityBookmarks extends DiscourseRoute {
let url = `/u/${this.modelFor("user").username}/bookmarks.json`;
if (params) {
- url += "?" + $.param(params);
+ const searchParams = new URLSearchParams();
+ Object.entries(params).forEach(([key, value]) =>
+ searchParams.set(key, value ?? "")
+ );
+ url += "?" + searchParams;
}
return ajax(url);
diff --git a/frontend/discourse/app/ui-kit/d-radio-button.js b/frontend/discourse/app/ui-kit/d-radio-button.js
index e49c24164ae..1781f97a4fd 100644
--- a/frontend/discourse/app/ui-kit/d-radio-button.js
+++ b/frontend/discourse/app/ui-kit/d-radio-button.js
@@ -1,8 +1,7 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/require-tagless-components */
+/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
import Component from "@ember/component";
import { computed } from "@ember/object";
import { attributeBindings, tagName } from "@ember-decorators/component";
-import $ from "jquery";
@tagName("input")
@attributeBindings(
@@ -16,7 +15,7 @@ export default class DRadioButton extends Component {
type = "radio";
click() {
- const value = $(this.element).val();
+ const value = this.element.value;
if (this.onChange) {
this.onChange(value);
diff --git a/frontend/discourse/select-kit/components/icon-picker.js b/frontend/discourse/select-kit/components/icon-picker.js
index 68a4c36356b..3fa89704578 100644
--- a/frontend/discourse/select-kit/components/icon-picker.js
+++ b/frontend/discourse/select-kit/components/icon-picker.js
@@ -1,7 +1,5 @@
-/* eslint-disable ember/no-jquery */
import { action, computed } from "@ember/object";
import { classNames } from "@ember-decorators/component";
-import $ from "jquery";
import { ajax } from "discourse/lib/ajax";
import deprecated from "discourse/lib/deprecated";
import { isDevelopment } from "discourse/lib/environment";
@@ -91,16 +89,22 @@ export default class IconPicker extends MultiSelectComponent {
holder = "ajax-icon-holder";
if (typeof icon === "object") {
- if ($(`${spriteEl} .${holder}`).length === 0) {
- $(spriteEl).append(
- `<div class="${holder}" style='display: none;'></div>`
- );
+ if (!document.querySelector(`${spriteEl} .${holder}`)) {
+ document
+ .querySelector(spriteEl)
+ .insertAdjacentHTML(
+ "beforeend",
+ `<div class="${holder}" style='display: none;'></div>`
+ );
}
- if (!$(`${spriteEl} symbol#${strippedIconName}`).length) {
- $(`${spriteEl} .${holder}`).append(
- `<svg xmlns='http://www.w3.org/2000/svg'>${icon.symbol}</svg>`
- );
+ if (!document.querySelector(`${spriteEl} symbol#${strippedIconName}`)) {
+ document
+ .querySelector(`${spriteEl} .${holder}`)
+ .insertAdjacentHTML(
+ "beforeend",
+ `<svg xmlns='http://www.w3.org/2000/svg'>${icon.symbol}</svg>`
+ );
}
}
@@ -112,7 +116,9 @@ export default class IconPicker extends MultiSelectComponent {
}
willDestroyElement() {
- $("#svg-sprites .ajax-icon-holder").remove();
+ document
+ .querySelectorAll("#svg-sprites .ajax-icon-holder")
+ .forEach((el) => el.remove());
super.willDestroyElement(...arguments);
this._cachedIconsList = null;
diff --git a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-markdown.js b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-markdown.js
index f2ecd5258f7..5ab3d48c696 100644
--- a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-markdown.js
+++ b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-markdown.js
@@ -1,13 +1,14 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/require-tagless-components */
+/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
import Component from "@ember/component";
-import $ from "jquery";
import { cook } from "discourse/lib/text";
export default class StyleguideMarkdown extends Component {
didInsertElement() {
super.didInsertElement(...arguments);
- const contents = $(this.element).html();
- cook(contents).then((cooked) => $(this.element).html(cooked.toString()));
+ const contents = this.element.innerHTML;
+ cook(contents).then(
+ (cooked) => (this.element.innerHTML = cooked.toString())
+ );
}
}