diff --git a/js/EditorInterface.js b/js/EditorInterface.js index e463f301d338d14704ef4bfada82849a0a77addf..ba20221fb348782cb5608983cf546a3d22b4f1a3 100644 --- a/js/EditorInterface.js +++ b/js/EditorInterface.js @@ -98,7 +98,8 @@ /** * @param {*} editor * @param {string} uuid - * @return {string|undefined} + * @return {string|null|undefined} Either an alignment value, null if + * alignment is not set, or undefined if there is no inserted image. */ getAlign: function(editor, uuid) { throw new Error('Method not overridden.'); diff --git a/js/ImageHandler.js b/js/ImageHandler.js index 40be94ef55b22480264cc166274d64ce0f5e1301..2948fb0d5ec8bf72345c6b9ec6c2a25bd7599fee 100644 --- a/js/ImageHandler.js +++ b/js/ImageHandler.js @@ -254,7 +254,10 @@ }); var value = this._getAlign(); - this._$align.find('[value="' + value + '"]').prop('checked', true); + + if (value) { + this._$align.find('[value="' + value + '"]').prop('checked', true); + } }, /** @@ -283,18 +286,26 @@ * (If there are different alignments for an image's instances, alignment * messed up somehow anyway.) * - * @return {string} + * @return {string|null} */ _getAlign: function() { var self = this; var value; + var hasInsertedImages = false; this._inserter.getFocusManager().getTextareas().each(function() { var $dom = $('<div>').html($(this).val()); - self._findByUUID($dom, self._uuid).each(function() { + var $nodes = self._findByUUID($dom, self._uuid); + + if ($nodes.length) { + hasInsertedImages = true; + } + + $nodes.each(function() { value = $(this).attr('data-align'); return false; }); + return !value; }); @@ -306,10 +317,11 @@ $.each(this._inserter.getFocusManager().getEditors(), function() { value = editorInterface.getAlign(this, self._uuid); + hasInsertedImages = hasInsertedImages || value !== undefined; return false; }); - return value ? value : 'none'; + return !hasInsertedImages ? null : value ? value : 'none'; }, /** diff --git a/js/editors/CKEditor.js b/js/editors/CKEditor.js index c4ee6c373469e7fc679230fdb7417e523b2bb99e..acd14bc794b58d6693a71f1b74b02b24746a76cd 100644 --- a/js/editors/CKEditor.js +++ b/js/editors/CKEditor.js @@ -133,14 +133,16 @@ * @inheritDoc */ getAlign: function(editor, uuid) { - var align = undefined; + var align = null; + var hasInstances = false; $.each(this._filterInstances(editor, uuid), function() { align = this.data.align; + hasInstances = true; return false; }); - return align; + return !hasInstances ? undefined : align; }, /**