effective_form_inputs 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/effective_panel_select/effective_panel_select.js.coffee +78 -13
- data/app/assets/stylesheets/effective_panel_select/input.scss +24 -0
- data/app/models/inputs/effective_panel_select/input.rb +5 -1
- data/app/views/effective/effective_panel_select/_input.html.haml +12 -10
- data/lib/effective_form_inputs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab1e879c3269d732932f02ddaf6001ef659e3872
|
4
|
+
data.tar.gz: 1baa2b3f41124384e55489e57b478a1b651e660a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815fdf0e52cdaf868ea11a6d14802e4bfd4337c90a9b2ad240bb6edf18d95d2883355874cd483d8a65d74925b1209ac7129d6085453cc6f6b8193b93532cb888
|
7
|
+
data.tar.gz: 1f142dbf0c2801b05e50db14b2bb582991e847e823b5cb62b3c5e397cda2512da7b7776121468c7cf159e048c759b7694d23b1780e07a7615a036e6348a7fe45
|
@@ -7,7 +7,8 @@
|
|
7
7
|
invade: '.row'
|
8
8
|
collapseOnSelect: true
|
9
9
|
resetOnCollapse: true
|
10
|
-
keepFetched: false # Keep any fetched ajax pages in the dom. Otherwise they're
|
10
|
+
keepFetched: false # Keep any fetched ajax pages in the dom. Otherwise they're removed on reset()
|
11
|
+
showSearch: true
|
11
12
|
ajax:
|
12
13
|
url: '' # /exercises/:id The string ':id' will be replaced with the viewed item value
|
13
14
|
target: '' # #container The string to pass to load
|
@@ -23,6 +24,8 @@
|
|
23
24
|
@input = @panel.find("input[type='hidden']")
|
24
25
|
@label = @panel.find('.selection-title')
|
25
26
|
@selector = @panel.children('.selector')
|
27
|
+
@searchVal = @panel.children('.search').find('.search-value')
|
28
|
+
@searchResults = @panel.children('.search').find('.search-results')
|
26
29
|
@tabList = @selector.find('ul.nav').first()
|
27
30
|
@tabContent = @selector.find('.tab-content').first()
|
28
31
|
|
@@ -32,6 +35,7 @@
|
|
32
35
|
@initEvents()
|
33
36
|
@initInvade()
|
34
37
|
@initAjax()
|
38
|
+
@reset()
|
35
39
|
true
|
36
40
|
|
37
41
|
# So we need to assign unique IDs to all the group tabs so we can have multiple selectors per page
|
@@ -51,12 +55,14 @@
|
|
51
55
|
tab.attr('id', href.substring(1))
|
52
56
|
|
53
57
|
initEvents: ->
|
54
|
-
@panel.on 'click', '.selection', (event) => @toggle()
|
58
|
+
@panel.on 'click', '.selection', (event) => @toggle() and true
|
55
59
|
@panel.on 'click', '.selection-clear', (event) => @clear() and false
|
56
60
|
@panel.on 'click', '[data-item-value]', (event) => @val($(event.currentTarget).data('item-value')) and false
|
57
61
|
@panel.on 'click', '[data-fetch-item]', (event) => @fetch($(event.currentTarget).closest('[data-item-value]').data('item-value')) and false
|
58
62
|
@panel.on 'click', '.fetched-clear', (event) => @reset() and false
|
59
63
|
@panel.on 'click', '.fetched-select', (event) => @setVal($(event.currentTarget).data('item-value')) and false
|
64
|
+
@panel.on 'keyup', '.search-value', (event) => @search($(event.currentTarget).val()) and true
|
65
|
+
@panel.on 'keydown', (event) => @searchVal.focus() and true
|
60
66
|
|
61
67
|
initInvade: ->
|
62
68
|
return if @options.invade == false || @options.invade == 'false'
|
@@ -76,12 +82,15 @@
|
|
76
82
|
|
77
83
|
expand: ->
|
78
84
|
@invade() if @options.invade
|
79
|
-
@selector.slideDown 'fast', =>
|
85
|
+
@selector.slideDown 'fast', =>
|
86
|
+
@panel.addClass('expanded')
|
87
|
+
@searchVal.focus()
|
80
88
|
|
81
89
|
collapse: ->
|
82
90
|
@selector.slideUp 'fast', =>
|
83
91
|
@panel.removeClass('expanded')
|
84
92
|
@reset() if @options.resetOnCollapse
|
93
|
+
@search('') if @options.resetOnCollapse
|
85
94
|
@retreat() if @options.invade
|
86
95
|
|
87
96
|
# Invade the nearest '.row'
|
@@ -111,22 +120,22 @@
|
|
111
120
|
|
112
121
|
@invading = false
|
113
122
|
|
123
|
+
title: (item) ->
|
124
|
+
(item || @label).find('a').clone().children().remove().end().text()
|
125
|
+
|
114
126
|
# Get / Set / Clear selection
|
115
127
|
val: (args...) ->
|
116
128
|
if args.length == 0 then @input.val() else @setVal(args[0])
|
117
129
|
|
118
|
-
title: (item) ->
|
119
|
-
(item || @label).find('a').clone().children().remove().end().text()
|
120
|
-
|
121
130
|
# Sets the input value, and the selected value text
|
122
131
|
setVal: (value) ->
|
123
132
|
@input.val(value)
|
124
133
|
|
125
134
|
if value == null || value == undefined || value == ''
|
126
|
-
@label.html("<span class='selection-placeholder'>#{@options.placeholder}</span>")
|
135
|
+
@label.html("<span class='selection-clear'>x</span> <span class='selection-placeholder'>#{@options.placeholder}</span>")
|
127
136
|
@reset()
|
128
137
|
else
|
129
|
-
$item = @
|
138
|
+
$item = @tabContent.find("li[data-item-value='#{value}']").first()
|
130
139
|
label = @title($item)
|
131
140
|
|
132
141
|
@label.html("<span class='selection-clear'>x</span> <span class='selection-label'>#{label}</span>")
|
@@ -135,27 +144,83 @@
|
|
135
144
|
@panel.trigger 'change'
|
136
145
|
true
|
137
146
|
|
147
|
+
search: (value) ->
|
148
|
+
# Set html input value, incase this is called from api
|
149
|
+
@searchVal.val(value) unless @searchVal.val() == value
|
150
|
+
|
151
|
+
# Reset existing search
|
152
|
+
@selector.find('.excluded').removeClass('excluded')
|
153
|
+
|
154
|
+
value = "#{value}".toLowerCase()
|
155
|
+
results = []
|
156
|
+
|
157
|
+
if value == ''
|
158
|
+
@searchResults.html('')
|
159
|
+
return results
|
160
|
+
|
161
|
+
@tabContent.children(':not(.fetched)').each (_, tabPane) =>
|
162
|
+
$tabPane = $(tabPane)
|
163
|
+
tabPaneExcluded = true
|
164
|
+
|
165
|
+
$tabPane.find('li').each (_, item) =>
|
166
|
+
$item = $(item)
|
167
|
+
|
168
|
+
if $item.text().toLowerCase().indexOf(value) > -1
|
169
|
+
results.push($item.data('item-value'))
|
170
|
+
tabPaneExcluded = false
|
171
|
+
else
|
172
|
+
$item.addClass('excluded')
|
173
|
+
|
174
|
+
true
|
175
|
+
|
176
|
+
if tabPaneExcluded
|
177
|
+
@tabList.find("a[href='##{$tabPane.attr('id')}']").parent('li').addClass('excluded')
|
178
|
+
|
179
|
+
if results.length > 0 && @options.showSearch
|
180
|
+
@searchResults.html("#{results.length} result#{if results.length > 1 then 's' else ''} for '#{value}'")
|
181
|
+
@activateTab(results[0]) if @tabList.find('li.active:not(.excluded)').length == 0 # activate first tab if no tab is displayed
|
182
|
+
else
|
183
|
+
@searchResults.html('')
|
184
|
+
|
185
|
+
results
|
186
|
+
|
187
|
+
activateTab: (value) ->
|
188
|
+
$item = @tabContent.find("li[data-item-value='#{value}']").first()
|
189
|
+
return false unless $item.length > 0
|
190
|
+
|
191
|
+
@selector.find('.active').removeClass('active')
|
192
|
+
|
193
|
+
$tab_pane = $item.closest('.tab-pane')
|
194
|
+
$tab = @tabList.find("a[href='##{$tab_pane.attr('id')}']").parent('li')
|
195
|
+
|
196
|
+
$tab_pane.addClass('active')
|
197
|
+
$tab.addClass('active')
|
198
|
+
|
138
199
|
# Syncs the tabs to the current value
|
139
200
|
reset: ->
|
140
201
|
value = @val()
|
141
202
|
|
142
203
|
@fetched.children(':not(.effective-panel-select-actions)').remove() if @fetched && @fetched.length && !@options.keepFetched
|
143
204
|
|
144
|
-
@selector.find(
|
205
|
+
@selector.find('li.selected').removeClass('selected')
|
145
206
|
@selector.find('.active').removeClass('active')
|
146
207
|
|
147
208
|
if (value == null || value == undefined || value == '') == false
|
148
|
-
$item = @
|
209
|
+
$item = @tabContent.find("li[data-item-value='#{value}']").first()
|
149
210
|
$item.addClass('selected').addClass('active')
|
150
211
|
|
151
212
|
$tab_pane = $item.closest('.tab-pane')
|
152
213
|
|
153
214
|
if $tab_pane.length
|
154
|
-
$tab = @
|
215
|
+
$tab = @tabList.find("a[href='##{$tab_pane.attr('id')}']").parent('li')
|
155
216
|
$tab.addClass('selected').addClass('active')
|
156
217
|
$tab_pane.addClass('active')
|
157
218
|
|
158
|
-
clear: ->
|
219
|
+
clear: ->
|
220
|
+
@val(null)
|
221
|
+
@search('')
|
222
|
+
@searchVal.focus()
|
223
|
+
false
|
159
224
|
|
160
225
|
# Ajax fetch and view page
|
161
226
|
fetch: (value) ->
|
@@ -208,4 +273,4 @@
|
|
208
273
|
|
209
274
|
$(document).on 'click', (event) ->
|
210
275
|
if !$(event.target).closest('.effective-panel-select').length
|
211
|
-
$('.effective-panel-select.initialized').effectivePanelSelect('collapse')
|
276
|
+
$('.effective-panel-select.initialized.expanded').effectivePanelSelect('collapse')
|
@@ -15,6 +15,29 @@
|
|
15
15
|
.tab-content { padding-top: 0px; }
|
16
16
|
}
|
17
17
|
|
18
|
+
.excluded {
|
19
|
+
display: none;
|
20
|
+
}
|
21
|
+
|
22
|
+
.search {
|
23
|
+
display: none;
|
24
|
+
|
25
|
+
padding: 0px 4px 4px 4px;
|
26
|
+
|
27
|
+
input {
|
28
|
+
border: 1px solid #ccc;
|
29
|
+
border-radius: 4px;
|
30
|
+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
31
|
+
padding: 4px;
|
32
|
+
width: 100%;
|
33
|
+
}
|
34
|
+
|
35
|
+
.search-results {
|
36
|
+
display: block;
|
37
|
+
padding-top: 4px;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
18
41
|
.tab-pane.fetched { padding: 15px 15px 15px 0; }
|
19
42
|
|
20
43
|
.selection {
|
@@ -69,6 +92,7 @@
|
|
69
92
|
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
|
70
93
|
|
71
94
|
.selector { display: block; }
|
95
|
+
.search { display: block; }
|
72
96
|
|
73
97
|
.selection-arrow {
|
74
98
|
margin-top: -38px;
|
@@ -14,7 +14,7 @@ module Inputs
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def default_input_js
|
17
|
-
{ placeholder: 'Please choose', invade: '.row', collapseOnSelect: true, resetOnCollapse: true, showCount: false }
|
17
|
+
{ placeholder: 'Please choose', invade: '.row', collapseOnSelect: true, resetOnCollapse: true, showCount: false, showSearch: true }
|
18
18
|
end
|
19
19
|
|
20
20
|
def default_input_html
|
@@ -37,6 +37,10 @@ module Inputs
|
|
37
37
|
return true if js_options[:showCount]
|
38
38
|
end
|
39
39
|
|
40
|
+
def show_search?
|
41
|
+
return true if js_options[:showSearch]
|
42
|
+
end
|
43
|
+
|
40
44
|
# option_value 1
|
41
45
|
# option_label Post A
|
42
46
|
# group_label Active
|
@@ -12,15 +12,21 @@
|
|
12
12
|
%span.selection-arrow
|
13
13
|
%b
|
14
14
|
|
15
|
+
- if input.show_search?
|
16
|
+
.search
|
17
|
+
.row
|
18
|
+
.col-sm-4
|
19
|
+
%input.search-value{type: 'search', autocomplete: :off, autocorrect: :off, autocapitalization: :off, spellcheck: false, role: 'textbox'}
|
20
|
+
.col-sm-8
|
21
|
+
%span.search-results
|
22
|
+
|
15
23
|
.selector
|
16
24
|
.row
|
17
25
|
.col-sm-4
|
18
26
|
%ul.nav.nav-pills{role: 'tablist', class: input.options[:sidebar_class]}
|
19
27
|
- input.collection.each do |group, items|
|
20
|
-
|
21
|
-
|
22
|
-
%li{class: ('active selected' if group_value == input.group_value) }
|
23
|
-
%a{'data-toggle': 'tab', role: 'tab', href: "##{group_value.parameterize}"}
|
28
|
+
%li
|
29
|
+
%a{'data-toggle': 'tab', role: 'tab', href: "##{group.send(input.options[:group_method]).parameterize}"}
|
24
30
|
= group.send(input.options[:group_label_method]).html_safe
|
25
31
|
- if input.show_count?
|
26
32
|
%span.badge= items.length
|
@@ -28,14 +34,10 @@
|
|
28
34
|
.col-sm-8
|
29
35
|
.tab-content
|
30
36
|
- input.collection.each do |group, items|
|
31
|
-
-
|
32
|
-
|
33
|
-
.tab-pane{id: group_value.parameterize, class: ('active' if group_value == input.group_value) }
|
37
|
+
.tab-pane{id: group.send(input.options[:group_method]).parameterize}
|
34
38
|
%ul.nav.nav-pills.nav-stacked
|
35
39
|
- Array(items).each do |item|
|
36
|
-
-
|
37
|
-
|
38
|
-
%li{class: ('active selected' if item_value == input.value), 'data-item-value' => item_value}
|
40
|
+
%li{'data-item-value' => item.send(input.options[:option_key_method])}
|
39
41
|
%a{href: '#'}
|
40
42
|
= item.send(input.options[:option_value_method]).html_safe
|
41
43
|
- if input.ajax?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_form_inputs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|