mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 19:37:55 +08:00
DEV: Remove all use of Ember/jQuery globals in core (#18670)
This commit is contained in:
parent
6b788d7329
commit
58e59e3579
|
@ -13,18 +13,15 @@ export function setEnvironment(e) {
|
|||
}
|
||||
|
||||
export function isTesting() {
|
||||
// eslint-disable-next-line no-undef
|
||||
return Ember.testing || environment === "testing";
|
||||
return environment === "testing";
|
||||
}
|
||||
|
||||
// Generally means "before we migrated to Ember CLI"
|
||||
// eslint-disable-next-line no-undef
|
||||
let _isLegacy = Ember.VERSION.startsWith("3.12");
|
||||
export function isLegacyEmber() {
|
||||
deprecated("`isLegacyEmber()` is now deprecated and always returns true", {
|
||||
deprecated("`isLegacyEmber()` is now deprecated and always returns false", {
|
||||
dropFrom: "3.0.0.beta1",
|
||||
});
|
||||
return _isLegacy;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isDevelopment() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* global Ember */
|
||||
import Ember from "ember";
|
||||
import { classify, dasherize, decamelize } from "@ember/string";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import { findHelper } from "discourse-common/lib/helpers";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* global Ember */
|
||||
import Ember from "ember";
|
||||
import { dasherize, decamelize } from "@ember/string";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import { findHelper } from "discourse-common/lib/helpers";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Component from "@ember/component";
|
||||
import { schedule } from "@ember/runloop";
|
||||
import tippy from "tippy.js";
|
||||
import Ember from "ember";
|
||||
|
||||
export default class DiscourseTooltip extends Component {
|
||||
tagName = "";
|
||||
|
@ -20,7 +21,6 @@ export default class DiscourseTooltip extends Component {
|
|||
// Ember.ViewUtils.getViewBounds is a private API,
|
||||
// but it's not going to be dropped without a public deprecation warning,
|
||||
// see: https://stackoverflow.com/a/50125938/3206146
|
||||
// eslint-disable-next-line no-undef
|
||||
const viewBounds = Ember.ViewUtils.getViewBounds(this);
|
||||
const element = viewBounds.firstNode;
|
||||
const parent = viewBounds.parentElement;
|
||||
|
|
|
@ -9,6 +9,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
|||
import { action, set } from "@ember/object";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import { inject as service } from "@ember/service";
|
||||
import Ember from "ember";
|
||||
|
||||
let _components = {};
|
||||
|
||||
|
@ -108,9 +109,7 @@ export default Component.extend({
|
|||
let dasherized = dasherize(type);
|
||||
let templatePath = `components/${dasherized}`;
|
||||
let template =
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[`${templatePath}`] ||
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[`javascripts/${templatePath}`];
|
||||
_components[type] = template ? dasherized : null;
|
||||
return _components[type];
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Ember from "ember";
|
||||
|
||||
let initializedOnce = false;
|
||||
|
||||
export default {
|
||||
|
@ -10,7 +12,6 @@ export default {
|
|||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.EventDispatcher.reopen({
|
||||
events: {
|
||||
touchend: "touchEnd",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import Ember from "ember";
|
||||
let initializedOnce = false;
|
||||
|
||||
export default {
|
||||
|
@ -8,7 +9,6 @@ export default {
|
|||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.LinkComponent.reopen({
|
||||
attributeBindings: ["name"],
|
||||
});
|
||||
|
|
|
@ -10,9 +10,9 @@ import { selectedText } from "discourse/lib/utilities";
|
|||
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
import jQuery from "jquery";
|
||||
|
||||
export function isValidLink(link) {
|
||||
// eslint-disable-next-line no-undef
|
||||
if (link instanceof jQuery) {
|
||||
link = link[0];
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { helperContext, makeArray } from "discourse-common/lib/helpers";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import I18n from "I18n";
|
||||
import jQuery from "jquery";
|
||||
|
||||
export function shortDate(date) {
|
||||
return moment(date).format(I18n.t("dates.medium.date_year"));
|
||||
|
@ -50,7 +51,6 @@ export function longDateNoYear(dt) {
|
|||
}
|
||||
|
||||
export function updateRelativeAge(elems) {
|
||||
// eslint-disable-next-line no-undef
|
||||
if (elems instanceof jQuery) {
|
||||
elems = elems.toArray();
|
||||
deprecated("updateRelativeAge now expects a DOM NodeList", {
|
||||
|
|
|
@ -34,8 +34,7 @@ export default function (elem, siteSettings) {
|
|||
mainClass: "mfp-zoom-in",
|
||||
tClose: I18n.t("lightbox.close"),
|
||||
tLoading: spinnerHTML,
|
||||
// eslint-disable-next-line no-undef
|
||||
prependTo: Ember.testing && document.getElementById("ember-testing"),
|
||||
prependTo: isTesting() && document.getElementById("ember-testing"),
|
||||
|
||||
gallery: {
|
||||
enabled: true,
|
||||
|
|
|
@ -2,13 +2,13 @@ import deprecated from "discourse-common/lib/deprecated";
|
|||
import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { replaceSpan } from "discourse/lib/category-hashtags";
|
||||
import jQuery from "jquery";
|
||||
|
||||
const categoryHashtags = {};
|
||||
const tagHashtags = {};
|
||||
const checkedHashtags = new Set();
|
||||
|
||||
export function linkSeenHashtags(elem) {
|
||||
// eslint-disable-next-line no-undef
|
||||
if (elem instanceof jQuery) {
|
||||
elem = elem[0];
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { ajax } from "discourse/lib/ajax";
|
|||
import { formatUsername } from "discourse/lib/utilities";
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import jQuery from "jquery";
|
||||
|
||||
let maxGroupMention;
|
||||
|
||||
|
@ -67,7 +68,6 @@ function updateFound(mentions, usernames) {
|
|||
}
|
||||
|
||||
export function linkSeenMentions(elem, siteSettings) {
|
||||
// eslint-disable-next-line no-undef
|
||||
if (elem instanceof jQuery) {
|
||||
elem = elem[0];
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { buildRawConnectorCache } from "discourse-common/lib/raw-templates";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import Ember from "ember";
|
||||
|
||||
let _connectorCache;
|
||||
let _rawConnectorCache;
|
||||
|
@ -65,14 +66,12 @@ function findClass(outletName, uniqueName) {
|
|||
function buildConnectorCache() {
|
||||
_connectorCache = {};
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
findOutlets(Ember.TEMPLATES, (outletName, resource, uniqueName) => {
|
||||
_connectorCache[outletName] = _connectorCache[outletName] || [];
|
||||
|
||||
_connectorCache[outletName].push({
|
||||
outletName,
|
||||
templateName: resource.replace("javascripts/", ""),
|
||||
// eslint-disable-next-line no-undef
|
||||
template: Ember.TEMPLATES[resource],
|
||||
classNames: `${outletName}-outlet ${uniqueName}`,
|
||||
connectorClass: findClass(outletName, uniqueName),
|
||||
|
|
|
@ -8,6 +8,7 @@ import identifySource, {
|
|||
consolePrefix,
|
||||
getThemeInfo,
|
||||
} from "discourse/lib/source-identifier";
|
||||
import Ember from "ember";
|
||||
|
||||
const showingErrors = new Set();
|
||||
|
||||
|
@ -52,7 +53,6 @@ function reportToLogster(name, error) {
|
|||
};
|
||||
|
||||
// TODO: To be moved out into a logster-provided lib
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.$.ajax(getURL("/logs/report_js_error"), {
|
||||
data,
|
||||
type: "POST",
|
||||
|
|
|
@ -2,15 +2,14 @@ import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
|
|||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { test } from "qunit";
|
||||
import { visit } from "@ember/test-helpers";
|
||||
import Ember from "ember";
|
||||
|
||||
acceptance("CustomHTML template", function (needs) {
|
||||
needs.hooks.beforeEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES["top"] = hbs`<span class='top-span'>TOP</span>`;
|
||||
});
|
||||
|
||||
needs.hooks.afterEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES["top"];
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import { test } from "qunit";
|
|||
import I18n from "I18n";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import Ember from "ember";
|
||||
|
||||
acceptance("Modal", function (needs) {
|
||||
let _translations;
|
||||
|
@ -53,7 +54,6 @@ acceptance("Modal", function (needs) {
|
|||
await triggerKeyEvent("#main-outlet", "keydown", "Escape");
|
||||
assert.ok(!exists(".d-modal:visible"), "ESC should close the modal");
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[
|
||||
"modal/not-dismissable"
|
||||
] = hbs`{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}`;
|
||||
|
@ -78,7 +78,6 @@ acceptance("Modal", function (needs) {
|
|||
});
|
||||
|
||||
test("rawTitle in modal panels", async function (assert) {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES["modal/test-raw-title-panels"] = hbs``;
|
||||
const panels = [
|
||||
{ id: "test1", rawTitle: "Test 1" },
|
||||
|
@ -97,9 +96,7 @@ acceptance("Modal", function (needs) {
|
|||
});
|
||||
|
||||
test("modal title", async function (assert) {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES["modal/test-title"] = hbs``;
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[
|
||||
"modal/test-title-with-body"
|
||||
] = hbs`{{#d-modal-body}}test{{/d-modal-body}}`;
|
||||
|
|
|
@ -9,6 +9,7 @@ import { action } from "@ember/object";
|
|||
import { extraConnectorClass } from "discourse/lib/plugin-connectors";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { test } from "qunit";
|
||||
import Ember from "ember";
|
||||
|
||||
const PREFIX = "javascripts/single-test/connectors";
|
||||
|
||||
|
@ -48,29 +49,23 @@ acceptance("Plugin Outlet - Connector Class", function (needs) {
|
|||
},
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[
|
||||
`${PREFIX}/user-profile-primary/hello`
|
||||
] = hbs`<span class='hello-username'>{{model.username}}</span>
|
||||
<button class='say-hello' {{on "click" (action "sayHello")}}></button>
|
||||
<span class='hello-result'>{{hello}}</span>`;
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[
|
||||
`${PREFIX}/user-profile-primary/hi`
|
||||
] = hbs`<button class='say-hi' {{on "click" (action "sayHi")}}></button>
|
||||
<span class='hi-result'>{{hi}}</span>`;
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[
|
||||
`${PREFIX}/user-profile-primary/dont-render`
|
||||
] = hbs`I'm not rendered!`;
|
||||
});
|
||||
|
||||
needs.hooks.afterEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`];
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import { hbs } from "ember-cli-htmlbars";
|
|||
import { test } from "qunit";
|
||||
import { visit } from "@ember/test-helpers";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import Ember from "ember";
|
||||
|
||||
const PREFIX = "javascripts/single-test/connectors";
|
||||
|
||||
|
@ -14,9 +15,7 @@ acceptance("Plugin Outlet - Decorator", function (needs) {
|
|||
needs.user();
|
||||
|
||||
needs.hooks.beforeEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`] = hbs`FOO`;
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`] = hbs`BAR`;
|
||||
|
||||
withPluginApi("0.8.38", (api) => {
|
||||
|
@ -39,9 +38,7 @@ acceptance("Plugin Outlet - Decorator", function (needs) {
|
|||
});
|
||||
|
||||
needs.hooks.afterEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`];
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`];
|
||||
});
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { test } from "qunit";
|
||||
import { visit } from "@ember/test-helpers";
|
||||
import Ember from "ember";
|
||||
|
||||
const HELLO = "javascripts/multi-test/connectors/user-profile-primary/hello";
|
||||
const GOODBYE =
|
||||
|
@ -13,16 +14,12 @@ const GOODBYE =
|
|||
|
||||
acceptance("Plugin Outlet - Multi Template", function (needs) {
|
||||
needs.hooks.beforeEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[HELLO] = hbs`<span class='hello-span'>Hello</span>`;
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[GOODBYE] = hbs`<span class='bye-span'>Goodbye</span>`;
|
||||
});
|
||||
|
||||
needs.hooks.afterEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[HELLO];
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[GOODBYE];
|
||||
});
|
||||
|
||||
|
|
|
@ -6,20 +6,19 @@ import {
|
|||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { test } from "qunit";
|
||||
import { visit } from "@ember/test-helpers";
|
||||
import Ember from "ember";
|
||||
|
||||
const CONNECTOR =
|
||||
"javascripts/single-test/connectors/user-profile-primary/hello";
|
||||
|
||||
acceptance("Plugin Outlet - Single Template", function (needs) {
|
||||
needs.hooks.beforeEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[
|
||||
CONNECTOR
|
||||
] = hbs`<span class='hello-username'>{{model.username}}</span>`;
|
||||
});
|
||||
|
||||
needs.hooks.afterEach(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
delete Ember.TEMPLATES[CONNECTOR];
|
||||
});
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import { click, fillIn, triggerEvent } from "@ember/test-helpers";
|
|||
import { exists, query, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import { moduleForComponent } from "ember-qunit";
|
||||
import jQuery from "jquery";
|
||||
|
||||
function checkSelectKitIsNotExpanded(selector) {
|
||||
if (query(selector).classList.contains("is-expanded")) {
|
||||
|
@ -65,7 +66,6 @@ async function keyboardHelper(value, target, selector) {
|
|||
|
||||
if (value === "selectAll") {
|
||||
// special casing the only one not working with triggerEvent
|
||||
// eslint-disable-next-line no-undef
|
||||
const event = jQuery.Event("keydown");
|
||||
event.key = "A";
|
||||
event.keyCode = 65;
|
||||
|
|
|
@ -39,6 +39,7 @@ import { disableCloaking } from "discourse/widgets/post-stream";
|
|||
import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender";
|
||||
import { addModuleExcludeMatcher } from "ember-cli-test-loader/test-support/index";
|
||||
import SiteSettingService from "discourse/services/site-settings";
|
||||
import jQuery from "jquery";
|
||||
|
||||
const Plugin = $.fn.modal;
|
||||
const Modal = Plugin.Constructor;
|
||||
|
@ -389,7 +390,6 @@ export default function setupTests(config) {
|
|||
addModuleExcludeMatcher((name) => !shouldLoadModule(name));
|
||||
|
||||
// forces 0 as duration for all jquery animations
|
||||
// eslint-disable-next-line no-undef
|
||||
jQuery.fx.off = true;
|
||||
|
||||
setupToolbar();
|
||||
|
|
|
@ -4,6 +4,7 @@ import { start } from "ember-qunit";
|
|||
import loadEmberExam from "ember-exam/test-support/load";
|
||||
import * as QUnit from "qunit";
|
||||
import { setup } from "qunit-dom";
|
||||
import Ember from "ember";
|
||||
|
||||
setEnvironment("testing");
|
||||
|
||||
|
@ -27,7 +28,6 @@ document.addEventListener("discourse-booted", () => {
|
|||
const skipCore = params.get("qunit_skip_core") === "1";
|
||||
const disableAutoStart = params.get("qunit_disable_auto_start") === "1";
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;
|
||||
|
||||
document.body.insertAdjacentHTML(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { buildResolver, setResolverOption } from "discourse-common/resolver";
|
||||
import { module, test } from "qunit";
|
||||
import Ember from "ember";
|
||||
|
||||
let originalTemplates;
|
||||
let resolver;
|
||||
|
@ -12,7 +13,6 @@ function lookupTemplate(assert, name, expectedTemplate, message) {
|
|||
|
||||
function setTemplates(lookupTemplateStrings) {
|
||||
lookupTemplateStrings.forEach(function (lookupTemplateString) {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES[lookupTemplateString] = lookupTemplateString;
|
||||
});
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ const DiscourseResolver = buildResolver("discourse");
|
|||
|
||||
module("Unit | Ember | resolver", function (hooks) {
|
||||
hooks.beforeEach(function () {
|
||||
// eslint-disable-next-line no-undef
|
||||
originalTemplates = Ember.TEMPLATES;
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES = {};
|
||||
|
||||
resolver = DiscourseResolver.create({
|
||||
|
@ -32,7 +30,6 @@ module("Unit | Ember | resolver", function (hooks) {
|
|||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
// eslint-disable-next-line no-undef
|
||||
Ember.TEMPLATES = originalTemplates;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user