bootstrap-submenu
Advanced tools
Comparing version 1.2.0 to 1.2.1
/*! | ||
* Bootstrap-submenu v1.2.0 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Bootstrap-submenu v1.2.1 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Copyright 2014 Vasily A. (https://github.com/vsn4ik) | ||
@@ -14,16 +14,14 @@ * Licensed under MIT (https://github.com/vsn4ik/bootstrap-submenu/blob/master/LICENSE) | ||
(function($) { | ||
var desc = ':not(.disabled, .divider, .dropdown-header)'; | ||
function Submenupicker(element) { | ||
var fake = ':not(.disabled, .divider, .dropdown-header)'; | ||
var desc = fake + ':first'; | ||
this.$element = $(element); | ||
this.$dropdown = this.$element.closest('.dropdown'); | ||
this.$menu = this.$element.parent(); | ||
this.$dropdown = this.$menu.parent().parent(); | ||
this.$drop = this.$menu.parent().parent(); | ||
this.$menus = this.$menu.siblings('.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); | ||
var $children = this.$menu.find('> .dropdown-menu > ' + desc); | ||
this.$children = $children.filter('.dropdown-submenu'); | ||
this.$submenus = $children.filter('.dropdown-submenu'); | ||
this.$items = $children.not('.dropdown-submenu'); | ||
@@ -39,4 +37,6 @@ | ||
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)); | ||
// Bootstrap fix | ||
this.$menu.nextAll(desc + ':first').not('.dropdown-submenu').children('a').keydown(this.next_keydown.bind(this)); | ||
}, | ||
@@ -65,3 +65,3 @@ click: function(event) { | ||
this.$menu.removeClass('open'); | ||
this.$children.trigger('hide.bs.submenu'); | ||
this.$submenus.trigger('hide.bs.submenu'); | ||
}, | ||
@@ -89,13 +89,36 @@ keydown: function(event) { | ||
this.$menus.trigger('hide.bs.submenu'); | ||
this.$dropdown.removeClass('open').children('a').focus(); | ||
this.$drop.removeClass('open').children('a').focus(); | ||
} | ||
} | ||
else if (event.keyCode == 38) { | ||
this.$prev.focus(); | ||
else { | ||
var $items = this.$dropdown.find('li:not(.disabled):visible > a'); | ||
var index = $items.index(this.$element); | ||
if (event.keyCode == 38 && index !== 0) { | ||
index--; | ||
} | ||
else if (event.keyCode == 40 && index !== $items.length - 1) { | ||
index++; | ||
} | ||
else { | ||
return; | ||
} | ||
$items.eq(index).focus(); | ||
} | ||
else if (event.keyCode == 40) { | ||
this.$next.focus(); | ||
} | ||
} | ||
}, | ||
item_keydown: function(event) { | ||
// 27: Esc | ||
if (event.keyCode != 27) { | ||
return; | ||
} | ||
event.stopPropagation(); | ||
this.close(); | ||
this.$element.focus(); | ||
}, | ||
next_keydown: function(event) { | ||
@@ -113,15 +136,8 @@ // 38: Arrow up | ||
this.$element.focus(); | ||
}, | ||
item_keydown: function(event) { | ||
// 27: Esc | ||
// Use this.$drop instead this.$dropdown (optimally) | ||
var $items = this.$drop.find('li:not(.disabled):visible > a'); | ||
if (event.keyCode != 27) { | ||
return; | ||
} | ||
var index = $items.index(event.target); | ||
event.stopPropagation(); | ||
this.close(); | ||
this.$element.focus(); | ||
$items.eq(index - 1).focus(); | ||
} | ||
@@ -128,0 +144,0 @@ }; |
/*! | ||
* Bootstrap-submenu v1.2.0 (http://vsn4ik.github.io/bootstrap-submenu) | ||
* Bootstrap-submenu v1.2.1 (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)",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); | ||
"use strict";if("undefined"==typeof jQuery)throw new Error("Bootstrap-submenu requires jQuery");!function(a){function b(b){this.$element=a(b),this.$dropdown=this.$element.closest(".dropdown"),this.$menu=this.$element.parent(),this.$drop=this.$menu.parent().parent(),this.$menus=this.$menu.siblings(".dropdown-submenu");var d=this.$menu.find("> .dropdown-menu > "+c);this.$submenus=d.filter(".dropdown-submenu"),this.$items=d.not(".dropdown-submenu"),this.init()}var c=":not(.disabled, .divider, .dropdown-header)";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.$items.keydown(this.item_keydown.bind(this)),this.$menu.nextAll(c+":first").not(".dropdown-submenu").children("a").keydown(this.next_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.$submenus.trigger("hide.bs.submenu")},keydown:function(a){if(/^(32|38|40)$/.test(a.keyCode)&&a.preventDefault(),/^(13|32)$/.test(a.keyCode))this.toggle();else if(/^(27|38|40)$/.test(a.keyCode))if(a.stopPropagation(),27==a.keyCode)this.$menu.hasClass("open")?this.close():(this.$menus.trigger("hide.bs.submenu"),this.$drop.removeClass("open").children("a").focus());else{var b=this.$dropdown.find("li:not(.disabled):visible > a"),c=b.index(this.$element);if(38==a.keyCode&&0!==c)c--;else{if(40!=a.keyCode||c===b.length-1)return;c++}b.eq(c).focus()}},item_keydown:function(a){27==a.keyCode&&(a.stopPropagation(),this.close(),this.$element.focus())},next_keydown:function(a){if(38==a.keyCode){a.preventDefault(),a.stopPropagation();var b=this.$drop.find("li:not(.disabled):visible > a"),c=b.index(a.target);b.eq(c-1).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); |
@@ -8,16 +8,14 @@ 'use strict'; | ||
(function($) { | ||
var desc = ':not(.disabled, .divider, .dropdown-header)'; | ||
function Submenupicker(element) { | ||
var fake = ':not(.disabled, .divider, .dropdown-header)'; | ||
var desc = fake + ':first'; | ||
this.$element = $(element); | ||
this.$dropdown = this.$element.closest('.dropdown'); | ||
this.$menu = this.$element.parent(); | ||
this.$dropdown = this.$menu.parent().parent(); | ||
this.$drop = this.$menu.parent().parent(); | ||
this.$menus = this.$menu.siblings('.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); | ||
var $children = this.$menu.find('> .dropdown-menu > ' + desc); | ||
this.$children = $children.filter('.dropdown-submenu'); | ||
this.$submenus = $children.filter('.dropdown-submenu'); | ||
this.$items = $children.not('.dropdown-submenu'); | ||
@@ -33,4 +31,6 @@ | ||
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)); | ||
// Bootstrap fix | ||
this.$menu.nextAll(desc + ':first').not('.dropdown-submenu').children('a').keydown(this.next_keydown.bind(this)); | ||
}, | ||
@@ -59,3 +59,3 @@ click: function(event) { | ||
this.$menu.removeClass('open'); | ||
this.$children.trigger('hide.bs.submenu'); | ||
this.$submenus.trigger('hide.bs.submenu'); | ||
}, | ||
@@ -83,13 +83,36 @@ keydown: function(event) { | ||
this.$menus.trigger('hide.bs.submenu'); | ||
this.$dropdown.removeClass('open').children('a').focus(); | ||
this.$drop.removeClass('open').children('a').focus(); | ||
} | ||
} | ||
else if (event.keyCode == 38) { | ||
this.$prev.focus(); | ||
else { | ||
var $items = this.$dropdown.find('li:not(.disabled):visible > a'); | ||
var index = $items.index(this.$element); | ||
if (event.keyCode == 38 && index !== 0) { | ||
index--; | ||
} | ||
else if (event.keyCode == 40 && index !== $items.length - 1) { | ||
index++; | ||
} | ||
else { | ||
return; | ||
} | ||
$items.eq(index).focus(); | ||
} | ||
else if (event.keyCode == 40) { | ||
this.$next.focus(); | ||
} | ||
} | ||
}, | ||
item_keydown: function(event) { | ||
// 27: Esc | ||
if (event.keyCode != 27) { | ||
return; | ||
} | ||
event.stopPropagation(); | ||
this.close(); | ||
this.$element.focus(); | ||
}, | ||
next_keydown: function(event) { | ||
@@ -107,15 +130,8 @@ // 38: Arrow up | ||
this.$element.focus(); | ||
}, | ||
item_keydown: function(event) { | ||
// 27: Esc | ||
// Use this.$drop instead this.$dropdown (optimally) | ||
var $items = this.$drop.find('li:not(.disabled):visible > a'); | ||
if (event.keyCode != 27) { | ||
return; | ||
} | ||
var index = $items.index(event.target); | ||
event.stopPropagation(); | ||
this.close(); | ||
this.$element.focus(); | ||
$items.eq(index - 1).focus(); | ||
} | ||
@@ -122,0 +138,0 @@ }; |
{ | ||
"name": "bootstrap-submenu", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Bootstrap Sub-Menus", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23183
324