Skip to content
Permalink
Browse files

[FIX] web_editor: handle snippet option submenus of submenus

Commit 8ca9233
did not think about submenus inside submenus, which is the case in the
website animate option. This made snippets potentially have multiple
animations on them, with undesired behaviors.

This commit also accordingly reviews the _setActive method for the
select-class option and also adapts following the recent forward-port of
#31440

Related to task-1929133

closes #31477

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
  • Loading branch information...
qsm-odoo committed Feb 27, 2019
1 parent f5ab04c commit 2a39ab0579fc88b9395a693b8e733aceced9ba45
Showing with 22 additions and 6 deletions.
  1. +22 −6 addons/web_editor/static/src/js/editor/snippets.options.js
@@ -126,7 +126,7 @@ var SnippetOption = Widget.extend({
* @param {jQuery} $li - the related DOMElement option
*/
selectClass: function (previewMode, value, $li) {
var $group = $li && $li.closest('.dropdown-submenu');
var $group = $li && $li.parents('.dropdown-submenu').last();
if (!$group || !$group.length) {
$group = this.$el;
}
@@ -288,13 +288,29 @@ var SnippetOption = Widget.extend({
})
.addClass('active');

_processSelectClassElements(this.$el);
// Get submenus which are not inside submenus
var $submenus = this.$el.find('.dropdown-submenu')
.addBack('.dropdown-submenu')
.not('.dropdown-submenu .dropdown-submenu');

function _processSelectClassElements($el) {
// Add unique active class for each submenu active item
_.each($submenus, function (submenu) {
var $elements = _getSelectClassElements($(submenu));
_processSelectClassElements($elements);
});

// Add unique active class for out-of-submenu active item
var $externalElements = _getSelectClassElements(this.$el)
.not('.dropdown-submenu *, .dropdown-submenu');
_processSelectClassElements($externalElements);

function _getSelectClassElements($el) {
return $el.find('[data-select-class]')
.addBack('[data-select-class]');
}
function _processSelectClassElements($elements) {
var maxNbClasses = -1;
$el.find('[data-select-class]')
.addBack('[data-select-class]')
.removeClass('active')
$elements.removeClass('active')
.filter(function () {
var className = $(this).data('selectClass');
var nbClasses = className ? className.split(' ').length : 0;

0 comments on commit 2a39ab0

Please sign in to comment.
You can’t perform that action at this time.