uber_select_rails 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c33585944dd942302f745e6ffdcff2406dd755568ead6ecb195df26fc8abfb2
4
- data.tar.gz: f311a4e680d52a839a6fcb2ef3fe4ab28d16ff6f355c15af6383e6eb3d6c81db
3
+ metadata.gz: 10c18743a0a4f7aa8ea982825a50907aeb75235437411bbafa9e1516ccaca952
4
+ data.tar.gz: 6886d3f7ea294125db58af7f8c810ab67dff4f4ec70f0507843c2b0580cf4308
5
5
  SHA512:
6
- metadata.gz: 462aed1760ab381a3ef0277301b6540c5127fe2c7eca293816288ac8674f44d372346bb05ad3a723ee0bbd7c2e7038d2ef01b286b26795bf7246b5978b505109
7
- data.tar.gz: 6beab32309f9d49e26f572eff928002040d053c1ca9d1f49a740597af39c5a1f0da0fc07c5d2b9afcfcd306c1714f328266f99d0b08b03e77f1f858218430f03
6
+ metadata.gz: 6b10307638757804884a9eee2b749da3dd661388b7f32abae304817952810794214b5403edb7d8a502ec706a84df34c1a96c088162cfe59b87af70fd327d4059
7
+ data.tar.gz: fd2484075d5a73cff0e80e704c939ea06195fc4bb15a78a6281983425c073400928b7d2e4d40f7e648fac1680e2ceaf71fb224e14507584385b4d130c3d5d586
@@ -1,3 +1,3 @@
1
1
  module UberSelectRails
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -106,6 +106,11 @@ Data is an array of objects. Each object may have the following properties:
106
106
  - ##### group
107
107
  This is used to visually group options. All options with the same group will appear together. *optional*
108
108
 
109
+ #### Methods
110
+
111
+ - ##### setData(data)
112
+ Sets the data. `data` should be an Array conforming to the specifications described in <a href="#data">Data</a>
113
+
109
114
 
110
115
  #### Options <a name="UberSearch options"></a>
111
116
  Options can be specified by setting the `data-uber-options` attribute on the `<select>` element. Values should be passed
@@ -14,6 +14,7 @@
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
@@ -79,6 +80,7 @@
79
80
  datum = {
80
81
  text: option.textContent,
81
82
  value: getAttribute(option, 'value'),
83
+ disabled: getAttribute(option, 'disabled'),
82
84
  matchValue: getAttribute(option, 'data-match-value'),
83
85
  visibility: getAttribute(option, 'data-visibility'),
84
86
  element: option
@@ -130,6 +132,7 @@
130
132
  }
131
133
 
132
134
  function refreshOptionsList(){
135
+ uberSearch.setDisabled($(select).is(':disabled'))
133
136
  uberSearch.setData(dataFromSelect(select))
134
137
  updateSelectedValue()
135
138
  }
@@ -66,18 +66,18 @@ 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
+ var enabledResult = enabledResults().filter(result)
76
+ if (enabledResult.length) {
77
+ enabledResult.addClass('highlighted')
78
78
 
79
79
  if (options.scroll){
80
- scrollResultIntoView(visibleResult)
80
+ scrollResultIntoView(enabledResult)
81
81
  }
82
82
  }
83
83
  }
@@ -90,6 +90,10 @@ function List(options) {
90
90
  return results().filter('.highlighted')
91
91
  }
92
92
 
93
+ function enabledResults(){
94
+ return visibleResults().not('.disabled')
95
+ }
96
+
93
97
  function visibleResults(){
94
98
  return results().not('.hidden')
95
99
  }
@@ -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,8 @@ 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.disabled) { result.addClass('disabled') }
247
+
239
248
  options.resultPostprocessor(result, datum)
240
249
 
241
250
  return result
@@ -311,5 +320,5 @@ var UberSearch = function(data, options){
311
320
 
312
321
  // PUBLIC INTERFACE
313
322
 
314
- $.extend(this, {view:view, searchField:searchField, setValue:setValue, setData:setData, options:options})
323
+ $.extend(this, {view:view, searchField:searchField, setValue:setValue, setData:setData, setDisabled:setDisabled, options:options})
315
324
  }
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -99,8 +99,7 @@ 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
102
+ rubygems_version: 3.0.3
104
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