2021-12-17 14:09:14 +01:00
|
|
|
function myPreviewRender(text) {
|
|
|
|
text = text.replace(/[\u00A0-\u9999<>\&]/gim, function (i) {
|
|
|
|
return "&#" + i.charCodeAt(0) + ";";
|
2016-05-12 16:20:47 +02:00
|
|
|
});
|
2021-12-20 17:46:50 +01:00
|
|
|
text = EasyMDE.prototype.markdown(text);
|
2021-03-22 15:56:09 +01:00
|
|
|
text = DOMPurify.sanitize(text);
|
2016-05-12 16:20:47 +02:00
|
|
|
|
|
|
|
return text;
|
2021-12-17 14:09:14 +01:00
|
|
|
}
|
2016-05-12 16:20:47 +02:00
|
|
|
|
|
|
|
function MDEWrapper(textarea, enableButton, disableButton) {
|
|
|
|
this.element = textarea;
|
|
|
|
this.enableButton = enableButton;
|
|
|
|
this.disableButton = disableButton;
|
|
|
|
this.simplemde = null;
|
|
|
|
|
|
|
|
var wrapper = this;
|
|
|
|
|
|
|
|
if (this.enableButton) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.enableButton.on("click", function () {
|
|
|
|
wrapper.enable();
|
|
|
|
});
|
2016-05-12 16:20:47 +02:00
|
|
|
}
|
|
|
|
if (this.disableButton) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.disableButton.on("click", function () {
|
|
|
|
wrapper.disable();
|
|
|
|
});
|
2016-05-12 16:20:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 14:06:53 +01:00
|
|
|
MDEWrapper.prototype.enable = function () {
|
2016-05-12 16:20:47 +02:00
|
|
|
var wrapper = this;
|
|
|
|
if (this.simplemde == null) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.simplemde = new EasyMDE({
|
2016-05-12 16:20:47 +02:00
|
|
|
element: wrapper.element,
|
|
|
|
forceSync: true,
|
|
|
|
status: true,
|
2021-12-20 17:46:50 +01:00
|
|
|
// previewRender: myPreviewRender,
|
|
|
|
renderingConfig: {
|
|
|
|
sanitizerFunction: function (text) {
|
|
|
|
return DOMPurify.sanitize(text);
|
|
|
|
},
|
|
|
|
},
|
2016-05-12 17:57:53 +02:00
|
|
|
spellChecker: false,
|
2018-04-15 12:14:28 +02:00
|
|
|
promptURLs: true,
|
2021-12-17 14:06:53 +01:00
|
|
|
minHeight: "200px",
|
|
|
|
maxHeight: "300px",
|
|
|
|
autoDownloadFontAwesome: false,
|
2016-05-12 16:20:47 +02:00
|
|
|
});
|
|
|
|
if (this.enableButton) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.enableButton.addClass("active");
|
2016-05-12 16:20:47 +02:00
|
|
|
}
|
|
|
|
if (this.disableButton) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.disableButton.removeClass("active");
|
2016-05-12 16:20:47 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-17 14:06:53 +01:00
|
|
|
};
|
2016-05-12 16:20:47 +02:00
|
|
|
|
2021-12-17 14:06:53 +01:00
|
|
|
MDEWrapper.prototype.disable = function () {
|
2016-05-12 16:20:47 +02:00
|
|
|
if (this.simplemde != null) {
|
|
|
|
this.simplemde.toTextArea();
|
|
|
|
this.simplemde = null;
|
|
|
|
if (this.disableButton) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.disableButton.addClass("active");
|
2016-05-12 16:20:47 +02:00
|
|
|
}
|
|
|
|
if (this.enableButton) {
|
2021-12-17 14:06:53 +01:00
|
|
|
this.enableButton.removeClass("active");
|
2016-05-12 16:20:47 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-17 14:06:53 +01:00
|
|
|
};
|
2016-05-12 16:20:47 +02:00
|
|
|
|
2021-12-17 14:06:53 +01:00
|
|
|
MDEWrapper.prototype.isEnabled = function () {
|
2016-05-12 16:20:47 +02:00
|
|
|
return this.simplemde != null;
|
2021-12-17 14:06:53 +01:00
|
|
|
};
|