bootstrap_ajax_typeahead 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5746f288470bfd13fbb1db1928af17fe04b641b
4
+ data.tar.gz: ccc5d2dc324c252ecc122d2b11e144b1fa01506e
5
+ SHA512:
6
+ metadata.gz: ed4d583aa9db0b08980da5c320893cf6d525e3f5d206dc0142cb887655f7cc495f322fa639a6addec5586bc0a5b1a3bc541df37574c3912ff4d870e6030bad3b
7
+ data.tar.gz: 16be1cbc4e06a2596035151a459069284d509209761c1ab608fde7e74d78960444791b09e4bfc39564fa48a952264b2f60476d56eee4b88e908fc8ea7304c7bf
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap_ajax_typeahead.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # BootstrapAjaxTypeahead
2
+
3
+ Gem for Twitter Bootstrap Ajax Typeahead plugin https://github.com/biggora/bootstrap-ajax-typeahead
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bootstrap_ajax_typeahead'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bootstrap_ajax_typeahead
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/apoyan/bootstrap_ajax_typeahead.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bootstrap_ajax_typeahead"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootstrap_ajax_typeahead/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bootstrap_ajax_typeahead"
8
+ spec.version = Bootstrap::AjaxTypeahead::Rails::VERSION
9
+ spec.authors = ["Apoyan Tigran"]
10
+ spec.email = ["apoyan.tigran@gmail.com"]
11
+
12
+ spec.summary = %q{To gemify bootstrap-ajax-typeahead for assets pipleline.}
13
+ spec.license = "MIT"
14
+
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,10 @@
1
+ require "bootstrap_ajax_typeahead/version"
2
+
3
+ module Bootstrap
4
+ module AjaxTypeahead
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Bootstrap
2
+ module AjaxTypeahead
3
+ module Rails
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,530 @@
1
+ /*!
2
+ * bootstrap-typeahead.js v0.0.5 (http://www.upbootstrap.com)
3
+ * Copyright 2012-2015 Twitter Inc.
4
+ * Licensed under MIT (https://github.com/biggora/bootstrap-ajax-typeahead/blob/master/LICENSE)
5
+ * See Demo: http://plugins.upbootstrap.com/bootstrap-ajax-typeahead
6
+ * Updated: 2015-04-05 11:43:56
7
+ *
8
+ * Modifications by Paul Warelis and Alexey Gordeyev
9
+ */
10
+ !function ($) {
11
+
12
+ "use strict"; // jshint ;_;
13
+
14
+ /* TYPEAHEAD PUBLIC CLASS DEFINITION
15
+ * ================================= */
16
+
17
+ var Typeahead = function (element, options) {
18
+
19
+ //deal with scrollBar
20
+ var defaultOptions = $.fn.typeahead.defaults;
21
+ if (options.scrollBar) {
22
+ options.items = 100;
23
+ options.menu = '<ul class="typeahead dropdown-menu" style="max-height:220px;overflow:auto;"></ul>';
24
+ }
25
+
26
+ var that = this;
27
+ that.$element = $(element);
28
+ that.options = $.extend({}, $.fn.typeahead.defaults, options);
29
+ that.$menu = $(that.options.menu).insertAfter(that.$element);
30
+
31
+ // Method overrides
32
+ that.eventSupported = that.options.eventSupported || that.eventSupported;
33
+ that.grepper = that.options.grepper || that.grepper;
34
+ that.highlighter = that.options.highlighter || that.highlighter;
35
+ that.lookup = that.options.lookup || that.lookup;
36
+ that.matcher = that.options.matcher || that.matcher;
37
+ that.render = that.options.render || that.render;
38
+ that.onSelect = that.options.onSelect || null;
39
+ that.sorter = that.options.sorter || that.sorter;
40
+ that.source = that.options.source || that.source;
41
+ that.displayField = that.options.displayField || that.displayField;
42
+ that.valueField = that.options.valueField || that.valueField;
43
+
44
+ if (that.options.ajax) {
45
+ var ajax = that.options.ajax;
46
+
47
+ if (typeof ajax === 'string') {
48
+ that.ajax = $.extend({}, $.fn.typeahead.defaults.ajax, {
49
+ url: ajax
50
+ });
51
+ } else {
52
+ if (typeof ajax.displayField === 'string') {
53
+ that.displayField = that.options.displayField = ajax.displayField;
54
+ }
55
+ if (typeof ajax.valueField === 'string') {
56
+ that.valueField = that.options.valueField = ajax.valueField;
57
+ }
58
+
59
+ that.ajax = $.extend({}, $.fn.typeahead.defaults.ajax, ajax);
60
+ }
61
+
62
+ if (!that.ajax.url) {
63
+ that.ajax = null;
64
+ }
65
+ that.query = "";
66
+ } else {
67
+ that.source = that.options.source;
68
+ that.ajax = null;
69
+ }
70
+ that.shown = false;
71
+ that.listen();
72
+ };
73
+
74
+ Typeahead.prototype = {
75
+ constructor: Typeahead,
76
+ //=============================================================================================================
77
+ // Utils
78
+ // Check if an event is supported by the browser eg. 'keypress'
79
+ // * This was included to handle the "exhaustive deprecation" of jQuery.browser in jQuery 1.8
80
+ //=============================================================================================================
81
+ eventSupported: function (eventName) {
82
+ var isSupported = (eventName in this.$element);
83
+
84
+ if (!isSupported) {
85
+ this.$element.setAttribute(eventName, 'return;');
86
+ isSupported = typeof this.$element[eventName] === 'function';
87
+ }
88
+
89
+ return isSupported;
90
+ },
91
+ select: function () {
92
+ var $selectedItem = this.$menu.find('.active');
93
+ var value = $selectedItem.attr('data-value');
94
+ var text = this.$menu.find('.active a').text();
95
+
96
+ if (this.options.onSelect) {
97
+ this.options.onSelect({
98
+ value: value,
99
+ text: text
100
+ });
101
+ }
102
+ this.$element
103
+ .val(this.updater(text))
104
+ .change();
105
+ return this.hide();
106
+ },
107
+ updater: function (item) {
108
+ return item;
109
+ },
110
+ show: function () {
111
+ var pos = $.extend({}, this.$element.position(), {
112
+ height: this.$element[0].offsetHeight
113
+ });
114
+
115
+ this.$menu.css({
116
+ top: pos.top + pos.height,
117
+ left: pos.left
118
+ });
119
+
120
+ if(this.options.alignWidth) {
121
+ var width = $(this.$element[0]).outerWidth();
122
+ this.$menu.css({
123
+ width: width
124
+ });
125
+ }
126
+
127
+ this.$menu.show();
128
+ this.shown = true;
129
+ return this;
130
+ },
131
+ hide: function () {
132
+ this.$menu.hide();
133
+ this.shown = false;
134
+ return this;
135
+ },
136
+ ajaxLookup: function () {
137
+
138
+ var query = $.trim(this.$element.val());
139
+
140
+ if (query === this.query) {
141
+ return this;
142
+ }
143
+
144
+ // Query changed
145
+ this.query = query;
146
+
147
+ // Cancel last timer if set
148
+ if (this.ajax.timerId) {
149
+ clearTimeout(this.ajax.timerId);
150
+ this.ajax.timerId = null;
151
+ }
152
+
153
+ if (!query || query.length < this.ajax.triggerLength) {
154
+ // cancel the ajax callback if in progress
155
+ if (this.ajax.xhr) {
156
+ this.ajax.xhr.abort();
157
+ this.ajax.xhr = null;
158
+ this.ajaxToggleLoadClass(false);
159
+ }
160
+
161
+ return this.shown ? this.hide() : this;
162
+ }
163
+
164
+ function execute() {
165
+ this.ajaxToggleLoadClass(true);
166
+
167
+ // Cancel last call if already in progress
168
+ if (this.ajax.xhr)
169
+ this.ajax.xhr.abort();
170
+
171
+ var params = this.ajax.preDispatch ? this.ajax.preDispatch(query) : {
172
+ query: query
173
+ };
174
+ this.ajax.xhr = $.ajax({
175
+ url: this.ajax.url,
176
+ data: params,
177
+ success: $.proxy(this.ajaxSource, this),
178
+ type: this.ajax.method || 'get',
179
+ dataType: 'json'
180
+ });
181
+ this.ajax.timerId = null;
182
+ }
183
+
184
+ // Query is good to send, set a timer
185
+ this.ajax.timerId = setTimeout($.proxy(execute, this), this.ajax.timeout);
186
+
187
+ return this;
188
+ },
189
+ ajaxSource: function (data) {
190
+ this.ajaxToggleLoadClass(false);
191
+ var that = this, items;
192
+ if (!that.ajax.xhr)
193
+ return;
194
+ if (that.ajax.preProcess) {
195
+ data = that.ajax.preProcess(data);
196
+ }
197
+ // Save for selection retreival
198
+ that.ajax.data = data;
199
+
200
+ // Manipulate objects
201
+ items = that.grepper(that.ajax.data) || [];
202
+ if (!items.length) {
203
+ return that.shown ? that.hide() : that;
204
+ }
205
+
206
+ that.ajax.xhr = null;
207
+ return that.render(items.slice(0, that.options.items)).show();
208
+ },
209
+ ajaxToggleLoadClass: function (enable) {
210
+ if (!this.ajax.loadingClass)
211
+ return;
212
+ this.$element.toggleClass(this.ajax.loadingClass, enable);
213
+ },
214
+ lookup: function (event) {
215
+ var that = this, items;
216
+ if (that.ajax) {
217
+ that.ajaxer();
218
+ }
219
+ else {
220
+ that.query = that.$element.val();
221
+
222
+ if (!that.query) {
223
+ return that.shown ? that.hide() : that;
224
+ }
225
+
226
+ items = that.grepper(that.source);
227
+
228
+
229
+ if (!items) {
230
+ return that.shown ? that.hide() : that;
231
+ }
232
+ //Bhanu added a custom message- Result not Found when no result is found
233
+ if (items.length == 0) {
234
+ items[0] = {'id': -21, 'name': "Result not Found"}
235
+ }
236
+ return that.render(items.slice(0, that.options.items)).show();
237
+ }
238
+ },
239
+ matcher: function (item) {
240
+ return ~item.toLowerCase().indexOf(this.query.toLowerCase());
241
+ },
242
+ sorter: function (items) {
243
+ if (!this.options.ajax) {
244
+ var beginswith = [],
245
+ caseSensitive = [],
246
+ caseInsensitive = [],
247
+ item;
248
+
249
+ while (item = items.shift()) {
250
+ if (!item.toLowerCase().indexOf(this.query.toLowerCase()))
251
+ beginswith.push(item);
252
+ else if (~item.indexOf(this.query))
253
+ caseSensitive.push(item);
254
+ else
255
+ caseInsensitive.push(item);
256
+ }
257
+
258
+ return beginswith.concat(caseSensitive, caseInsensitive);
259
+ } else {
260
+ return items;
261
+ }
262
+ },
263
+ highlighter: function (item) {
264
+ var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
265
+ return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
266
+ return '<strong>' + match + '</strong>';
267
+ });
268
+ },
269
+ render: function (items) {
270
+ var that = this, display, isString = typeof that.options.displayField === 'string';
271
+
272
+ items = $(items).map(function (i, item) {
273
+ if (typeof item === 'object') {
274
+ display = isString ? item[that.options.displayField] : that.options.displayField(item);
275
+ i = $(that.options.item).attr('data-value', item[that.options.valueField]);
276
+ } else {
277
+ display = item;
278
+ i = $(that.options.item).attr('data-value', item);
279
+ }
280
+ i.find('a').html(that.highlighter(display));
281
+ return i[0];
282
+ });
283
+
284
+ items.first().addClass('active');
285
+
286
+ this.$menu.html(items);
287
+ return this;
288
+ },
289
+ //------------------------------------------------------------------
290
+ // Filters relevent results
291
+ //
292
+ grepper: function (data) {
293
+ var that = this, items, display, isString = typeof that.options.displayField === 'string';
294
+
295
+ if (isString && data && data.length) {
296
+ if (data[0].hasOwnProperty(that.options.displayField)) {
297
+ items = $.grep(data, function (item) {
298
+ display = isString ? item[that.options.displayField] : that.options.displayField(item);
299
+ return that.matcher(display);
300
+ });
301
+ } else if (typeof data[0] === 'string') {
302
+ items = $.grep(data, function (item) {
303
+ return that.matcher(item);
304
+ });
305
+ } else {
306
+ return null;
307
+ }
308
+ } else {
309
+ return null;
310
+ }
311
+ return this.sorter(items);
312
+ },
313
+ next: function (event) {
314
+ var active = this.$menu.find('.active').removeClass('active'),
315
+ next = active.next();
316
+
317
+ if (!next.length) {
318
+ next = $(this.$menu.find('li')[0]);
319
+ }
320
+
321
+ if (this.options.scrollBar) {
322
+ var index = this.$menu.children("li").index(next);
323
+ if (index % 8 == 0) {
324
+ this.$menu.scrollTop(index * 26);
325
+ }
326
+ }
327
+
328
+ next.addClass('active');
329
+ },
330
+ prev: function (event) {
331
+ var active = this.$menu.find('.active').removeClass('active'),
332
+ prev = active.prev();
333
+
334
+ if (!prev.length) {
335
+ prev = this.$menu.find('li').last();
336
+ }
337
+
338
+ if (this.options.scrollBar) {
339
+
340
+ var $li = this.$menu.children("li");
341
+ var total = $li.length - 1;
342
+ var index = $li.index(prev);
343
+
344
+ if ((total - index) % 8 == 0) {
345
+ this.$menu.scrollTop((index - 7) * 26);
346
+ }
347
+
348
+ }
349
+
350
+ prev.addClass('active');
351
+
352
+ },
353
+ listen: function () {
354
+ this.$element
355
+ .on('focus', $.proxy(this.focus, this))
356
+ .on('blur', $.proxy(this.blur, this))
357
+ .on('keypress', $.proxy(this.keypress, this))
358
+ .on('keyup', $.proxy(this.keyup, this));
359
+
360
+ if (this.eventSupported('keydown')) {
361
+ this.$element.on('keydown', $.proxy(this.keydown, this))
362
+ }
363
+
364
+ this.$menu
365
+ .on('click', $.proxy(this.click, this))
366
+ .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
367
+ .on('mouseleave', 'li', $.proxy(this.mouseleave, this))
368
+ },
369
+ move: function (e) {
370
+ if (!this.shown)
371
+ return
372
+
373
+ switch (e.keyCode) {
374
+ case 9: // tab
375
+ case 13: // enter
376
+ case 27: // escape
377
+ e.preventDefault();
378
+ break
379
+
380
+ case 38: // up arrow
381
+ e.preventDefault()
382
+ this.prev()
383
+ break
384
+
385
+ case 40: // down arrow
386
+ e.preventDefault()
387
+ this.next()
388
+ break
389
+ }
390
+
391
+ e.stopPropagation();
392
+ },
393
+ keydown: function (e) {
394
+ this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40, 38, 9, 13, 27])
395
+ this.move(e)
396
+ },
397
+ keypress: function (e) {
398
+ if (this.suppressKeyPressRepeat)
399
+ return
400
+ this.move(e)
401
+ },
402
+ keyup: function (e) {
403
+ switch (e.keyCode) {
404
+ case 40: // down arrow
405
+ case 38: // up arrow
406
+ case 16: // shift
407
+ case 17: // ctrl
408
+ case 18: // alt
409
+ break
410
+
411
+ case 9: // tab
412
+ case 13: // enter
413
+ if (!this.shown)
414
+ return
415
+ this.select()
416
+ break
417
+
418
+ case 27: // escape
419
+ if (!this.shown)
420
+ return
421
+ this.hide()
422
+ break
423
+
424
+ default:
425
+ if (this.ajax)
426
+ this.ajaxLookup()
427
+ else
428
+ this.lookup()
429
+ }
430
+
431
+ e.stopPropagation()
432
+ e.preventDefault()
433
+ },
434
+ focus: function (e) {
435
+ this.focused = true
436
+ },
437
+ blur: function (e) {
438
+ this.focused = false
439
+ if (!this.mousedover && this.shown)
440
+ this.hide()
441
+ },
442
+ click: function (e) {
443
+ e.stopPropagation()
444
+ e.preventDefault()
445
+ this.select()
446
+ this.$element.focus()
447
+ },
448
+ mouseenter: function (e) {
449
+ this.mousedover = true
450
+ this.$menu.find('.active').removeClass('active')
451
+ $(e.currentTarget).addClass('active')
452
+ },
453
+ mouseleave: function (e) {
454
+ this.mousedover = false
455
+ if (!this.focused && this.shown)
456
+ this.hide()
457
+ },
458
+ destroy: function() {
459
+ this.$element
460
+ .off('focus', $.proxy(this.focus, this))
461
+ .off('blur', $.proxy(this.blur, this))
462
+ .off('keypress', $.proxy(this.keypress, this))
463
+ .off('keyup', $.proxy(this.keyup, this));
464
+
465
+ if (this.eventSupported('keydown')) {
466
+ this.$element.off('keydown', $.proxy(this.keydown, this))
467
+ }
468
+
469
+ this.$menu
470
+ .off('click', $.proxy(this.click, this))
471
+ .off('mouseenter', 'li', $.proxy(this.mouseenter, this))
472
+ .off('mouseleave', 'li', $.proxy(this.mouseleave, this))
473
+ this.$element.removeData('typeahead');
474
+ }
475
+ };
476
+
477
+
478
+ /* TYPEAHEAD PLUGIN DEFINITION
479
+ * =========================== */
480
+
481
+ $.fn.typeahead = function (option) {
482
+ return this.each(function () {
483
+ var $this = $(this),
484
+ data = $this.data('typeahead'),
485
+ options = typeof option === 'object' && option;
486
+ if (!data)
487
+ $this.data('typeahead', (data = new Typeahead(this, options)));
488
+ if (typeof option === 'string')
489
+ data[option]();
490
+ });
491
+ };
492
+
493
+ $.fn.typeahead.defaults = {
494
+ source: [],
495
+ items: 10,
496
+ scrollBar: false,
497
+ alignWidth: true,
498
+ menu: '<ul class="typeahead dropdown-menu"></ul>',
499
+ item: '<li><a href="#"></a></li>',
500
+ valueField: 'id',
501
+ displayField: 'name',
502
+ onSelect: function () {
503
+ },
504
+ ajax: {
505
+ url: null,
506
+ timeout: 300,
507
+ method: 'get',
508
+ triggerLength: 1,
509
+ loadingClass: null,
510
+ preDispatch: null,
511
+ preProcess: null
512
+ }
513
+ };
514
+
515
+ $.fn.typeahead.Constructor = Typeahead;
516
+
517
+ /* TYPEAHEAD DATA-API
518
+ * ================== */
519
+
520
+ $(function () {
521
+ $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
522
+ var $this = $(this);
523
+ if ($this.data('typeahead'))
524
+ return;
525
+ e.preventDefault();
526
+ $this.typeahead($this.data());
527
+ });
528
+ });
529
+
530
+ }(window.jQuery);
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * bootstrap-typeahead.js v0.0.5 (http://www.upbootstrap.com)
3
+ * Copyright 2012-2015 Twitter Inc.
4
+ * Licensed under MIT (https://github.com/biggora/bootstrap-ajax-typeahead/blob/master/LICENSE)
5
+ * See Demo: http://plugins.upbootstrap.com/bootstrap-ajax-typeahead
6
+ * Updated: 2015-04-05 11:43:56
7
+ *
8
+ * Modifications by Paul Warelis and Alexey Gordeyev
9
+ */
10
+ !function(a){"use strict";var b=function(b,c){a.fn.typeahead.defaults;c.scrollBar&&(c.items=100,c.menu='<ul class="typeahead dropdown-menu" style="max-height:220px;overflow:auto;"></ul>');var d=this;if(d.$element=a(b),d.options=a.extend({},a.fn.typeahead.defaults,c),d.$menu=a(d.options.menu).insertAfter(d.$element),d.eventSupported=d.options.eventSupported||d.eventSupported,d.grepper=d.options.grepper||d.grepper,d.highlighter=d.options.highlighter||d.highlighter,d.lookup=d.options.lookup||d.lookup,d.matcher=d.options.matcher||d.matcher,d.render=d.options.render||d.render,d.onSelect=d.options.onSelect||null,d.sorter=d.options.sorter||d.sorter,d.source=d.options.source||d.source,d.displayField=d.options.displayField||d.displayField,d.valueField=d.options.valueField||d.valueField,d.options.ajax){var e=d.options.ajax;"string"==typeof e?d.ajax=a.extend({},a.fn.typeahead.defaults.ajax,{url:e}):("string"==typeof e.displayField&&(d.displayField=d.options.displayField=e.displayField),"string"==typeof e.valueField&&(d.valueField=d.options.valueField=e.valueField),d.ajax=a.extend({},a.fn.typeahead.defaults.ajax,e)),d.ajax.url||(d.ajax=null),d.query=""}else d.source=d.options.source,d.ajax=null;d.shown=!1,d.listen()};b.prototype={constructor:b,eventSupported:function(a){var b=a in this.$element;return b||(this.$element.setAttribute(a,"return;"),b="function"==typeof this.$element[a]),b},select:function(){var a=this.$menu.find(".active"),b=a.attr("data-value"),c=this.$menu.find(".active a").text();return this.options.onSelect&&this.options.onSelect({value:b,text:c}),this.$element.val(this.updater(c)).change(),this.hide()},updater:function(a){return a},show:function(){var b=a.extend({},this.$element.position(),{height:this.$element[0].offsetHeight});if(this.$menu.css({top:b.top+b.height,left:b.left}),this.options.alignWidth){var c=a(this.$element[0]).outerWidth();this.$menu.css({width:c})}return this.$menu.show(),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},ajaxLookup:function(){function b(){this.ajaxToggleLoadClass(!0),this.ajax.xhr&&this.ajax.xhr.abort();var b=this.ajax.preDispatch?this.ajax.preDispatch(c):{query:c};this.ajax.xhr=a.ajax({url:this.ajax.url,data:b,success:a.proxy(this.ajaxSource,this),type:this.ajax.method||"get",dataType:"json"}),this.ajax.timerId=null}var c=a.trim(this.$element.val());return c===this.query?this:(this.query=c,this.ajax.timerId&&(clearTimeout(this.ajax.timerId),this.ajax.timerId=null),!c||c.length<this.ajax.triggerLength?(this.ajax.xhr&&(this.ajax.xhr.abort(),this.ajax.xhr=null,this.ajaxToggleLoadClass(!1)),this.shown?this.hide():this):(this.ajax.timerId=setTimeout(a.proxy(b,this),this.ajax.timeout),this))},ajaxSource:function(a){this.ajaxToggleLoadClass(!1);var b,c=this;if(c.ajax.xhr)return c.ajax.preProcess&&(a=c.ajax.preProcess(a)),c.ajax.data=a,b=c.grepper(c.ajax.data)||[],b.length?(c.ajax.xhr=null,c.render(b.slice(0,c.options.items)).show()):c.shown?c.hide():c},ajaxToggleLoadClass:function(a){this.ajax.loadingClass&&this.$element.toggleClass(this.ajax.loadingClass,a)},lookup:function(){var a,b=this;return b.ajax?void b.ajaxer():(b.query=b.$element.val(),b.query&&(a=b.grepper(b.source))?(0==a.length&&(a[0]={id:-21,name:"Result not Found"}),b.render(a.slice(0,b.options.items)).show()):b.shown?b.hide():b)},matcher:function(a){return~a.toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(a){if(this.options.ajax)return a;for(var b,c=[],d=[],e=[];b=a.shift();)b.toLowerCase().indexOf(this.query.toLowerCase())?~b.indexOf(this.query)?d.push(b):e.push(b):c.push(b);return c.concat(d,e)},highlighter:function(a){var b=this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&");return a.replace(new RegExp("("+b+")","ig"),function(a,b){return"<strong>"+b+"</strong>"})},render:function(b){var c,d=this,e="string"==typeof d.options.displayField;return b=a(b).map(function(b,f){return"object"==typeof f?(c=e?f[d.options.displayField]:d.options.displayField(f),b=a(d.options.item).attr("data-value",f[d.options.valueField])):(c=f,b=a(d.options.item).attr("data-value",f)),b.find("a").html(d.highlighter(c)),b[0]}),b.first().addClass("active"),this.$menu.html(b),this},grepper:function(b){var c,d,e=this,f="string"==typeof e.options.displayField;if(!(f&&b&&b.length))return null;if(b[0].hasOwnProperty(e.options.displayField))c=a.grep(b,function(a){return d=f?a[e.options.displayField]:e.options.displayField(a),e.matcher(d)});else{if("string"!=typeof b[0])return null;c=a.grep(b,function(a){return e.matcher(a)})}return this.sorter(c)},next:function(){var b=this.$menu.find(".active").removeClass("active"),c=b.next();if(c.length||(c=a(this.$menu.find("li")[0])),this.options.scrollBar){var d=this.$menu.children("li").index(c);d%8==0&&this.$menu.scrollTop(26*d)}c.addClass("active")},prev:function(){var a=this.$menu.find(".active").removeClass("active"),b=a.prev();if(b.length||(b=this.$menu.find("li").last()),this.options.scrollBar){var c=this.$menu.children("li"),d=c.length-1,e=c.index(b);(d-e)%8==0&&this.$menu.scrollTop(26*(e-7))}b.addClass("active")},listen:function(){this.$element.on("focus",a.proxy(this.focus,this)).on("blur",a.proxy(this.blur,this)).on("keypress",a.proxy(this.keypress,this)).on("keyup",a.proxy(this.keyup,this)),this.eventSupported("keydown")&&this.$element.on("keydown",a.proxy(this.keydown,this)),this.$menu.on("click",a.proxy(this.click,this)).on("mouseenter","li",a.proxy(this.mouseenter,this)).on("mouseleave","li",a.proxy(this.mouseleave,this))},move:function(a){if(this.shown){switch(a.keyCode){case 9:case 13:case 27:a.preventDefault();break;case 38:a.preventDefault(),this.prev();break;case 40:a.preventDefault(),this.next()}a.stopPropagation()}},keydown:function(b){this.suppressKeyPressRepeat=~a.inArray(b.keyCode,[40,38,9,13,27]),this.move(b)},keypress:function(a){this.suppressKeyPressRepeat||this.move(a)},keyup:function(a){switch(a.keyCode){case 40:case 38:case 16:case 17:case 18:break;case 9:case 13:if(!this.shown)return;this.select();break;case 27:if(!this.shown)return;this.hide();break;default:this.ajax?this.ajaxLookup():this.lookup()}a.stopPropagation(),a.preventDefault()},focus:function(){this.focused=!0},blur:function(){this.focused=!1,!this.mousedover&&this.shown&&this.hide()},click:function(a){a.stopPropagation(),a.preventDefault(),this.select(),this.$element.focus()},mouseenter:function(b){this.mousedover=!0,this.$menu.find(".active").removeClass("active"),a(b.currentTarget).addClass("active")},mouseleave:function(){this.mousedover=!1,!this.focused&&this.shown&&this.hide()},destroy:function(){this.$element.off("focus",a.proxy(this.focus,this)).off("blur",a.proxy(this.blur,this)).off("keypress",a.proxy(this.keypress,this)).off("keyup",a.proxy(this.keyup,this)),this.eventSupported("keydown")&&this.$element.off("keydown",a.proxy(this.keydown,this)),this.$menu.off("click",a.proxy(this.click,this)).off("mouseenter","li",a.proxy(this.mouseenter,this)).off("mouseleave","li",a.proxy(this.mouseleave,this)),this.$element.removeData("typeahead")}},a.fn.typeahead=function(c){return this.each(function(){var d=a(this),e=d.data("typeahead"),f="object"==typeof c&&c;e||d.data("typeahead",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.typeahead.defaults={source:[],items:10,scrollBar:!1,alignWidth:!0,menu:'<ul class="typeahead dropdown-menu"></ul>',item:'<li><a href="#"></a></li>',valueField:"id",displayField:"name",onSelect:function(){},ajax:{url:null,timeout:300,method:"get",triggerLength:1,loadingClass:null,preDispatch:null,preProcess:null}},a.fn.typeahead.Constructor=b,a(function(){a("body").on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(b){var c=a(this);c.data("typeahead")||(b.preventDefault(),c.typeahead(c.data()))})})}(window.jQuery);
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap_ajax_typeahead
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Apoyan Tigran
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - apoyan.tigran@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - bootstrap_ajax_typeahead.gemspec
57
+ - lib/bootstrap_ajax_typeahead.rb
58
+ - lib/bootstrap_ajax_typeahead/version.rb
59
+ - vendor/assets/javascripts/bootstrap-typeahead.js
60
+ - vendor/assets/javascripts/bootstrap-typeahead.min.js
61
+ homepage:
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: To gemify bootstrap-ajax-typeahead for assets pipleline.
85
+ test_files: []