/*! * bootstrap-submenu v2.0.4 (https://vsn4ik.github.io/bootstrap-submenu/) * copyright 2014-2016 vasily a. (https://github.com/vsn4ik) * licensed under the mit license */ /** * $.inarray: friends with ie8. use array.prototype.indexof in future. * $.proxy: friends with ie8. use function.prototype.bind in future. */ 'use strict'; (function(factory) { if (typeof define == 'function' && define.amd) { // amd. register as an anonymous module define(['jquery'], factory); } else if (typeof exports == 'object') { // node/commonjs module.exports = factory(require('jquery')); } else { // browser globals factory(jquery); } })(function($) { function item(element) { this.$element = $(element); this.$menu = this.$element.closest('.dropdown-menu'); this.$main = this.$menu.parent(); this.$items = this.$menu.children('.dropdown-submenu'); this.init(); } item.prototype = { init: function() { this.$element.on('keydown', $.proxy(this, 'keydown')); }, close: function() { this.$main.removeclass('open'); this.$items.trigger('hide.bs.submenu'); }, keydown: function(event) { // 27: esc if (event.keycode == 27) { event.stoppropagation(); this.close(); this.$main.children('a, button').trigger('focus'); } } }; function submenuitem(element) { this.$element = $(element); this.$main = this.$element.parent(); this.$menu = this.$main.children('.dropdown-menu'); this.$subs = this.$main.siblings('.dropdown-submenu'); this.$items = this.$menu.children('.dropdown-submenu'); this.init(); } $.extend(submenuitem.prototype, item.prototype, { init: function() { this.$element.on({ click: $.proxy(this, 'click'), keydown: $.proxy(this, 'keydown') }); this.$main.on('hide.bs.submenu', $.proxy(this, 'hide')); }, click: function(event) { // fix a[href="#"]. for community event.preventdefault(); event.stoppropagation(); this.toggle(); }, hide: function(event) { // stop event bubbling event.stoppropagation(); this.close(); }, open: function() { this.$main.addclass('open'); this.$subs.trigger('hide.bs.submenu'); }, toggle: function() { if (this.$main.hasclass('open')) { this.close(); } else { this.open(); } }, keydown: function(event) { // 13: return, 32: spacebar if (event.keycode == 32) { // off vertical scrolling event.preventdefault(); } if ($.inarray(event.keycode, [13, 32]) != -1) { this.toggle(); } } }); function submenupicker(element) { this.$element = $(element); this.$main = this.$element.parent(); this.$menu = this.$main.children('.dropdown-menu'); this.$items = this.$menu.children('.dropdown-submenu'); this.init(); } submenupicker.prototype = { init: function() { this.$menu.off('keydown.bs.dropdown.data-api'); this.$menu.on('keydown', $.proxy(this, 'itemkeydown')); this.$menu.find('li > a').each(function() { new item(this); }); this.$menu.find('.dropdown-submenu > a').each(function() { new submenuitem(this); }); this.$main.on('hidden.bs.dropdown', $.proxy(this, 'hidden')); }, hidden: function() { this.$items.trigger('hide.bs.submenu'); }, itemkeydown: function(event) { // 38: arrow up, 40: arrow down if ($.inarray(event.keycode, [38, 40]) != -1) { // off vertical scrolling event.preventdefault(); event.stoppropagation(); var $items = this.$menu.find('li:not(.disabled):visible > a'); var index = $items.index(event.target); if (event.keycode == 38 && index !== 0) { index--; } else if (event.keycode == 40 && index !== $items.length - 1) { index++; } else { return; } $items.eq(index).trigger('focus'); } } }; var old = $.fn.submenupicker; // for amd/node/commonjs used elements (optional) // http://learn.jquery.com/jquery-ui/environments/amd/ $.fn.submenupicker = function(elements) { var $elements = this instanceof $ ? this : $(elements); return $elements.each(function() { var data = $.data(this, 'bs.submenu'); if (!data) { data = new submenupicker(this); $.data(this, 'bs.submenu', data); } }); }; $.fn.submenupicker.constructor = submenupicker; $.fn.submenupicker.noconflict = function() { $.fn.submenupicker = old; return this; }; return $.fn.submenupicker; });