Skip to content
Snippets Groups Projects
Commit 9208bbe0 authored by snater's avatar snater
Browse files

Issue #3348398 by Snater: Set default image alignment

parent ea91d933
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,8 @@ ...@@ -98,7 +98,8 @@
/** /**
* @param {*} editor * @param {*} editor
* @param {string} uuid * @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) { getAlign: function(editor, uuid) {
throw new Error('Method not overridden.'); throw new Error('Method not overridden.');
......
...@@ -254,7 +254,10 @@ ...@@ -254,7 +254,10 @@
}); });
var value = this._getAlign(); 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 @@ ...@@ -283,18 +286,26 @@
* (If there are different alignments for an image's instances, alignment * (If there are different alignments for an image's instances, alignment
* messed up somehow anyway.) * messed up somehow anyway.)
* *
* @return {string} * @return {string|null}
*/ */
_getAlign: function() { _getAlign: function() {
var self = this; var self = this;
var value; var value;
var hasInsertedImages = false;
this._inserter.getFocusManager().getTextareas().each(function() { this._inserter.getFocusManager().getTextareas().each(function() {
var $dom = $('<div>').html($(this).val()); 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'); value = $(this).attr('data-align');
return false; return false;
}); });
return !value; return !value;
}); });
...@@ -306,10 +317,11 @@ ...@@ -306,10 +317,11 @@
$.each(this._inserter.getFocusManager().getEditors(), function() { $.each(this._inserter.getFocusManager().getEditors(), function() {
value = editorInterface.getAlign(this, self._uuid); value = editorInterface.getAlign(this, self._uuid);
hasInsertedImages = hasInsertedImages || value !== undefined;
return false; return false;
}); });
return value ? value : 'none'; return !hasInsertedImages ? null : value ? value : 'none';
}, },
/** /**
......
...@@ -133,14 +133,16 @@ ...@@ -133,14 +133,16 @@
* @inheritDoc * @inheritDoc
*/ */
getAlign: function(editor, uuid) { getAlign: function(editor, uuid) {
var align = undefined; var align = null;
var hasInstances = false;
$.each(this._filterInstances(editor, uuid), function() { $.each(this._filterInstances(editor, uuid), function() {
align = this.data.align; align = this.data.align;
hasInstances = true;
return false; return false;
}); });
return align; return !hasInstances ? undefined : align;
}, },
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment