REFACTOR: Remove `Discourse.SiteSettings` from clipboardData

Also rename method to `clipboardHelpers` to make searching easier since
`clipboardData` refers to browser functionality.
This commit is contained in:
Robin Ward 2020-07-22 14:57:38 -04:00
parent 0213211068
commit bad083b3a3
3 changed files with 12 additions and 6 deletions

View File

@ -25,7 +25,7 @@ import { iconHTML } from "discourse-common/lib/icon-library";
import {
tinyAvatar,
formatUsername,
clipboardData,
clipboardHelpers,
caretPosition,
inCodeBlock
} from "discourse/lib/utilities";
@ -656,7 +656,10 @@ export default Component.extend({
return;
}
const { canUpload, canPasteHtml, types } = clipboardData(e, true);
const { canUpload, canPasteHtml, types } = clipboardHelpers(e, {
siteSettings: this.siteSettings,
canUpload: true
});
if (!canUpload || canPasteHtml || types.includes("text/plain")) {
e.preventDefault();

View File

@ -15,7 +15,7 @@ import { findRawTemplate } from "discourse-common/lib/raw-templates";
import { siteDir } from "discourse/lib/text-direction";
import {
determinePostReplaceSelection,
clipboardData,
clipboardHelpers,
safariHacksDisabled,
caretPosition,
inCodeBlock
@ -863,7 +863,10 @@ export default Component.extend({
}
const isComposer = $("#reply-control .d-editor-input").is(":focus");
let { clipboard, canPasteHtml, canUpload } = clipboardData(e, isComposer);
let { clipboard, canPasteHtml, canUpload } = clipboardHelpers(e, {
siteSettings: this.siteSettings,
canUpload: isComposer
});
let plainText = clipboard.getData("text/plain");
let html = clipboard.getData("text/html");

View File

@ -310,7 +310,7 @@ const toArray = items => {
return items;
};
export function clipboardData(e, canUpload) {
export function clipboardHelpers(e, opts) {
const clipboard =
e.clipboardData ||
e.originalEvent.clipboardData ||
@ -324,7 +324,7 @@ export function clipboardData(e, canUpload) {
files = toArray(clipboard.items).filter(i => i.kind === "file");
}
canUpload = files && canUpload && types.includes("Files");
let canUpload = files && opts.canUpload && types.includes("Files");
const canUploadImage =
canUpload && files.filter(f => f.type.match("^image/"))[0];
const canPasteHtml =