From 333b6f2460721e46596293bb413778dfbf74104b Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Fri, 8 Jan 2016 18:36:01 +1300 Subject: [PATCH] Disable list expansion if aria-disabled is true on link element --- README.md | 12 +++++++++++- dist/metisMenu.css | 6 +++--- dist/metisMenu.js | 5 ++++- dist/metisMenu.min.css | 2 +- dist/metisMenu.min.js | 4 ++-- package.json | 5 +++-- src/metisMenu.js | 3 +++ 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b5d4b80..c6b4a4b 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,8 @@ composer require onokumus/metismenu:dev-master ```javascript $("#menu").metisMenu(); - ``` + ``` + ### Options @@ -191,6 +192,14 @@ Prevents or allows dropdowns' onclick events after expanding/collapsing. }); ``` +### Stopping list opening on certain elements +Setting aria-disabled="true" in the `` element as shown will stop metisMenu opening the menu for that particular list. This can be changed dynamically and will be obeyed correctly: + +```html + +``` + + ### Testing ```bash npm install @@ -217,6 +226,7 @@ Contains a simple HTML file to demonstrate metisMenu plugin. ### Release History **DATE** **VERSION** **CHANGES** +* 2016-01-08 v2.3.0 Adding aria-disabled=true to the link element prevents the dropdown from opening * 2015-09-27 v2.2.0 Events supported & added preventDefault options * 2015-08-06 v2.1.0 RTL & `aria-expanded` attribute & TypeScript type definitions support * 2015-07-25 v2.0.3 When the active item has doubleTapToGo should not collapse diff --git a/dist/metisMenu.css b/dist/metisMenu.css index d47dda2..8634ca5 100644 --- a/dist/metisMenu.css +++ b/dist/metisMenu.css @@ -1,5 +1,5 @@ /* - * metismenu - v2.2.0 + * metismenu - v2.3.0 * A jQuery menu plugin * https://github.com/onokumus/metisMenu#readme * @@ -94,6 +94,6 @@ -o-transition-duration: .35s; transition-duration: .35s; -webkit-transition-property: height, visibility; - -o-transition-property: height, visibility; - transition-property: height, visibility; + -o-transition-property: height, visibility; + transition-property: height, visibility; } diff --git a/dist/metisMenu.js b/dist/metisMenu.js index 156337a..6824983 100644 --- a/dist/metisMenu.js +++ b/dist/metisMenu.js @@ -1,5 +1,5 @@ /* - * metismenu - v2.2.0 + * metismenu - v2.3.0 * A jQuery menu plugin * https://github.com/onokumus/metisMenu#readme * @@ -128,6 +128,9 @@ if($this.options.preventDefault){ e.preventDefault(); } + if(self.attr('aria-disabled') === 'true'){ + return; + } if ($parent.hasClass(activeClass) && !$this.options.doubleTapToGo) { $this.hide($list); self.attr('aria-expanded',false); diff --git a/dist/metisMenu.min.css b/dist/metisMenu.min.css index 8762056..89075be 100644 --- a/dist/metisMenu.min.css +++ b/dist/metisMenu.min.css @@ -1,5 +1,5 @@ /* - * metismenu - v2.2.0 + * metismenu - v2.3.0 * A jQuery menu plugin * https://github.com/onokumus/metisMenu#readme * diff --git a/dist/metisMenu.min.js b/dist/metisMenu.min.js index 80ea3f9..6c13b06 100644 --- a/dist/metisMenu.min.js +++ b/dist/metisMenu.min.js @@ -1,5 +1,5 @@ /* - * metismenu - v2.2.0 + * metismenu - v2.3.0 * A jQuery menu plugin * https://github.com/onokumus/metisMenu#readme * @@ -7,4 +7,4 @@ * Under MIT License */ -!function(a){"use strict";function b(){var a=document.createElement("mm"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}function c(b){return this.each(function(){var c=a(this),d=c.data("mm"),f=a.extend({},e.DEFAULTS,c.data(),"object"==typeof b&&b);d||c.data("mm",d=new e(this,f)),"string"==typeof b&&d[b]()})}a.fn.emulateTransitionEnd=function(b){var c=!1,e=this;a(this).one("mmTransitionEnd",function(){c=!0});var f=function(){c||a(e).trigger(d.end)};return setTimeout(f,b),this};var d=b();d&&(a.event.special.mmTransitionEnd={bindType:d.end,delegateType:d.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}});var e=function(b,c){this.$element=a(b),this.options=a.extend({},e.DEFAULTS,c),this.transitioning=null,this.init()};e.TRANSITION_DURATION=350,e.DEFAULTS={toggle:!0,doubleTapToGo:!1,preventDefault:!0,activeClass:"active",collapseClass:"collapse",collapseInClass:"in",collapsingClass:"collapsing",onTransitionStart:!1,onTransitionEnd:!1},e.prototype.init=function(){var b=this,c=this.options.activeClass,d=this.options.collapseClass,e=this.options.collapseInClass;this.$element.find("li."+c).has("ul").children("ul").attr("aria-expanded",!0).addClass(d+" "+e),this.$element.find("li").not("."+c).has("ul").children("ul").attr("aria-expanded",!1).addClass(d),this.options.doubleTapToGo&&this.$element.find("li."+c).has("ul").children("a").addClass("doubleTapToGo"),this.$element.find("li").has("ul").children("a").on("click.metisMenu",function(d){var e=a(this),f=e.parent("li"),g=f.children("ul");return b.options.preventDefault&&d.preventDefault(),f.hasClass(c)&&!b.options.doubleTapToGo?(b.hide(g),e.attr("aria-expanded",!1)):(b.show(g),e.attr("aria-expanded",!0)),b.options.onTransitionStart&&b.options.onTransitionStart(),b.options.doubleTapToGo&&b.doubleTapToGo(e)&&"#"!==e.attr("href")&&""!==e.attr("href")?(d.stopPropagation(),void(document.location=e.attr("href"))):void 0})},e.prototype.doubleTapToGo=function(a){var b=this.$element;return a.hasClass("doubleTapToGo")?(a.removeClass("doubleTapToGo"),!0):a.parent().children("ul").length?(b.find(".doubleTapToGo").removeClass("doubleTapToGo"),a.addClass("doubleTapToGo"),!1):void 0},e.prototype.show=function(b){var c=this.options.activeClass,f=this.options.collapseClass,g=this.options.collapseInClass,h=this.options.collapsingClass,i=a(b),j=i.parent("li");if(!this.transitioning&&!i.hasClass(g)){j.addClass(c),this.options.toggle&&this.hide(j.siblings().children("ul."+g).attr("aria-expanded",!1)),i.removeClass(f).addClass(h).height(0),this.transitioning=1;var k=function(){this.transitioning&&this.options.onTransitionEnd&&this.options.onTransitionEnd(),i.removeClass(h).addClass(f+" "+g).height("").attr("aria-expanded",!0),this.transitioning=0};return d?void i.one("mmTransitionEnd",a.proxy(k,this)).emulateTransitionEnd(e.TRANSITION_DURATION).height(i[0].scrollHeight):k.call(this)}},e.prototype.hide=function(b){var c=this.options.activeClass,f=this.options.collapseClass,g=this.options.collapseInClass,h=this.options.collapsingClass,i=a(b);if(!this.transitioning&&i.hasClass(g)){i.parent("li").removeClass(c),i.height(i.height())[0].offsetHeight,i.addClass(h).removeClass(f).removeClass(g),this.transitioning=1;var j=function(){this.transitioning&&this.options.onTransitionEnd&&this.options.onTransitionEnd(),this.transitioning=0,i.removeClass(h).addClass(f).attr("aria-expanded",!1)};return d?void i.height(0).one("mmTransitionEnd",a.proxy(j,this)).emulateTransitionEnd(e.TRANSITION_DURATION):j.call(this)}};var f=a.fn.metisMenu;a.fn.metisMenu=c,a.fn.metisMenu.Constructor=e,a.fn.metisMenu.noConflict=function(){return a.fn.metisMenu=f,this}}(jQuery); \ No newline at end of file +!function(a){"use strict";function b(){var a=document.createElement("mm"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}function c(b){return this.each(function(){var c=a(this),d=c.data("mm"),f=a.extend({},e.DEFAULTS,c.data(),"object"==typeof b&&b);d||c.data("mm",d=new e(this,f)),"string"==typeof b&&d[b]()})}a.fn.emulateTransitionEnd=function(b){var c=!1,e=this;a(this).one("mmTransitionEnd",function(){c=!0});var f=function(){c||a(e).trigger(d.end)};return setTimeout(f,b),this};var d=b();d&&(a.event.special.mmTransitionEnd={bindType:d.end,delegateType:d.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}});var e=function(b,c){this.$element=a(b),this.options=a.extend({},e.DEFAULTS,c),this.transitioning=null,this.init()};e.TRANSITION_DURATION=350,e.DEFAULTS={toggle:!0,doubleTapToGo:!1,preventDefault:!0,activeClass:"active",collapseClass:"collapse",collapseInClass:"in",collapsingClass:"collapsing",onTransitionStart:!1,onTransitionEnd:!1},e.prototype.init=function(){var b=this,c=this.options.activeClass,d=this.options.collapseClass,e=this.options.collapseInClass;this.$element.find("li."+c).has("ul").children("ul").attr("aria-expanded",!0).addClass(d+" "+e),this.$element.find("li").not("."+c).has("ul").children("ul").attr("aria-expanded",!1).addClass(d),this.options.doubleTapToGo&&this.$element.find("li."+c).has("ul").children("a").addClass("doubleTapToGo"),this.$element.find("li").has("ul").children("a").on("click.metisMenu",function(d){var e=a(this),f=e.parent("li"),g=f.children("ul");return b.options.preventDefault&&d.preventDefault(),"true"!==e.attr("aria-disabled")?(f.hasClass(c)&&!b.options.doubleTapToGo?(b.hide(g),e.attr("aria-expanded",!1)):(b.show(g),e.attr("aria-expanded",!0)),b.options.onTransitionStart&&b.options.onTransitionStart(),b.options.doubleTapToGo&&b.doubleTapToGo(e)&&"#"!==e.attr("href")&&""!==e.attr("href")?(d.stopPropagation(),void(document.location=e.attr("href"))):void 0):void 0})},e.prototype.doubleTapToGo=function(a){var b=this.$element;return a.hasClass("doubleTapToGo")?(a.removeClass("doubleTapToGo"),!0):a.parent().children("ul").length?(b.find(".doubleTapToGo").removeClass("doubleTapToGo"),a.addClass("doubleTapToGo"),!1):void 0},e.prototype.show=function(b){var c=this.options.activeClass,f=this.options.collapseClass,g=this.options.collapseInClass,h=this.options.collapsingClass,i=a(b),j=i.parent("li");if(!this.transitioning&&!i.hasClass(g)){j.addClass(c),this.options.toggle&&this.hide(j.siblings().children("ul."+g).attr("aria-expanded",!1)),i.removeClass(f).addClass(h).height(0),this.transitioning=1;var k=function(){this.transitioning&&this.options.onTransitionEnd&&this.options.onTransitionEnd(),i.removeClass(h).addClass(f+" "+g).height("").attr("aria-expanded",!0),this.transitioning=0};return d?void i.one("mmTransitionEnd",a.proxy(k,this)).emulateTransitionEnd(e.TRANSITION_DURATION).height(i[0].scrollHeight):k.call(this)}},e.prototype.hide=function(b){var c=this.options.activeClass,f=this.options.collapseClass,g=this.options.collapseInClass,h=this.options.collapsingClass,i=a(b);if(!this.transitioning&&i.hasClass(g)){i.parent("li").removeClass(c),i.height(i.height())[0].offsetHeight,i.addClass(h).removeClass(f).removeClass(g),this.transitioning=1;var j=function(){this.transitioning&&this.options.onTransitionEnd&&this.options.onTransitionEnd(),this.transitioning=0,i.removeClass(h).addClass(f).attr("aria-expanded",!1)};return d?void i.height(0).one("mmTransitionEnd",a.proxy(j,this)).emulateTransitionEnd(e.TRANSITION_DURATION):j.call(this)}};var f=a.fn.metisMenu;a.fn.metisMenu=c,a.fn.metisMenu.Constructor=e,a.fn.metisMenu.noConflict=function(){return a.fn.metisMenu=f,this}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 6c192bd..2194ad6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metismenu", - "version": "2.2.0", + "version": "2.3.0", "description": "A jQuery menu plugin", "main": "./dist/metisMenu.js", "scripts": { @@ -29,7 +29,8 @@ "Andrew Eastwood (https://github.com/AndrewEastwood)", "Marcelo Tosco (http://ecapy.com)", "Radoslav Štofko (http://www.stoweb.cz)", - "Umut Karcı " + "Umut Karcı ", + "Chris Wiggins (https://github.com/chriswiggins)" ], "license": "MIT", "bugs": { diff --git a/src/metisMenu.js b/src/metisMenu.js index 877f9b2..75ca688 100644 --- a/src/metisMenu.js +++ b/src/metisMenu.js @@ -119,6 +119,9 @@ if($this.options.preventDefault){ e.preventDefault(); } + if(self.attr('aria-disabled') === 'true'){ + return; + } if ($parent.hasClass(activeClass) && !$this.options.doubleTapToGo) { $this.hide($list); self.attr('aria-expanded',false);