Diffstat (limited to 'frontend/gamma/js/Bootstrap/bootstrap-typeahead.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Bootstrap/bootstrap-typeahead.js | 346 |
1 files changed, 0 insertions, 346 deletions
diff --git a/frontend/gamma/js/Bootstrap/bootstrap-typeahead.js b/frontend/gamma/js/Bootstrap/bootstrap-typeahead.js deleted file mode 100644 index d3d8d32..0000000 --- a/frontend/gamma/js/Bootstrap/bootstrap-typeahead.js +++ b/dev/null | |||
@@ -1,346 +0,0 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | /* ============================================================= | ||
25 | * bootstrap-typeahead.js v2.2.2 | ||
26 | * http://twitter.github.com/bootstrap/javascript.html#typeahead | ||
27 | * ============================================================= | ||
28 | * Copyright 2012 Twitter, Inc. | ||
29 | * | ||
30 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
31 | * you may not use this file except in compliance with the License. | ||
32 | * You may obtain a copy of the License at | ||
33 | * | ||
34 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
35 | * | ||
36 | * Unless required by applicable law or agreed to in writing, software | ||
37 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
39 | * See the License for the specific language governing permissions and | ||
40 | * limitations under the License. | ||
41 | * ============================================================ */ | ||
42 | |||
43 | |||
44 | !function($){ | ||
45 | |||
46 | "use strict"; // jshint ;_; | ||
47 | |||
48 | |||
49 | /* TYPEAHEAD PUBLIC CLASS DEFINITION | ||
50 | * ================================= */ | ||
51 | |||
52 | var Typeahead = function (element, options) { | ||
53 | this.$element = $(element) | ||
54 | this.options = $.extend({}, $.fn.typeahead.defaults, options) | ||
55 | this.matcher = this.options.matcher || this.matcher | ||
56 | this.sorter = this.options.sorter || this.sorter | ||
57 | this.highlighter = this.options.highlighter || this.highlighter | ||
58 | this.updater = this.options.updater || this.updater | ||
59 | this.source = this.options.source | ||
60 | this.$menu = $(this.options.menu) | ||
61 | this.shown = false | ||
62 | this.listen() | ||
63 | } | ||
64 | |||
65 | Typeahead.prototype = { | ||
66 | |||
67 | constructor: Typeahead | ||
68 | |||
69 | , select: function () { | ||
70 | var val = this.$menu.find('.active').attr('data-value') | ||
71 | this.$element | ||
72 | .val(this.updater(val)) | ||
73 | .change() | ||
74 | return this.hide() | ||
75 | } | ||
76 | |||
77 | , updater: function (item) { | ||
78 | return item | ||
79 | } | ||
80 | |||
81 | , show: function () { | ||
82 | var pos = $.extend({}, this.$element.position(), { | ||
83 | height: this.$element[0].offsetHeight | ||
84 | }) | ||
85 | |||
86 | this.$menu | ||
87 | .insertAfter(this.$element) | ||
88 | .css({ | ||
89 | top: pos.top + pos.height | ||
90 | , left: pos.left | ||
91 | }) | ||
92 | .show() | ||
93 | |||
94 | this.shown = true | ||
95 | return this | ||
96 | } | ||
97 | |||
98 | , hide: function () { | ||
99 | this.$menu.hide() | ||
100 | this.shown = false | ||
101 | return this | ||
102 | } | ||
103 | |||
104 | , lookup: function (event) { | ||
105 | var items | ||
106 | |||
107 | this.query = this.$element.val() | ||
108 | |||
109 | if (!this.query || this.query.length < this.options.minLength) { | ||
110 | return this.shown ? this.hide() : this | ||
111 | } | ||
112 | |||
113 | items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source | ||
114 | |||
115 | return items ? this.process(items) : this | ||
116 | } | ||
117 | |||
118 | , process: function (items) { | ||
119 | var that = this | ||
120 | |||
121 | items = $.grep(items, function (item) { | ||
122 | return that.matcher(item) | ||
123 | }) | ||
124 | |||
125 | items = this.sorter(items) | ||
126 | |||
127 | if (!items.length) { | ||
128 | return this.shown ? this.hide() : this | ||
129 | } | ||
130 | |||
131 | return this.render(items.slice(0, this.options.items)).show() | ||
132 | } | ||
133 | |||
134 | , matcher: function (item) { | ||
135 | return ~item.toLowerCase().indexOf(this.query.toLowerCase()) | ||
136 | } | ||
137 | |||
138 | , sorter: function (items) { | ||
139 | var beginswith = [] | ||
140 | , caseSensitive = [] | ||
141 | , caseInsensitive = [] | ||
142 | , item | ||
143 | |||
144 | while (item = items.shift()) { | ||
145 | if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item) | ||
146 | else if (~item.indexOf(this.query)) caseSensitive.push(item) | ||
147 | else caseInsensitive.push(item) | ||
148 | } | ||
149 | |||
150 | return beginswith.concat(caseSensitive, caseInsensitive) | ||
151 | } | ||
152 | |||
153 | , highlighter: function (item) { | ||
154 | var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&') | ||
155 | return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { | ||
156 | return '<strong>' + match + '</strong>' | ||
157 | }) | ||
158 | } | ||
159 | |||
160 | , render: function (items) { | ||
161 | var that = this | ||
162 | |||
163 | items = $(items).map(function (i, item) { | ||
164 | i = $(that.options.item).attr('data-value', item) | ||
165 | i.find('a').html(that.highlighter(item)) | ||
166 | return i[0] | ||
167 | }) | ||
168 | |||
169 | items.first().addClass('active') | ||
170 | this.$menu.html(items) | ||
171 | return this | ||
172 | } | ||
173 | |||
174 | , next: function (event) { | ||
175 | var active = this.$menu.find('.active').removeClass('active') | ||
176 | , next = active.next() | ||
177 | |||
178 | if (!next.length) { | ||
179 | next = $(this.$menu.find('li')[0]) | ||
180 | } | ||
181 | |||
182 | next.addClass('active') | ||
183 | } | ||
184 | |||
185 | , prev: function (event) { | ||
186 | var active = this.$menu.find('.active').removeClass('active') | ||
187 | , prev = active.prev() | ||
188 | |||
189 | if (!prev.length) { | ||
190 | prev = this.$menu.find('li').last() | ||
191 | } | ||
192 | |||
193 | prev.addClass('active') | ||
194 | } | ||
195 | |||
196 | , listen: function () { | ||
197 | this.$element | ||
198 | .on('blur', $.proxy(this.blur, this)) | ||
199 | .on('keypress', $.proxy(this.keypress, this)) | ||
200 | .on('keyup', $.proxy(this.keyup, this)) | ||
201 | |||
202 | if (this.eventSupported('keydown')) { | ||
203 | this.$element.on('keydown', $.proxy(this.keydown, this)) | ||
204 | } | ||
205 | |||
206 | this.$menu | ||
207 | .on('click', $.proxy(this.click, this)) | ||
208 | .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) | ||
209 | } | ||
210 | |||
211 | , eventSupported: function(eventName) { | ||
212 | var isSupported = eventName in this.$element | ||
213 | if (!isSupported) { | ||
214 | this.$element.setAttribute(eventName, 'return;') | ||
215 | isSupported = typeof this.$element[eventName] === 'function' | ||
216 | } | ||
217 | return isSupported | ||
218 | } | ||
219 | |||
220 | , move: function (e) { | ||
221 | if (!this.shown) return | ||
222 | |||
223 | switch(e.keyCode) { | ||
224 | case 9: // tab | ||
225 | case 13: // enter | ||
226 | case 27: // escape | ||
227 | e.preventDefault() | ||
228 | break | ||
229 | |||
230 | case 38: // up arrow | ||
231 | e.preventDefault() | ||
232 | this.prev() | ||
233 | break | ||
234 | |||
235 | case 40: // down arrow | ||
236 | e.preventDefault() | ||
237 | this.next() | ||
238 | break | ||
239 | } | ||
240 | |||
241 | e.stopPropagation() | ||
242 | } | ||
243 | |||
244 | , keydown: function (e) { | ||
245 | this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]) | ||
246 | this.move(e) | ||
247 | } | ||
248 | |||
249 | , keypress: function (e) { | ||
250 | if (this.suppressKeyPressRepeat) return | ||
251 | this.move(e) | ||
252 | } | ||
253 | |||
254 | , keyup: function (e) { | ||
255 | switch(e.keyCode) { | ||
256 | case 40: // down arrow | ||
257 | case 38: // up arrow | ||
258 | case 16: // shift | ||
259 | case 17: // ctrl | ||
260 | case 18: // alt | ||
261 | break | ||
262 | |||
263 | case 9: // tab | ||
264 | case 13: // enter | ||
265 | if (!this.shown) return | ||
266 | this.select() | ||
267 | break | ||
268 | |||
269 | case 27: // escape | ||
270 | if (!this.shown) return | ||
271 | this.hide() | ||
272 | break | ||
273 | |||
274 | default: | ||
275 | this.lookup() | ||
276 | } | ||
277 | |||
278 | e.stopPropagation() | ||
279 | e.preventDefault() | ||
280 | } | ||
281 | |||
282 | , blur: function (e) { | ||
283 | var that = this | ||
284 | setTimeout(function () { that.hide() }, 150) | ||
285 | } | ||
286 | |||
287 | , click: function (e) { | ||
288 | e.stopPropagation() | ||
289 | e.preventDefault() | ||
290 | this.select() | ||
291 | } | ||
292 | |||
293 | , mouseenter: function (e) { | ||
294 | this.$menu.find('.active').removeClass('active') | ||
295 | $(e.currentTarget).addClass('active') | ||
296 | } | ||
297 | |||
298 | } | ||
299 | |||
300 | |||
301 | /* TYPEAHEAD PLUGIN DEFINITION | ||
302 | * =========================== */ | ||
303 | |||
304 | var old = $.fn.typeahead | ||
305 | |||
306 | $.fn.typeahead = function (option) { | ||
307 | return this.each(function () { | ||
308 | var $this = $(this) | ||
309 | , data = $this.data('typeahead') | ||
310 | , options = typeof option == 'object' && option | ||
311 | if (!data) $this.data('typeahead', (data = new Typeahead(this, options))) | ||
312 | if (typeof option == 'string') data[option]() | ||
313 | }) | ||
314 | } | ||
315 | |||
316 | $.fn.typeahead.defaults = { | ||
317 | source: [] | ||
318 | , items: 8 | ||
319 | , menu: '<ul class="typeahead dropdown-menu"></ul>' | ||
320 | , item: '<li><a href="#"></a></li>' | ||
321 | , minLength: 1 | ||
322 | } | ||
323 | |||
324 | $.fn.typeahead.Constructor = Typeahead | ||
325 | |||
326 | |||
327 | /* TYPEAHEAD NO CONFLICT | ||
328 | * =================== */ | ||
329 | |||
330 | $.fn.typeahead.noConflict = function () { | ||
331 | $.fn.typeahead = old | ||
332 | return this | ||
333 | } | ||
334 | |||
335 | |||
336 | /* TYPEAHEAD DATA-API | ||
337 | * ================== */ | ||
338 | |||
339 | $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { | ||
340 | var $this = $(this) | ||
341 | if ($this.data('typeahead')) return | ||
342 | e.preventDefault() | ||
343 | $this.typeahead($this.data()) | ||
344 | }) | ||
345 | |||
346 | }(window.jQuery); | ||