PageSourceSearch

https://sansomlab.github.io/fibroblasts/ext/bootstrap-submenu.js?b90795f435

js sansomlab.github.io collected 2026-10-03 09:54:52 UTC 4,772 bytes, 193 lines download raw bytes

1/*!
2 * Bootstrap-submenu v2.0.4 (https://vsn4ik.github.io/bootstrap-submenu/)
3 * Copyright 2014-2018 Vasilii A. (https://github.com/vsn4ik)
4 * Licensed under the MIT license
5 */
6
7/**
8 * $.inArray: friends with IE8. Use Array.prototype.indexOf in future.
9 * $.proxy: friends with IE8. Use Function.prototype.bind in future.
10 */
11
12'use strict';
13
14(function(factory) {
15  if (typeof define === 'function' && define.amd) {
16    // AMD. Register as an anonymous module
17    define(['jquery'], factory);
18  } else if (typeof exports === 'object') {
19    // Node/CommonJS
20    module.exports = factory(require('jquery'));
21  } else {
22    // Browser globals
23    factory(jQuery);
24  }
25})(function($) {
26  function Item(element) {
27    this.$element = $(element);
28    this.$menu = this.$element.closest('.dropdown-menu');
29    this.$main = this.$menu.parent();
30    this.$items = this.$menu.children('.dropdown-submenu');
31
32    this.init();
33  }
34
35  Item.prototype = {
36    init: function() {
37      this.$element.on('keydown', $.proxy(this, 'keydown'));
38    },
39    close: function() {
40      this.$main.removeClass('open');
41      this.$items.trigger('hide.bs.submenu');
42    },
43    keydown: function(event) {
44      // 27: Esc
45
46      if (event.keyCode == 27) {
47        event.stopPropagation();
48
49        this.close();
50        this.$main.children('a, button').trigger('focus');
51      }
52    }
53  };
54
55  function SubmenuItem(element) {
56    this.$element = $(element);
57    this.$main = this.$element.parent();
58    this.$menu = this.$main.children('.dropdown-menu');
59    this.$subs = this.$main.siblings('.dropdown-submenu');
60    this.$items = this.$menu.children('.dropdown-submenu');
61
62    this.init();
63  }
64
65  $.extend(SubmenuItem.prototype, Item.prototype, {
66    init: function() {
67      this.$element.on({
68        click: $.proxy(this, 'click'),
69        keydown: $.proxy(this, 'keydown')
70      });
71
72      this.$main.on('hide.bs.submenu', $.proxy(this, 'hide'));
73    },
74    click: function(event) {
75      // Fix a[href="#"]. For community
76      event.preventDefault();
77
78      event.stopPropagation();
79
80      this.toggle();
81    },
82    hide: function(event) {
83      // Stop event bubbling
84      event.stopPropagation();
85
86      this.close();
87    },
88    open: function() {
89      this.$main.addClass('open');
90      this.$subs.trigger('hide.bs.submenu');
91    },
92    toggle: function() {
93      if (this.$main.hasClass('open')) {
94        this.close();
95      }
96      else {
97        this.open();
98      }
99    },
100    keydown: function(event) {
101      // 13: Return, 32: Spacebar
102
103      if (event.keyCode == 32) {
104        // Off vertical scrolling
105        event.preventDefault();
106      }
107
108      if ($.inArray(event.keyCode, [13, 32]) != -1) {
109        this.toggle();
110      }
111    }
112  });
113
114  function Submenupicker(element) {
115    this.$element = $(element);
116    this.$main = this.$element.parent();
117    this.$menu = this.$main.children('.dropdown-menu');
118    this.$items = this.$menu.children('.dropdown-submenu');
119
120    this.init();
121  }
122
123  Submenupicker.prototype = {
124    init: function() {
125      this.$menu.off('keydown.bs.dropdown.data-api');
126      this.$menu.on('keydown', $.proxy(this, 'itemKeydown'));
127
128      this.$menu.find('li > a').each(function() {
129        new Item(this);
130      });
131
132      this.$menu.find('.dropdown-submenu > a').each(function() {
133        new SubmenuItem(this);
134      });
135
136      this.$main.on('hidden.bs.dropdown', $.proxy(this, 'hidden'));
137    },
138    hidden: function() {
139      this.$items.trigger('hide.bs.submenu');
140    },
141    itemKeydown: function(event) {
142      // 38: Arrow up, 40: Arrow down
143
144      if ($.inArray(event.keyCode, [38, 40]) != -1) {
145        // Off vertical scrolling
146        event.preventDefault();
147
148        event.stopPropagation();
149
150        var $items = this.$menu.find('li:not(.disabled):visible > a');
151        var index = $items.index(event.target);
152
153        if (event.keyCode == 38 && index !== 0) {
154          index--;
155        }
156        else if (event.keyCode == 40 && index !== $items.length - 1) {
157          index++;
158        }
159        else {
160          return;
161        }
162
163        $items.eq(index).trigger('focus');
164      }
165    }
166  };
167
168  var old = $.fn.submenupicker;
169
170  // For AMD/Node/CommonJS used elements (optional)
171  // http://learn.jquery.com/jquery-ui/environments/amd/
172  $.fn.submenupicker = function(elements) {
173    var $elements = this instanceof $ ? this : $(elements);
174
175    return $elements.each(function() {
176      var data = $.data(this, 'bs.submenu');
177
178      if (!data) {
179        data = new Submenupicker(this);
180
181        $.data(this, 'bs.submenu', data);
182      }
183    });
184  };
185
186  $.fn.submenupicker.Constructor = Submenupicker;
187  $.fn.submenupicker.noConflict = function() {
188    $.fn.submenupicker = old;
189    return this;
190  };
191
192  return $.fn.submenupicker;
193});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.