summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js
diff options
context:
space:
mode:
authorSébastien Mottet (oms) <oms@odoo.com>2021-05-12 09:03:00 +0000
committerSébastien Mottet (oms) <oms@odoo.com>2021-05-18 12:57:35 +0000
commit51c868bd9bfcd9a7e81f386b0c889befa5dd6e20 (patch)
treeca6792423fdd03b315f43d92b5e88b62600163b9 /addons/website/static/src/js
parent6aaf337558e59474efcef937f0175ee531b4b477 (diff)
[FIX] website: correctly set accordion ids
data-parent fields were set on tab link and not on the tabpanel div. It prevented the accordion of having the right behavior: closing all the other tabs when a tab is clicked to be opened. closes odoo/odoo#70960 X-original-commit: 32b2c17eb7bec5293dfc0cfb4bb07d19dc2ec5c3 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/website/static/src/js')
-rw-r--r--addons/website/static/src/js/editor/snippets.options.js48
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);
},
});