chosen-koenpunt-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/vendor/assets/javascripts/chosen.jquery.js +1241 -0
- data/vendor/assets/stylesheets/{chosen.css.scss → chosen.scss} +0 -0
- metadata +94 -20
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/chosen-koenpunt-rails.gemspec +0 -19
- data/lib/chosen-koenpunt-rails.rb +0 -5
- data/lib/chosen-koenpunt-rails/version.rb +0 -3
- data/vendor/assets/javascripts/chosen.jquery.js.coffee +0 -520
- data/vendor/assets/javascripts/chosen.proto.js.coffee +0 -528
- data/vendor/assets/javascripts/lib/abstract-chosen.coffee +0 -280
- data/vendor/assets/javascripts/lib/select-parser.coffee +0 -64
File without changes
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chosen-koenpunt-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- tnarik
|
@@ -10,7 +9,91 @@ autorequire:
|
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
date: 2013-09-03 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coffee-script
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sass
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sass-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: compass-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sprockets
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
14
97
|
description: Integrate Koenpunt branch of the Chosen javascript library with the Rails
|
15
98
|
asset pipeline
|
16
99
|
email:
|
@@ -19,41 +102,32 @@ executables: []
|
|
19
102
|
extensions: []
|
20
103
|
extra_rdoc_files: []
|
21
104
|
files:
|
22
|
-
-
|
23
|
-
-
|
105
|
+
- vendor/assets/javascripts/chosen.jquery.js
|
106
|
+
- vendor/assets/stylesheets/chosen.scss
|
24
107
|
- README.md
|
25
|
-
-
|
26
|
-
- chosen-koenpunt-rails.gemspec
|
27
|
-
- lib/chosen-koenpunt-rails.rb
|
28
|
-
- lib/chosen-koenpunt-rails/version.rb
|
29
|
-
- vendor/assets/javascripts/chosen.jquery.js.coffee
|
30
|
-
- vendor/assets/javascripts/chosen.proto.js.coffee
|
31
|
-
- vendor/assets/javascripts/lib/abstract-chosen.coffee
|
32
|
-
- vendor/assets/javascripts/lib/select-parser.coffee
|
33
|
-
- vendor/assets/stylesheets/chosen.css.scss
|
108
|
+
- LICENSE.txt
|
34
109
|
homepage: ''
|
35
110
|
licenses: []
|
111
|
+
metadata: {}
|
36
112
|
post_install_message:
|
37
113
|
rdoc_options: []
|
38
114
|
require_paths:
|
39
115
|
- lib
|
40
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
117
|
requirements:
|
43
|
-
- -
|
118
|
+
- - '>='
|
44
119
|
- !ruby/object:Gem::Version
|
45
120
|
version: '0'
|
46
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
122
|
requirements:
|
49
|
-
- -
|
123
|
+
- - '>='
|
50
124
|
- !ruby/object:Gem::Version
|
51
125
|
version: '0'
|
52
126
|
requirements: []
|
53
127
|
rubyforge_project:
|
54
|
-
rubygems_version:
|
128
|
+
rubygems_version: 2.0.7
|
55
129
|
signing_key:
|
56
|
-
specification_version:
|
130
|
+
specification_version: 4
|
57
131
|
summary: Integrate Koenpunt branch of the Chosen javascript library with the Rails
|
58
132
|
asset pipeline
|
59
133
|
test_files: []
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'chosen-koenpunt-rails/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "chosen-koenpunt-rails"
|
8
|
-
gem.version = ChosenKoenpuntRails::VERSION
|
9
|
-
gem.authors = ["tnarik"]
|
10
|
-
gem.email = ["tnarik@gmail.com"]
|
11
|
-
gem.description = %q{Integrate Koenpunt branch of the Chosen javascript library with the Rails asset pipeline}
|
12
|
-
gem.summary = %q{Integrate Koenpunt branch of the Chosen javascript library with the Rails asset pipeline}
|
13
|
-
gem.homepage = ""
|
14
|
-
|
15
|
-
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = ["lib"]
|
19
|
-
end
|
@@ -1,520 +0,0 @@
|
|
1
|
-
$ = jQuery
|
2
|
-
|
3
|
-
$.fn.extend({
|
4
|
-
chosen: (options) ->
|
5
|
-
# Do no harm and return as soon as possible for unsupported browsers, namely IE6 and IE7
|
6
|
-
# Continue on if running IE document type but in compatibility mode
|
7
|
-
return this unless AbstractChosen.browser_is_supported()
|
8
|
-
this.each (input_field) ->
|
9
|
-
$this = $ this
|
10
|
-
chosen = $this.data('chosen')
|
11
|
-
if options is 'destroy' && chosen
|
12
|
-
chosen.destroy()
|
13
|
-
else unless chosen
|
14
|
-
$this.data('chosen', new Chosen(this, options))
|
15
|
-
|
16
|
-
return
|
17
|
-
|
18
|
-
})
|
19
|
-
|
20
|
-
class Chosen extends AbstractChosen
|
21
|
-
|
22
|
-
setup: ->
|
23
|
-
@form_field_jq = $ @form_field
|
24
|
-
@current_selectedIndex = @form_field.selectedIndex
|
25
|
-
@is_rtl = @form_field_jq.hasClass "chosen-rtl"
|
26
|
-
|
27
|
-
set_up_html: ->
|
28
|
-
container_classes = ["chosen-container"]
|
29
|
-
container_classes.push "chosen-container-" + (if @is_multiple then "multi" else "single")
|
30
|
-
container_classes.push @form_field.className if @inherit_select_classes && @form_field.className
|
31
|
-
container_classes.push "chosen-rtl" if @is_rtl
|
32
|
-
|
33
|
-
container_props =
|
34
|
-
'class': container_classes.join ' '
|
35
|
-
'style': "width: #{this.container_width()};"
|
36
|
-
'title': @form_field.title
|
37
|
-
|
38
|
-
container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length
|
39
|
-
|
40
|
-
@container = ($ "<div />", container_props)
|
41
|
-
|
42
|
-
if @is_multiple
|
43
|
-
@container.html '<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'
|
44
|
-
else
|
45
|
-
@container.html '<a class="chosen-single chosen-default" tabindex="-1"><span>' + @default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'
|
46
|
-
|
47
|
-
@form_field_jq.hide().after @container
|
48
|
-
@dropdown = @container.find('div.chosen-drop').first()
|
49
|
-
|
50
|
-
@search_field = @container.find('input').first()
|
51
|
-
@search_results = @container.find('ul.chosen-results').first()
|
52
|
-
this.search_field_scale()
|
53
|
-
|
54
|
-
@search_no_results = @container.find('li.no-results').first()
|
55
|
-
|
56
|
-
if @is_multiple
|
57
|
-
@search_choices = @container.find('ul.chosen-choices').first()
|
58
|
-
@search_container = @container.find('li.search-field').first()
|
59
|
-
else
|
60
|
-
@search_container = @container.find('div.chosen-search').first()
|
61
|
-
@selected_item = @container.find('.chosen-single').first()
|
62
|
-
|
63
|
-
this.results_build()
|
64
|
-
this.set_tab_index()
|
65
|
-
this.set_label_behavior()
|
66
|
-
@form_field_jq.trigger("chosen:ready", {chosen: this})
|
67
|
-
|
68
|
-
register_observers: ->
|
69
|
-
@container.bind 'mousedown.chosen', (evt) => this.container_mousedown(evt); return
|
70
|
-
@container.bind 'mouseup.chosen', (evt) => this.container_mouseup(evt); return
|
71
|
-
@container.bind 'mouseenter.chosen', (evt) => this.mouse_enter(evt); return
|
72
|
-
@container.bind 'mouseleave.chosen', (evt) => this.mouse_leave(evt); return
|
73
|
-
|
74
|
-
@search_results.bind 'mouseup.chosen', (evt) => this.search_results_mouseup(evt); return
|
75
|
-
@search_results.bind 'mouseover.chosen', (evt) => this.search_results_mouseover(evt); return
|
76
|
-
@search_results.bind 'mouseout.chosen', (evt) => this.search_results_mouseout(evt); return
|
77
|
-
@search_results.bind 'mousewheel.chosen DOMMouseScroll.chosen', (evt) => this.search_results_mousewheel(evt); return
|
78
|
-
|
79
|
-
@search_results.bind 'touchstart.chosen', (evt) => this.search_results_touchstart(evt); return
|
80
|
-
@search_results.bind 'touchmove.chosen', (evt) => this.search_results_touchmove(evt); return
|
81
|
-
@search_results.bind 'touchend.chosen', (evt) => this.search_results_touchend(evt); return
|
82
|
-
|
83
|
-
@form_field_jq.bind "chosen:updated.chosen", (evt) => this.results_update_field(evt); return
|
84
|
-
@form_field_jq.bind "chosen:activate.chosen", (evt) => this.activate_field(evt); return
|
85
|
-
@form_field_jq.bind "chosen:open.chosen", (evt) => this.container_mousedown(evt); return
|
86
|
-
|
87
|
-
@search_field.bind 'blur.chosen', (evt) => this.input_blur(evt); return
|
88
|
-
@search_field.bind 'keyup.chosen', (evt) => this.keyup_checker(evt); return
|
89
|
-
@search_field.bind 'keydown.chosen', (evt) => this.keydown_checker(evt); return
|
90
|
-
@search_field.bind 'focus.chosen', (evt) => this.input_focus(evt); return
|
91
|
-
|
92
|
-
if @is_multiple
|
93
|
-
@search_choices.bind 'click.chosen', (evt) => this.choices_click(evt); return
|
94
|
-
else
|
95
|
-
@container.bind 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
|
96
|
-
|
97
|
-
destroy: ->
|
98
|
-
$(document).unbind "click.chosen", @click_test_action
|
99
|
-
if @search_field[0].tabIndex
|
100
|
-
@form_field_jq[0].tabIndex = @search_field[0].tabIndex
|
101
|
-
|
102
|
-
@container.remove()
|
103
|
-
@form_field_jq.removeData('chosen')
|
104
|
-
@form_field_jq.show()
|
105
|
-
|
106
|
-
search_field_disabled: ->
|
107
|
-
@is_disabled = @form_field_jq[0].disabled
|
108
|
-
if(@is_disabled)
|
109
|
-
@container.addClass 'chosen-disabled'
|
110
|
-
@search_field[0].disabled = true
|
111
|
-
@selected_item.unbind "focus.chosen", @activate_action if !@is_multiple
|
112
|
-
this.close_field()
|
113
|
-
else
|
114
|
-
@container.removeClass 'chosen-disabled'
|
115
|
-
@search_field[0].disabled = false
|
116
|
-
@selected_item.bind "focus.chosen", @activate_action if !@is_multiple
|
117
|
-
|
118
|
-
container_mousedown: (evt) ->
|
119
|
-
if !@is_disabled
|
120
|
-
if evt and evt.type is "mousedown" and not @results_showing
|
121
|
-
evt.preventDefault()
|
122
|
-
|
123
|
-
if not (evt? and ($ evt.target).hasClass "search-choice-close")
|
124
|
-
if not @active_field
|
125
|
-
@search_field.val "" if @is_multiple
|
126
|
-
$(document).bind 'click.chosen', @click_test_action
|
127
|
-
this.results_show()
|
128
|
-
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
|
129
|
-
evt.preventDefault()
|
130
|
-
this.results_toggle()
|
131
|
-
|
132
|
-
this.activate_field()
|
133
|
-
|
134
|
-
container_mouseup: (evt) ->
|
135
|
-
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
|
136
|
-
|
137
|
-
search_results_mousewheel: (evt) ->
|
138
|
-
delta = -evt.originalEvent?.wheelDelta or evt.originialEvent?.detail
|
139
|
-
if delta?
|
140
|
-
evt.preventDefault()
|
141
|
-
delta = delta * 40 if evt.type is 'DOMMouseScroll'
|
142
|
-
@search_results.scrollTop(delta + @search_results.scrollTop())
|
143
|
-
|
144
|
-
blur_test: (evt) ->
|
145
|
-
this.close_field() if not @active_field and @container.hasClass "chosen-container-active"
|
146
|
-
|
147
|
-
close_field: ->
|
148
|
-
$(document).unbind "click.chosen", @click_test_action
|
149
|
-
|
150
|
-
@active_field = false
|
151
|
-
this.results_hide()
|
152
|
-
|
153
|
-
@container.removeClass "chosen-container-active"
|
154
|
-
this.clear_backstroke()
|
155
|
-
|
156
|
-
this.show_search_field_default()
|
157
|
-
this.search_field_scale()
|
158
|
-
|
159
|
-
activate_field: ->
|
160
|
-
@container.addClass "chosen-container-active"
|
161
|
-
@active_field = true
|
162
|
-
|
163
|
-
@search_field.val(@search_field.val())
|
164
|
-
@search_field.focus()
|
165
|
-
|
166
|
-
|
167
|
-
test_active_click: (evt) ->
|
168
|
-
if @container.is($(evt.target).closest('.chosen-container'))
|
169
|
-
@active_field = true
|
170
|
-
else
|
171
|
-
this.close_field()
|
172
|
-
|
173
|
-
results_build: ->
|
174
|
-
@parsing = true
|
175
|
-
@selected_option_count = null
|
176
|
-
|
177
|
-
@results_data = SelectParser.select_to_array @form_field
|
178
|
-
|
179
|
-
if @is_multiple
|
180
|
-
@search_choices.find("li.search-choice").remove()
|
181
|
-
else if not @is_multiple
|
182
|
-
this.single_set_selected_text()
|
183
|
-
if @disable_search or @form_field.options.length <= @disable_search_threshold and not @create_option
|
184
|
-
@search_field[0].readOnly = true
|
185
|
-
@container.addClass "chosen-container-single-nosearch"
|
186
|
-
else
|
187
|
-
@search_field[0].readOnly = false
|
188
|
-
@container.removeClass "chosen-container-single-nosearch"
|
189
|
-
|
190
|
-
this.update_results_content this.results_option_build({first:true})
|
191
|
-
|
192
|
-
this.search_field_disabled()
|
193
|
-
this.show_search_field_default()
|
194
|
-
this.search_field_scale()
|
195
|
-
|
196
|
-
@parsing = false
|
197
|
-
|
198
|
-
result_do_highlight: (el) ->
|
199
|
-
if el.length
|
200
|
-
this.result_clear_highlight()
|
201
|
-
|
202
|
-
@result_highlight = el
|
203
|
-
@result_highlight.addClass "highlighted"
|
204
|
-
|
205
|
-
maxHeight = parseInt @search_results.css("maxHeight"), 10
|
206
|
-
visible_top = @search_results.scrollTop()
|
207
|
-
visible_bottom = maxHeight + visible_top
|
208
|
-
|
209
|
-
high_top = @result_highlight.position().top + @search_results.scrollTop()
|
210
|
-
high_bottom = high_top + @result_highlight.outerHeight()
|
211
|
-
|
212
|
-
if high_bottom >= visible_bottom
|
213
|
-
@search_results.scrollTop if (high_bottom - maxHeight) > 0 then (high_bottom - maxHeight) else 0
|
214
|
-
else if high_top < visible_top
|
215
|
-
@search_results.scrollTop high_top
|
216
|
-
|
217
|
-
result_clear_highlight: ->
|
218
|
-
@result_highlight.removeClass "highlighted" if @result_highlight
|
219
|
-
@result_highlight = null
|
220
|
-
|
221
|
-
results_show: ->
|
222
|
-
if @is_multiple and @max_selected_options <= this.choices_count()
|
223
|
-
@form_field_jq.trigger("chosen:maxselected", {chosen: this})
|
224
|
-
return false
|
225
|
-
|
226
|
-
@container.addClass "chosen-with-drop"
|
227
|
-
@form_field_jq.trigger("chosen:showing_dropdown", {chosen: this})
|
228
|
-
|
229
|
-
@results_showing = true
|
230
|
-
|
231
|
-
@search_field.focus()
|
232
|
-
@search_field.val @search_field.val()
|
233
|
-
|
234
|
-
this.winnow_results()
|
235
|
-
|
236
|
-
update_results_content: (content) ->
|
237
|
-
@search_results.html content
|
238
|
-
|
239
|
-
results_hide: ->
|
240
|
-
if @results_showing
|
241
|
-
this.result_clear_highlight()
|
242
|
-
|
243
|
-
@container.removeClass "chosen-with-drop"
|
244
|
-
@form_field_jq.trigger("chosen:hiding_dropdown", {chosen: this})
|
245
|
-
|
246
|
-
@results_showing = false
|
247
|
-
|
248
|
-
|
249
|
-
set_tab_index: (el) ->
|
250
|
-
if @form_field.tabIndex
|
251
|
-
ti = @form_field.tabIndex
|
252
|
-
@form_field.tabIndex = -1
|
253
|
-
@search_field[0].tabIndex = ti
|
254
|
-
|
255
|
-
set_label_behavior: ->
|
256
|
-
@form_field_label = @form_field_jq.parents("label") # first check for a parent label
|
257
|
-
if not @form_field_label.length and @form_field.id.length
|
258
|
-
@form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id}
|
259
|
-
|
260
|
-
if @form_field_label.length > 0
|
261
|
-
@form_field_label.bind 'click.chosen', (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
|
262
|
-
|
263
|
-
show_search_field_default: ->
|
264
|
-
if @is_multiple and this.choices_count() < 1 and not @active_field
|
265
|
-
@search_field.val(@default_text)
|
266
|
-
@search_field.addClass "default"
|
267
|
-
else
|
268
|
-
@search_field.val("")
|
269
|
-
@search_field.removeClass "default"
|
270
|
-
|
271
|
-
search_results_mouseup: (evt) ->
|
272
|
-
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
273
|
-
if target.length
|
274
|
-
@result_highlight = target
|
275
|
-
this.result_select(evt)
|
276
|
-
@search_field.focus()
|
277
|
-
|
278
|
-
search_results_mouseover: (evt) ->
|
279
|
-
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
280
|
-
this.result_do_highlight( target ) if target
|
281
|
-
|
282
|
-
search_results_mouseout: (evt) ->
|
283
|
-
this.result_clear_highlight() if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
|
284
|
-
|
285
|
-
choice_build: (item) ->
|
286
|
-
choice = $('<li />', { class: "search-choice" }).html("<span>#{item.html}</span>")
|
287
|
-
|
288
|
-
if item.disabled
|
289
|
-
choice.addClass 'search-choice-disabled'
|
290
|
-
else
|
291
|
-
close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index })
|
292
|
-
close_link.bind 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
|
293
|
-
choice.append close_link
|
294
|
-
|
295
|
-
@search_container.before choice
|
296
|
-
|
297
|
-
choice_destroy_link_click: (evt) ->
|
298
|
-
evt.preventDefault()
|
299
|
-
evt.stopPropagation()
|
300
|
-
this.choice_destroy $(evt.target) unless @is_disabled
|
301
|
-
|
302
|
-
choice_destroy: (link) ->
|
303
|
-
if this.result_deselect( link[0].getAttribute("data-option-array-index") )
|
304
|
-
this.show_search_field_default()
|
305
|
-
|
306
|
-
this.results_hide() if @is_multiple and this.choices_count() > 0 and @search_field.val().length < 1
|
307
|
-
|
308
|
-
link.parents('li').first().remove()
|
309
|
-
|
310
|
-
this.search_field_scale()
|
311
|
-
|
312
|
-
results_reset: ->
|
313
|
-
this.reset_single_select_options()
|
314
|
-
@form_field.options[0].selected = true
|
315
|
-
this.single_set_selected_text()
|
316
|
-
this.show_search_field_default()
|
317
|
-
this.results_reset_cleanup()
|
318
|
-
@form_field_jq.trigger "change"
|
319
|
-
this.results_hide() if @active_field
|
320
|
-
|
321
|
-
results_reset_cleanup: ->
|
322
|
-
@current_selectedIndex = @form_field.selectedIndex
|
323
|
-
@selected_item.find("abbr").remove()
|
324
|
-
|
325
|
-
result_select: (evt) ->
|
326
|
-
if @result_highlight
|
327
|
-
high = @result_highlight
|
328
|
-
|
329
|
-
if high.hasClass "create-option"
|
330
|
-
this.select_create_option(@search_field.val())
|
331
|
-
return this.results_hide()
|
332
|
-
|
333
|
-
this.result_clear_highlight()
|
334
|
-
|
335
|
-
if @is_multiple and @max_selected_options <= this.choices_count()
|
336
|
-
@form_field_jq.trigger("chosen:maxselected", {chosen: this})
|
337
|
-
return false
|
338
|
-
|
339
|
-
if @is_multiple
|
340
|
-
high.removeClass("active-result")
|
341
|
-
else
|
342
|
-
this.reset_single_select_options()
|
343
|
-
|
344
|
-
item = @results_data[ high[0].getAttribute("data-option-array-index") ]
|
345
|
-
item.selected = true
|
346
|
-
|
347
|
-
@form_field.options[item.options_index].selected = true
|
348
|
-
@selected_option_count = null
|
349
|
-
|
350
|
-
if @is_multiple
|
351
|
-
this.choice_build item
|
352
|
-
else
|
353
|
-
this.single_set_selected_text(item.text)
|
354
|
-
|
355
|
-
this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
|
356
|
-
|
357
|
-
@search_field.val ""
|
358
|
-
|
359
|
-
@form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
|
360
|
-
@current_selectedIndex = @form_field.selectedIndex
|
361
|
-
this.search_field_scale()
|
362
|
-
|
363
|
-
single_set_selected_text: (text=@default_text) ->
|
364
|
-
if text is @default_text
|
365
|
-
@selected_item.addClass("chosen-default")
|
366
|
-
else
|
367
|
-
this.single_deselect_control_build()
|
368
|
-
@selected_item.removeClass("chosen-default")
|
369
|
-
|
370
|
-
@selected_item.find("span").text(text)
|
371
|
-
|
372
|
-
result_deselect: (pos) ->
|
373
|
-
result_data = @results_data[pos]
|
374
|
-
|
375
|
-
if not @form_field.options[result_data.options_index].disabled
|
376
|
-
result_data.selected = false
|
377
|
-
|
378
|
-
@form_field.options[result_data.options_index].selected = false
|
379
|
-
@selected_option_count = null
|
380
|
-
|
381
|
-
this.result_clear_highlight()
|
382
|
-
this.winnow_results() if @results_showing
|
383
|
-
|
384
|
-
@form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
|
385
|
-
this.search_field_scale()
|
386
|
-
|
387
|
-
return true
|
388
|
-
else
|
389
|
-
return false
|
390
|
-
|
391
|
-
single_deselect_control_build: ->
|
392
|
-
return unless @allow_single_deselect
|
393
|
-
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" unless @selected_item.find("abbr").length
|
394
|
-
@selected_item.addClass("chosen-single-with-deselect")
|
395
|
-
|
396
|
-
get_search_text: ->
|
397
|
-
if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
398
|
-
|
399
|
-
winnow_results_set_highlight: ->
|
400
|
-
selected_results = if not @is_multiple then @search_results.find(".result-selected.active-result") else []
|
401
|
-
do_high = if selected_results.length then selected_results.first() else @search_results.find(".active-result").first()
|
402
|
-
|
403
|
-
this.result_do_highlight do_high if do_high?
|
404
|
-
|
405
|
-
no_results: (terms) ->
|
406
|
-
no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
|
407
|
-
no_results_html.find("span").first().html(terms)
|
408
|
-
@search_results.append no_results_html
|
409
|
-
|
410
|
-
show_create_option: (terms) ->
|
411
|
-
create_option_html = $('<li class="create-option active-result"><a href="javascript:void(0);">' + @create_option_text + '</a>: "' + terms + '"</li>')
|
412
|
-
@search_results.append create_option_html
|
413
|
-
|
414
|
-
create_option_clear: ->
|
415
|
-
@search_results.find(".create-option").remove()
|
416
|
-
|
417
|
-
select_create_option: (terms) ->
|
418
|
-
if $.isFunction(@create_option)
|
419
|
-
@create_option.call this, terms
|
420
|
-
else
|
421
|
-
this.select_append_option( {value: terms, text: terms} )
|
422
|
-
|
423
|
-
select_append_option: ( options ) ->
|
424
|
-
option = $('<option />', options ).attr('selected', 'selected')
|
425
|
-
@form_field_jq.append option
|
426
|
-
@form_field_jq.trigger "chosen:updated"
|
427
|
-
@form_field_jq.trigger "change"
|
428
|
-
@search_field.trigger "focus"
|
429
|
-
|
430
|
-
no_results_clear: ->
|
431
|
-
@search_results.find(".no-results").remove()
|
432
|
-
|
433
|
-
keydown_arrow: ->
|
434
|
-
if @results_showing and @result_highlight
|
435
|
-
next_sib = @result_highlight.nextAll("li.active-result").first()
|
436
|
-
this.result_do_highlight next_sib if next_sib
|
437
|
-
else if @results_showing and @create_option
|
438
|
-
this.result_do_highlight(@search_results.find('.create-option'))
|
439
|
-
else
|
440
|
-
this.results_show()
|
441
|
-
|
442
|
-
keyup_arrow: ->
|
443
|
-
if not @results_showing and not @is_multiple
|
444
|
-
this.results_show()
|
445
|
-
else if @result_highlight
|
446
|
-
prev_sibs = @result_highlight.prevAll("li.active-result")
|
447
|
-
|
448
|
-
if prev_sibs.length
|
449
|
-
this.result_do_highlight prev_sibs.first()
|
450
|
-
else
|
451
|
-
this.results_hide() if this.choices_count() > 0
|
452
|
-
this.result_clear_highlight()
|
453
|
-
|
454
|
-
keydown_backstroke: ->
|
455
|
-
if @pending_backstroke
|
456
|
-
this.choice_destroy @pending_backstroke.find("a").first()
|
457
|
-
this.clear_backstroke()
|
458
|
-
else
|
459
|
-
next_available_destroy = @search_container.siblings("li.search-choice").last()
|
460
|
-
if next_available_destroy.length and not next_available_destroy.hasClass("search-choice-disabled")
|
461
|
-
@pending_backstroke = next_available_destroy
|
462
|
-
if @single_backstroke_delete
|
463
|
-
@keydown_backstroke()
|
464
|
-
else
|
465
|
-
@pending_backstroke.addClass "search-choice-focus"
|
466
|
-
|
467
|
-
clear_backstroke: ->
|
468
|
-
@pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke
|
469
|
-
@pending_backstroke = null
|
470
|
-
|
471
|
-
keydown_checker: (evt) ->
|
472
|
-
stroke = evt.which ? evt.keyCode
|
473
|
-
this.search_field_scale()
|
474
|
-
|
475
|
-
this.clear_backstroke() if stroke != 8 and this.pending_backstroke
|
476
|
-
|
477
|
-
switch stroke
|
478
|
-
when 8
|
479
|
-
@backstroke_length = this.search_field.val().length
|
480
|
-
break
|
481
|
-
when 9
|
482
|
-
this.result_select(evt) if this.results_showing and not @is_multiple
|
483
|
-
@mouse_on_container = false
|
484
|
-
break
|
485
|
-
when 13
|
486
|
-
evt.preventDefault()
|
487
|
-
break
|
488
|
-
when 38
|
489
|
-
evt.preventDefault()
|
490
|
-
this.keyup_arrow()
|
491
|
-
break
|
492
|
-
when 40
|
493
|
-
evt.preventDefault()
|
494
|
-
this.keydown_arrow()
|
495
|
-
break
|
496
|
-
|
497
|
-
search_field_scale: ->
|
498
|
-
if @is_multiple
|
499
|
-
h = 0
|
500
|
-
w = 0
|
501
|
-
|
502
|
-
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"
|
503
|
-
styles = ['font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing']
|
504
|
-
|
505
|
-
for style in styles
|
506
|
-
style_block += style + ":" + @search_field.css(style) + ";"
|
507
|
-
|
508
|
-
div = $('<div />', { 'style' : style_block })
|
509
|
-
div.text @search_field.val()
|
510
|
-
$('body').append div
|
511
|
-
|
512
|
-
w = div.width() + 25
|
513
|
-
div.remove()
|
514
|
-
|
515
|
-
f_width = @container.outerWidth()
|
516
|
-
|
517
|
-
if( w > f_width - 10 )
|
518
|
-
w = f_width - 10
|
519
|
-
|
520
|
-
@search_field.css({'width': w + 'px'})
|