uber_select_rails 0.3.0 → 0.4.4

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
  SHA256:
3
- metadata.gz: 41f2e1a1877958978c0a5577a899c31130a2a77e6392e5aa05b61286e5cfa4df
4
- data.tar.gz: ed725ab8f9ab6d676c77c340cec323ee6082c539500fffe02611694e0de05c5e
3
+ metadata.gz: f2d36958541100b720bfbe57c1254bcb97cf73c5a0adf9cadac4d6144befabf2
4
+ data.tar.gz: 198a50727d3c91b584c5abbd33bcb415c06d02acd82c45854526f7b8cde17b47
5
5
  SHA512:
6
- metadata.gz: 0dab72aac31c287920ea7ce4d75c3919c9a27d5954efc537fd609f6f87d3f9841bf55a5c083ff48f1af66c62135fe221dc1f9e8679ab87e247b08e9ab6256016
7
- data.tar.gz: b633f6e04dd022376cf002ace1752ec08e84821255717ac85365372521cef766b0cd8b7750207b0eb683fa79360a70f02308c09e5768aea70aa653d17f42c50b
6
+ metadata.gz: c73c8c86106767c26c2fc32afac1d46c57dc78ff1d0014c4ca4d4866be8277c745a003d4c77e678b0b41d3f92964848b7e13533e95e3fe010e0df0cfc0dd5716
7
+ data.tar.gz: 88e29bddfd24bde521540c0040742982acecd1da4116ba1b3bc5a8a9da9703aecad82424a4af86c28565736bfd2e177e68abb9be1ee191180bcf6833736222e8
@@ -1,3 +1,3 @@
1
1
  module UberSelectRails
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.4"
3
3
  end
data/uber_select.gemspec CHANGED
@@ -3,6 +3,8 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'uber_select_rails/version'
5
5
 
6
+ `git submodule update` # Ensure we've checked the correct submodule files
7
+
6
8
  Gem::Specification.new do |spec|
7
9
  spec.name = "uber_select_rails"
8
10
  spec.version = UberSelectRails::VERSION
@@ -21,6 +21,10 @@ you can use UberSelect to gussy up forms, without changing any of the underlying
21
21
  $('.my_selects').uberSelect(options);
