X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/9d566b4741eb66bf09b5c7d213aa8541886e100a..fbb8f42993d02108b506028dc85466a0541be359:/src/redakcja/static/js/wiki/view_editor_wysiwyg.js diff --git a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js index c8f84e1f..decc7339 100644 --- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -526,6 +526,7 @@ $origin.html($(element).html()); } $overlay.remove(); + $.wiki.activePerspective().flush(); }, error: function(text){ alert('BÅÄ d! ' + text); @@ -609,89 +610,89 @@ class VisualPerspective extends $.wiki.Perspective { constructor(options) { - var old_callback = options.callback; - - options.callback = function(){ - let self = this; - var element = $("#html-view"); - var button = $(''); - var uwagaButton = $(''); - - if (!CurrentDocument.readonly) { - - $('#html-view').bind('mousemove', function(event){ - var editable = $(event.target).closest('*[x-editable]'); - $('.active', element).not(editable).removeClass('active').children('.active-block-button').remove(); - - if (!editable.hasClass('active')) { - editable.addClass('active').append(button); - if (!editable.is('[x-edit-attribute]') && - !editable.is('.annotation-inline-box') && - !editable.is('[x-edit-no-format]') - ) { - editable.append(uwagaButton); - } - } - if (editable.is('.annotation-inline-box')) { - $('*[x-annotation-box]', editable).css({ - }).show(); + super(options); + let self = this; + var element = $("#html-view"); + var button = $(''); + var uwagaButton = $(''); + + if (!CurrentDocument.readonly) { + + $('#html-view').bind('mousemove', function(event){ + var editable = $(event.target).closest('*[x-editable]'); + $('.active', element).not(editable).removeClass('active').children('.active-block-button').remove(); + + if (!editable.hasClass('active')) { + editable.addClass('active').append(button); + if (!editable.is('[x-edit-attribute]') && + !editable.is('.annotation-inline-box') && + !editable.is('[x-edit-no-format]') + ) { + editable.append(uwagaButton); } - }); - - self.caret = new Caret(element); - - $('#insert-reference-button').click(function(){ - self.addReference(); - return false; - }); - - $('#insert-annotation-button').click(function(){ - addAnnotation(); - return false; - }); + } + if (editable.is('.annotation-inline-box')) { + $('*[x-annotation-box]', editable).css({ + }).show(); + } + }); - $('#insert-theme-button').click(function(){ - addTheme(); - return false; - }); + self.caret = new Caret(element); + $('#insert-reference-button').click(function(){ + self.flush(); + self.addReference(); + return false; + }); - $(".insert-inline-tag").click(function() { - self.insertInlineTag($(this).attr('data-tag')); - return false; - }); + $('#insert-annotation-button').click(function(){ + self.flush(); + addAnnotation(); + return false; + }); - $(".insert-char").click(function() { - addSymbol(caret=self.caret); - return false; - }); + $('#insert-theme-button').click(function(){ + self.flush(); + addTheme(); + return false; + }); - $(document).on('click', '.edit-button', function(event){ - event.preventDefault(); - openForEdit($(this).parent()); - }); + $(".insert-inline-tag").click(function() { + self.flush(); + self.insertInlineTag($(this).attr('data-tag')); + return false; + }); - $(document).on('click', '.uwaga-button', function(event){ - event.preventDefault(); - createUwagaBefore($(this).parent()); - }); - } + $(".insert-char").click(function() { + self.flush(); + addSymbol(caret=self.caret); + return false; + }); - $(document).on('click', '[x-node="motyw"]', function(){ - selectTheme($(this).attr('theme-class')); + $(document).on('click', '.edit-button', function(event){ + self.flush(); + event.preventDefault(); + openForEdit($(this).parent()); }); - element.on('click', '.annotation', function(event) { + $(document).on('click', '.uwaga-button', function(event){ + self.flush(); event.preventDefault(); - event.redakcja_caret_ignore = true; - $('[x-annotation-box]', $(this).parent()).toggleClass('editing'); - self.caret.detach(); + createUwagaBefore($(this).parent()); }); + } - old_callback.call(this); - }; + $(document).on('click', '[x-node="motyw"]', function(){ + selectTheme($(this).attr('theme-class')); + }); - super(options); + element.on('click', '.annotation', function(event) { + self.flush(); + event.preventDefault(); + event.redakcja_caret_ignore = true; + $('[x-annotation-box]', $(this).parent()).toggleClass('editing'); + self.caret.detach(); + }); } onEnter(success, failure) { @@ -714,6 +715,8 @@ var htmlView = $('#html-view'); htmlView.html(element); + if ('PropertiesPerspective' in $.wiki.perspectives) + $.wiki.perspectives.PropertiesPerspective.enable(); _finalize(success); }, @@ -725,44 +728,51 @@ _finalize(failure); } }); - }; + } + + flush() { + let self = this; + return new Promise((resolve, reject) => { + if ($('#html-view .error').length > 0) { + reject() + } else { + //return _finalize(failure); + html2text({ + element: $('#html-view').get(0), + stripOuter: true, + success: (text) => { + self.doc.setText(text); + resolve(); + }, + error: (text) => { + reject(text); + //$('#source-editor').html('
WystÄ piÅ bÅÄ d:
' + text + ''); + } + }); + } + }); + } onExit(success, failure) { var self = this; self.caret.detach(); - $.wiki.exitTab('#PropertiesPerspective'); + if ('PropertiesPerspective' in $.wiki.perspectives) + $.wiki.perspectives.PropertiesPerspective.disable(); - $.blockUI({ - message: 'Zapisywanie widoku...' - }); - - function _finalize(callback){ - $.unblockUI(); - if (callback) - callback(); - } - - if ($('#html-view .error').length > 0) - return _finalize(failure); - - html2text({ - element: $('#html-view').get(0), - stripOuter: true, - success: function(text){ - self.doc.setText(text); - _finalize(success); - }, - error: function(text){ - $('#source-editor').html('
WystÄ piÅ bÅÄ d:
' + text + ''); - _finalize(failure); - } + self.flush().then(() => { + success && success(); + }).catch((e) => { + // TODO report + console.log('REJECTED!', e); + failure && failure(); }); }; insertInlineTag(tag) { this.caret.detach(); + let self = this; let selection = window.getSelection(); var n = selection.rangeCount; @@ -832,6 +842,7 @@ success: function(html) { // What if no end? node.insertBefore($(html)[0], end); + self.flush(); } }); },