Commit e5ef435b authored by Antonio's avatar Antonio 🇪🇺

no jQuery in TinyMCE

parent 8f70a5a1
This diff is collapsed.
require('./tinymce/helper');
import faq from './tinymce/faq';
import job from './tinymce/job';
import multiFaq from './tinymce/multiFaq';
......@@ -27,52 +29,3 @@ import course from './tinymce/course';
}
})();
jQuery(document).ready(function () {
jQuery(document).on('click', '.mce-select_image', upload_image_tinymce);
function upload_image_tinymce(e) {
e.preventDefault();
let idTarget;
let val = true;
if (typeof e.target.dataset.target === 'undefined') {
idTarget = jQuery('.mce-image');
} else {
idTarget = jQuery(`#${e.target.dataset.target}`);
val = !val;
}
const customUploader = (
wp.media.frames.file_frame = wp.media(
{
title : 'Add Image',
button : {
text: 'Add Image',
},
multiple: false,
}
)
);
customUploader.on('select', () => {
const attachment = customUploader
.state()
.get('selection')
.first()
.toJSON();
val ? idTarget.val(attachment.id) : idTarget.html(attachment.id);
});
customUploader.open();
}
});
window.datetimeLocalSupported = function () {
let input = document.createElement('input');
input.setAttribute('type', 'datetime-local');
return input.type === 'datetime-local';
};
window.dateSupported = function () {
let input = document.createElement('input');
input.setAttribute('type', 'date');
return input.type === 'date';
};
jQuery(document).ready(function () {
jQuery(document).on('click', '.mce-select_image', upload_image_tinymce);
function upload_image_tinymce(e) {
e.preventDefault();
let idTarget;
let val = true;
if (typeof e.target.dataset.target === 'undefined') {
idTarget = jQuery('.mce-image');
} else {
idTarget = jQuery(`#${e.target.dataset.target}`);
val = !val;
}
const customUploader = (
wp.media.frames.file_frame = wp.media(
{
title : 'Add Image',
button : {
text: 'Add Image',
},
multiple: false,
}
)
);
customUploader.on('select', () => {
const attachment = customUploader
.state()
.get('selection')
.first()
.toJSON();
val ? idTarget.val(attachment.id) : idTarget.html(attachment.id);
});
customUploader.open();
}
});
window.datetimeLocalSupported = function () {
let input = document.createElement('input');
input.setAttribute('type', 'datetime-local');
return input.type === 'datetime-local';
};
window.dateSupported = function () {
let input = document.createElement('input');
input.setAttribute('type', 'date');
return input.type === 'date';
};
window.setHeight = function (el, val) {
if (typeof val === 'function') val = val();
if (typeof val === 'string') el.style.height = val;
else el.style.height = val + 'px';
};
window.insertAfter = function (el, referenceNode) {
referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling);
};
window.createElementFromHTML = function (htmlString) {
let div = document.createElement('div');
div.innerHTML = htmlString.trim();
// Change this to div.childNodes to support multiple top-level nodes
return div.firstChild;
}
\ No newline at end of file
......@@ -70,8 +70,12 @@ export default function (editor) {
},
});
document.getElementById('addOne').addEventListener('click', () => {
let id = document.querySelectorAll('#fields fieldset').length,
height = id === 1 ? document.querySelector(`#fields #fieldset-${id - 1}`).offsetHeight + 30 : document.querySelector(`#fields #fieldset-${id - 1}`).offsetHeight - 30;
let id = document.querySelectorAll('#fields fieldset').length,
baseHeight = document.querySelector(`#fields #fieldset-${id - 1}`).offsetHeight,
height = id === 1 ? baseHeight + 30 : baseHeight - 30,
layoutWrapper = document.querySelector('.mce-container > .mce-container-body.mce-abs-layout'),
nextField = document.querySelector(`#fields #fieldset-${id - 1}`);
const template = `
<fieldset id="fieldset-${id}" data-key="${id}">
<hr class="sc-hr">
......@@ -101,13 +105,12 @@ export default function (editor) {
</div>
</div>
<div class="mce-btn removeLast">
<button type="button" onclick="removeLast()" data-target="bild-${id}">- Remove Last One</button>
<button type="button" onclick="removeLastFAQ()" data-target="bild-${id}">- Remove Last One</button>
</div>
</fieldset>
`;
jQuery('.mce-container > .mce-container-body.mce-abs-layout')
.height(jQuery('.mce-container > .mce-container-body.mce-abs-layout').outerHeight() + height);
jQuery(template).insertAfter(`#fields #fieldset-${id - 1}`);
setHeight(layoutWrapper, layoutWrapper.offsetHeight + height);
insertAfter(createElementFromHTML(template), nextField);
});
},
}
......@@ -115,17 +118,25 @@ export default function (editor) {
window.createShortcode = function (e) {
let shortcode = `[sc_fs_multi_faq `;
let count = 0;
jQuery('#sc-start-point fieldset').each(function () {
const key = this.dataset.key;
shortcode += `headline-${key}="${jQuery('#headlineTag-' + key).val()}" question-${key}="${jQuery('#question-' + key).val()}" answer-${key}="${jQuery('#answer-' + key).val()}" image-${key}="${jQuery('#imageID-' + key).val()}" `;
count++;
});
shortcode += ` count="${count}" html="${e.data.giveHTML}" css_class="${e.data.sc_css_classes}"]`;
let shortcode = `[sc_fs_multi_faq `,
fieldsets = document.querySelectorAll('#sc-start-point fieldset');
for (const fieldset of fieldsets) {
const key = fieldset.dataset.key,
headlineTag = document.getElementById('headlineTag-' + key).value,
question = document.getElementById('question-' + key).value,
answer = document.getElementById('answer-' + key).value,
imageID = document.getElementById('imageID-' + key).value;
shortcode += `headline-${key}="${headlineTag}" question-${key}="${question}" answer-${key}="${answer}" image-${key}="${imageID}" `;
}
shortcode += ` count="${fieldsets.length}" html="${e.data.giveHTML}" css_class="${e.data.sc_css_classes}"]`;
return shortcode;
};
window.removeLast = function () {
jQuery('#sc-start-point fieldset:last-of-type').remove();
window.removeLastFAQ = function () {
document.querySelector('#sc-start-point fieldset:last-of-type').remove();
};
......@@ -42,6 +42,11 @@ form#sc-start-point fieldset .mce-btn.long {
width: 100%;
}
#fields + .mce-btn.long {
width: 100%;
margin-top: 15px;
}
form#sc-start-point fieldset .mce-btn.removeLast {
display: none;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment