uber_select_rails 0.1.8 → 0.4.1

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: 2c33585944dd942302f745e6ffdcff2406dd755568ead6ecb195df26fc8abfb2
4
- data.tar.gz: f311a4e680d52a839a6fcb2ef3fe4ab28d16ff6f355c15af6383e6eb3d6c81db
3
+ metadata.gz: 8c03ef32585a000f449ad3851d5a90da08a0ec646c3bae0fddb335c67522062d
4
+ data.tar.gz: 36c973de206ac86363ceed385a516b2f0cc3ba396e3723501d23e984b666910c
5
5
  SHA512:
6
- metadata.gz: 462aed1760ab381a3ef0277301b6540c5127fe2c7eca293816288ac8674f44d372346bb05ad3a723ee0bbd7c2e7038d2ef01b286b26795bf7246b5978b505109
7
- data.tar.gz: 6beab32309f9d49e26f572eff928002040d053c1ca9d1f49a740597af39c5a1f0da0fc07c5d2b9afcfcd306c1714f328266f99d0b08b03e77f1f858218430f03
6
+ metadata.gz: 7701b85c337519d3694ddde32fe59bf779ca762bbd874b6cb34363d9ab8194bae46e922c866928eced917179eadfc524485337609e6be19d2d9e40e1af7ff464
7
+ data.tar.gz: 6edaa218f7e0e43bcf72959fd24bd0577c890704e156b61e6618cca6ed4b4121b5b272490d1ce147e4a12bd540c80b77efce8d6f1e8546950bb965cdd1c5d7f5
@@ -1,3 +1,3 @@
1
1
  module UberSelectRails
2
- VERSION = "0.1.8"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -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).
@@ -94,6 +98,12 @@ Data is an array of objects. Each object may have the following properties:
94
98
  - ##### text
95
99
  String shown to the user in the list of results. This value is required if *value* is not provided.
96
100
 
101
+ - ##### selectedText
102
+ String shown to the user in the output container when this option is selected. *optional*
103
+
104
+ - ##### title
105
+ Title text shown to the user when hovering over the result. *optional*
106
+
97
107
  - ##### value
98
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.
99
109
 
@@ -103,9 +113,17 @@ Data is an array of objects. Each object may have the following properties:
103
113
  - ##### visibility
104
114
  This is used to determine whether the option appears only when searching or only when not searching. Values accepted: `query`, `no-query`. *optional*
105
115
 
116
+ - ##### disabled
117
+ This is used to determine whether the option appears disabled. *optional*
118
+
106
119
  - ##### group
107
120
  This is used to visually group options. All options with the same group will appear together. *optional*
108
121
 
122
+ #### Methods
123
+
124
+ - ##### setData(data)
125
+ Sets the data. `data` should be an Array conforming to the specifications described in <a href="#data">Data</a>
126
+
109
127
 
110
128
  #### Options <a name="UberSearch options"></a>
111
129
  Options can be specified by setting the `data-uber-options` attribute on the `<select>` element. Values should be passed
@@ -14,12 +14,13 @@
14
14
  var options = $.extend({
15
15
  prepopulateSearchOnOpen: false, // Should the search input start with the selected value in it when the pane is opened?
16
16
  clearSearchClearsSelect: false, // Should the select value be cleared When the search is cleared?
17
+ disabled: $(select).is(':disabled'), // Whether the select is currently disabled
17
18
  placeholder: $(select).attr('placeholder') || $(select).attr('data-placeholder'), // Placeholder to show in the selected text area
18
19
  dataUrl: null, // A url to pre-fetch select options from, see optionsFromData for data format
19
20
  optionFromDatum: optionFromDatum, // A function to create select options
20
21
  value: $(select).val() // Initialize the UberSearch with this selected value
21
22
  }, opts, $(select).data('uber-options'))
22
-
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.
23
24
  var uberSearch = this.uberSearch = new UberSearch(dataFromSelect(select), options)
24
25
 
25
26
 
@@ -52,6 +53,10 @@
52
53
 
53
54
  // INITIALIZATION
54
55
 
56
+ if (uberAttributes) {
57
+ uberSearch.view.attr(uberAttributes)
58
+ }
59
+
55
60
  uberSearch.view.insertBefore(select).append(select)
56
61
  hideSelect()
57
62
  if (options.dataUrl) {
@@ -78,7 +83,10 @@
78
83
  // This is optimized for performance and does not use jQuery convenience methods. Seems to be about 30% faster loading during non-scientific tests.
79
84
  datum = {
80
85
  text: option.textContent,
86
+ selectedText: getAttribute(option, 'data-selected-text'),
81
87
  value: getAttribute(option, 'value'),
88
+ title: getAttribute(option, 'title'),
89
+ disabled: getAttribute(option, 'disabled'),
82
90
  matchValue: getAttribute(option, 'data-match-value'),
83
91
  visibility: getAttribute(option, 'data-visibility'),
84
92
  element: option
@@ -130,6 +138,7 @@
130
138
  }
131
139
 
132
140
  function refreshOptionsList(){
141
+ uberSearch.setDisabled($(select).is(':disabled'))
133
142
  uberSearch.setData(dataFromSelect(select))
134
143
  updateSelectedValue()
135
144
  }
@@ -26,7 +26,7 @@ function List(options) {
26
26
  })
27
27
 
28
28
  // When a list item is hovered
29
- $(view).on('mouseenter', '.result', function(){
29
+ $(view).on('mouseenter', '.result:not(.disabled)', function(){
30
30
  unhighlightResults()
31
31
  highlightResult(this, {scroll: false})
32
32
  })
@@ -57,8 +57,8 @@ function List(options) {
57
57
  this.highlightResult = highlightResult
58
58
 
59
59
  function stepHighlight(amount, allowUnhighlight){
60
- var index = visibleResults().index(highlightedResult())
61
- var result = visibleResults()[index + amount]
60
+ var index = selectableResults().index(highlightedResult())
61
+ var result = selectableResults()[index + amount]
62
62
 
63
63
  if (result || allowUnhighlight){
64
64
  unhighlightResults()
@@ -66,19 +66,16 @@ function List(options) {
66
66
  }
67
67
  }
68
68
 
69
- function highlightResult(result, options){
69
+ function highlightResult(result, options) {
70
70
  result = $(result)
71
71
  options = $.extend({scroll: true}, options)
72
72
 
73
73
  if (!result.length) { return }
74
74
 
75
- var visibleResult = visibleResults().filter(result)
76
- if (visibleResult.length) {
77
- visibleResult.addClass('highlighted')
75
+ result.addClass('highlighted')
78
76
 
79
- if (options.scroll){
80
- scrollResultIntoView(visibleResult)
81
- }
77
+ if (options.scroll){
78
+ scrollResultIntoView(result)
82
79
  }
83
80
  }
84
81
 
@@ -90,6 +87,10 @@ function List(options) {
90
87
  return results().filter('.highlighted')
91
88
  }
92
89
 
90
+ function selectableResults(){
91
+ return visibleResults().not('.disabled')
92
+ }
93
+
93
94
  function visibleResults(){
94
95
  return results().not('.hidden')
95
96
  }
@@ -15,7 +15,11 @@ var OutputContainer = function(options){
15
15
  view.toggleClass('empty', !value)
16
16
  }
17
17
 
18
+ function setDisabled(boolean) {
19
+ view.toggleClass('disabled', boolean)
20
+ }
21
+
18
22
  // PUBLIC INTERFACE
19
23
 
20
- $.extend(this, {view: view, setValue: setValue})
24
+ $.extend(this, {view: view, setValue: setValue, setDisabled: setDisabled})
21
25
  }
@@ -20,11 +20,15 @@ function Pane(options){
20
20
  if (options.trigger){
21
21
  // Show the pane when the select element is clicked
22
22
  $(options.trigger).on('click', function(event){
23
+ if ($(options.trigger).hasClass('disabled')) { return }
24
+
23
25
  context.show()
24
26
  })
25
27
 
26
28
  // Show the pane if the user was tabbed onto the trigger and pressed enter or space
27
29
  $(options.trigger).on('keyup', function(event){
30
+ if ($(options.trigger).hasClass('disabled')) { return }
31
+
28
32
  if (event.which == 13 || event.which == 32){
29
33
  context.show()
30
34
  return false
@@ -8,7 +8,8 @@ var UberSearch = function(data, options){
8
8
 
9
9
  options = $.extend({
10
10
  value: null, // Initialize with this selectedValue
11
- search:true, // Show the search input
11
+ disabled: false, // Initialize with this disabled value
12
+ search: true, // Show the search input
12
13
  clearSearchButton:'&#x2715;', // Text content of clear search button
13
14
  selectCaret: '&#x2304;', // Text content of select caret
14
15
  hideBlankOption: false, // Should blank options be hidden automatically?
@@ -87,7 +88,7 @@ var UberSearch = function(data, options){
87
88
  })
88
89
 
89
90
  // When a search result is chosen
90
- resultsContainer.on('click', '.result', function(event){
91
+ resultsContainer.on('click', '.result:not(.disabled)', function(event){
91
92
  var datum = $(this).data()
92
93
 
93
94
  if (options.onSelect(datum, this, event) === false) {
@@ -113,6 +114,7 @@ var UberSearch = function(data, options){
113
114
 
114
115
  // INITIALIZATION
115
116
 
117
+ setDisabled(options.disabled)
116
118
  setData(data)
117
119
 
118
120
  if (options.search){
@@ -150,6 +152,11 @@ var UberSearch = function(data, options){
150
152
  markSelected()
151
153
  }
152
154
 
155
+ // Enables or disables UberSearch
156
+ function setDisabled(boolean){
157
+ outputContainer.setDisabled(boolean)
158
+ }
159
+
153
160
  // Updates the enhanced select with the text of the selected result
154
161
  function setSelectedText(text){
155
162
  if (text) {
@@ -236,6 +243,9 @@ var UberSearch = function(data, options){
236
243
  .html((options.treatBlankOptionAsPlaceholder ? datum.text || options.placeholder : datum.text) || "&nbsp;")
237
244
  .data(datum) // Store the datum so we can get know what the value of the selected item is
238
245
 
246
+ if (datum.title) { result.attr('title', datum.title) }
247
+ if (datum.disabled) { result.addClass('disabled') }
248
+
239
249
  options.resultPostprocessor(result, datum)
240
250
 
241
251
  return result
@@ -253,7 +263,7 @@ var UberSearch = function(data, options){
253
263
  if (selected) {
254
264
  search.highlightResult(selected)
255
265
  } else if (options.highlightByDefault) {
256
- search.highlightResult(results.not('.hidden').first())
266
+ search.highlightResult(results.not('.hidden').not('.disabled').first())
257
267
  }
258
268
  }
259
269
 
@@ -279,7 +289,11 @@ var UberSearch = function(data, options){
279
289
  }
280
290
 
281
291
  function textFromValue(value){
282
- return $.map(data, function(datum){ if (datum.value == value) return datum.text })[0]
292
+ return $.map(data, function(datum) {
293
+ if (datum.value == value) {
294
+ return datum.selectedText || datum.text
295
+ }
296
+ })[0]
283
297
  }
284
298
 
285
299
  function updateMessages(){
@@ -311,5 +325,5 @@ var UberSearch = function(data, options){
311
325
 
312
326
  // PUBLIC INTERFACE
313
327
 
314
- $.extend(this, {view:view, searchField:searchField, setValue:setValue, setData:setData, options:options})
328
+ $.extend(this, {view:view, searchField:searchField, setValue:setValue, setData:setData, setDisabled:setDisabled, options:options})
315
329
  }
@@ -39,6 +39,10 @@ label {
39
39
  text-overflow: ellipsis;
40
40
  position: relative; /* Contain caret */
41
41
  }
42
+ .uber_select .selected_text_container.disabled{
43
+ cursor: default;
44
+ opacity: 0.5;
45
+ }
42
46
  .uber_select .selected_text.empty{
43
47
  color: #aaa;
44
48
  }
@@ -103,6 +107,10 @@ label {
103
107
  overflow: hidden;
104
108
  text-overflow: ellipsis;
105
109
  }
110
+ .uber_select .result.disabled{
111
+ cursor: default;
112
+ opacity: 0.5;
113
+ }
106
114
  .uber_select .result.selected{
107
115
  font-weight: bold;
108
116
  }
@@ -167,6 +167,70 @@
167
167
  </p>
168
168
  </span>
169
169
 
170
+ <span class="example">
171
+ <label for="select">
172
+ Disabled Options
173
+ </label>
174
+ <select>
175
+ <option></option>
176
+ <option>Jimmy Johnson</option>
177
+ <option>Amanda Hugginkiss</option>
178
+ <option disabled="disabled">Cosmo Kramer</option>
179
+ <option>Bob Zickowski</option>
180
+ <option>Nicholas Cage</option>
181
+ <option>Queen Latifah</option>
182
+ </select>
183
+ <p>This example has a disabled option that should not highlight or be selectable.</p>
184
+ </span>
185
+
186
+ <span class="example">
187
+ <label for="select">
188
+ Disabled Select
189
+ </label>
190
+ <select disabled="disabled">
191
+ <option></option>
192
+ <option>Jimmy Johnson</option>
193
+ <option>Amanda Hugginkiss</option>
194
+ <option>Cosmo Kramer</option>
195
+ <option>Bob Zickowski</option>
196
+ <option>Nicholas Cage</option>
197
+ <option>Queen Latifah</option>
198
+ </select>
199
+ <p>This example has a disabled select that should disable the entire UI.</p>
200
+ </span>
201
+
202
+ <span class="example">
203
+ <label for="select">
204
+ Selected Text
205
+ </label>
206
+ <select>
207
+ <option></option>
208
+ <option>Jimmy Johnson</option>
209
+ <option data-selected-text="Good Choice!">Custom Selected Text</option>
210
+ <option>Cosmo Kramer</option>
211
+ <option>Bob Zickowski</option>
212
+ <option>Nicholas Cage</option>
213
+ <option>Queen Latifah</option>
214
+ </select>
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
+ </span>
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
+
170
234
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
171
235
  <script src="javascript/string_extensions.js"></script>
172
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.1.8
4
+ version: 0.4.1
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: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2020-09-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,9 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.7.9
104
- signing_key:
102
+ rubygems_version: 3.0.8
103
+ signing_key:
105
104
  specification_version: 4
106
105
  summary: A Rails gem containing a javascript plugin that adds a layer of UI goodness
107
106
  overtop of basic HTML select elements