selectivity-rails 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4461c4f15d732317f7c29bfe4a3d662145fee35
4
- data.tar.gz: 4381055dc91b1f0d98e308dfe2caa4eaab938acd
3
+ metadata.gz: f193b5755b553f98fc709e5290054ec9f02d6b19
4
+ data.tar.gz: e0df86c48b839a856bce58f13d4a3239416e3032
5
5
  SHA512:
6
- metadata.gz: e867c641b4750b28e8f06ed2ba3bf7ee0b7a3499d8f5fc56d716dbe97989fea3456b7aa930d694b6589bdce00bf49a843a358bd7ddbaffaf5fbdb4c2e46e41d2
7
- data.tar.gz: 4738e0bafd7ce4343c6e8cc64876c85132e0b4a8502e060007e46b6d5337e551ce29ef0ab6de333c9e6ac3dbffe7d1b4f6552ac9b223b2c30da72e68d1508007
6
+ metadata.gz: 5b70b0fe542ad62b62bc52c13004bce87aecb11c7fa15f572667c49b81f2ce2479b3f7559953730b2ce3bf8a4ef365c77bda5cb0f258eeb7fefc644b4f772ec1
7
+ data.tar.gz: 568502d3cb475107c5c3d2d04fb7e0656c6a27a326eb21a07f5a4b312e8e2e537bd7c83917a0d3c515ff1ffc3923ff2589b17b5ffb54f77f3d318f6526162f9a
data/README.md CHANGED
@@ -108,11 +108,13 @@ selectivity_select('Poland', from: '#country')
108
108
  To handle multiple select:
109
109
 
110
110
  ```ruby
111
- selectivity_select('Netherlands', 'Russia', from: '#countries')
111
+ selectivity_select('Netherlands', 'Russia', 'Spain', from: '#countries')
112
112
  # or, by single value:
113
- selectivity_select('Russia', from: '#countries')
113
+ selectivity_select('Poland', from: '#countries')
114
114
 
115
- selectivity_unselect('Russia', from: '#countries')
115
+ selectivity_unselect('Russia', 'Spain', from: '#countries')
116
+ # or, by single value:
117
+ selectivity_unselect('Netherlands', from: '#countries')
116
118
  ```
117
119
 
118
120
  ## Demos and examples
@@ -1,5 +1,5 @@
1
1
  module Selectivity
2
2
  module Rails
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.9'
4
4
  end
5
5
  end
@@ -2964,6 +2964,9 @@ var KEY_UP_ARROW = 38;
2964
2964
  */
