date.chapril.org-framadate/js/mde-wrapper.js

75 lines
2.0 KiB
JavaScript
Raw Normal View History

function myPreviewRender(text) {
text = text.replace(/[\u00A0-\u9999<>\&]/gim, function (i) {
return "&#" + i.charCodeAt(0) + ";";
2016-05-12 16:20:47 +02:00
});
text = EasyMDE.prototype.markdown(text);
text = DOMPurify.sanitize(text);
2016-05-12 16:20:47 +02:00
return text;
}
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) {
this.enableButton.on("click", function () {
wrapper.enable();
});
2016-05-12 16:20:47 +02:00
}
if (this.disableButton) {
this.disableButton.on("click", function () {
wrapper.disable();
});
2016-05-12 16:20:47 +02:00
}
}
MDEWrapper.prototype.enable = function () {
2016-05-12 16:20:47 +02:00
var wrapper = this;
if (this.simplemde == null) {
this.simplemde = new EasyMDE({
2016-05-12 16:20:47 +02:00
element: wrapper.element,
forceSync: true,
status: true,
// previewRender: myPreviewRender,
renderingConfig: {
sanitizerFunction: function (text) {
return DOMPurify.sanitize(text);
},
},
spellChecker: false,
promptURLs: true,
minHeight: "200px",
maxHeight: "300px",
autoDownloadFontAwesome: false,
2016-05-12 16:20:47 +02:00
});
if (this.enableButton) {
this.enableButton.addClass("active");
2016-05-12 16:20:47 +02:00
}
if (this.disableButton) {
this.disableButton.removeClass("active");
2016-05-12 16:20:47 +02:00
}
}
};
2016-05-12 16:20:47 +02: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) {
this.disableButton.addClass("active");
2016-05-12 16:20:47 +02:00
}
if (this.enableButton) {
this.enableButton.removeClass("active");
2016-05-12 16:20:47 +02:00
}
}
};
2016-05-12 16:20:47 +02:00
MDEWrapper.prototype.isEnabled = function () {
2016-05-12 16:20:47 +02:00
return this.simplemde != null;
};