intesys_asset_manager 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/app/assets/javascripts/asset_manager.js.coffee +1 -1
- data/app/assets/stylesheets/asset_manager/plugins/plugins.css.sass +1 -1
- data/lib/asset_manager.rb +0 -3
- data/lib/intesys_asset_manager/version.rb +1 -1
- data/vendor/assets/images/asset_manager/chosen-rails/chosen-sprite.png +0 -0
- data/vendor/assets/images/asset_manager/chosen-rails/chosen-sprite@2x.png +0 -0
- data/vendor/assets/javascripts/asset_manager/chosen-rails/chosen-jquery.js +3 -0
- data/vendor/assets/javascripts/asset_manager/chosen-rails/chosen-prototype.js +3 -0
- data/vendor/assets/javascripts/asset_manager/chosen-rails/chosen.jquery.coffee +500 -0
- data/vendor/assets/javascripts/asset_manager/chosen-rails/chosen.proto.coffee +498 -0
- data/vendor/assets/javascripts/asset_manager/chosen-rails/lib/abstract-chosen.coffee +271 -0
- data/vendor/assets/javascripts/asset_manager/chosen-rails/lib/select-parser.coffee +66 -0
- data/vendor/assets/stylesheets/asset_manager/chosen-rails/chosen.css.scss +446 -0
- metadata +10 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06714d71553ceb082aa1c8ec949ad75bbd743c1f
|
4
|
+
data.tar.gz: ed8b29a0a8673c91e31d4d8ab7fb98f277a8266b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dd505e9478c53b54959abf96673731cb24d9596bfe342f76c5921d754d1d09351e56b582c4985be098dbdac5d14db39194f5e286db0c4d6264c4c07ea37ee77
|
7
|
+
data.tar.gz: eb5d69fa3f3ec239e63886b835a18aa1bc263a4f35fc9d835a31e7d9c3281cf18df085303a37121a7a37bd77cc763463c8f95e92258bfe17066a30d0f408175e
|
data/README.rdoc
CHANGED
@@ -44,7 +44,7 @@ If, for example, we have a Product that has a main image and a series of picture
|
|
44
44
|
|
45
45
|
You have two methods to choose from: has_file when the association is singular and has_files when multiple files need to be associated. These methods accept a series of parameters to specify which file types are accepted, how many files can be associated (for has_files), etc.
|
46
46
|
|
47
|
-
Once you have your models configured you can connect assets with your records. Asset Manager provides Formtastic and SimpleForm input types to make it easier to manage your forms:
|
47
|
+
Once you have your models configured you can connect assets with your records. Asset Manager provides {Formtastic}[https://github.com/justinfrench/formtastic] and {SimpleForm}[https://github.com/plataformatec/simple_form] input types to make it easier to manage your forms:
|
48
48
|
= semantic_form_for @product do |f|
|
49
49
|
= f.inputs do
|
50
50
|
= f.input :title
|
data/lib/asset_manager.rb
CHANGED
@@ -3,10 +3,7 @@ require 'asset_manager/engine'
|
|
3
3
|
require 'acts-as-taggable-on'
|
4
4
|
require 'bootstrap_kaminari'
|
5
5
|
require 'carrierwave'
|
6
|
-
require 'chosen-rails'
|
7
|
-
require 'compass-rails'
|
8
6
|
require 'fancybox2-rails'
|
9
|
-
# require "font-awesome-rails"
|
10
7
|
require 'formtastic-bootstrap'
|
11
8
|
require 'globalize'
|
12
9
|
require 'haml-rails'
|
Binary file
|
@@ -0,0 +1,500 @@
|
|
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
|
+
@form_field_jq.bind "chosen:close.chosen", (evt) => this.input_blur(evt); return
|
87
|
+
|
88
|
+
@search_field.bind 'blur.chosen', (evt) => this.input_blur(evt); return
|
89
|
+
@search_field.bind 'keyup.chosen', (evt) => this.keyup_checker(evt); return
|
90
|
+
@search_field.bind 'keydown.chosen', (evt) => this.keydown_checker(evt); return
|
91
|
+
@search_field.bind 'focus.chosen', (evt) => this.input_focus(evt); return
|
92
|
+
@search_field.bind 'cut.chosen', (evt) => this.clipboard_event_checker(evt); return
|
93
|
+
@search_field.bind 'paste.chosen', (evt) => this.clipboard_event_checker(evt); return
|
94
|
+
|
95
|
+
if @is_multiple
|
96
|
+
@search_choices.bind 'click.chosen', (evt) => this.choices_click(evt); return
|
97
|
+
else
|
98
|
+
@container.bind 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
|
99
|
+
|
100
|
+
destroy: ->
|
101
|
+
$(@container[0].ownerDocument).unbind "click.chosen", @click_test_action
|
102
|
+
if @search_field[0].tabIndex
|
103
|
+
@form_field_jq[0].tabIndex = @search_field[0].tabIndex
|
104
|
+
|
105
|
+
@container.remove()
|
106
|
+
@form_field_jq.removeData('chosen')
|
107
|
+
@form_field_jq.show()
|
108
|
+
|
109
|
+
search_field_disabled: ->
|
110
|
+
@is_disabled = @form_field_jq[0].disabled
|
111
|
+
if(@is_disabled)
|
112
|
+
@container.addClass 'chosen-disabled'
|
113
|
+
@search_field[0].disabled = true
|
114
|
+
@selected_item.unbind "focus.chosen", @activate_action if !@is_multiple
|
115
|
+
this.close_field()
|
116
|
+
else
|
117
|
+
@container.removeClass 'chosen-disabled'
|
118
|
+
@search_field[0].disabled = false
|
119
|
+
@selected_item.bind "focus.chosen", @activate_action if !@is_multiple
|
120
|
+
|
121
|
+
container_mousedown: (evt) ->
|
122
|
+
if !@is_disabled
|
123
|
+
if evt and evt.type is "mousedown" and not @results_showing
|
124
|
+
evt.preventDefault()
|
125
|
+
|
126
|
+
if not (evt? and ($ evt.target).hasClass "search-choice-close")
|
127
|
+
if not @active_field
|
128
|
+
@search_field.val "" if @is_multiple
|
129
|
+
$(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
|
130
|
+
this.results_show()
|
131
|
+
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
|
132
|
+
evt.preventDefault()
|
133
|
+
this.results_toggle()
|
134
|
+
|
135
|
+
this.activate_field()
|
136
|
+
|
137
|
+
container_mouseup: (evt) ->
|
138
|
+
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
|
139
|
+
|
140
|
+
search_results_mousewheel: (evt) ->
|
141
|
+
delta = -evt.originalEvent.wheelDelta or evt.originalEvent.detail if evt.originalEvent
|
142
|
+
if delta?
|
143
|
+
evt.preventDefault()
|
144
|
+
delta = delta * 40 if evt.type is 'DOMMouseScroll'
|
145
|
+
@search_results.scrollTop(delta + @search_results.scrollTop())
|
146
|
+
|
147
|
+
blur_test: (evt) ->
|
148
|
+
this.close_field() if not @active_field and @container.hasClass "chosen-container-active"
|
149
|
+
|
150
|
+
close_field: ->
|
151
|
+
$(@container[0].ownerDocument).unbind "click.chosen", @click_test_action
|
152
|
+
|
153
|
+
@active_field = false
|
154
|
+
this.results_hide()
|
155
|
+
|
156
|
+
@container.removeClass "chosen-container-active"
|
157
|
+
this.clear_backstroke()
|
158
|
+
|
159
|
+
this.show_search_field_default()
|
160
|
+
this.search_field_scale()
|
161
|
+
|
162
|
+
activate_field: ->
|
163
|
+
@container.addClass "chosen-container-active"
|
164
|
+
@active_field = true
|
165
|
+
|
166
|
+
@search_field.val(@search_field.val())
|
167
|
+
@search_field.focus()
|
168
|
+
|
169
|
+
|
170
|
+
test_active_click: (evt) ->
|
171
|
+
active_container = $(evt.target).closest('.chosen-container')
|
172
|
+
if active_container.length and @container[0] == active_container[0]
|
173
|
+
@active_field = true
|
174
|
+
else
|
175
|
+
this.close_field()
|
176
|
+
|
177
|
+
results_build: ->
|
178
|
+
@parsing = true
|
179
|
+
@selected_option_count = null
|
180
|
+
|
181
|
+
@results_data = SelectParser.select_to_array @form_field
|
182
|
+
|
183
|
+
if @is_multiple
|
184
|
+
@search_choices.find("li.search-choice").remove()
|
185
|
+
else if not @is_multiple
|
186
|
+
this.single_set_selected_text()
|
187
|
+
if @disable_search or @form_field.options.length <= @disable_search_threshold
|
188
|
+
@search_field[0].readOnly = true
|
189
|
+
@container.addClass "chosen-container-single-nosearch"
|
190
|
+
else
|
191
|
+
@search_field[0].readOnly = false
|
192
|
+
@container.removeClass "chosen-container-single-nosearch"
|
193
|
+
|
194
|
+
this.update_results_content this.results_option_build({first:true})
|
195
|
+
|
196
|
+
this.search_field_disabled()
|
197
|
+
this.show_search_field_default()
|
198
|
+
this.search_field_scale()
|
199
|
+
|
200
|
+
@parsing = false
|
201
|
+
|
202
|
+
result_do_highlight: (el) ->
|
203
|
+
if el.length
|
204
|
+
this.result_clear_highlight()
|
205
|
+
|
206
|
+
@result_highlight = el
|
207
|
+
@result_highlight.addClass "highlighted"
|
208
|
+
|
209
|
+
maxHeight = parseInt @search_results.css("maxHeight"), 10
|
210
|
+
visible_top = @search_results.scrollTop()
|
211
|
+
visible_bottom = maxHeight + visible_top
|
212
|
+
|
213
|
+
high_top = @result_highlight.position().top + @search_results.scrollTop()
|
214
|
+
high_bottom = high_top + @result_highlight.outerHeight()
|
215
|
+
|
216
|
+
if high_bottom >= visible_bottom
|
217
|
+
@search_results.scrollTop if (high_bottom - maxHeight) > 0 then (high_bottom - maxHeight) else 0
|
218
|
+
else if high_top < visible_top
|
219
|
+
@search_results.scrollTop high_top
|
220
|
+
|
221
|
+
result_clear_highlight: ->
|
222
|
+
@result_highlight.removeClass "highlighted" if @result_highlight
|
223
|
+
@result_highlight = null
|
224
|
+
|
225
|
+
results_show: ->
|
226
|
+
if @is_multiple and @max_selected_options <= this.choices_count()
|
227
|
+
@form_field_jq.trigger("chosen:maxselected", {chosen: this})
|
228
|
+
return false
|
229
|
+
|
230
|
+
@container.addClass "chosen-with-drop"
|
231
|
+
@results_showing = true
|
232
|
+
|
233
|
+
@search_field.focus()
|
234
|
+
@search_field.val @search_field.val()
|
235
|
+
|
236
|
+
this.winnow_results()
|
237
|
+
@form_field_jq.trigger("chosen:showing_dropdown", {chosen: this})
|
238
|
+
|
239
|
+
update_results_content: (content) ->
|
240
|
+
@search_results.html content
|
241
|
+
|
242
|
+
results_hide: ->
|
243
|
+
if @results_showing
|
244
|
+
this.result_clear_highlight()
|
245
|
+
|
246
|
+
@container.removeClass "chosen-with-drop"
|
247
|
+
@form_field_jq.trigger("chosen:hiding_dropdown", {chosen: this})
|
248
|
+
|
249
|
+
@results_showing = false
|
250
|
+
|
251
|
+
|
252
|
+
set_tab_index: (el) ->
|
253
|
+
if @form_field.tabIndex
|
254
|
+
ti = @form_field.tabIndex
|
255
|
+
@form_field.tabIndex = -1
|
256
|
+
@search_field[0].tabIndex = ti
|
257
|
+
|
258
|
+
set_label_behavior: ->
|
259
|
+
@form_field_label = @form_field_jq.parents("label") # first check for a parent label
|
260
|
+
if not @form_field_label.length and @form_field.id.length
|
261
|
+
@form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id}
|
262
|
+
|
263
|
+
if @form_field_label.length > 0
|
264
|
+
@form_field_label.bind 'click.chosen', (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
|
265
|
+
|
266
|
+
show_search_field_default: ->
|
267
|
+
if @is_multiple and this.choices_count() < 1 and not @active_field
|
268
|
+
@search_field.val(@default_text)
|
269
|
+
@search_field.addClass "default"
|
270
|
+
else
|
271
|
+
@search_field.val("")
|
272
|
+
@search_field.removeClass "default"
|
273
|
+
|
274
|
+
search_results_mouseup: (evt) ->
|
275
|
+
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
276
|
+
if target.length
|
277
|
+
@result_highlight = target
|
278
|
+
this.result_select(evt)
|
279
|
+
@search_field.focus()
|
280
|
+
|
281
|
+
search_results_mouseover: (evt) ->
|
282
|
+
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
283
|
+
this.result_do_highlight( target ) if target
|
284
|
+
|
285
|
+
search_results_mouseout: (evt) ->
|
286
|
+
this.result_clear_highlight() if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
|
287
|
+
|
288
|
+
choice_build: (item) ->
|
289
|
+
choice = $('<li />', { class: "search-choice" }).html("<span>#{item.html}</span>")
|
290
|
+
|
291
|
+
if item.disabled
|
292
|
+
choice.addClass 'search-choice-disabled'
|
293
|
+
else
|
294
|
+
close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index })
|
295
|
+
close_link.bind 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
|
296
|
+
choice.append close_link
|
297
|
+
|
298
|
+
@search_container.before choice
|
299
|
+
|
300
|
+
choice_destroy_link_click: (evt) ->
|
301
|
+
evt.preventDefault()
|
302
|
+
evt.stopPropagation()
|
303
|
+
this.choice_destroy $(evt.target) unless @is_disabled
|
304
|
+
|
305
|
+
choice_destroy: (link) ->
|
306
|
+
if this.result_deselect( link[0].getAttribute("data-option-array-index") )
|
307
|
+
this.show_search_field_default()
|
308
|
+
|
309
|
+
this.results_hide() if @is_multiple and this.choices_count() > 0 and @search_field.val().length < 1
|
310
|
+
|
311
|
+
link.parents('li').first().remove()
|
312
|
+
|
313
|
+
this.search_field_scale()
|
314
|
+
|
315
|
+
results_reset: ->
|
316
|
+
this.reset_single_select_options()
|
317
|
+
@form_field.options[0].selected = true
|
318
|
+
this.single_set_selected_text()
|
319
|
+
this.show_search_field_default()
|
320
|
+
this.results_reset_cleanup()
|
321
|
+
@form_field_jq.trigger "change"
|
322
|
+
this.results_hide() if @active_field
|
323
|
+
|
324
|
+
results_reset_cleanup: ->
|
325
|
+
@current_selectedIndex = @form_field.selectedIndex
|
326
|
+
@selected_item.find("abbr").remove()
|
327
|
+
|
328
|
+
result_select: (evt) ->
|
329
|
+
if @result_highlight
|
330
|
+
high = @result_highlight
|
331
|
+
|
332
|
+
this.result_clear_highlight()
|
333
|
+
|
334
|
+
if @is_multiple and @max_selected_options <= this.choices_count()
|
335
|
+
@form_field_jq.trigger("chosen:maxselected", {chosen: this})
|
336
|
+
return false
|
337
|
+
|
338
|
+
if @is_multiple
|
339
|
+
high.removeClass("active-result")
|
340
|
+
else
|
341
|
+
this.reset_single_select_options()
|
342
|
+
|
343
|
+
item = @results_data[ high[0].getAttribute("data-option-array-index") ]
|
344
|
+
item.selected = true
|
345
|
+
|
346
|
+
@form_field.options[item.options_index].selected = true
|
347
|
+
@selected_option_count = null
|
348
|
+
|
349
|
+
if @is_multiple
|
350
|
+
this.choice_build item
|
351
|
+
else
|
352
|
+
this.single_set_selected_text(item.text)
|
353
|
+
|
354
|
+
this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
|
355
|
+
|
356
|
+
@search_field.val ""
|
357
|
+
|
358
|
+
@form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
|
359
|
+
@current_selectedIndex = @form_field.selectedIndex
|
360
|
+
this.search_field_scale()
|
361
|
+
|
362
|
+
single_set_selected_text: (text=@default_text) ->
|
363
|
+
if text is @default_text
|
364
|
+
@selected_item.addClass("chosen-default")
|
365
|
+
else
|
366
|
+
this.single_deselect_control_build()
|
367
|
+
@selected_item.removeClass("chosen-default")
|
368
|
+
|
369
|
+
@selected_item.find("span").text(text)
|
370
|
+
|
371
|
+
result_deselect: (pos) ->
|
372
|
+
result_data = @results_data[pos]
|
373
|
+
|
374
|
+
if not @form_field.options[result_data.options_index].disabled
|
375
|
+
result_data.selected = false
|
376
|
+
|
377
|
+
@form_field.options[result_data.options_index].selected = false
|
378
|
+
@selected_option_count = null
|
379
|
+
|
380
|
+
this.result_clear_highlight()
|
381
|
+
this.winnow_results() if @results_showing
|
382
|
+
|
383
|
+
@form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
|
384
|
+
this.search_field_scale()
|
385
|
+
|
386
|
+
return true
|
387
|
+
else
|
388
|
+
return false
|
389
|
+
|
390
|
+
single_deselect_control_build: ->
|
391
|
+
return unless @allow_single_deselect
|
392
|
+
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" unless @selected_item.find("abbr").length
|
393
|
+
@selected_item.addClass("chosen-single-with-deselect")
|
394
|
+
|
395
|
+
get_search_text: ->
|
396
|
+
if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
397
|
+
|
398
|
+
winnow_results_set_highlight: ->
|
399
|
+
|
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
|
+
|
409
|
+
@search_results.append no_results_html
|
410
|
+
@form_field_jq.trigger("chosen:no_results", {chosen:this})
|
411
|
+
|
412
|
+
no_results_clear: ->
|
413
|
+
@search_results.find(".no-results").remove()
|
414
|
+
|
415
|
+
keydown_arrow: ->
|
416
|
+
if @results_showing and @result_highlight
|
417
|
+
next_sib = @result_highlight.nextAll("li.active-result").first()
|
418
|
+
this.result_do_highlight next_sib if next_sib
|
419
|
+
else
|
420
|
+
this.results_show()
|
421
|
+
|
422
|
+
keyup_arrow: ->
|
423
|
+
if not @results_showing and not @is_multiple
|
424
|
+
this.results_show()
|
425
|
+
else if @result_highlight
|
426
|
+
prev_sibs = @result_highlight.prevAll("li.active-result")
|
427
|
+
|
428
|
+
if prev_sibs.length
|
429
|
+
this.result_do_highlight prev_sibs.first()
|
430
|
+
else
|
431
|
+
this.results_hide() if this.choices_count() > 0
|
432
|
+
this.result_clear_highlight()
|
433
|
+
|
434
|
+
keydown_backstroke: ->
|
435
|
+
if @pending_backstroke
|
436
|
+
this.choice_destroy @pending_backstroke.find("a").first()
|
437
|
+
this.clear_backstroke()
|
438
|
+
else
|
439
|
+
next_available_destroy = @search_container.siblings("li.search-choice").last()
|
440
|
+
if next_available_destroy.length and not next_available_destroy.hasClass("search-choice-disabled")
|
441
|
+
@pending_backstroke = next_available_destroy
|
442
|
+
if @single_backstroke_delete
|
443
|
+
@keydown_backstroke()
|
444
|
+
else
|
445
|
+
@pending_backstroke.addClass "search-choice-focus"
|
446
|
+
|
447
|
+
clear_backstroke: ->
|
448
|
+
@pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke
|
449
|
+
@pending_backstroke = null
|
450
|
+
|
451
|
+
keydown_checker: (evt) ->
|
452
|
+
stroke = evt.which ? evt.keyCode
|
453
|
+
this.search_field_scale()
|
454
|
+
|
455
|
+
this.clear_backstroke() if stroke != 8 and this.pending_backstroke
|
456
|
+
|
457
|
+
switch stroke
|
458
|
+
when 8
|
459
|
+
@backstroke_length = this.search_field.val().length
|
460
|
+
break
|
461
|
+
when 9
|
462
|
+
this.result_select(evt) if this.results_showing and not @is_multiple
|
463
|
+
@mouse_on_container = false
|
464
|
+
break
|
465
|
+
when 13
|
466
|
+
evt.preventDefault()
|
467
|
+
break
|
468
|
+
when 38
|
469
|
+
evt.preventDefault()
|
470
|
+
this.keyup_arrow()
|
471
|
+
break
|
472
|
+
when 40
|
473
|
+
evt.preventDefault()
|
474
|
+
this.keydown_arrow()
|
475
|
+
break
|
476
|
+
|
477
|
+
search_field_scale: ->
|
478
|
+
if @is_multiple
|
479
|
+
h = 0
|
480
|
+
w = 0
|
481
|
+
|
482
|
+
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"
|
483
|
+
styles = ['font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing']
|
484
|
+
|
485
|
+
for style in styles
|
486
|
+
style_block += style + ":" + @search_field.css(style) + ";"
|
487
|
+
|
488
|
+
div = $('<div />', { 'style' : style_block })
|
489
|
+
div.text @search_field.val()
|
490
|
+
$('body').append div
|
491
|
+
|
492
|
+
w = div.width() + 25
|
493
|
+
div.remove()
|
494
|
+
|
495
|
+
f_width = @container.outerWidth()
|
496
|
+
|
497
|
+
if( w > f_width - 10 )
|
498
|
+
w = f_width - 10
|
499
|
+
|
500
|
+
@search_field.css({'width': w + 'px'})
|