From 099486f294e79bfe1f2c6b431ee4696237f616cd Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 7 Mar 2017 10:46:08 +0100 Subject: Detach accordions from .card --- js/src/collapse.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/src/collapse.js b/js/src/collapse.js index 28c4493cc..e2c9efe11 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -57,7 +57,8 @@ const Collapse = (($) => { const Selector = { ACTIVES : '.card > .show, .card > .collapsing', - DATA_TOGGLE : '[data-toggle="collapse"]' + DATA_TOGGLE : '[data-toggle="collapse"]', + DATA_CHILDREN : 'data-children' } @@ -84,6 +85,14 @@ const Collapse = (($) => { this._addAriaAndCollapsedClass(this._element, this._triggerArray) } + this._selectorActives = Selector.ACTIVES + if (this._parent) { + const childrenSelector = this._parent.hasAttribute(Selector.DATA_CHILDREN) ? this._parent.getAttribute(Selector.DATA_CHILDREN) : null + if (childrenSelector !== null) { + this._selectorActives = childrenSelector + ' > .show, ' + childrenSelector + ' > .collapsing' + } + } + if (this._config.toggle) { this.toggle() } @@ -124,7 +133,7 @@ const Collapse = (($) => { let activesData if (this._parent) { - actives = $.makeArray($(this._parent).find(Selector.ACTIVES)) + actives = $.makeArray($(this._parent).find(this._selectorActives)) if (!actives.length) { actives = null } -- cgit v1.2.3 From fa1504e6f68974114e3ab58b8b18a601bc973103 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Wed, 8 Mar 2017 11:15:58 +0100 Subject: Fix code style --- js/src/collapse.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'js') diff --git a/js/src/collapse.js b/js/src/collapse.js index e2c9efe11..0776519ff 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -78,7 +78,6 @@ const Collapse = (($) => { `[data-toggle="collapse"][href="#${element.id}"],` + `[data-toggle="collapse"][data-target="#${element.id}"]` )) - this._parent = this._config.parent ? this._getParent() : null if (!this._config.parent) { @@ -89,7 +88,7 @@ const Collapse = (($) => { if (this._parent) { const childrenSelector = this._parent.hasAttribute(Selector.DATA_CHILDREN) ? this._parent.getAttribute(Selector.DATA_CHILDREN) : null if (childrenSelector !== null) { - this._selectorActives = childrenSelector + ' > .show, ' + childrenSelector + ' > .collapsing' + this._selectorActives = `${childrenSelector} > .show, ${childrenSelector} > .collapsing` } } -- cgit v1.2.3 From 21b537cc2424f8b51044ad93c70993f29780524a Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 9 Mar 2017 11:08:47 +0100 Subject: Add unit test --- js/tests/unit/collapse.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'js') diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 713930433..c39adacdb 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -490,4 +490,27 @@ $(function () { .bootstrapCollapse('show') }) + QUnit.test('should allow accordion to use children other than card', function (assert) { + assert.expect(2) + var done = assert.async() + var accordionHTML = '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + $(accordionHTML).appendTo('#qunit-fixture') + var $target = $('#linkTrigger') + $('#collapseOne').on('shown.bs.collapse', function () { + assert.ok($(this).hasClass('show')) + assert.ok(!$('#collapseTwo').hasClass('show')) + done() + }) + $target.trigger($.Event('click')) + }) }) -- cgit v1.2.3 From 84ce248f0661d99a221d9d69fa12243672fd0034 Mon Sep 17 00:00:00 2001 From: Bardi Harborow Date: Sun, 12 Mar 2017 16:01:14 +1100 Subject: Update config files across the board. --- js/.eslintrc.json | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/.eslintrc.json b/js/.eslintrc.json index 930e1f3c2..07a307a74 100644 --- a/js/.eslintrc.json +++ b/js/.eslintrc.json @@ -13,6 +13,8 @@ }, "rules": { // Possible Errors + "no-await-in-loop": "error", + "no-compare-neg-zero": "error", "no-extra-parens": "error", "no-prototype-builtins": "off", "no-template-curly-in-string": "error", @@ -67,6 +69,7 @@ } ], "no-multi-str": "error", + "no-new": "error", "no-new-func": "off", "no-new-wrappers": "error", "no-new": "error", @@ -75,6 +78,7 @@ "no-proto": "error", "no-restricted-properties": "error", "no-return-assign": "off", + "no-return-await": "error", "no-script-url": "error", "no-self-compare": "error", "no-sequences": "error", @@ -84,9 +88,11 @@ "no-useless-call": "error", "no-useless-concat": "error", "no-useless-escape": "error", + "no-useless-return": "off", "no-void": "error", "no-warning-comments": "off", "no-with": "error", + "prefer-promise-reject-errors": "error", "radix": "error", "vars-on-top": "error", "wrap-iife": "error", @@ -100,8 +106,8 @@ "no-catch-shadow": "error", "no-label-var": "error", "no-restricted-globals": "error", - "no-shadow-restricted-names": "error", "no-shadow": "off", + "no-shadow-restricted-names": "error", "no-undef-init": "error", "no-undefined": "off", "no-use-before-define": "off", @@ -122,6 +128,7 @@ "array-bracket-spacing": "error", "block-spacing": "error", "brace-style": "error", + "capitalized-comments": "off", "camelcase": "error", "comma-dangle": "error", "comma-spacing": "error", @@ -130,6 +137,7 @@ "consistent-this": "error", "eol-last": "error", "func-call-spacing": "error", + "func-name-matching": "error", "func-names": "off", "func-style": ["error", "declaration"], "id-blacklist": "error", @@ -148,8 +156,8 @@ "max-lines": "off", "max-nested-callbacks": "error", "max-params": "off", - "max-statements-per-line": "error", "max-statements": "off", + "max-statements-per-line": "error", "multiline-ternary": "off", "new-cap": ["error", { "capIsNewExceptionPattern": "$.*" }], "new-parens": "error", @@ -162,6 +170,7 @@ "no-inline-comments": "off", "no-lonely-if": "error", "no-mixed-operators": "off", + "no-multi-assign": "error", "no-multiple-empty-lines": "error", "no-negated-condition": "off", "no-nested-ternary": "error", @@ -174,19 +183,20 @@ "no-underscore-dangle": "off", "no-unneeded-ternary": "error", "no-whitespace-before-property": "error", + "nonblock-statement-body-position": "error", "object-curly-newline": ["error", { "minProperties": 1 }], "object-curly-spacing": ["error", "always"], "object-property-newline": "error", - "one-var-declaration-per-line": "error", "one-var": ["error", "never"], + "one-var-declaration-per-line": "error", "operator-assignment": "error", "operator-linebreak": "off", "padded-blocks": "off", "quote-props": ["error", "as-needed"], "quotes": ["error", "single"], "require-jsdoc": "off", - "semi-spacing": "error", "semi": ["error", "never"], + "semi-spacing": "error", "sort-keys": "off", "sort-vars": "error", "space-before-blocks": "error", @@ -198,6 +208,7 @@ "space-infix-ops": "error", "space-unary-ops": "error", "spaced-comment": "error", + "template-tag-spacing": "error", "unicode-bom": "error", "wrap-regex": "off", @@ -217,7 +228,6 @@ "prefer-arrow-callback": "error", "prefer-const": "error", "prefer-numeric-literals": "error", - "prefer-reflect": "off", "prefer-rest-params": "error", "prefer-spread": "error", "prefer-template": "error", -- cgit v1.2.3 From 1a46d8c7309092566c2da8cbaa9999ae0a1bacc7 Mon Sep 17 00:00:00 2001 From: Johann Date: Sun, 19 Mar 2017 00:36:33 +0100 Subject: Allow to use Tab.js with list-group (#21756) * Allow to use Tab.js with list-group * Allow to use list-group with div parent instead of an ul parent --- js/src/tab.js | 12 +++++++++--- js/tests/unit/tab.js | 16 ++++++++++++++++ js/tests/visual/tab.html | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/src/tab.js b/js/src/tab.js index c069b0a9a..d5669b7ad 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -45,10 +45,10 @@ const Tab = (($) => { A : 'a', LI : 'li', DROPDOWN : '.dropdown', - LIST : 'ul:not(.dropdown-menu), ol:not(.dropdown-menu), nav:not(.dropdown-menu)', - FADE_CHILD : '> .nav-item .fade, > .fade', + LIST : 'ul:not(.dropdown-menu), ol:not(.dropdown-menu), nav:not(.dropdown-menu), .list-group:not(.dropdown-menu)', + FADE_CHILD : '> .nav-item .fade, > .list-group-item .fade, > .fade', ACTIVE : '.active', - ACTIVE_CHILD : '> .nav-item > .active, > .active', + ACTIVE_CHILD : '> .nav-item > .active, > .list-group-item > .active, > .active', DATA_TOGGLE : '[data-toggle="tab"], [data-toggle="pill"]', DROPDOWN_TOGGLE : '.dropdown-toggle', DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu .active' @@ -182,6 +182,9 @@ const Tab = (($) => { _transitionComplete(element, active, isTransitioning, callback) { if (active) { $(active).removeClass(ClassName.ACTIVE) + if ($(active).hasClass('list-group-item')) { + $(active).find('a.nav-link').removeClass(ClassName.ACTIVE) + } const dropdownChild = $(active.parentNode).find( Selector.DROPDOWN_ACTIVE_CHILD @@ -195,6 +198,9 @@ const Tab = (($) => { } $(element).addClass(ClassName.ACTIVE) + if ($(element.parentNode).hasClass('list-group-item')) { + $(element.parentNode).addClass(ClassName.ACTIVE) + } element.setAttribute('aria-expanded', true) if (isTransitioning) { diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index 734648e9e..d0aeb372b 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -108,6 +108,22 @@ $(function () { assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home') }) + QUnit.test('should activate element by tab id in list-group', function (assert) { + assert.expect(2) + var ulHTML = '' + + $('