intesys_asset_manager 1.1.2 → 1.1.3

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.
@@ -0,0 +1,271 @@
1
+ class AbstractChosen
2
+
3
+ constructor: (@form_field, @options={}) ->
4
+ return unless AbstractChosen.browser_is_supported()
5
+ @is_multiple = @form_field.multiple
6
+ this.set_default_text()
7
+ this.set_default_values()
8
+
9
+ this.setup()
10
+
11
+ this.set_up_html()
12
+ this.register_observers()
13
+
14
+ set_default_values: ->
15
+ @click_test_action = (evt) => this.test_active_click(evt)
16
+ @activate_action = (evt) => this.activate_field(evt)
17
+ @active_field = false
18
+ @mouse_on_container = false
19
+ @results_showing = false
20
+ @result_highlighted = null
21
+ @allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
22
+ @disable_search_threshold = @options.disable_search_threshold || 0
23
+ @disable_search = @options.disable_search || false
24
+ @enable_split_word_search = if @options.enable_split_word_search? then @options.enable_split_word_search else true
25
+ @group_search = if @options.group_search? then @options.group_search else true
26
+ @search_contains = @options.search_contains || false
27
+ @single_backstroke_delete = if @options.single_backstroke_delete? then @options.single_backstroke_delete else true
28
+ @max_selected_options = @options.max_selected_options || Infinity
29
+ @inherit_select_classes = @options.inherit_select_classes || false
30
+ @display_selected_options = if @options.display_selected_options? then @options.display_selected_options else true
31
+ @display_disabled_options = if @options.display_disabled_options? then @options.display_disabled_options else true
32
+
33
+ set_default_text: ->
34
+ if @form_field.getAttribute("data-placeholder")
35
+ @default_text = @form_field.getAttribute("data-placeholder")
36
+ else if @is_multiple
37
+ @default_text = @options.placeholder_text_multiple || @options.placeholder_text || AbstractChosen.default_multiple_text
38
+ else
39
+ @default_text = @options.placeholder_text_single || @options.placeholder_text || AbstractChosen.default_single_text
40
+
41
+ @results_none_found = @form_field.getAttribute("data-no_results_text") || @options.no_results_text || AbstractChosen.default_no_result_text
42
+
43
+ mouse_enter: -> @mouse_on_container = true
44
+ mouse_leave: -> @mouse_on_container = false
45
+
46
+ input_focus: (evt) ->
47
+ if @is_multiple
48
+ setTimeout (=> this.container_mousedown()), 50 unless @active_field
49
+ else
50
+ @activate_field() unless @active_field
51
+
52
+ input_blur: (evt) ->
53
+ if not @mouse_on_container
54
+ @active_field = false
55
+ setTimeout (=> this.blur_test()), 100
56
+
57
+ results_option_build: (options) ->
58
+ content = ''
59
+ for data in @results_data
60
+ if data.group
61
+ content += this.result_add_group data
62
+ else
63
+ content += this.result_add_option data
64
+
65
+ # this select logic pins on an awkward flag
66
+ # we can make it better
67
+ if options?.first
68
+ if data.selected and @is_multiple
69
+ this.choice_build data
70
+ else if data.selected and not @is_multiple
71
+ this.single_set_selected_text(data.text)
72
+
73
+ content
74
+
75
+ result_add_option: (option) ->
76
+ return '' unless option.search_match
77
+ return '' unless this.include_option_in_results(option)
78
+
79
+ classes = []
80
+ classes.push "active-result" if !option.disabled and !(option.selected and @is_multiple)
81
+ classes.push "disabled-result" if option.disabled and !(option.selected and @is_multiple)
82
+ classes.push "result-selected" if option.selected
83
+ classes.push "group-option" if option.group_array_index?
84
+ classes.push option.classes if option.classes != ""
85
+
86
+ option_el = document.createElement("li")
87
+ option_el.className = classes.join(" ")
88
+ option_el.style.cssText = option.style
89
+ option_el.setAttribute("data-option-array-index", option.array_index)
90
+ option_el.innerHTML = option.search_text
91
+
92
+ this.outerHTML(option_el)
93
+
94
+ result_add_group: (group) ->
95
+ return '' unless group.search_match || group.group_match
96
+ return '' unless group.active_options > 0
97
+
98
+ group_el = document.createElement("li")
99
+ group_el.className = "group-result"
100
+ group_el.innerHTML = group.search_text
101
+
102
+ this.outerHTML(group_el)
103
+
104
+ results_update_field: ->
105
+ this.set_default_text()
106
+ this.results_reset_cleanup() if not @is_multiple
107
+ this.result_clear_highlight()
108
+ this.results_build()
109
+ this.winnow_results() if @results_showing
110
+
111
+ reset_single_select_options: () ->
112
+ for result in @results_data
113
+ result.selected = false if result.selected
114
+
115
+ results_toggle: ->
116
+ if @results_showing
117
+ this.results_hide()
118
+ else
119
+ this.results_show()
120
+
121
+ results_search: (evt) ->
122
+ if @results_showing
123
+ this.winnow_results()
124
+ else
125
+ this.results_show()
126
+
127
+ winnow_results: ->
128
+ this.no_results_clear()
129
+
130
+ results = 0
131
+
132
+ searchText = this.get_search_text()
133
+ escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
134
+ regexAnchor = if @search_contains then "" else "^"
135
+ regex = new RegExp(regexAnchor + escapedSearchText, 'i')
136
+ zregex = new RegExp(escapedSearchText, 'i')
137
+
138
+ for option in @results_data
139
+
140
+ option.search_match = false
141
+ results_group = null
142
+
143
+ if this.include_option_in_results(option)
144
+
145
+ if option.group
146
+ option.group_match = false
147
+ option.active_options = 0
148
+
149
+ if option.group_array_index? and @results_data[option.group_array_index]
150
+ results_group = @results_data[option.group_array_index]
151
+ results += 1 if results_group.active_options is 0 and results_group.search_match
152
+ results_group.active_options += 1
153
+
154
+ unless option.group and not @group_search
155
+
156
+ option.search_text = if option.group then option.label else option.html
157
+ option.search_match = this.search_string_match(option.search_text, regex)
158
+ results += 1 if option.search_match and not option.group
159
+
160
+ if option.search_match
161
+ if searchText.length
162
+ startpos = option.search_text.search zregex
163
+ text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length)
164
+ option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos)
165
+
166
+ results_group.group_match = true if results_group?
167
+
168
+ else if option.group_array_index? and @results_data[option.group_array_index].search_match
169
+ option.search_match = true
170
+
171
+ this.result_clear_highlight()
172
+
173
+ if results < 1 and searchText.length
174
+ this.update_results_content ""
175
+ this.no_results searchText
176
+ else
177
+ this.update_results_content this.results_option_build()
178
+ this.winnow_results_set_highlight()
179
+
180
+ search_string_match: (search_string, regex) ->
181
+ if regex.test search_string
182
+ return true
183
+ else if @enable_split_word_search and (search_string.indexOf(" ") >= 0 or search_string.indexOf("[") == 0)
184
+ #TODO: replace this substitution of /\[\]/ with a list of characters to skip.
185
+ parts = search_string.replace(/\[|\]/g, "").split(" ")
186
+ if parts.length
187
+ for part in parts
188
+ if regex.test part
189
+ return true
190
+
191
+ choices_count: ->
192
+ return @selected_option_count if @selected_option_count?
193
+
194
+ @selected_option_count = 0
195
+ for option in @form_field.options
196
+ @selected_option_count += 1 if option.selected
197
+
198
+ return @selected_option_count
199
+
200
+ choices_click: (evt) ->
201
+ evt.preventDefault()
202
+ this.results_show() unless @results_showing or @is_disabled
203
+
204
+ keyup_checker: (evt) ->
205
+ stroke = evt.which ? evt.keyCode
206
+ this.search_field_scale()
207
+
208
+ switch stroke
209
+ when 8
210
+ if @is_multiple and @backstroke_length < 1 and this.choices_count() > 0
211
+ this.keydown_backstroke()
212
+ else if not @pending_backstroke
213
+ this.result_clear_highlight()
214
+ this.results_search()
215
+ when 13
216
+ evt.preventDefault()
217
+ this.result_select(evt) if this.results_showing
218
+ when 27
219
+ this.results_hide() if @results_showing
220
+ return true
221
+ when 9, 38, 40, 16, 91, 17
222
+ # don't do anything on these keys
223
+ else this.results_search()
224
+
225
+ clipboard_event_checker: (evt) ->
226
+ setTimeout (=> this.results_search()), 50
227
+
228
+ container_width: ->
229
+ return if @options.width? then @options.width else "#{@form_field.offsetWidth}px"
230
+
231
+ include_option_in_results: (option) ->
232
+ return false if @is_multiple and (not @display_selected_options and option.selected)
233
+ return false if not @display_disabled_options and option.disabled
234
+ return false if option.empty
235
+
236
+ return true
237
+
238
+ search_results_touchstart: (evt) ->
239
+ @touch_started = true
240
+ this.search_results_mouseover(evt)
241
+
242
+ search_results_touchmove: (evt) ->
243
+ @touch_started = false
244
+ this.search_results_mouseout(evt)
245
+
246
+ search_results_touchend: (evt) ->
247
+ this.search_results_mouseup(evt) if @touch_started
248
+
249
+ outerHTML: (element) ->
250
+ return element.outerHTML if element.outerHTML
251
+ tmp = document.createElement("div")
252
+ tmp.appendChild(element)
253
+ tmp.innerHTML
254
+
255
+ # class methods and variables ============================================================
256
+
257
+ @browser_is_supported: ->
258
+ if window.navigator.appName == "Microsoft Internet Explorer"
259
+ return document.documentMode >= 8
260
+ if /iP(od|hone)/i.test(window.navigator.userAgent)
261
+ return false
262
+ if /Android/i.test(window.navigator.userAgent)
263
+ return false if /Mobile/i.test(window.navigator.userAgent)
264
+ return true
265
+
266
+ @default_multiple_text: "Select Some Options"
267
+ @default_single_text: "Select an Option"
268
+ @default_no_result_text: "No results match"
269
+
270
+
271
+ window.AbstractChosen = AbstractChosen
@@ -0,0 +1,66 @@
1
+ class SelectParser
2
+
3
+ constructor: ->
4
+ @options_index = 0
5
+ @parsed = []
6
+
7
+ add_node: (child) ->
8
+ if child.nodeName.toUpperCase() is "OPTGROUP"
9
+ this.add_group child
10
+ else
11
+ this.add_option child
12
+
13
+ add_group: (group) ->
14
+ group_position = @parsed.length
15
+ @parsed.push
16
+ array_index: group_position
17
+ group: true
18
+ label: this.escapeExpression(group.label)
19
+ children: 0
20
+ disabled: group.disabled
21
+ this.add_option( option, group_position, group.disabled ) for option in group.childNodes
22
+
23
+ add_option: (option, group_position, group_disabled) ->
24
+ if option.nodeName.toUpperCase() is "OPTION"
25
+ if option.text != ""
26
+ if group_position?
27
+ @parsed[group_position].children += 1
28
+ @parsed.push
29
+ array_index: @parsed.length
30
+ options_index: @options_index
31
+ value: option.value
32
+ text: option.text
33
+ html: option.innerHTML
34
+ selected: option.selected
35
+ disabled: if group_disabled is true then group_disabled else option.disabled
36
+ group_array_index: group_position
37
+ classes: option.className
38
+ style: option.style.cssText
39
+ else
40
+ @parsed.push
41
+ array_index: @parsed.length
42
+ options_index: @options_index
43
+ empty: true
44
+ @options_index += 1
45
+
46
+ escapeExpression: (text) ->
47
+ if not text? or text is false
48
+ return ""
49
+ unless /[\&\<\>\"\'\`]/.test(text)
50
+ return text
51
+ map =
52
+ "<": "&lt;"
53
+ ">": "&gt;"
54
+ '"': "&quot;"
55
+ "'": "&#x27;"
56
+ "`": "&#x60;"
57
+ unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g
58
+ text.replace unsafe_chars, (chr) ->
59
+ map[chr] || "&amp;"
60
+
61
+ SelectParser.select_to_array = (select) ->
62
+ parser = new SelectParser()
63
+ parser.add_node( child ) for child in select.childNodes
64
+ parser.parsed
65
+
66
+ window.SelectParser = SelectParser