|
|
|
@ -151,7 +151,7 @@ var CLASS_REGEX = {};
|
|
|
|
|
* @param {String} className Class name to convert to regex for matching.
|
|
|
|
|
* @returns {RegExp} Regular expression option that will match className.
|
|
|
|
|
*/
|
|
|
|
|
function getClassRegex (className) {
|
|
|
|
|
function getClassRegex(className) {
|
|
|
|
|
return CLASS_REGEX[className] || (CLASS_REGEX[className] = new RegExp('\\s*' + className + '(\\s*)', 'g'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -161,7 +161,7 @@ function getClassRegex (className) {
|
|
|
|
|
* @param {String} className Class string to apply
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
function addClass (el, className) {
|
|
|
|
|
function addClass(el, className) {
|
|
|
|
|
if (!el || !className) return;
|
|
|
|
|
var classRegex = getClassRegex(className);
|
|
|
|
|
if (el.className.match(classRegex)) return; // already applied
|
|
|
|
@ -174,7 +174,7 @@ function addClass (el, className) {
|
|
|
|
|
* @param {String} className Class string to remove
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
function removeClass (el, className) {
|
|
|
|
|
function removeClass(el, className) {
|
|
|
|
|
if (!el || !className) return;
|
|
|
|
|
var classRegex = getClassRegex(className);
|
|
|
|
|
if (!el.className.match(classRegex)) return; // not available to remove
|
|
|
|
@ -241,7 +241,7 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts,
|
|
|
|
|
|
|
|
|
|
// Prevent errors if there is no class name in custom options
|
|
|
|
|
var classNameParts = [];
|
|
|
|
|
if(typeof options.className !== 'undefined') {
|
|
|
|
|
if (typeof options.className !== 'undefined') {
|
|
|
|
|
classNameParts = options.className.split(' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2036,7 +2036,7 @@ EasyMDE.prototype.render = function (el) {
|
|
|
|
|
|
|
|
|
|
// CodeMirror overlay mode
|
|
|
|
|
if (options.overlayMode) {
|
|
|
|
|
CodeMirror.defineMode('overlay-mode', function(config) {
|
|
|
|
|
CodeMirror.defineMode('overlay-mode', function (config) {
|
|
|
|
|
return CodeMirror.overlayMode(CodeMirror.getMode(config, options.spellChecker !== false ? 'spell-checker' : 'gfm'), options.overlayMode.mode, options.overlayMode.combine);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2149,7 +2149,7 @@ EasyMDE.prototype.render = function (el) {
|
|
|
|
|
|
|
|
|
|
function assignImageBlockAttributes(parentEl, img) {
|
|
|
|
|
parentEl.setAttribute('data-img-src', img.url);
|
|
|
|
|
parentEl.setAttribute('style', '--bg-image:url('+img.url+');--width:'+img.naturalWidth+'px;--height:'+calcHeight(img.naturalWidth, img.naturalHeight));
|
|
|
|
|
parentEl.setAttribute('style', '--bg-image:url(' + img.url + ');--width:' + img.naturalWidth + 'px;--height:' + calcHeight(img.naturalWidth, img.naturalHeight));
|
|
|
|
|
_vm.codemirror.setSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2158,7 +2158,7 @@ EasyMDE.prototype.render = function (el) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
easyMDEContainer.querySelectorAll('.cm-image-marker').forEach(function(e) {
|
|
|
|
|
easyMDEContainer.querySelectorAll('.cm-image-marker').forEach(function (e) {
|
|
|
|
|
var parentEl = e.parentElement;
|
|
|
|
|
if (!parentEl.innerText.match(/^!\[.*?\]\(.*\)/g)) {
|
|
|
|
|
// if img pasted on the same line with other text, don't preview, preview only images on separate line
|
|
|
|
@ -2173,9 +2173,9 @@ EasyMDE.prototype.render = function (el) {
|
|
|
|
|
if (srcAttr && srcAttr.length >= 2) {
|
|
|
|
|
var keySrc = srcAttr[1];
|
|
|
|
|
|
|
|
|
|
if (! window.EMDEimagesCache[keySrc]) {
|
|
|
|
|
if (!window.EMDEimagesCache[keySrc]) {
|
|
|
|
|
var img = document.createElement('img');
|
|
|
|
|
img.onload = function() {
|
|
|
|
|
img.onload = function () {
|
|
|
|
|
window.EMDEimagesCache[keySrc] = {
|
|
|
|
|
naturalWidth: img.naturalWidth,
|
|
|
|
|
naturalHeight: img.naturalHeight,
|
|
|
|
@ -2191,6 +2191,7 @@ EasyMDE.prototype.render = function (el) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.codemirror.on('update', function () {
|
|
|
|
|
handleImages();
|
|
|
|
|
});
|
|
|
|
@ -2409,8 +2410,9 @@ EasyMDE.prototype.uploadImage = function (file, onSuccess, onError) {
|
|
|
|
|
* @param imageUploadFunction {Function} The custom function to upload the image passed in options
|
|
|
|
|
* @param file {File} The image to upload, as a HTML5 File object (https://developer.mozilla.org/en-US/docs/Web/API/File).
|
|
|
|
|
*/
|
|
|
|
|
EasyMDE.prototype.uploadImageUsingCustomFunction = function(imageUploadFunction, file) {
|
|
|
|
|
EasyMDE.prototype.uploadImageUsingCustomFunction = function (imageUploadFunction, file) {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
function onSuccess(imageUrl) {
|
|
|
|
|
afterImageUploaded(self, imageUrl);
|
|
|
|
|
}
|
|
|
|
|