Insert image in description blocks

pull/1/head
yflory 4 years ago
parent 562bcf64e2
commit a0cd1d7195

@ -646,6 +646,11 @@ define([
}).filter(Boolean); }).filter(Boolean);
}; };
var checkMt = function (framework) {
var cm = $('.CodeMirror').length;
if (!cm) { framework.setMediaTagEmbedder(); }
};
var STATIC_TYPES = { var STATIC_TYPES = {
md: { md: {
defaultOpts: { defaultOpts: {
@ -661,7 +666,7 @@ define([
var cursorGetter; var cursorGetter;
return { return {
tag: tag, tag: tag,
edit: function (cb, tmp) { edit: function (cb, tmp, framework) {
var t = h('textarea'); var t = h('textarea');
var block = h('div.cp-form-edit-options-block', [t]); var block = h('div.cp-form-edit-options-block', [t]);
var cm = SFCodeMirror.create("gfm", CMeditor, t); var cm = SFCodeMirror.create("gfm", CMeditor, t);
@ -671,6 +676,14 @@ define([
editor.setOption('styleActiveLine', true); editor.setOption('styleActiveLine', true);
editor.setOption('readOnly', false); editor.setOption('readOnly', false);
editor.on('focus', function () {
framework.setMediaTagEmbedder();
framework.setMediaTagEmbedder(function (mt) {
editor.focus();
editor.replaceSelection($(mt)[0].outerHTML);
});
})
var text = opts.text; var text = opts.text;
var cursor; var cursor;
if (tmp && tmp.content && tmp.old.text === text) { if (tmp && tmp.content && tmp.old.text === text) {
@ -699,7 +712,10 @@ define([
} }
// Cancel changes // Cancel changes
var cancelBlock = h('button.btn.btn-secondary', Messages.cancel); var cancelBlock = h('button.btn.btn-secondary', Messages.cancel);
$(cancelBlock).click(function () { cb(); }); $(cancelBlock).click(function () {
cb();
checkMt(framework);
});
// Save changes // Save changes
var saveBlock = h('button.btn.btn-primary', [ var saveBlock = h('button.btn.btn-primary', [
h('i.fa.fa-floppy-o'), h('i.fa.fa-floppy-o'),
@ -714,6 +730,7 @@ define([
$(saveBlock).click(function () { $(saveBlock).click(function () {
$(saveBlock).attr('disabled', 'disabled'); $(saveBlock).attr('disabled', 'disabled');
cb(getContent()); cb(getContent());
checkMt(framework);
}); });
cursorGetter = function () { cursorGetter = function () {
@ -1568,8 +1585,6 @@ define([
var updateAddInline = function () { var updateAddInline = function () {
$container.find('.cp-form-creator-add-inline').remove(); $container.find('.cp-form-creator-add-inline').remove();
$container.find('.cp-form-block').each(function (i, el) { $container.find('.cp-form-block').each(function (i, el) {
console.log(i, el);
if (i === 0) { return; }
var $el = $(el); var $el = $(el);
var uid = $el.attr('data-id'); var uid = $el.attr('data-id');
$el.before(getFormCreator(uid)); $el.before(getFormCreator(uid));
@ -1634,6 +1649,12 @@ define([
} }
var v = $inputQ.val(); var v = $inputQ.val();
if (!v || !v.trim()) { return void UI.warn(Messages.error); } if (!v || !v.trim()) { return void UI.warn(Messages.error); }
// Don't save if no change
if (v.trim() === block.q) {
$(q).removeClass('editing');
if (!e) { $inputQ.blur(); }
return;
}
if (saving && !e) { return; } // Prevent spam Enter if (saving && !e) { return; } // Prevent spam Enter
block.q = v.trim(); block.q = v.trim();
framework.localChange(); framework.localChange();
@ -1677,6 +1698,7 @@ define([
$('.cp-form-block[data-id="'+uid+'"]').remove(); $('.cp-form-block[data-id="'+uid+'"]').remove();
framework.localChange(); framework.localChange();
updateAddInline(); updateAddInline();
checkMt(framework);
}); });
// Values // Values
@ -1710,7 +1732,7 @@ define([
var onEdit = function (tmp) { var onEdit = function (tmp) {
data.editing = true; data.editing = true;
$(data.tag).hide(); $(data.tag).hide();
$(editContainer).append(data.edit(onSave, tmp)); $(editContainer).append(data.edit(onSave, tmp, framework));
$(editButtons).hide(); $(editButtons).hide();
}; };
$(edit).click(function () { $(edit).click(function () {
@ -1811,6 +1833,7 @@ define([
preventOnFilter: false, preventOnFilter: false,
draggable: ".cp-form-block", draggable: ".cp-form-block",
forceFallback: true, forceFallback: true,
fallbackTolerance: 5,
onStart: function () { onStart: function () {
$container.find('.cp-form-creator-add-inline').remove(); $container.find('.cp-form-creator-add-inline').remove();
}, },

Loading…
Cancel
Save