Add data-markdownx-init check to typescript file

This commit is contained in:
Sebastiaan ten Pas 2017-07-07 11:46:15 +02:00
parent 71c5a4aa11
commit 50c730b9a4
3 changed files with 19 additions and 7 deletions

View file

@ -363,8 +363,8 @@ var MarkdownX = function (parent, editor, preview) {
// --------------------------------------------------------
// Mounting the defined events.
utils_1.mountEvents(editorListeners, documentListeners);
// Set animation for image uploads lock down.
properties.editor.setAttribute('data-markdownx-init', '');
// Set animation for image uploads lock down.
properties.editor.style.transition = "opacity 1s ease";
properties.editor.style.webkitTransition = "opacity 1s ease";
// Upload latency - must be a value >= 500 microseconds.
@ -566,6 +566,7 @@ exports.MarkdownX = MarkdownX;
docReady(function () {
var ELEMENTS = document.getElementsByClassName('markdownx');
return Object.keys(ELEMENTS).map(function (key) {
// Only add the new MarkdownX instance to fields that have no MarkdownX instance yet
if (!ELEMENTS[key].querySelector('.markdownx-editor').hasAttribute('data-markdownx-init')) {
return new MarkdownX(ELEMENTS[key], ELEMENTS[key].querySelector('.markdownx-editor'), ELEMENTS[key].querySelector('.markdownx-preview'));
}

File diff suppressed because one or more lines are too long

View file

@ -534,6 +534,8 @@ const MarkdownX = function (parent: HTMLElement, editor: HTMLTextAreaElement, pr
// Mounting the defined events.
mountEvents(editorListeners, documentListeners);
properties.editor.setAttribute('data-markdownx-init', '');
// Set animation for image uploads lock down.
properties.editor.style.transition = "opacity 1s ease";
properties.editor.style.webkitTransition = "opacity 1s ease";
@ -828,11 +830,20 @@ docReady(() => {
const ELEMENTS = document.getElementsByClassName('markdownx');
return Object.keys(ELEMENTS).map(key => new MarkdownX(
ELEMENTS[key],
ELEMENTS[key].querySelector('.markdownx-editor'),
ELEMENTS[key].querySelector('.markdownx-preview')
));
return Object.keys(ELEMENTS).map(key => {
// Only add the new MarkdownX instance to fields that have no MarkdownX instance yet
if (!ELEMENTS[key].querySelector('.markdownx-editor').hasAttribute('data-markdownx-init')) {
return new MarkdownX(
ELEMENTS[key],
ELEMENTS[key].querySelector('.markdownx-editor'),
ELEMENTS[key].querySelector('.markdownx-preview')
)
}
});
});