2965
2965
  function listener(selectivity, $input) {
2966
2966
 
2967
+ var keydownCanceled = false;
2968
+ var closeSubmenu = null;
2969
+
2967
2970
  /**
2968
2971
  * Moves a dropdown's highlight to the next or previous result item.
2969
2972
  *
@@ -3037,7 +3040,20 @@ function listener(selectivity, $input) {
3037
3040
 
3038
3041
  var dropdown = selectivity.dropdown;
3039
3042
  if (dropdown) {
3040
- if (event.keyCode === KEY_DOWN_ARROW) {
3043
+ if (event.keyCode === KEY_BACKSPACE) {
3044
+ if (!$input.val()) {
3045
+ if (dropdown.submenu) {
3046
+ var submenu = dropdown.submenu;
3047
+ while (submenu.submenu) {
3048
+ submenu = submenu.submenu;
3049
+ }
3050
+ closeSubmenu = submenu;
3051
+ }
3052
+
3053
+ event.preventDefault();
3054
+ keydownCanceled = true;
3055
+ }
3056
+ } else if (event.keyCode === KEY_DOWN_ARROW) {
3041
3057
  moveHighlight(dropdown, 1);
3042
3058
  } else if (event.keyCode === KEY_UP_ARROW) {
3043
3059
  moveHighlight(dropdown, -1);
@@ -3058,18 +3074,13 @@ function listener(selectivity, $input) {
3058
3074
  }
3059
3075
 
3060
3076
  var dropdown = selectivity.dropdown;
3061
- if (event.keyCode === KEY_BACKSPACE) {
3062
- if (!$input.val()) {
3063
- if (dropdown && dropdown.submenu) {
3064
- var submenu = dropdown.submenu;
3065
- while (submenu.submenu) {
3066
- submenu = submenu.submenu;
3067
- }
3068
- submenu.close();
3069
- selectivity.focus();
3070
- }
3077
+ if (keydownCanceled) {
3078
+ event.preventDefault();
3079
+ keydownCanceled = false;
3071
3080
 
3072
- event.preventDefault();
3081
+ if (closeSubmenu) {
3082
+ closeSubmenu.close();
3083
+ closeSubmenu = null;
3073
3084
  }
3074
3085
  } else if (event.keyCode === KEY_ENTER && !event.ctrlKey) {
3075
3086
  if (dropdown) {
@@ -4283,11 +4294,11 @@ Selectivity.Templates = {
4283
4294
  return (
4284
4295
  '<span class="selectivity-multiple-selected-item' + extraClass + '" ' +
4285
4296
  'data-item-id="' + escape(options.id) + '">' +
4286
- escape(options.text) +
4287
4297
  (options.removable ? '<a class="selectivity-multiple-selected-item-remove">' +
4288
4298
  '<i class="fa fa-remove"></i>' +
4289
4299
  '</a>'
4290
4300
  : '') +
4301
+ escape(options.text) +
4291
4302
  '</span>'
4292
4303
  );
4293
4304
  },
@@ -4420,8 +4431,8 @@ Selectivity.Templates = {
4420
4431
  * mode - Mode in which select exists, single or multiple.
4421
4432
  */
4422
4433
  selectCompliance: function(options) {
4423
- if (options.mode === 'multiple' && !options.name.match(/\[\]$/)) {
4424
- options.name = options.name + '[]';
4434
+ if (options.mode === 'multiple' && options.name.slice(-2) !== '[]') {
4435
+ options.name += '[]';
4425
4436
  }
4426
4437
  return ('<select name="' + options.name + '"' + (options.mode === 'multiple' ? ' multiple' : '') + '></select>');
4427
4438
  },
@@ -4519,23 +4530,25 @@ var Selectivity = _dereq_(7);
4519
4530
 
4520
4531
  function replaceSelectElement($el, options) {
4521
4532
 
4522
- var value = (options.multiple ? [] : null);
4533
+ var data = (options.multiple ? [] : null);
4523
4534
 
4524
4535
  var mapOptions = function() {
4525
4536
  var $this = $(this);
4526
4537
  if ($this.is('option')) {
4527
- var id = $this.attr('value') || $this.text();
4538
+ var text = $this.text();
4539
+ var id = $this.attr('value') || text;
4528
4540
  if ($this.prop('selected')) {
4541
+ var item = { id: id, text: text };
4529
4542
  if (options.multiple) {
4530
- value.push(id);
4543
+ data.push(item);
4531
4544
  } else {
4532
- value = id;
4545
+ data = item;
4533
4546
  }
4534
4547
  }
4535
4548
 
4536
4549
  return {
4537
4550
  id: id,
4538
- text: $this.attr('label') || $this.text()
4551
+ text: $this.attr('label') || text
4539
4552
  };
4540
4553
  } else {
4541
4554
  return {
@@ -4547,11 +4560,12 @@ function replaceSelectElement($el, options) {
4547
4560
 
4548
4561
  options.allowClear = ('allowClear' in options ? options.allowClear : !$el.prop('required'));
4549
4562
 
4550
- options.items = $el.children('option,optgroup').map(mapOptions).get();
4563
+ var items = $el.children('option,optgroup').map(mapOptions).get();
4564
+ options.items = (options.query ? null : items);
4551
4565
 
4552
4566
  options.placeholder = options.placeholder || $el.data('placeholder') || '';
4553
4567
 
4554
- options.value = value;
4568
+ options.data = data;
4555
4569
 
4556
4570
  var classes = ($el.attr('class') || 'selectivity-input').split(' ');
4557
4571
  if (classes.indexOf('selectivity-input') === -1) {
@@ -47,7 +47,7 @@ input[type='text'].selectivity-multiple-input
47
47
  float: left
48
48
  line-height: 2em
49
49
  margin: 2px
50
- padding-left: 5px
50
+ padding-right: 5px
51
51
  position: relative
52
52
  -moz-user-select: none
53
53
  -ms-user-select: none
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selectivity-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konrad Jurkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-18 00:00:00.000000000 Z
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler