diff options
Diffstat (limited to 'addons/website/static/src')
| -rw-r--r-- | addons/website/static/src/js/editor/snippets.options.js | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 8305f5d9e04..d9204139dad 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -1685,8 +1685,6 @@ options.registry.collapse = options.Class.extend({ * @override */ onClone: function () { - this.$target.find('[data-toggle="collapse"]').removeAttr('data-target').removeData('target'); - this.$target.find('.collapse').removeAttr('id'); this._createIDs(); }, /** @@ -1715,30 +1713,30 @@ options.registry.collapse = options.Class.extend({ * @private */ _createIDs: function () { - var time = new Date().getTime(); - var $tab = this.$target.find('[data-toggle="collapse"]'); - - // link to the parent group - var $tablist = this.$target.closest('.accordion'); - var tablist_id = $tablist.attr('id'); - if (!tablist_id) { - tablist_id = 'myCollapse' + time; - $tablist.attr('id', tablist_id); - } - $tab.attr('data-parent', '#' + tablist_id); - $tab.data('parent', '#' + tablist_id); - - // link to the collapse - var $panel = this.$target.find('.collapse'); - var panel_id = $panel.attr('id'); - if (!panel_id) { - while ($('#' + (panel_id = 'myCollapseTab' + time)).length) { - time++; + let time = new Date().getTime(); + const $tablist = this.$target.closest('[role="tablist"]'); + const $tab = this.$target.find('[role="tab"]'); + const $panel = this.$target.find('[role="tabpanel"]'); + + const setUniqueId = ($elem, label) => { + let elemId = $elem.attr('id'); + if (!elemId || $('[id="' + elemId + '"]').length > 1) { + do { + time++; + elemId = label + time; + } while ($('#' + elemId).length); + $elem.attr('id', elemId); } - $panel.attr('id', panel_id); - } - $tab.attr('data-target', '#' + panel_id); - $tab.data('target', '#' + panel_id); + return elemId; + }; + + const tablistId = setUniqueId($tablist, 'myCollapse'); + $panel.attr('data-parent', '#' + tablistId); + $panel.data('parent', '#' + tablistId); + + const panelId = setUniqueId($panel, 'myCollapseTab'); + $tab.attr('data-target', '#' + panelId); + $tab.data('target', '#' + panelId); }, }); |
