bootstrap-submenu
Advanced tools
Comparing version 1.1.9 to 1.2.0
/*! | ||
* Bootstrap-submenu v1.1.9 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Bootstrap-submenu v1.2.0 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Copyright 2014 Vasily A. (https://github.com/vsn4ik) | ||
@@ -15,11 +15,17 @@ * Licensed under MIT (https://github.com/vsn4ik/bootstrap-submenu/blob/master/LICENSE) | ||
function Submenupicker(element) { | ||
var desc = ':not(.disabled, .divider, .dropdown-header):first'; | ||
var fake = ':not(.disabled, .divider, .dropdown-header)'; | ||
var desc = fake + ':first'; | ||
this.$element = $(element); | ||
this.$menu = this.$element.parent(); | ||
this.$dropdown = this.$menu.parent().parent(); | ||
this.$menus = this.$menu.siblings('.dropdown-submenu'); | ||
this.$children = this.$menu.find('> .dropdown-menu > .dropdown-submenu'); | ||
this.$prev = this.$menu.prevAll(desc).children('a'); | ||
this.$next = this.$menu.nextAll(desc).children('a'); | ||
var $children = this.$menu.find('> .dropdown-menu > ' + fake); | ||
this.$children = $children.filter('.dropdown-submenu'); | ||
this.$items = $children.not('.dropdown-submenu'); | ||
this.init(); | ||
@@ -33,2 +39,4 @@ } | ||
this.$menu.on('hide.bs.submenu', this.hide.bind(this)); | ||
this.$next.keydown(this.next_keydown.bind(this)); | ||
this.$items.keydown(this.item_keydown.bind(this)); | ||
}, | ||
@@ -60,3 +68,3 @@ click: function(event) { | ||
keydown: function(event) { | ||
// 13: Return, 32: Spacebar | ||
// 13: Return, 27: Esc, 32: Spacebar | ||
// 38: Arrow up, 40: Arrow down | ||
@@ -72,6 +80,15 @@ | ||
} | ||
else if (/^(38|40)$/.test(event.keyCode)) { | ||
else if (/^(27|38|40)$/.test(event.keyCode)) { | ||
event.stopPropagation(); | ||
if (event.keyCode == 38) { | ||
if (event.keyCode == 27) { | ||
if (this.$menu.hasClass('open')) { | ||
this.close(); | ||
} | ||
else { | ||
this.$menus.trigger('hide.bs.submenu'); | ||
this.$dropdown.removeClass('open').children('a').focus(); | ||
} | ||
} | ||
else if (event.keyCode == 38) { | ||
this.$prev.focus(); | ||
@@ -83,2 +100,28 @@ } | ||
} | ||
}, | ||
next_keydown: function(event) { | ||
// 38: Arrow up | ||
if (event.keyCode != 38) { | ||
return; | ||
} | ||
// Off vertical scrolling | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.$element.focus(); | ||
}, | ||
item_keydown: function(event) { | ||
// 27: Esc | ||
if (event.keyCode != 27) { | ||
return; | ||
} | ||
event.stopPropagation(); | ||
this.close(); | ||
this.$element.focus(); | ||
} | ||
@@ -85,0 +128,0 @@ }; |
/*! | ||
* Bootstrap-submenu v1.1.9 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Bootstrap-submenu v1.2.0 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Copyright 2014 Vasily A. (https://github.com/vsn4ik) | ||
@@ -7,2 +7,2 @@ * Licensed under MIT (https://github.com/vsn4ik/bootstrap-submenu/blob/master/LICENSE) | ||
"use strict";if("undefined"==typeof jQuery)throw new Error("Bootstrap-submenu requires jQuery");!function(a){function b(b){var c=":not(.disabled, .divider, .dropdown-header):first";this.$element=a(b),this.$menu=this.$element.parent(),this.$menus=this.$menu.siblings(".dropdown-submenu"),this.$children=this.$menu.find("> .dropdown-menu > .dropdown-submenu"),this.$prev=this.$menu.prevAll(c).children("a"),this.$next=this.$menu.nextAll(c).children("a"),this.init()}b.prototype={init:function(){this.$element.on("click.bs.dropdown",this.click.bind(this)),this.$element.keydown(this.keydown.bind(this)),this.$menu.on("hide.bs.submenu",this.hide.bind(this))},click:function(a){a.stopPropagation(),this.toggle()},toggle:function(){this.$menu.hasClass("open")?this.close():(this.$menu.addClass("open"),this.$menus.trigger("hide.bs.submenu"))},hide:function(a){a.stopPropagation(),this.close()},close:function(){this.$menu.removeClass("open"),this.$children.trigger("hide.bs.submenu")},keydown:function(a){/^(32|38|40)$/.test(a.keyCode)&&a.preventDefault(),/^(13|32)$/.test(a.keyCode)?this.toggle():/^(38|40)$/.test(a.keyCode)&&(a.stopPropagation(),38==a.keyCode?this.$prev.focus():40==a.keyCode&&this.$next.focus())}},a.fn.submenupicker=function(){return this.each(function(){var c=a.data(this,"bs.submenu");c||(new b(this),a.data(this,"bs.submenu",!0))})}}(jQuery); | ||
"use strict";if("undefined"==typeof jQuery)throw new Error("Bootstrap-submenu requires jQuery");!function(a){function b(b){var c=":not(.disabled, .divider, .dropdown-header)",d=c+":first";this.$element=a(b),this.$menu=this.$element.parent(),this.$dropdown=this.$menu.parent().parent(),this.$menus=this.$menu.siblings(".dropdown-submenu"),this.$prev=this.$menu.prevAll(d).children("a"),this.$next=this.$menu.nextAll(d).children("a");var e=this.$menu.find("> .dropdown-menu > "+c);this.$children=e.filter(".dropdown-submenu"),this.$items=e.not(".dropdown-submenu"),this.init()}b.prototype={init:function(){this.$element.on("click.bs.dropdown",this.click.bind(this)),this.$element.keydown(this.keydown.bind(this)),this.$menu.on("hide.bs.submenu",this.hide.bind(this)),this.$next.keydown(this.next_keydown.bind(this)),this.$items.keydown(this.item_keydown.bind(this))},click:function(a){a.stopPropagation(),this.toggle()},toggle:function(){this.$menu.hasClass("open")?this.close():(this.$menu.addClass("open"),this.$menus.trigger("hide.bs.submenu"))},hide:function(a){a.stopPropagation(),this.close()},close:function(){this.$menu.removeClass("open"),this.$children.trigger("hide.bs.submenu")},keydown:function(a){/^(32|38|40)$/.test(a.keyCode)&&a.preventDefault(),/^(13|32)$/.test(a.keyCode)?this.toggle():/^(27|38|40)$/.test(a.keyCode)&&(a.stopPropagation(),27==a.keyCode?this.$menu.hasClass("open")?this.close():(this.$menus.trigger("hide.bs.submenu"),this.$dropdown.removeClass("open").children("a").focus()):38==a.keyCode?this.$prev.focus():40==a.keyCode&&this.$next.focus())},next_keydown:function(a){38==a.keyCode&&(a.preventDefault(),a.stopPropagation(),this.$element.focus())},item_keydown:function(a){27==a.keyCode&&(a.stopPropagation(),this.close(),this.$element.focus())}},a.fn.submenupicker=function(){return this.each(function(){var c=a.data(this,"bs.submenu");c||(new b(this),a.data(this,"bs.submenu",!0))})}}(jQuery); |
@@ -9,11 +9,17 @@ 'use strict'; | ||
function Submenupicker(element) { | ||
var desc = ':not(.disabled, .divider, .dropdown-header):first'; | ||
var fake = ':not(.disabled, .divider, .dropdown-header)'; | ||
var desc = fake + ':first'; | ||
this.$element = $(element); | ||
this.$menu = this.$element.parent(); | ||
this.$dropdown = this.$menu.parent().parent(); | ||
this.$menus = this.$menu.siblings('.dropdown-submenu'); | ||
this.$children = this.$menu.find('> .dropdown-menu > .dropdown-submenu'); | ||
this.$prev = this.$menu.prevAll(desc).children('a'); | ||
this.$next = this.$menu.nextAll(desc).children('a'); | ||
var $children = this.$menu.find('> .dropdown-menu > ' + fake); | ||
this.$children = $children.filter('.dropdown-submenu'); | ||
this.$items = $children.not('.dropdown-submenu'); | ||
this.init(); | ||
@@ -27,2 +33,4 @@ } | ||
this.$menu.on('hide.bs.submenu', this.hide.bind(this)); | ||
this.$next.keydown(this.next_keydown.bind(this)); | ||
this.$items.keydown(this.item_keydown.bind(this)); | ||
}, | ||
@@ -54,3 +62,3 @@ click: function(event) { | ||
keydown: function(event) { | ||
// 13: Return, 32: Spacebar | ||
// 13: Return, 27: Esc, 32: Spacebar | ||
// 38: Arrow up, 40: Arrow down | ||
@@ -66,6 +74,15 @@ | ||
} | ||
else if (/^(38|40)$/.test(event.keyCode)) { | ||
else if (/^(27|38|40)$/.test(event.keyCode)) { | ||
event.stopPropagation(); | ||
if (event.keyCode == 38) { | ||
if (event.keyCode == 27) { | ||
if (this.$menu.hasClass('open')) { | ||
this.close(); | ||
} | ||
else { | ||
this.$menus.trigger('hide.bs.submenu'); | ||
this.$dropdown.removeClass('open').children('a').focus(); | ||
} | ||
} | ||
else if (event.keyCode == 38) { | ||
this.$prev.focus(); | ||
@@ -77,2 +94,28 @@ } | ||
} | ||
}, | ||
next_keydown: function(event) { | ||
// 38: Arrow up | ||
if (event.keyCode != 38) { | ||
return; | ||
} | ||
// Off vertical scrolling | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.$element.focus(); | ||
}, | ||
item_keydown: function(event) { | ||
// 27: Esc | ||
if (event.keyCode != 27) { | ||
return; | ||
} | ||
event.stopPropagation(); | ||
this.close(); | ||
this.$element.focus(); | ||
} | ||
@@ -79,0 +122,0 @@ }; |
{ | ||
"name": "bootstrap-submenu", | ||
"version": "1.1.9", | ||
"version": "1.2.0", | ||
"description": "Bootstrap Sub-Menus", | ||
@@ -39,2 +39,3 @@ "keywords": [ | ||
"grunt-contrib-less": "~0.11.4", | ||
"grunt-contrib-symlink": "~0.3.0", | ||
"grunt-contrib-uglify": "~0.6.0", | ||
@@ -41,0 +42,0 @@ "load-grunt-tasks": "~0.6.0" |
@@ -12,3 +12,3 @@ # [Bootstrap-submenu](http://vsn4ik.github.io/bootstrap-submenu) | ||
Four quick start options are available: | ||
Five quick start options are available: | ||
@@ -19,2 +19,3 @@ - [Download ZIP](https://github.com/vsn4ik/bootstrap-submenu/archive/master.zip "Download Bootstrap-submenu"). | ||
- Install with [npm](https://www.npmjs.org): `npm install bootstrap-submenu`. | ||
- Install with [Composer](https://getcomposer.org): `composer require vsn4ik/bootstrap-submenu "dev-master"`. | ||
@@ -21,0 +22,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22205
304
44
12