Skip to content

Commit

Permalink
MDL-46920 theme_bootstrapbase: fix dropdown to use data-target
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetha Chan committed Sep 17, 2014
1 parent 35143c1 commit 76cb69b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ var CSS = {
SELECTORS = {
NAVBAR_BUTTON: '.btn-navbar',
// FIXME This is deliberately wrong because of a breaking issue in the upstream library.
TOGGLECOLLAPSE: '*[data-disabledtoggle="collapse"]',
NAV_COLLAPSE: '.nav-collapse'
TOGGLECOLLAPSE: '*[data-disabledtoggle="collapse"]'
},
NS = Y.namespace('Moodle.theme_bootstrapbase.bootstrap');

Expand Down Expand Up @@ -706,9 +705,19 @@ NS.setup_toggle_show = function() {
* @param {EventFacade} e
*/
NS.toggle_show = function(e) {
// Toggle the active class on both the clicked .btn-navbar and the .nav-collapse.
// Our CSS will set the height for these.
Y.all(SELECTORS.NAV_COLLAPSE).toggleClass(CSS.ACTIVE);
// Toggle the active class on both the clicked .btn-navbar and the
// associated target, defined by a CSS selector string set as the
// data-target attribute on the .btn-navbar element in question.
//
// This will allow for us to have multiple .btn-navbar elements
// each with their own collapse/expand targets - these targets
// should be of class .nav-collapse.
var myTarget = this.get('parentNode').one(this.getAttribute('data-target'));
if (myTarget) {
this.siblings(".btn-navbar").removeClass(CSS.ACTIVE);
myTarget.siblings(".nav-collapse").removeClass(CSS.ACTIVE);
myTarget.toggleClass(CSS.ACTIVE);
}
e.currentTarget.toggleClass(CSS.ACTIVE);
};

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ var CSS = {
SELECTORS = {
NAVBAR_BUTTON: '.btn-navbar',
// FIXME This is deliberately wrong because of a breaking issue in the upstream library.
TOGGLECOLLAPSE: '*[data-disabledtoggle="collapse"]',
NAV_COLLAPSE: '.nav-collapse'
TOGGLECOLLAPSE: '*[data-disabledtoggle="collapse"]'
},
NS = Y.namespace('Moodle.theme_bootstrapbase.bootstrap');

Expand Down Expand Up @@ -696,9 +695,19 @@ NS.setup_toggle_show = function() {
* @param {EventFacade} e
*/
NS.toggle_show = function(e) {
// Toggle the active class on both the clicked .btn-navbar and the .nav-collapse.
// Our CSS will set the height for these.
Y.all(SELECTORS.NAV_COLLAPSE).toggleClass(CSS.ACTIVE);
// Toggle the active class on both the clicked .btn-navbar and the
// associated target, defined by a CSS selector string set as the
// data-target attribute on the .btn-navbar element in question.
//
// This will allow for us to have multiple .btn-navbar elements
// each with their own collapse/expand targets - these targets
// should be of class .nav-collapse.
var myTarget = this.get('parentNode').one(this.getAttribute('data-target'));
if (myTarget) {
this.siblings(".btn-navbar").removeClass(CSS.ACTIVE);
myTarget.siblings(".nav-collapse").removeClass(CSS.ACTIVE);
myTarget.toggleClass(CSS.ACTIVE);
}
e.currentTarget.toggleClass(CSS.ACTIVE);
};

Expand Down
19 changes: 14 additions & 5 deletions theme/bootstrapbase/yui/src/bootstrap/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ var CSS = {
SELECTORS = {
NAVBAR_BUTTON: '.btn-navbar',
// FIXME This is deliberately wrong because of a breaking issue in the upstream library.
TOGGLECOLLAPSE: '*[data-disabledtoggle="collapse"]',
NAV_COLLAPSE: '.nav-collapse'
TOGGLECOLLAPSE: '*[data-disabledtoggle="collapse"]'
},
NS = Y.namespace('Moodle.theme_bootstrapbase.bootstrap');

Expand Down Expand Up @@ -96,8 +95,18 @@ NS.setup_toggle_show = function() {
* @param {EventFacade} e
*/
NS.toggle_show = function(e) {
// Toggle the active class on both the clicked .btn-navbar and the .nav-collapse.
// Our CSS will set the height for these.
Y.all(SELECTORS.NAV_COLLAPSE).toggleClass(CSS.ACTIVE);
// Toggle the active class on both the clicked .btn-navbar and the
// associated target, defined by a CSS selector string set as the
// data-target attribute on the .btn-navbar element in question.
//
// This will allow for us to have multiple .btn-navbar elements
// each with their own collapse/expand targets - these targets
// should be of class .nav-collapse.
var myTarget = this.get('parentNode').one(this.getAttribute('data-target'));
if (myTarget) {
this.siblings(".btn-navbar").removeClass(CSS.ACTIVE);
myTarget.siblings(".nav-collapse").removeClass(CSS.ACTIVE);
myTarget.toggleClass(CSS.ACTIVE);
}
e.currentTarget.toggleClass(CSS.ACTIVE);
};

0 comments on commit 76cb69b

Please sign in to comment.