A platform for community discussion. Free, open, simple.
DEV: Remove INLINE_ONEBOX_* constants
Robin Wardf9608c0af5f7
diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.jsindex 7d89caa0701..7af84831e70 100644--- a/app/assets/javascripts/discourse/app/components/composer-editor.js+++ b/app/assets/javascripts/discourse/app/components/composer-editor.js@@ -43,10 +43,6 @@ import {cacheShortUploadUrl,resolveAllShortUrls} from "pretty-text/upload-short-url";-import {- INLINE_ONEBOX_LOADING_CSS_CLASS,- INLINE_ONEBOX_CSS_CLASS-} from "pretty-text/context/inline-onebox-css-classes";import ENV from "discourse-common/config/environment";const REBUILD_SCROLL_MAP_EVENTS = ["composer:resized", "composer:typed-reply"];@@ -968,32 +964,29 @@ export default Component.extend({// Inline Oneboxes = `a.inline-onebox-loading` -> `a.inline-onebox`let loadedOneboxes = $preview.find(- `aside.onebox, a.${LOADING_ONEBOX_CSS_CLASS}, a.${INLINE_ONEBOX_CSS_CLASS}`+ `aside.onebox, a.${LOADING_ONEBOX_CSS_CLASS}, a.inline-onebox-loading`).length;- $preview- .find(`a.onebox, a.${INLINE_ONEBOX_LOADING_CSS_CLASS}`)- .each((_, link) => {- const $link = $(link);- const text = $link.text();- const isInline =- $link.attr("class") === INLINE_ONEBOX_LOADING_CSS_CLASS;- const m = isInline ? inlineOneboxes : oneboxes;-- if (loadedOneboxes < this.siteSettings.max_oneboxes_per_post) {- if (m[text] === undefined) {- m[text] = [];- loadedOneboxes++;- }+ $preview.find(`a.onebox, a.inline-onebox-loading`).each((_, link) => {+ const $link = $(link);+ const text = $link.text();+ const isInline = $link.attr("class") === "inline-onebox-loading";+ const m = isInline ? inlineOneboxes : oneboxes;++ if (loadedOneboxes < this.siteSettings.max_oneboxes_per_post) {+ if (m[text] === undefined) {+ m[text] = [];+ loadedOneboxes++;+ }+ m[text].push(link);+ } else {+ if (m[text] !== undefined) {m[text].push(link);- } else {- if (m[text] !== undefined) {- m[text].push(link);- } else if (isInline) {- $link.removeClass(INLINE_ONEBOX_LOADING_CSS_CLASS);- }+ } else if (isInline) {+ $link.removeClass("inline-onebox-loading");}- });+ }+ });if (Object.keys(oneboxes).length > 0) {this._loadOneboxes(oneboxes);diff --git a/app/assets/javascripts/pretty-text-bundle.js b/app/assets/javascripts/pretty-text-bundle.jsindex a2adade3823..62dd6c1439c 100644--- a/app/assets/javascripts/pretty-text-bundle.js+++ b/app/assets/javascripts/pretty-text-bundle.js@@ -11,6 +11,5 @@//= require ./pretty-text/addon/sanitizer//= require ./pretty-text/addon/oneboxer//= require ./pretty-text/addon/oneboxer-cache-//= require ./pretty-text/addon/context/inline-onebox-css-classes//= require ./pretty-text/addon/inline-oneboxer//= require ./pretty-text/addon/upload-short-urldiff --git a/app/assets/javascripts/pretty-text/addon/context/inline-onebox-css-classes.js.erb b/app/assets/javascripts/pretty-text/addon/context/inline-onebox-css-classes.js.erbdeleted file mode 100644index a252fb28803..00000000000--- a/app/assets/javascripts/pretty-text/addon/context/inline-onebox-css-classes.js.erb+++ /dev/null@@ -1,5 +0,0 @@-export const INLINE_ONEBOX_LOADING_CSS_CLASS =- "<%= CookedPostProcessor::INLINE_ONEBOX_LOADING_CSS_CLASS %>";--export const INLINE_ONEBOX_CSS_CLASS =- "<%= CookedPostProcessor::INLINE_ONEBOX_CSS_CLASS %>";diff --git a/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown/onebox.js b/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown/onebox.jsindex 7358bdaa062..94bd5dd60f3 100644--- a/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown/onebox.js+++ b/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown/onebox.js@@ -1,9 +1,5 @@import { lookupCache } from "pretty-text/oneboxer-cache";import { cachedInlineOnebox } from "pretty-text/inline-oneboxer";-import {- INLINE_ONEBOX_LOADING_CSS_CLASS,- INLINE_ONEBOX_CSS_CLASS-} from "pretty-text/context/inline-onebox-css-classes";const ONEBOX = 1;const INLINE = 2;@@ -103,9 +99,9 @@ function applyOnebox(state, silent) {if (onebox && onebox.title) {text.content = onebox.title;- attrs.push(["class", INLINE_ONEBOX_CSS_CLASS]);+ attrs.push(["class", "inline-onebox"]);} else if (!onebox) {- attrs.push(["class", INLINE_ONEBOX_LOADING_CSS_CLASS]);+ attrs.push(["class", "inline-onebox-loading"]);}}}diff --git a/app/assets/javascripts/pretty-text/addon/inline-oneboxer.js b/app/assets/javascripts/pretty-text/addon/inline-oneboxer.jsindex 6645d1dac7e..a4587eda745 100644--- a/app/assets/javascripts/pretty-text/addon/inline-oneboxer.js+++ b/app/assets/javascripts/pretty-text/addon/inline-oneboxer.js@@ -1,8 +1,3 @@-import {- INLINE_ONEBOX_LOADING_CSS_CLASS,- INLINE_ONEBOX_CSS_CLASS-} from "pretty-text/context/inline-onebox-css-classes";-const _cache = {};export function applyInlineOneboxes(inline, ajax, opts) {@@ -27,8 +22,8 @@ export function applyInlineOneboxes(inline, ajax, opts) {links.forEach(link => {$(link).text(onebox.title)- .addClass(INLINE_ONEBOX_CSS_CLASS)- .removeClass(INLINE_ONEBOX_LOADING_CSS_CLASS);+ .addClass("inline-onebox")+ .removeClass("inline-onebox-loading");});}});diff --git a/app/assets/javascripts/pretty-text/addon/white-lister.js b/app/assets/javascripts/pretty-text/addon/white-lister.jsindex 8a3a1140f1e..88eb29085b4 100644--- a/app/assets/javascripts/pretty-text/addon/white-lister.js+++ b/app/assets/javascripts/pretty-text/addon/white-lister.js@@ -1,8 +1,3 @@-import {- INLINE_ONEBOX_LOADING_CSS_CLASS,- INLINE_ONEBOX_CSS_CLASS-} from "pretty-text/context/inline-onebox-css-classes";-// to match:// abcd// abcd[test]@@ -121,8 +116,8 @@ export const DEFAULT_LIST = ["a.mention","a.mention-group","a.onebox",- `a.${INLINE_ONEBOX_CSS_CLASS}`,- `a.${INLINE_ONEBOX_LOADING_CSS_CLASS}`,+ `a.inline-onebox`,+ `a.inline-onebox-loading`,"a[data-bbcode]","a[name]","a[rel=nofollow]",diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex d2e8f4d2d50..d6fb05a3084 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -4,8 +4,6 @@# For example, inserting the onebox content, or image sizes/thumbnails.class CookedPostProcessor- INLINE_ONEBOX_LOADING_CSS_CLASS = "inline-onebox-loading"- INLINE_ONEBOX_CSS_CLASS = "inline-onebox"LIGHTBOX_WRAPPER_CSS_CLASS = "lightbox-wrapper"LOADING_SIZE = 10LOADING_COLORS = 32@@ -518,7 +516,7 @@ class CookedPostProcessoroneboxes = {}inlineOneboxes = {}- Oneboxer.apply(@doc, extra_paths: [".#{INLINE_ONEBOX_LOADING_CSS_CLASS}"]) do |url, element|+ Oneboxer.apply(@doc, extra_paths: [".inline-onebox-loading"]) do |url, element|is_onebox = element["class"] == Oneboxer::ONEBOX_CSS_CLASSmap = is_onebox ? oneboxes : inlineOneboxesskip_onebox = limit <= 0 && !map[url]@@ -724,14 +722,14 @@ class CookedPostProcessorif title = inline_onebox&.dig(:title)element.children = CGI.escapeHTML(title)- element.add_class(INLINE_ONEBOX_CSS_CLASS)+ element.add_class("inline-onebox")endremove_inline_onebox_loading_class(element)enddef remove_inline_onebox_loading_class(element)- element.remove_class(INLINE_ONEBOX_LOADING_CSS_CLASS)+ element.remove_class("inline-onebox-loading")enddef is_svg?(img)diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex a429d64bee7..b62350d2be5 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -97,10 +97,7 @@ describe CookedPostProcessor docpp.post_processexpect(cpp.html).to have_tag('a',- with: {- href: url,- class: described_class::INLINE_ONEBOX_CSS_CLASS- },+ with: { href: url, class: "inline-onebox" },text: title,count: 2)@@ -113,9 +110,7 @@ describe CookedPostProcessor do)expect(cpp.html).to have_tag('a',- without: {- class: described_class::INLINE_ONEBOX_LOADING_CSS_CLASS- },+ without: { class: "inline-onebox-loading" },text: not_oneboxed_url,count: 1)@@ -131,10 +126,6 @@ describe CookedPostProcessor doenddescribe 'when post contains inline oneboxes' do- let(:loading_css_class) do- described_class::INLINE_ONEBOX_LOADING_CSS_CLASS- end-before doSiteSetting.enable_inline_onebox_on_all_domains = trueend@@ -148,12 +139,8 @@ describe CookedPostProcessor docpp.post_processexpect(cpp.html).to have_tag('a',- with: {- href: UrlHelper.cook_url(url)- },- without: {- class: loading_css_class- },+ with: { href: UrlHelper.cook_url(url) },+ without: { class: "inline-onebox-loading" },text: topic.title,count: 1)@@ -163,12 +150,8 @@ describe CookedPostProcessor docpp.post_processexpect(cpp.html).to have_tag('a',- with: {- href: UrlHelper.cook_url(url)- },- without: {- class: loading_css_class- },+ with: { href: UrlHelper.cook_url(url) },+ without: { class: "inline-onebox-loading" },text: topic.title,count: 1)@@ -235,33 +218,21 @@ describe CookedPostProcessor dohtml = cpp.htmlexpect(html).to_not have_tag('a',- with: {- href: url_no_path- },- without: {- class: loading_css_class- },+ with: { href: url_no_path },+ without: { class: "inline-onebox-loading" },text: title)expect(html).to have_tag('a',- with: {- href: url_with_path- },- without: {- class: loading_css_class- },+ with: { href: url_with_path },+ without: { class: "inline-onebox-loading" },text: title,count: 2)expect(html).to have_tag('a',- with: {- href: url_with_query_param- },- without: {- class: loading_css_class- },+ with: { href: url_with_query_param },+ without: { class: "inline-onebox-loading" },text: title,count: 1)diff --git a/test/javascripts/acceptance/composer-onebox-test.js b/test/javascripts/acceptance/composer-onebox-test.jsindex 6e047238b03..ab2484d1e9e 100644--- a/test/javascripts/acceptance/composer-onebox-test.js+++ b/test/javascripts/acceptance/composer-onebox-test.js@@ -1,5 +1,4 @@import { acceptance } from "helpers/qunit-helpers";-import { INLINE_ONEBOX_CSS_CLASS } from "pretty-text/context/inline-onebox-css-classes";acceptance("Composer - Onebox", {loggedIn: true,@@ -36,10 +35,10 @@ http://www.example.com/has-title.html.trim(),`<p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\">An interesting article</a></h3></article></aside><br>-This is another test <a href=\"http://www.example.com/has-title.html\" class=\"${INLINE_ONEBOX_CSS_CLASS}\">This is a great title</a></p>+This is another test <a href=\"http://www.example.com/has-title.html\" class=\"inline-onebox\">This is a great title</a></p><p><a href=\"http://www.example.com/no-title.html\" class=\"onebox\" target=\"_blank\">http://www.example.com/no-title.html</a></p><p>This is another test <a href=\"http://www.example.com/no-title.html\" class=\"\">http://www.example.com/no-title.html</a><br>-This is another test <a href=\"http://www.example.com/has-title.html\" class=\"${INLINE_ONEBOX_CSS_CLASS}\">This is a great title</a></p>+This is another test <a href=\"http://www.example.com/has-title.html\" class=\"inline-onebox\">This is a great title</a></p><p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\">An interesting article</a></h3></article></aside></p>`.trim());diff --git a/test/javascripts/lib/pretty-text-test.js b/test/javascripts/lib/pretty-text-test.jsindex 8443cccdb63..a5619bcc77d 100644--- a/test/javascripts/lib/pretty-text-test.js+++ b/test/javascripts/lib/pretty-text-test.js@@ -2,7 +2,6 @@ import { buildQuote } from "discourse/lib/quote";import Post from "discourse/models/post";import PrettyText, { buildOptions } from "pretty-text/pretty-text";import { IMAGE_VERSION as v } from "pretty-text/emoji/version";-import { INLINE_ONEBOX_LOADING_CSS_CLASS } from "pretty-text/context/inline-onebox-css-classes";import {applyCachedInlineOnebox,deleteCachedInlineOnebox@@ -205,7 +204,7 @@ QUnit.test("Links", assert => {assert.cooked(`Youtube: ${link}`,- `<p>Youtube: <a href="${link}" class="${INLINE_ONEBOX_LOADING_CSS_CLASS}">${link}</a></p>`,+ `<p>Youtube: <a href="${link}" class="inline-onebox-loading">${link}</a></p>`,"allows links to contain query params");@@ -222,7 +221,7 @@ QUnit.test("Links", assert => {assert.cooked("Derpy: http://derp.com?__test=1",- `<p>Derpy: <a href="http://derp.com?__test=1" class="${INLINE_ONEBOX_LOADING_CSS_CLASS}">http://derp.com?__test=1</a></p>`,+ `<p>Derpy: <a href="http://derp.com?__test=1" class="inline-onebox-loading">http://derp.com?__test=1</a></p>`,"works with double underscores in urls");@@ -252,7 +251,7 @@ QUnit.test("Links", assert => {assert.cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",- `<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)" class="${INLINE_ONEBOX_LOADING_CSS_CLASS}">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>`,+ `<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)" class="inline-onebox-loading">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>`,"autolinks a URL with parentheses (like Wikipedia)");@@ -264,7 +263,7 @@ QUnit.test("Links", assert => {assert.cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",- `<ol>\n<li>View <span class="mention">@eviltrout</span>\'s profile here: <a href="http://meta.discourse.org/u/eviltrout/activity" class="${INLINE_ONEBOX_LOADING_CSS_CLASS}">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li>\n</ol>`,+ `<ol>\n<li>View <span class="mention">@eviltrout</span>\'s profile here: <a href="http://meta.discourse.org/u/eviltrout/activity" class="inline-onebox-loading">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li>\n</ol>`,"allows autolinking within a list without inserting a paragraph.");@@ -289,8 +288,8 @@ QUnit.test("Links", assert => {assert.cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",'<p><a href="http://discourse.org">http://discourse.org</a> and ' +- `<a href="http://discourse.org/another_url" class="${INLINE_ONEBOX_LOADING_CSS_CLASS}">http://discourse.org/another_url</a> and ` +- `<a href="http://www.imdb.com/name/nm2225369" class="${INLINE_ONEBOX_LOADING_CSS_CLASS}">http://www.imdb.com/name/nm2225369</a></p>`,+ `<a href="http://discourse.org/another_url" class="inline-onebox-loading">http://discourse.org/another_url</a> and ` ++ `<a href="http://www.imdb.com/name/nm2225369" class="inline-onebox-loading">http://www.imdb.com/name/nm2225369</a></p>`,"allows multiple links on one line");