bootstrap-select-rails 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap-select-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Maciej Krajowski-Kukiel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Bootstrap::Select::Rails
2
+
3
+ Assets for https://github.com/silviomoreto/bootstrap-select - see it for details
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bootstrap-select-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bootstrap-select-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ # Copyright and license
32
+
33
+ Copyright (C) 2013 bootstrap-select-rails
34
+
35
+ Licensed under the MIT license.
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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/select/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bootstrap-select-rails"
8
+ spec.version = Bootstrap::Select::Rails::VERSION
9
+ spec.authors = ["Maciej Krajowski-Kukiel"]
10
+ spec.email = ["maciej.krajowski@gmail.com"]
11
+ spec.description = %q{assets for bootstrap-select}
12
+ spec.summary = %q{assets for bootstrap-select}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib, vendor"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,10 @@
1
+ require "bootstrap/select/rails/version"
2
+
3
+ module Bootstrap
4
+ module Select
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 Select
3
+ module Rails
4
+ VERSION = "1.3.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,557 @@
1
+ !function($) {
2
+ var Selectpicker = function(element, options, e) {
3
+ if (e ) {
4
+ e.stopPropagation();
5
+ e.preventDefault();
6
+ }
7
+ this.$element = $(element);
8
+ this.$newElement = null;
9
+ this.button = null;
10
+
11
+ //Merge defaults, options and data-attributes to make our options
12
+ this.options = $.extend({}, $.fn.selectpicker.defaults, this.$element.data(), typeof options == 'object' && options);
13
+
14
+ //If we have no title yet, check the attribute 'title' (this is missed by jq as its not a data-attribute
15
+ if(this.options.title==null)
16
+ this.options.title = this.$element.attr('title');
17
+
18
+ //Expose public methods
19
+ this.val = Selectpicker.prototype.val;
20
+ this.render = Selectpicker.prototype.render;
21
+ this.refresh = Selectpicker.prototype.refresh;
22
+ this.selectAll = Selectpicker.prototype.selectAll;
23
+ this.deselectAll = Selectpicker.prototype.deselectAll;
24
+ this.init();
25
+ };
26
+
27
+ Selectpicker.prototype = {
28
+
29
+ constructor: Selectpicker,
30
+
31
+ init: function (e) {
32
+ if (!this.options.container) {
33
+ this.$element.hide();
34
+ } else {
35
+ this.$element.css('visibility','hidden');
36
+ };
37
+ this.multiple = this.$element.prop('multiple');
38
+ var classList = this.$element.attr('class') !== undefined ? this.$element.attr('class').split(/\s+/) : '';
39
+ var id = this.$element.attr('id');
40
+ this.$element.after( this.createView() );
41
+ this.$newElement = this.$element.next('.bootstrap-select');
42
+ if (this.options.container) {
43
+ this.selectPosition();
44
+ }
45
+ this.button = this.$newElement.find('> button');
46
+ if (id !== undefined) {
47
+ var _this = this;
48
+ this.button.attr('data-id', id);
49
+ $('label[for="' + id + '"]').click(function(){
50
+ _this.$newElement.find('button[data-id='+id+']').focus();
51
+ })
52
+ }
53
+ for (var i = 0; i < classList.length; i++) {
54
+ if(classList[i] != 'selectpicker') {
55
+ this.$newElement.addClass(classList[i]);
56
+ }
57
+ }
58
+ //If we are multiple, then add the show-tick class by default
59
+ if(this.multiple) {
60
+ this.$newElement.addClass('show-tick');
61
+ }
62
+ this.button.addClass(this.options.style);
63
+ this.checkDisabled();
64
+ this.checkTabIndex();
65
+ this.clickListener();
66
+
67
+ this.render();
68
+ this.setSize();
69
+ },
70
+
71
+ createDropdown: function() {
72
+ var drop =
73
+ "<div class='btn-group bootstrap-select'>" +
74
+ "<button type='button' class='btn dropdown-toggle' data-toggle='dropdown'>" +
75
+ "<span class='filter-option pull-left'></span>&nbsp;" +
76
+ "<span class='caret'></span>" +
77
+ "</button>" +
78
+ "<ul class='dropdown-menu' role='menu'>" +
79
+ "</ul>" +
80
+ "</div>";
81
+
82
+ return $(drop);
83
+ },
84
+
85
+
86
+ createView: function() {
87
+ var $drop = this.createDropdown();
88
+ var $li = this.createLi();
89
+ $drop.find('ul').append($li);
90
+ return $drop;
91
+ },
92
+
93
+ reloadLi: function() {
94
+ //Remove all children.
95
+ this.destroyLi();
96
+ //Re build
97
+ $li = this.createLi();
98
+ this.$newElement.find('ul').append( $li );
99
+ },
100
+
101
+ destroyLi:function() {
102
+ this.$newElement.find('li').remove();
103
+ },
104
+
105
+ createLi: function() {
106
+
107
+ var _this = this;
108
+ var _li = [];
109
+ var _liA = [];
110
+ var _liHtml = '';
111
+
112
+ this.$element.find('option').each(function(){
113
+ _li.push($(this).text());
114
+ });
115
+
116
+ this.$element.find('option').each(function(index) {
117
+ var $this = $(this);
118
+
119
+ //Get the class and text for the option
120
+ var optionClass = $this.attr("class") !== undefined ? $this.attr("class") : '';
121
+ var text = $this.text();
122
+ var subtext = $this.data('subtext') !== undefined ? '<small class="muted">'+$this.data('subtext')+'</small>' : '';
123
+ var icon = $this.data('icon') !== undefined ? '<i class="'+$this.data('icon')+'"></i> ' : '';
124
+ if ($this.is(':disabled') || $this.parent().is(':disabled')) {
125
+ icon = '<span>'+icon+'</span>';
126
+ }
127
+
128
+ //Prepend any icon and append any subtext to the main text.
129
+ text = icon + '<span class="text">' + text + subtext + '</span>';
130
+
131
+ if (_this.options.hideDisabled && ($this.is(':disabled') || $this.parent().is(':disabled'))) {
132
+ _liA.push('<a style="min-height: 0; padding: 0"></a>');
133
+ } else if ($this.parent().is('optgroup') && $this.data('divider') != true) {
134
+ if ($this.index() == 0) {
135
+ //Get the opt group label
136
+ var label = $this.parent().attr('label');
137
+ var labelSubtext = $this.parent().data('subtext') !== undefined ? '<small class="muted">'+$this.parent().data('subtext')+'</small>' : '';
138
+ var labelIcon = $this.parent().data('icon') ? '<i class="'+$this.parent().data('icon')+'"></i> ' : '';
139
+ label = labelIcon + '<span class="text">' + label + labelSubtext + '</span>';
140
+
141
+ if ($this[0].index != 0) {
142
+ _liA.push(
143
+ '<div class="div-contain"><div class="divider"></div></div>'+
144
+ '<dt>'+label+'</dt>'+
145
+ _this.createA(text, "opt " + optionClass )
146
+ );
147
+ } else {
148
+ _liA.push(
149
+ '<dt>'+label+'</dt>'+
150
+ _this.createA(text, "opt " + optionClass ));
151
+ }
152
+ } else {
153
+ _liA.push( _this.createA(text, "opt " + optionClass ) );
154
+ }
155
+ } else if ($this.data('divider') == true) {
156
+ _liA.push('<div class="div-contain"><div class="divider"></div></div>');
157
+ } else if ($(this).data('hidden') == true) {
158
+ _liA.push('');
159
+ } else {
160
+ _liA.push( _this.createA(text, optionClass ) );
161
+ }
162
+ });
163
+
164
+ if (_li.length > 0) {
165
+ for (var i = 0; i < _li.length; i++) {
166
+ var $option = this.$element.find('option').eq(i);
167
+ _liHtml += "<li rel=" + i + ">" + _liA[i] + "</li>";
168
+ }
169
+ }
170
+
171
+ //If we are not multiple, and we dont have a selected item, and we dont have a title, select the first element so something is set in the button
172
+ if(!this.multiple && this.$element.find('option:selected').length==0 && !_this.options.title) {
173
+ this.$element.find('option').eq(0).prop('selected', true).attr('selected', 'selected');
174
+ }
175
+
176
+ return $(_liHtml);
177
+ },
178
+
179
+ createA:function(text, classes) {
180
+ return '<a tabindex="0" class="'+classes+'">' +
181
+ text +
182
+ '<i class="icon-ok check-mark"></i>' +
183
+ '</a>';
184
+ },
185
+
186
+ render:function() {
187
+ var _this = this;
188
+
189
+ //Update the LI to match the SELECT
190
+ this.$element.find('option').each(function(index) {
191
+ _this.setDisabled(index, $(this).is(':disabled') || $(this).parent().is(':disabled') );
192
+ _this.setSelected(index, $(this).is(':selected') );
193
+ });
194
+
195
+ var selectedItems = this.$element.find('option:selected').map(function(index,value) {
196
+ if($(this).attr('title')!=undefined) {
197
+ return $(this).attr('title');
198
+ } else {
199
+ return $(this).text();
200
+ }
201
+ }).toArray();
202
+
203
+ //Fixes issue in IE10 occurring when no default option is selected and at least one option is disabled
204
+ //Convert all the values into a comma delimited string
205
+ var title = !this.multiple ? selectedItems[0] : selectedItems.join(", ");
206
+
207
+ //If this is multi select, and the selectText type is count, the show 1 of 2 selected etc..
208
+ if(_this.multiple && _this.options.selectedTextFormat.indexOf('count') > -1) {
209
+ var max = _this.options.selectedTextFormat.split(">");
210
+ if( (max.length>1 && selectedItems.length > max[1]) || (max.length==1 && selectedItems.length>=2)) {
211
+ title = selectedItems.length +' of ' + this.$element.find('option').length + ' selected';
212
+ }
213
+ }
214
+
215
+ //If we dont have a title, then use the default, or if nothing is set at all, use the not selected text
216
+ if(!title) {
217
+ title = _this.options.title != undefined ? _this.options.title : _this.options.noneSelectedText;
218
+ }
219
+
220
+ _this.$newElement.find('.filter-option').html( title );
221
+ },
222
+
223
+ setSize:function() {
224
+ var _this = this;
225
+ var menu = this.$newElement.find('.dropdown-menu');
226
+ var menuA = menu.find('li > a');
227
+ var liHeight = this.$newElement.addClass('open').find('.dropdown-menu li > a').outerHeight();
228
+ this.$newElement.removeClass('open');
229
+ var divHeight = menu.find('li .divider').outerHeight(true);
230
+ var selectOffset_top = this.$newElement.offset().top;
231
+ var selectHeight = this.$newElement.outerHeight();
232
+ var menuPadding = parseInt(menu.css('padding-top')) + parseInt(menu.css('padding-bottom')) + parseInt(menu.css('border-top-width')) + parseInt(menu.css('border-bottom-width'));
233
+ var notDisabled = this.options.hideDisabled ? ':not(.disabled)' : '';
234
+ if (this.options.size == 'auto') {
235
+ function getSize() {
236
+ var selectOffset_top_scroll = selectOffset_top - $(window).scrollTop();
237
+ var windowHeight = window.innerHeight;
238
+ var menuExtras = menuPadding + parseInt(menu.css('margin-top')) + parseInt(menu.css('margin-bottom')) + 2;
239
+ var selectOffset_bot = windowHeight - selectOffset_top_scroll - selectHeight - menuExtras;
240
+ menuHeight = selectOffset_bot;
241
+ if (_this.$newElement.hasClass('dropup')) {
242
+ menuHeight = selectOffset_top_scroll - menuExtras;
243
+ }
244
+ if ((menu.find('li').length + menu.find('dt').length) > 3) {
245
+ minHeight = liHeight*3 + menuExtras - 2;
246
+ } else {
247
+ minHeight = 0;
248
+ }
249
+ menu.css({'max-height' : menuHeight + 'px', 'overflow-y' : 'auto', 'min-height' : minHeight + 'px'});
250
+ }
251
+ getSize();
252
+ $(window).resize(getSize);
253
+ $(window).scroll(getSize);
254
+ } else if (this.options.size && this.options.size != 'auto' && menu.find('li'+notDisabled).length > this.options.size) {
255
+ var optIndex = menu.find("li"+notDisabled+" > *").filter(':not(.div-contain)').slice(0,this.options.size).last().parent().index();
256
+ var divLength = menu.find("li").slice(0,optIndex + 1).find('.div-contain').length;
257
+ menuHeight = liHeight*this.options.size + divLength*divHeight + menuPadding;
258
+ menu.css({'max-height' : menuHeight + 'px', 'overflow-y' : 'auto'});
259
+ }
260
+
261
+ //Set width of select
262
+ if (this.options.width == 'auto') {
263
+ this.$newElement.find('.dropdown-menu').css('min-width','0');
264
+ var ulWidth = this.$newElement.find('.dropdown-menu').css('width');
265
+ this.$newElement.css('width',ulWidth);
266
+ if (this.options.container) {
267
+ this.$element.css('width',ulWidth);
268
+ }
269
+ } else if (this.options.width && this.options.width != 'auto') {
270
+ this.$newElement.css('width',this.options.width);
271
+ if (this.options.container) {
272
+ this.$element.css('width',this.options.width);
273
+ }
274
+ }
275
+ },
276
+
277
+ selectPosition:function() {
278
+ var selectElementTop = this.$element.offset().top;
279
+ var selectElementLeft = this.$element.offset().left;
280
+ this.$newElement.appendTo(this.options.container);
281
+ this.$newElement.css({'position':'absolute', 'top':selectElementTop+'px', 'left':selectElementLeft+'px'});
282
+ },
283
+
284
+ refresh:function() {
285
+ this.reloadLi();
286
+ this.render();
287
+ this.setSize();
288
+ this.checkDisabled();
289
+ if (this.options.container) {
290
+ this.selectPosition();
291
+ }
292
+ },
293
+
294
+ setSelected:function(index, selected) {
295
+ if(selected) {
296
+ this.$newElement.find('li').eq(index).addClass('selected');
297
+ } else {
298
+ this.$newElement.find('li').eq(index).removeClass('selected');
299
+ }
300
+ },
301
+
302
+ setDisabled:function(index, disabled) {
303
+ if(disabled) {
304
+ this.$newElement.find('li').eq(index).addClass('disabled').find('a').attr('href','#').attr('tabindex',-1);
305
+ } else {
306
+ this.$newElement.find('li').eq(index).removeClass('disabled').find('a').removeAttr('href').attr('tabindex',0);
307
+ }
308
+ },
309
+
310
+ isDisabled: function() {
311
+ return this.$element.is(':disabled') || this.$element.attr('readonly');
312
+ },
313
+
314
+ checkDisabled: function() {
315
+ if (this.isDisabled()) {
316
+ this.button.addClass('disabled');
317
+ this.button.click(function(e) {
318
+ e.preventDefault();
319
+ });
320
+ this.button.attr('tabindex','-1');
321
+ } else if (!this.isDisabled() && this.button.hasClass('disabled')) {
322
+ this.button.removeClass('disabled');
323
+ this.button.click(function() {
324
+ return true;
325
+ });
326
+ this.button.removeAttr('tabindex');
327
+ }
328
+ },
329
+
330
+ checkTabIndex: function() {
331
+ if (this.$element.is('[tabindex]')) {
332
+ var tabindex = this.$element.attr("tabindex");
333
+ this.button.attr('tabindex', tabindex);
334
+ }
335
+ },
336
+
337
+ clickListener: function() {
338
+ var _this = this;
339
+
340
+ $('body').on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); });
341
+
342
+ this.$newElement.on('click', 'li a', function(e){
343
+ var clickedIndex = $(this).parent().index(),
344
+ $this = $(this).parent(),
345
+ $select = $this.parents('.bootstrap-select'),
346
+ prevValue = _this.$element.val();
347
+
348
+ //Dont close on multi choice menu
349
+ if(_this.multiple) {
350
+ e.stopPropagation();
351
+ }
352
+
353
+ e.preventDefault();
354
+
355
+ //Dont run if we have been disabled
356
+ if (_this.$element.not(':disabled') && !$(this).parent().hasClass('disabled')){
357
+ //Deselect all others if not multi select box
358
+ if (!_this.multiple) {
359
+ _this.$element.find('option').removeAttr('selected');
360
+ _this.$element.find('option').eq(clickedIndex).prop('selected', true).attr('selected', 'selected');
361
+ }
362
+ //Else toggle the one we have chosen if we are multi select.
363
+ else {
364
+ var selected = _this.$element.find('option').eq(clickedIndex).prop('selected');
365
+
366
+ if(selected) {
367
+ _this.$element.find('option').eq(clickedIndex).removeAttr('selected');
368
+ } else {
369
+ _this.$element.find('option').eq(clickedIndex).prop('selected', true).attr('selected', 'selected');
370
+ }
371
+ }
372
+
373
+
374
+ $select.find('.filter-option').html($this.text());
375
+ $select.find('button').focus();
376
+
377
+ // Trigger select 'change'
378
+ if (prevValue != _this.$element.val()) {
379
+ _this.$element.trigger('change');
380
+ }
381
+
382
+ _this.render();
383
+ }
384
+
385
+ });
386
+
387
+ this.$newElement.on('click', 'li.disabled a, li dt, li .div-contain', function(e) {
388
+ e.preventDefault();
389
+ e.stopPropagation();
390
+ $select = $(this).parent().parents('.bootstrap-select');
391
+ $select.find('button').focus();
392
+ });
393
+
394
+ this.$element.on('change', function(e) {
395
+ _this.render();
396
+ });
397
+ },
398
+
399
+ val:function(value) {
400
+
401
+ if(value!=undefined) {
402
+ this.$element.val( value );
403
+
404
+ this.$element.trigger('change');
405
+ return this.$element;
406
+ } else {
407
+ return this.$element.val();
408
+ }
409
+ },
410
+
411
+ selectAll:function() {
412
+ this.$element.find('option').prop('selected', true).attr('selected', 'selected');
413
+ this.render();
414
+ },
415
+
416
+ deselectAll:function() {
417
+ this.$element.find('option').prop('selected', false).removeAttr('selected');
418
+ this.render();
419
+ },
420
+
421
+ keydown: function (e) {
422
+ var $this,
423
+ $items,
424
+ $parent,
425
+ index,
426
+ next,
427
+ first,
428
+ last,
429
+ prev,
430
+ nextPrev
431
+
432
+ $this = $(this);
433
+
434
+ $parent = $this.parent();
435
+
436
+ $items = $('[role=menu] li:not(.divider):visible a', $parent);
437
+
438
+ if (!$items.length) return;
439
+
440
+ if (/(38|40)/.test(e.keyCode)) {
441
+
442
+ index = $items.index($items.filter(':focus'));
443
+
444
+ first = $items.parent(':not(.disabled)').first().index();
445
+ last = $items.parent(':not(.disabled)').last().index();
446
+ next = $items.eq(index).parent().nextAll(':not(.disabled)').eq(0).index();
447
+ prev = $items.eq(index).parent().prevAll(':not(.disabled)').eq(0).index();
448
+ nextPrev = $items.eq(next).parent().prevAll(':not(.disabled)').eq(0).index();
449
+
450
+ if (e.keyCode == 38) {
451
+ if (index != nextPrev && index > prev) index = prev;
452
+ if (index < first) index = first;
453
+ }
454
+
455
+ if (e.keyCode == 40) {
456
+ if (index != nextPrev && index < next) index = next;
457
+ if (index > last) index = last;
458
+ }
459
+
460
+ $items.eq(index).focus()
461
+ } else {
462
+ var keyCodeMap = {
463
+ 48:"0", 49:"1", 50:"2", 51:"3", 52:"4", 53:"5", 54:"6", 55:"7", 56:"8", 57:"9", 59:";",
464
+ 65:"a", 66:"b", 67:"c", 68:"d", 69:"e", 70:"f", 71:"g", 72:"h", 73:"i", 74:"j", 75:"k", 76:"l",
465
+ 77:"m", 78:"n", 79:"o", 80:"p", 81:"q", 82:"r", 83:"s", 84:"t", 85:"u", 86:"v", 87:"w", 88:"x", 89:"y", 90:"z",
466
+ 96:"0", 97:"1", 98:"2", 99:"3", 100:"4", 101:"5", 102:"6", 103:"7", 104:"8", 105:"9"
467
+ }
468
+
469
+ var keyIndex = [];
470
+
471
+ $items.each(function() {
472
+ if ($(this).parent().is(':not(.disabled)')) {
473
+ if ($.trim($(this).text().toLowerCase()).substring(0,1) == keyCodeMap[e.keyCode]) {
474
+ keyIndex.push($(this).parent().index());
475
+ }
476
+ }
477
+ });
478
+
479
+ var count = $(document).data('keycount');
480
+ count++;
481
+ $(document).data('keycount',count);
482
+
483
+ var prevKey = $.trim($(':focus').text().toLowerCase()).substring(0,1);
484
+
485
+ if (prevKey != keyCodeMap[e.keyCode]) {
486
+ count = 1;
487
+ $(document).data('keycount',count);
488
+ } else if (count >= keyIndex.length) {
489
+ $(document).data('keycount',0);
490
+ }
491
+
492
+ $items.eq(keyIndex[count - 1]).focus();
493
+ }
494
+
495
+ if (/(13)/.test(e.keyCode)) {
496
+ $(':focus').click();
497
+ $parent.addClass('open');
498
+ $(document).data('keycount',0);
499
+ }
500
+ }
501
+ };
502
+
503
+ $.fn.selectpicker = function(option, event) {
504
+ //get the args of the outer function..
505
+ var args = arguments;
506
+ var value;
507
+ var chain = this.each(function () {
508
+ if ($(this).is('select')) {
509
+ var $this = $(this),
510
+ data = $this.data('selectpicker'),
511
+ options = typeof option == 'object' && option;
512
+
513
+ if (!data) {
514
+ $this.data('selectpicker', (data = new Selectpicker(this, options, event)));
515
+ } else if(options){
516
+ for(var i in options) {
517
+ data.options[i]=options[i];
518
+ }
519
+ }
520
+
521
+ if (typeof option == 'string') {
522
+ //Copy the value of option, as once we shift the arguments
523
+ //it also shifts the value of option.
524
+ property = option;
525
+ if(data[property] instanceof Function) {
526
+ [].shift.apply(args);
527
+ value = data[property].apply(data, args);
528
+ } else {
529
+ value = data.options[property];
530
+ }
531
+ }
532
+ }
533
+ });
534
+
535
+ if(value!=undefined) {
536
+ return value;
537
+ } else {
538
+ return chain;
539
+ }
540
+ };
541
+
542
+ $.fn.selectpicker.defaults = {
543
+ style: null,
544
+ size: 'auto',
545
+ title: null,
546
+ selectedTextFormat : 'values',
547
+ noneSelectedText : 'Nothing selected',
548
+ width: null,
549
+ container: false,
550
+ hideDisabled: false
551
+ }
552
+
553
+ $(document)
554
+ .data('keycount',0)
555
+ .on('keydown', '[data-toggle=dropdown], [role=menu]' , Selectpicker.prototype.keydown)
556
+
557
+ }(window.jQuery);
@@ -0,0 +1,178 @@
1
+ .bootstrap-select.btn-group,
2
+ .bootstrap-select.btn-group[class*="span"] {
3
+ float:none;
4
+ display: inline-block;
5
+ margin-bottom: 10px;
6
+ margin-left:0;
7
+ }
8
+
9
+ .bootstrap-select.btn-group.pull-right,
10
+ .bootstrap-select.btn-group[class*="span"].pull-right,
11
+ .row-fluid .bootstrap-select.btn-group[class*="span"].pull-right {
12
+ float:right;
13
+ }
14
+
15
+ .input-append .bootstrap-select.btn-group {
16
+ margin-left: -1px;
17
+ }
18
+
19
+ .input-prepend .bootstrap-select.btn-group {
20
+ margin-right: -1px;
21
+ }
22
+
23
+ .bootstrap-select:not([class*="span"]) {
24
+ width: 220px;
25
+ }
26
+
27
+ .bootstrap-select {
28
+ width: 220px\9; /*IE8 and below*/
29
+ }
30
+
31
+ .bootstrap-select .btn {
32
+ width: 100%;
33
+ }
34
+
35
+ .bootstrap-select.show-menu-arrow.open .btn {
36
+ z-index:1001;
37
+ }
38
+
39
+ .bootstrap-select .btn:focus {
40
+ outline: thin dotted #333333 !important;
41
+ outline: 5px auto -webkit-focus-ring-color !important;
42
+ outline-offset: -2px;
43
+ }
44
+
45
+ .bootstrap-select.btn-group .btn .filter-option {
46
+ overflow:hidden;
47
+ position:absolute;
48
+ left:12px;
49
+ right:25px;
50
+ text-align:left;
51
+ }
52
+
53
+ .bootstrap-select.btn-group .btn .caret {
54
+ position:absolute;
55
+ right:12px;
56
+ }
57
+
58
+ .bootstrap-select.btn-group > .disabled,
59
+ .bootstrap-select.btn-group .dropdown-menu li.disabled > a {
60
+ cursor: not-allowed;
61
+ }
62
+
63
+ .bootstrap-select.btn-group[class*="span"] .btn {
64
+ width:100%;
65
+ }
66
+
67
+ .bootstrap-select.btn-group .dropdown-menu {
68
+ min-width:100%;
69
+ -moz-box-sizing:border-box;
70
+ -webkit-box-sizing:border-box;
71
+ box-sizing:border-box;
72
+ }
73
+
74
+ .bootstrap-select.btn-group .dropdown-menu dt {
75
+ display:block;
76
+ padding:3px 20px;
77
+ cursor:default;
78
+ }
79
+
80
+ .bootstrap-select.btn-group .div-contain {
81
+ overflow:hidden;
82
+ }
83
+
84
+ .bootstrap-select.btn-group .dropdown-menu li > a.opt {
85
+ padding-left:35px;
86
+ }
87
+
88
+ .bootstrap-select.btn-group .dropdown-menu li > a {
89
+ min-height:20px;
90
+ cursor: pointer;
91
+ }
92
+
93
+ .bootstrap-select.btn-group .dropdown-menu li > dt small {
94
+ font-weight:normal;
95
+ }
96
+
97
+ .bootstrap-select.btn-group.show-tick .dropdown-menu li.selected a i.check-mark {
98
+ display:inline-block;
99
+ position: absolute;
100
+ right: 15px;
101
+ margin-top: 2.5px;
102
+ }
103
+
104
+ .bootstrap-select.btn-group .dropdown-menu li a i.check-mark {
105
+ display: none;
106
+ }
107
+
108
+ .bootstrap-select.btn-group.show-tick .dropdown-menu li a span.text {
109
+ margin-right: 34px;
110
+ }
111
+
112
+ .bootstrap-select.btn-group .dropdown-menu li small {
113
+ padding-left:0.5em;
114
+ }
115
+
116
+ .bootstrap-select.btn-group .dropdown-menu li:not(.disabled) > a:hover small,
117
+ .bootstrap-select.btn-group .dropdown-menu li:not(.disabled) > a:focus small {
118
+ color: #64b1d8;
119
+ color:rgba(255,255,255,0.4);
120
+ }
121
+
122
+ .bootstrap-select.btn-group .dropdown-menu li > dt small {
123
+ font-weight:normal;
124
+ }
125
+
126
+ .bootstrap-select.show-menu-arrow .dropdown-toggle:before {
127
+ content: '';
128
+ display: inline-block;
129
+ border-left: 7px solid transparent;
130
+ border-right: 7px solid transparent;
131
+ border-bottom: 7px solid #CCC;
132
+ border-bottom-color: rgba(0, 0, 0, 0.2);
133
+ position: absolute;
134
+ bottom: -4px;
135
+ left: 9px;
136
+ display: none;
137
+ }
138
+
139
+ .bootstrap-select.show-menu-arrow .dropdown-toggle:after {
140
+ content: '';
141
+ display: inline-block;
142
+ border-left: 6px solid transparent;
143
+ border-right: 6px solid transparent;
144
+ border-bottom: 6px solid white;
145
+ position: absolute;
146
+ bottom: -4px;
147
+ left: 10px;
148
+ display: none;
149
+ }
150
+
151
+ .bootstrap-select.show-menu-arrow.dropup .dropdown-toggle:before {
152
+ bottom: auto;
153
+ top: -3px;
154
+ border-top: 7px solid #ccc;
155
+ border-bottom: 0;
156
+ border-top-color: rgba(0, 0, 0, 0.2);
157
+ }
158
+
159
+ .bootstrap-select.show-menu-arrow.dropup .dropdown-toggle:after {
160
+ bottom: auto;
161
+ top: -3px;
162
+ border-top: 6px solid #ffffff;
163
+ border-bottom: 0;
164
+ }
165
+
166
+ .bootstrap-select.show-menu-arrow.pull-right .dropdown-toggle:before {
167
+ right: 12px;
168
+ left: auto;
169
+ }
170
+ .bootstrap-select.show-menu-arrow.pull-right .dropdown-toggle:after {
171
+ right: 13px;
172
+ left: auto;
173
+ }
174
+
175
+ .bootstrap-select.show-menu-arrow.open > .dropdown-toggle:before,
176
+ .bootstrap-select.show-menu-arrow.open > .dropdown-toggle:after {
177
+ display: block;
178
+ }
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap-select-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Maciej Krajowski-Kukiel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-05-24 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ version: "1.3"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :development
44
+ version_requirements: *id002
45
+ description: assets for bootstrap-select
46
+ email:
47
+ - maciej.krajowski@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bootstrap-select-rails.gemspec
61
+ - lib/bootstrap/select/rails.rb
62
+ - lib/bootstrap/select/rails/version.rb
63
+ - vendor/assets/javascripts/bootstrap-select.js
64
+ - vendor/assets/stylesheets/bootstrap-select.css
65
+ has_rdoc: true
66
+ homepage: ""
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib, vendor
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: assets for bootstrap-select
95
+ test_files: []
96
+