0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 11:00:28 +01:00

prettified the file

Dieser Commit ist enthalten in:
Faizaan Gagan 2020-11-11 17:07:30 +05:30
Ursprung f096f7d05f
Commit 295eaf2b21

Datei anzeigen

@ -1,5 +1,8 @@
import ComposerEditor from "discourse/components/composer-editor"; import ComposerEditor from "discourse/components/composer-editor";
import { default as discourseComputed, on } from "discourse-common/utils/decorators"; import {
default as discourseComputed,
on,
} from "discourse-common/utils/decorators";
import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { findRawTemplate } from "discourse-common/lib/raw-templates";
import { throttle } from "@ember/runloop"; import { throttle } from "@ember/runloop";
import { scheduleOnce, next } from "@ember/runloop"; import { scheduleOnce, next } from "@ember/runloop";
@ -12,7 +15,7 @@ import highlightSyntax from "discourse/lib/highlight-syntax";
import { getToken } from "wizard/lib/ajax"; import { getToken } from "wizard/lib/ajax";
import { import {
validateUploadedFiles, validateUploadedFiles,
getUploadMarkdown getUploadMarkdown,
} from "discourse/lib/uploads"; } from "discourse/lib/uploads";
import { cacheShortUploadUrl } from "pretty-text/upload-short-url"; import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
import { alias } from "@ember/object/computed"; import { alias } from "@ember/object/computed";
@ -51,7 +54,7 @@ export default ComposerEditor.extend({
scheduleOnce("afterRender", () => $input.blur().focus()); scheduleOnce("afterRender", () => $input.blur().focus());
}, },
triggerRule: (textarea) => triggerRule: (textarea) =>
!inCodeBlock(textarea.value, caretPosition(textarea)) !inCodeBlock(textarea.value, caretPosition(textarea)),
}); });
} }
@ -68,12 +71,13 @@ export default ComposerEditor.extend({
@discourseComputed @discourseComputed
allowedFileTypes() { allowedFileTypes() {
return this.siteSettings.authorized_extensions.split('|') return this.siteSettings.authorized_extensions
.map(ext => "." + ext) .split("|")
.join(',') .map((ext) => "." + ext)
.join(",");
}, },
@discourseComputed('currentUser') @discourseComputed("currentUser")
uploadIcon(currentUser) { uploadIcon(currentUser) {
return uploadIcon(false, this.siteSettings); return uploadIcon(false, this.siteSettings);
}, },
@ -89,11 +93,7 @@ export default ComposerEditor.extend({
this._super(...arguments); this._super(...arguments);
const $element = $(this.element); const $element = $(this.element);
// adding dropZone property post initialization // adding dropZone property post initialization
$element.fileupload( $element.fileupload("option", "dropZone", $element);
'option',
'dropZone',
$element
);
$element.off("fileuploadsubmit"); $element.off("fileuploadsubmit");
@ -176,7 +176,7 @@ export default ComposerEditor.extend({
this.appEvents.trigger("wizard-editor:insert-text", { this.appEvents.trigger("wizard-editor:insert-text", {
fieldId: this.field.id, fieldId: this.field.id,
text: this.uploadPlaceholder text: this.uploadPlaceholder,
}); });
if (data.xhr && data.originalFiles.length === 1) { if (data.xhr && data.originalFiles.length === 1) {
@ -197,13 +197,11 @@ export default ComposerEditor.extend({
); );
cacheShortUploadUrl(upload.short_url, upload); cacheShortUploadUrl(upload.short_url, upload);
this.appEvents.trigger( this.appEvents.trigger("wizard-editor:replace-text", {
"wizard-editor:replace-text", { fieldId: this.field.id,
fieldId: this.field.id, oldVal: this.uploadPlaceholder.trim(),
oldVal: this.uploadPlaceholder.trim(), newVal: markdown,
newVal: markdown });
}
);
this._resetUpload(false); this._resetUpload(false);
} else { } else {
this._resetUpload(true); this._resetUpload(true);
@ -224,13 +222,11 @@ export default ComposerEditor.extend({
}); });
} }
if (removePlaceholder) { if (removePlaceholder) {
this.appEvents.trigger( this.appEvents.trigger("wizard-editor:replace-text", {
"wizard-editor:replace-text", { fieldId: this.field.id,
fieldId: this.field.id, oldVal: this.uploadPlaceholder,
oldVal: this.uploadPlaceholder, newVal: "",
newVal: "" });
}
);
} }
this._resetUploadFilenamePlaceholder(); this._resetUploadFilenamePlaceholder();
}); });
@ -255,18 +251,15 @@ export default ComposerEditor.extend({
`![$1|$2, ${scale}%$4]($5)` `![$1|$2, ${scale}%$4]($5)`
); );
this.appEvents.trigger( this.appEvents.trigger("wizard-editor:replace-text", {
"wizard-editor:replace-text", fieldId: this.field.id,
{ oldVal: matchingPlaceholder[index],
fieldId: this.field.id, newVal: replacement,
oldVal: matchingPlaceholder[index], options: {
newVal: replacement, regex: imageScaleRegex,
options: { index,
regex: imageScaleRegex, },
index });
}
}
);
} }
} }
@ -276,8 +269,8 @@ export default ComposerEditor.extend({
}, },
click(e) { click(e) {
if ($(e.target).hasClass('wizard-composer-hyperlink')) { if ($(e.target).hasClass("wizard-composer-hyperlink")) {
this.set('showHyperlinkBox', false); this.set("showHyperlinkBox", false);
} }
}, },
@ -314,7 +307,7 @@ export default ComposerEditor.extend({
let link = `[${linkName}](${linkUrl})`; let link = `[${linkName}](${linkUrl})`;
this.appEvents.trigger("wizard-editor:insert-text", { this.appEvents.trigger("wizard-editor:insert-text", {
fieldId: this.field.id, fieldId: this.field.id,
text: link text: link,
}); });
this.set("showHyperlinkBox", false); this.set("showHyperlinkBox", false);
}, },
@ -325,6 +318,6 @@ export default ComposerEditor.extend({
showUploadModal() { showUploadModal() {
$(this.element.querySelector(".wizard-composer-upload")).trigger("click"); $(this.element.querySelector(".wizard-composer-upload")).trigger("click");
} },
}, },
}); });