22
22
  ```
23
23
 
24
+ #### Attributes <a name="UberSearch attributes"></a>
25
+ Attribtes on the outermost element can be specified by setting the `data-uber-attributes` attribute on the `<select>` element. Values should be passed
26
+ as a JSON string of key/value pairs where the key is the attribute name and the value is the attribute value.
27
+
24
28
  #### Options
25
29
  Options can be specified by setting the `data-uber-options` attribute on the `<select>` element. Values should be passed
26
30
  as a JSON string. All options on the are passed to the underlying UberSearch, see [UberSearch options](#UberSearchOptions).
@@ -97,6 +101,9 @@ Data is an array of objects. Each object may have the following properties:
97
101
  - ##### selectedText
98
102
  String shown to the user in the output container when this option is selected. *optional*
99
103
 
104
+ - ##### title
105
+ Title text shown to the user when hovering over the result. *optional*
106
+
100
107
  - ##### value
101
108
  This is matched against the *value* option passed UberSearch and will appear selected if it matches. It is also used to match against search input text when the user searches. This value is required if *text* is not provided.
102
109
 
@@ -20,7 +20,7 @@
20
20
  optionFromDatum: optionFromDatum, // A function to create select options
21
21
  value: $(select).val() // Initialize the UberSearch with this selected value
22
22
  }, opts, $(select).data('uber-options'))
23
-
23
+ var uberAttributes = $(select).data('uber-attributes'); // Attributes defined as data-uber-attributes on the original select element. These will be added as attributes on the uberSelect element.
24
24
  var uberSearch = this.uberSearch = new UberSearch(dataFromSelect(select), options)
25
25
 
26
26
 
@@ -53,11 +53,16 @@
53
53
 
54
54
  // INITIALIZATION
55
55
 
56
+ if (uberAttributes) {
57
+ uberSearch.view.attr(uberAttributes)
58
+ }
59
+
56
60
  uberSearch.view.insertBefore(select).append(select)
57
61
  hideSelect()
58
62
  if (options.dataUrl) {
59
63
  $.getJSON(options.dataUrl).done(function(data){
60
64
  $(select).append(optionsFromData(data))
65
+ updateSelectValue(options.value)
61
66
  uberSearch.setData(dataFromSelect(select))
62
67
  $(select).trigger(eventsTriggered.ready)
63
68
  })
@@ -81,7 +86,8 @@
81
86
  text: option.textContent,
82
87
  selectedText: getAttribute(option, 'data-selected-text'),
83
88
  value: getAttribute(option, 'value'),
84
- disabled: getAttribute(option, 'disabled'),
89
+ title: getAttribute(option, 'title'),
90
+ disabled: getAttribute(option, 'disabled') === undefined ? false : true,
85
91
  matchValue: getAttribute(option, 'data-match-value'),
86
92
  visibility: getAttribute(option, 'data-visibility'),
87
93
  element: option
@@ -135,7 +141,7 @@
135
141
  function refreshOptionsList(){
136
142
  uberSearch.setDisabled($(select).is(':disabled'))
137
143
  uberSearch.setData(dataFromSelect(select))
138
- updateSelectedValue()
144
+ updateSelectValue($(select).find('option[selected]').attr('value')) // Read the value of the option that is selected because the <select> element's value is defunct now that we've updated the <option> elements
139
145
  }
140
146
 
141
147
  // Updates the UberSearch's selected value from the select element's value
@@ -144,7 +150,9 @@
144
150
  }
145
151
 
146
152
  function updateSelectValue(value){
147
- $(select).val(value).trigger('change')
153
+ var before = $(select).val()
154
+ $(select).val(value)
155
+ if (before != value) { $(select).trigger('change') } // Only trigger a change if the value has actually changed
148
156
  }
149
157
 
150
158
  // Selects the option with an emptystring value, or the first option if there is no blank option
@@ -243,6 +243,7 @@ var UberSearch = function(data, options){
243
243
  .html((options.treatBlankOptionAsPlaceholder ? datum.text || options.placeholder : datum.text) || "&nbsp;")
244
244
  .data(datum) // Store the datum so we can get know what the value of the selected item is
245
245
 
246
+ if (datum.title) { result.attr('title', datum.title) }
246
247
  if (datum.disabled) { result.addClass('disabled') }
247
248
 
248
249
  options.resultPostprocessor(result, datum)
@@ -215,6 +215,22 @@
215
215
  <p>This example has an option with <code>data-selected-text</code> that should show custom text in the output container when selected.</p>
216
216
  </span>
217
217
 
218
+ <span class="example">
219
+ <label for="select">
220
+ Title Attribute
221
+ </label>
222
+ <select>
223
+ <option></option>
224
+ <option>Jimmy Johnson</option>
225
+ <option title="Cooltip!">Option with Title</option>
226
+ <option>Cosmo Kramer</option>
227
+ <option>Bob Zickowski</option>
228
+ <option>Nicholas Cage</option>
229
+ <option>Queen Latifah</option>
230
+ </select>
231
+ <p>This example has an option with a <code>title</code> attribute that should show as a tooltip.</p>
232
+ </span>
233
+
218
234
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
219
235
  <script src="javascript/string_extensions.js"></script>
220
236
  <script src="javascript/search_field.js"></script>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber_select_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2021-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
- description:
55
+ description:
56
56
  email:
57
57
  - nicholas.jakobsen@gmail.com
58
58
  executables: []
@@ -84,7 +84,7 @@ files:
84
84
  homepage: https://github.com/culturecode/uber_select_rails
85
85
  licenses: []
86
86
  metadata: {}
87
- post_install_message:
87
+ post_install_message:
88
88
  rdoc_options: []
89
89
  require_paths:
90
90
  - lib
@@ -99,8 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.0.3
103
- signing_key:
102
+ rubygems_version: 3.0.8
103
+ signing_key:
104
104
  specification_version: 4
105
105
  summary: A Rails gem containing a javascript plugin that adds a layer of UI goodness
106
106
  overtop of basic HTML select elements