DEV: Remove `jQuery` global usage where possible (#14905)

This commit is contained in:
Jarek Radosz 2021-11-12 19:23:20 +01:00 committed by GitHub
parent 97aa56bdc3
commit 9ca93f57cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 16 additions and 8 deletions

View File

@ -5,6 +5,7 @@
"eol-last": 2 "eol-last": 2
}, },
"globals": { "globals": {
"jQuery": "off",
"moduleFor": "off", "moduleFor": "off",
"moduleForComponent": "off", "moduleForComponent": "off",
"testStart": "off", "testStart": "off",

View File

@ -18,7 +18,7 @@ function lookupView(templateName) {
} }
function renderRaw(ctx, template, templateName, params) { function renderRaw(ctx, template, templateName, params) {
params = jQuery.extend({}, params); params = Object.assign({}, params);
params.parent = params.parent || ctx; params.parent = params.parent || ctx;
let context = helperContext(); let context = helperContext();
@ -30,7 +30,7 @@ function renderRaw(ctx, template, templateName, params) {
} }
if (!params.view) { if (!params.view) {
params = jQuery.extend({}, params, context); params = Object.assign({}, params, context);
} }
} }

View File

@ -50,6 +50,7 @@ export function longDateNoYear(dt) {
} }
export function updateRelativeAge(elems) { export function updateRelativeAge(elems) {
// eslint-disable-next-line no-undef
if (elems instanceof jQuery) { if (elems instanceof jQuery) {
elems = elems.toArray(); elems = elems.toArray();
deprecated("updateRelativeAge now expects a DOM NodeList", { deprecated("updateRelativeAge now expects a DOM NodeList", {

View File

@ -14,6 +14,7 @@ export default function highlightSyntax(elem, siteSettings, session) {
: "pre code[class]"; : "pre code[class]";
const path = session.highlightJsPath; const path = session.highlightJsPath;
// eslint-disable-next-line no-undef
if (elem instanceof jQuery) { if (elem instanceof jQuery) {
deprecated( deprecated(
"highlightSyntax now takes a DOM node instead of a jQuery object.", "highlightSyntax now takes a DOM node instead of a jQuery object.",

View File

@ -8,6 +8,7 @@ const tagHashtags = {};
const checkedHashtags = new Set(); const checkedHashtags = new Set();
export function linkSeenHashtags(elem) { export function linkSeenHashtags(elem) {
// eslint-disable-next-line no-undef
if (elem instanceof jQuery) { if (elem instanceof jQuery) {
elem = elem[0]; elem = elem[0];

View File

@ -67,6 +67,7 @@ function updateFound(mentions, usernames) {
} }
export function linkSeenMentions(elem, siteSettings) { export function linkSeenMentions(elem, siteSettings) {
// eslint-disable-next-line no-undef
if (elem instanceof jQuery) { if (elem instanceof jQuery) {
elem = elem[0]; elem = elem[0];

View File

@ -53,7 +53,7 @@ function findClass(outletName, uniqueName) {
let foundClass = _extraConnectorClasses[id] || _classPaths[id]; let foundClass = _extraConnectorClasses[id] || _classPaths[id];
return foundClass return foundClass
? jQuery.extend({}, DefaultConnectorClass, foundClass) ? Object.assign({}, DefaultConnectorClass, foundClass)
: DefaultConnectorClass; : DefaultConnectorClass;
} }

View File

@ -6,7 +6,7 @@ const TIMEFRAME_BASE = {
}; };
function buildTimeframe(opts) { function buildTimeframe(opts) {
return jQuery.extend({}, TIMEFRAME_BASE, opts); return Object.assign({}, TIMEFRAME_BASE, opts);
} }
const TIMEFRAMES = [ const TIMEFRAMES = [

View File

@ -131,7 +131,7 @@ export default createWidget("button", ButtonClass);
createWidget( createWidget(
"flat-button", "flat-button",
jQuery.extend(ButtonClass, { Object.assign(ButtonClass, {
tagName: "button.widget-button.btn-flat", tagName: "button.widget-button.btn-flat",
}) })
); );

View File

@ -146,7 +146,7 @@ createWidget("header-notifications", {
createWidget( createWidget(
"user-dropdown", "user-dropdown",
jQuery.extend( Object.assign(
{ {
tagName: "li.header-dropdown-toggle.current-user", tagName: "li.header-dropdown-toggle.current-user",
@ -176,7 +176,7 @@ createWidget(
createWidget( createWidget(
"header-dropdown", "header-dropdown",
jQuery.extend( Object.assign(
{ {
tagName: "li.header-dropdown-toggle", tagName: "li.header-dropdown-toggle",

View File

@ -4,7 +4,7 @@ import { h } from "virtual-dom";
createWidget( createWidget(
"post-admin-menu-button", "post-admin-menu-button",
jQuery.extend(ButtonClass, { tagName: "li.btn" }) Object.assign(ButtonClass, { tagName: "li.btn" })
); );
createWidget("post-admin-menu-button", { createWidget("post-admin-menu-button", {

View File

@ -65,6 +65,7 @@ async function keyboardHelper(value, target, selector) {
if (value === "selectAll") { if (value === "selectAll") {
// special casing the only one not working with triggerEvent // special casing the only one not working with triggerEvent
// eslint-disable-next-line no-undef
const event = jQuery.Event("keydown"); const event = jQuery.Event("keydown");
event.key = "A"; event.key = "A";
event.keyCode = 65; event.keyCode = 65;

View File

@ -379,6 +379,7 @@ function setupTestsCommon(application, container, config) {
} }
// forces 0 as duration for all jquery animations // forces 0 as duration for all jquery animations
// eslint-disable-next-line no-undef
jQuery.fx.off = true; jQuery.fx.off = true;
setupToolbar(); setupToolbar();

View File

@ -5,6 +5,7 @@ import getUrl from "discourse-common/lib/get-url";
import { htmlSafe } from "@ember/template"; import { htmlSafe } from "@ember/template";
import { schedule } from "@ember/runloop"; import { schedule } from "@ember/runloop";
// eslint-disable-next-line no-undef
jQuery.fn.wiggle = function (times, duration) { jQuery.fn.wiggle = function (times, duration) {
if (times > 0) { if (times > 0) {
this.animate( this.animate(