testcentricity_web 4.1.10 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -1
  3. data/README.md +301 -230
  4. data/lib/testcentricity_web/browser_helper.rb +2 -1
  5. data/lib/testcentricity_web/data_objects/environment.rb +0 -3
  6. data/lib/testcentricity_web/version.rb +1 -1
  7. data/lib/testcentricity_web/web_core/page_objects_helper.rb +39 -2
  8. data/lib/testcentricity_web/web_core/webdriver_helper.rb +162 -152
  9. data/lib/testcentricity_web/web_elements/media.rb +108 -0
  10. data/lib/testcentricity_web/web_elements/textfield.rb +28 -0
  11. data/lib/testcentricity_web/web_elements/ui_elements_helper.rb +39 -1
  12. metadata +18 -162
  13. data/.gitignore +0 -39
  14. data/.idea/.name +0 -1
  15. data/.idea/encodings.xml +0 -6
  16. data/.idea/misc.xml +0 -4
  17. data/.idea/modules.xml +0 -8
  18. data/.idea/vcs.xml +0 -7
  19. data/.rspec +0 -4
  20. data/.rubocop.yml +0 -38
  21. data/.ruby-version +0 -1
  22. data/.simplecov +0 -9
  23. data/CODE_OF_CONDUCT.md +0 -13
  24. data/Gemfile +0 -6
  25. data/Rakefile +0 -115
  26. data/config/cucumber.yml +0 -171
  27. data/config/locales/en-US.yml +0 -56
  28. data/config/test_data/LOCAL_data.json +0 -15
  29. data/config/test_data/LOCAL_data.xls +0 -0
  30. data/config/test_data/LOCAL_data.yml +0 -11
  31. data/config/test_data/data.json +0 -25
  32. data/config/test_data/data.xls +0 -0
  33. data/config/test_data/data.yml +0 -20
  34. data/docker-compose.yml +0 -48
  35. data/features/basic_form_page_css.feature +0 -54
  36. data/features/basic_form_page_xpath.feature +0 -26
  37. data/features/custom_controls.feature +0 -29
  38. data/features/media_players.feature +0 -67
  39. data/features/step_definitions/generic_steps.rb.rb +0 -124
  40. data/features/step_definitions/media_steps.rb +0 -30
  41. data/features/support/data/form_data.rb +0 -43
  42. data/features/support/env.rb +0 -53
  43. data/features/support/hooks.rb +0 -270
  44. data/features/support/pages/base_test_page.rb +0 -22
  45. data/features/support/pages/basic_css_form_page.rb +0 -57
  46. data/features/support/pages/basic_form_page.rb +0 -500
  47. data/features/support/pages/basic_xpath_form_page.rb +0 -58
  48. data/features/support/pages/custom_controls_page.rb +0 -263
  49. data/features/support/pages/indexed_sections_page.rb +0 -57
  50. data/features/support/pages/media_test_page.rb +0 -207
  51. data/features/support/sections/header_nav.rb +0 -48
  52. data/features/support/sections/product_card.rb +0 -39
  53. data/features/support/world_data.rb +0 -12
  54. data/features/support/world_pages.rb +0 -18
  55. data/reports/.keep +0 -1
  56. data/spec/fixtures/page_object.rb +0 -22
  57. data/spec/fixtures/section_object.rb +0 -21
  58. data/spec/spec_helper.rb +0 -33
  59. data/spec/testcentricity_web/browser_spec.rb +0 -41
  60. data/spec/testcentricity_web/elements/audio_spec.rb +0 -68
  61. data/spec/testcentricity_web/elements/button_spec.rb +0 -18
  62. data/spec/testcentricity_web/elements/checkbox_spec.rb +0 -33
  63. data/spec/testcentricity_web/elements/file_field_spec.rb +0 -13
  64. data/spec/testcentricity_web/elements/image_spec.rb +0 -33
  65. data/spec/testcentricity_web/elements/label_spec.rb +0 -18
  66. data/spec/testcentricity_web/elements/link_spec.rb +0 -23
  67. data/spec/testcentricity_web/elements/list_spec.rb +0 -13
  68. data/spec/testcentricity_web/elements/radio_spec.rb +0 -28
  69. data/spec/testcentricity_web/elements/ui_element_spec.rb +0 -125
  70. data/spec/testcentricity_web/elements/video_spec.rb +0 -68
  71. data/spec/testcentricity_web/helper_specs/object_helpers_spec.rb +0 -39
  72. data/spec/testcentricity_web/helper_specs/string_helpers_spec.rb +0 -49
  73. data/spec/testcentricity_web/page_object_spec.rb +0 -90
  74. data/spec/testcentricity_web/section_object_spec.rb +0 -72
  75. data/spec/testcentricity_web/version_spec.rb +0 -7
  76. data/spec/testcentricity_web/webdriver_connect/grid_webdriver_spec.rb +0 -72
  77. data/spec/testcentricity_web/webdriver_connect/local_webdriver_spec.rb +0 -86
  78. data/spec/testcentricity_web/webdriver_connect/mobile_webdriver_spec.rb +0 -65
  79. data/test_site/basic_test_page.html +0 -269
  80. data/test_site/chosen/chosen-sprite.png +0 -0
  81. data/test_site/chosen/chosen-sprite@2x.png +0 -0
  82. data/test_site/chosen/chosen.css +0 -496
  83. data/test_site/chosen/chosen.jquery.js +0 -1359
  84. data/test_site/chosen/chosen.jquery.min.js +0 -3
  85. data/test_site/chosen/chosen.min.css +0 -11
  86. data/test_site/chosen/chosen.proto.js +0 -1399
  87. data/test_site/chosen/chosen.proto.min.js +0 -3
  88. data/test_site/chosen/composer.json +0 -36
  89. data/test_site/custom_controls_page.html +0 -629
  90. data/test_site/docsupport/chosen.png +0 -0
  91. data/test_site/docsupport/init.js +0 -11
  92. data/test_site/docsupport/init.proto.js +0 -16
  93. data/test_site/docsupport/jquery-1.12.4.min.js +0 -5
  94. data/test_site/docsupport/jquery-3.2.1.min.js +0 -4
  95. data/test_site/docsupport/oss-credit.png +0 -0
  96. data/test_site/docsupport/prism.css +0 -108
  97. data/test_site/docsupport/prism.js +0 -9
  98. data/test_site/docsupport/prototype-1.7.0.0.js +0 -6082
  99. data/test_site/docsupport/style.css +0 -219
  100. data/test_site/images/Blouse_Black.jpg +0 -0
  101. data/test_site/images/Granny.jpg +0 -0
  102. data/test_site/images/Printed_Dress.jpg +0 -0
  103. data/test_site/images/T-shirt.jpg +0 -0
  104. data/test_site/images/Wilder.jpg +0 -0
  105. data/test_site/images/You_Betcha.jpg +0 -0
  106. data/test_site/images/jeans3.jpg +0 -0
  107. data/test_site/indexed_sections_page.html +0 -215
  108. data/test_site/media/MIB2-subtitles-pt-BR.vtt +0 -49
  109. data/test_site/media/MIB2.mp4 +0 -0
  110. data/test_site/media/MP4_small.mp4 +0 -0
  111. data/test_site/media/MPS_sample.mp3 +0 -0
  112. data/test_site/media/bbc_scotland_report.mp3 +0 -0
  113. data/test_site/media/count_and_bars.mp4 +0 -0
  114. data/test_site/media_page.html +0 -86
  115. data/testcentricity_web.gemspec +0 -59
@@ -1,1359 +0,0 @@
1
- /*!
2
- Chosen, a Select Box Enhancer for jQuery and Prototype
3
- by Patrick Filler for Harvest, http://getharvest.com
4
-
5
- Version 1.8.7
6
- Full source at https://github.com/harvesthq/chosen
7
- Copyright (c) 2011-2018 Harvest http://getharvest.com
8
-
9
- MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
10
- This file is generated by `grunt build`, do not edit it by hand.
11
- */
12
-
13
- (function() {
14
- var $, AbstractChosen, Chosen, SelectParser,
15
- bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
16
- extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
17
- hasProp = {}.hasOwnProperty;
18
-
19
- SelectParser = (function() {
20
- function SelectParser() {
21
- this.options_index = 0;
22
- this.parsed = [];
23
- }
24
-
25
- SelectParser.prototype.add_node = function(child) {
26
- if (child.nodeName.toUpperCase() === "OPTGROUP") {
27
- return this.add_group(child);
28
- } else {
29
- return this.add_option(child);
30
- }
31
- };
32
-
33
- SelectParser.prototype.add_group = function(group) {
34
- var group_position, i, len, option, ref, results1;
35
- group_position = this.parsed.length;
36
- this.parsed.push({
37
- array_index: group_position,
38
- group: true,
39
- label: group.label,
40
- title: group.title ? group.title : void 0,
41
- children: 0,
42
- disabled: group.disabled,
43
- classes: group.className
44
- });
45
- ref = group.childNodes;
46
- results1 = [];
47
- for (i = 0, len = ref.length; i < len; i++) {
48
- option = ref[i];
49
- results1.push(this.add_option(option, group_position, group.disabled));
50
- }
51
- return results1;
52
- };
53
-
54
- SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
55
- if (option.nodeName.toUpperCase() === "OPTION") {
56
- if (option.text !== "") {
57
- if (group_position != null) {
58
- this.parsed[group_position].children += 1;
59
- }
60
- this.parsed.push({
61
- array_index: this.parsed.length,
62
- options_index: this.options_index,
63
- value: option.value,
64
- text: option.text,
65
- html: option.innerHTML,
66
- title: option.title ? option.title : void 0,
67
- selected: option.selected,
68
- disabled: group_disabled === true ? group_disabled : option.disabled,
69
- group_array_index: group_position,
70
- group_label: group_position != null ? this.parsed[group_position].label : null,
71
- classes: option.className,
72
- style: option.style.cssText
73
- });
74
- } else {
75
- this.parsed.push({
76
- array_index: this.parsed.length,
77
- options_index: this.options_index,
78
- empty: true
79
- });
80
- }
81
- return this.options_index += 1;
82
- }
83
- };
84
-
85
- return SelectParser;
86
-
87
- })();
88
-
89
- SelectParser.select_to_array = function(select) {
90
- var child, i, len, parser, ref;
91
- parser = new SelectParser();
92
- ref = select.childNodes;
93
- for (i = 0, len = ref.length; i < len; i++) {
94
- child = ref[i];
95
- parser.add_node(child);
96
- }
97
- return parser.parsed;
98
- };
99
-
100
- AbstractChosen = (function() {
101
- function AbstractChosen(form_field, options1) {
102
- this.form_field = form_field;
103
- this.options = options1 != null ? options1 : {};
104
- this.label_click_handler = bind(this.label_click_handler, this);
105
- if (!AbstractChosen.browser_is_supported()) {
106
- return;
107
- }
108
- this.is_multiple = this.form_field.multiple;
109
- this.set_default_text();
110
- this.set_default_values();
111
- this.setup();
112
- this.set_up_html();
113
- this.register_observers();
114
- this.on_ready();
115
- }
116
-
117
- AbstractChosen.prototype.set_default_values = function() {
118
- this.click_test_action = (function(_this) {
119
- return function(evt) {
120
- return _this.test_active_click(evt);
121
- };
122
- })(this);
123
- this.activate_action = (function(_this) {
124
- return function(evt) {
125
- return _this.activate_field(evt);
126
- };
127
- })(this);
128
- this.active_field = false;
129
- this.mouse_on_container = false;
130
- this.results_showing = false;
131
- this.result_highlighted = null;
132
- this.is_rtl = this.options.rtl || /\bchosen-rtl\b/.test(this.form_field.className);
133
- this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
134
- this.disable_search_threshold = this.options.disable_search_threshold || 0;
135
- this.disable_search = this.options.disable_search || false;
136
- this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
137
- this.group_search = this.options.group_search != null ? this.options.group_search : true;
138
- this.search_contains = this.options.search_contains || false;
139
- this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
140
- this.max_selected_options = this.options.max_selected_options || Infinity;
141
- this.inherit_select_classes = this.options.inherit_select_classes || false;
142
- this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
143
- this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
144
- this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
145
- this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
146
- this.case_sensitive_search = this.options.case_sensitive_search || false;
147
- return this.hide_results_on_select = this.options.hide_results_on_select != null ? this.options.hide_results_on_select : true;
148
- };
149
-
150
- AbstractChosen.prototype.set_default_text = function() {
151
- if (this.form_field.getAttribute("data-placeholder")) {
152
- this.default_text = this.form_field.getAttribute("data-placeholder");
153
- } else if (this.is_multiple) {
154
- this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
155
- } else {
156
- this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
157
- }
158
- this.default_text = this.escape_html(this.default_text);
159
- return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
160
- };
161
-
162
- AbstractChosen.prototype.choice_label = function(item) {
163
- if (this.include_group_label_in_selected && (item.group_label != null)) {
164
- return "<b class='group-name'>" + (this.escape_html(item.group_label)) + "</b>" + item.html;
165
- } else {
166
- return item.html;
167
- }
168
- };
169
-
170
- AbstractChosen.prototype.mouse_enter = function() {
171
- return this.mouse_on_container = true;
172
- };
173
-
174
- AbstractChosen.prototype.mouse_leave = function() {
175
- return this.mouse_on_container = false;
176
- };
177
-
178
- AbstractChosen.prototype.input_focus = function(evt) {
179
- if (this.is_multiple) {
180
- if (!this.active_field) {
181
- return setTimeout(((function(_this) {
182
- return function() {
183
- return _this.container_mousedown();
184
- };
185
- })(this)), 50);
186
- }
187
- } else {
188
- if (!this.active_field) {
189
- return this.activate_field();
190
- }
191
- }
192
- };
193
-
194
- AbstractChosen.prototype.input_blur = function(evt) {
195
- if (!this.mouse_on_container) {
196
- this.active_field = false;
197
- return setTimeout(((function(_this) {
198
- return function() {
199
- return _this.blur_test();
200
- };
201
- })(this)), 100);
202
- }
203
- };
204
-
205
- AbstractChosen.prototype.label_click_handler = function(evt) {
206
- if (this.is_multiple) {
207
- return this.container_mousedown(evt);
208
- } else {
209
- return this.activate_field();
210
- }
211
- };
212
-
213
- AbstractChosen.prototype.results_option_build = function(options) {
214
- var content, data, data_content, i, len, ref, shown_results;
215
- content = '';
216
- shown_results = 0;
217
- ref = this.results_data;
218
- for (i = 0, len = ref.length; i < len; i++) {
219
- data = ref[i];
220
- data_content = '';
221
- if (data.group) {
222
- data_content = this.result_add_group(data);
223
- } else {
224
- data_content = this.result_add_option(data);
225
- }
226
- if (data_content !== '') {
227
- shown_results++;
228
- content += data_content;
229
- }
230
- if (options != null ? options.first : void 0) {
231
- if (data.selected && this.is_multiple) {
232
- this.choice_build(data);
233
- } else if (data.selected && !this.is_multiple) {
234
- this.single_set_selected_text(this.choice_label(data));
235
- }
236
- }
237
- if (shown_results >= this.max_shown_results) {
238
- break;
239
- }
240
- }
241
- return content;
242
- };
243
-
244
- AbstractChosen.prototype.result_add_option = function(option) {
245
- var classes, option_el;
246
- if (!option.search_match) {
247
- return '';
248
- }
249
- if (!this.include_option_in_results(option)) {
250
- return '';
251
- }
252
- classes = [];
253
- if (!option.disabled && !(option.selected && this.is_multiple)) {
254
- classes.push("active-result");
255
- }
256
- if (option.disabled && !(option.selected && this.is_multiple)) {
257
- classes.push("disabled-result");
258
- }
259
- if (option.selected) {
260
- classes.push("result-selected");
261
- }
262
- if (option.group_array_index != null) {
263
- classes.push("group-option");
264
- }
265
- if (option.classes !== "") {
266
- classes.push(option.classes);
267
- }
268
- option_el = document.createElement("li");
269
- option_el.className = classes.join(" ");
270
- if (option.style) {
271
- option_el.style.cssText = option.style;
272
- }
273
- option_el.setAttribute("data-option-array-index", option.array_index);
274
- option_el.innerHTML = option.highlighted_html || option.html;
275
- if (option.title) {
276
- option_el.title = option.title;
277
- }
278
- return this.outerHTML(option_el);
279
- };
280
-
281
- AbstractChosen.prototype.result_add_group = function(group) {
282
- var classes, group_el;
283
- if (!(group.search_match || group.group_match)) {
284
- return '';
285
- }
286
- if (!(group.active_options > 0)) {
287
- return '';
288
- }
289
- classes = [];
290
- classes.push("group-result");
291
- if (group.classes) {
292
- classes.push(group.classes);
293
- }
294
- group_el = document.createElement("li");
295
- group_el.className = classes.join(" ");
296
- group_el.innerHTML = group.highlighted_html || this.escape_html(group.label);
297
- if (group.title) {
298
- group_el.title = group.title;
299
- }
300
- return this.outerHTML(group_el);
301
- };
302
-
303
- AbstractChosen.prototype.results_update_field = function() {
304
- this.set_default_text();
305
- if (!this.is_multiple) {
306
- this.results_reset_cleanup();
307
- }
308
- this.result_clear_highlight();
309
- this.results_build();
310
- if (this.results_showing) {
311
- return this.winnow_results();
312
- }
313
- };
314
-
315
- AbstractChosen.prototype.reset_single_select_options = function() {
316
- var i, len, ref, result, results1;
317
- ref = this.results_data;
318
- results1 = [];
319
- for (i = 0, len = ref.length; i < len; i++) {
320
- result = ref[i];
321
- if (result.selected) {
322
- results1.push(result.selected = false);
323
- } else {
324
- results1.push(void 0);
325
- }
326
- }
327
- return results1;
328
- };
329
-
330
- AbstractChosen.prototype.results_toggle = function() {
331
- if (this.results_showing) {
332
- return this.results_hide();
333
- } else {
334
- return this.results_show();
335
- }
336
- };
337
-
338
- AbstractChosen.prototype.results_search = function(evt) {
339
- if (this.results_showing) {
340
- return this.winnow_results();
341
- } else {
342
- return this.results_show();
343
- }
344
- };
345
-
346
- AbstractChosen.prototype.winnow_results = function(options) {
347
- var escapedQuery, fix, i, len, option, prefix, query, ref, regex, results, results_group, search_match, startpos, suffix, text;
348
- this.no_results_clear();
349
- results = 0;
350
- query = this.get_search_text();
351
- escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
352
- regex = this.get_search_regex(escapedQuery);
353
- ref = this.results_data;
354
- for (i = 0, len = ref.length; i < len; i++) {
355
- option = ref[i];
356
- option.search_match = false;
357
- results_group = null;
358
- search_match = null;
359
- option.highlighted_html = '';
360
- if (this.include_option_in_results(option)) {
361
- if (option.group) {
362
- option.group_match = false;
363
- option.active_options = 0;
364
- }
365
- if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
366
- results_group = this.results_data[option.group_array_index];
367
- if (results_group.active_options === 0 && results_group.search_match) {
368
- results += 1;
369
- }
370
- results_group.active_options += 1;
371
- }
372
- text = option.group ? option.label : option.text;
373
- if (!(option.group && !this.group_search)) {
374
- search_match = this.search_string_match(text, regex);
375
- option.search_match = search_match != null;
376
- if (option.search_match && !option.group) {
377
- results += 1;
378
- }
379
- if (option.search_match) {
380
- if (query.length) {
381
- startpos = search_match.index;
382
- prefix = text.slice(0, startpos);
383
- fix = text.slice(startpos, startpos + query.length);
384
- suffix = text.slice(startpos + query.length);
385
- option.highlighted_html = (this.escape_html(prefix)) + "<em>" + (this.escape_html(fix)) + "</em>" + (this.escape_html(suffix));
386
- }
387
- if (results_group != null) {
388
- results_group.group_match = true;
389
- }
390
- } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
391
- option.search_match = true;
392
- }
393
- }
394
- }
395
- }
396
- this.result_clear_highlight();
397
- if (results < 1 && query.length) {
398
- this.update_results_content("");
399
- return this.no_results(query);
400
- } else {
401
- this.update_results_content(this.results_option_build());
402
- if (!(options != null ? options.skip_highlight : void 0)) {
403
- return this.winnow_results_set_highlight();
404
- }
405
- }
406
- };
407
-
408
- AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
409
- var regex_flag, regex_string;
410
- regex_string = this.search_contains ? escaped_search_string : "(^|\\s|\\b)" + escaped_search_string + "[^\\s]*";
411
- if (!(this.enable_split_word_search || this.search_contains)) {
412
- regex_string = "^" + regex_string;
413
- }
414
- regex_flag = this.case_sensitive_search ? "" : "i";
415
- return new RegExp(regex_string, regex_flag);
416
- };
417
-
418
- AbstractChosen.prototype.search_string_match = function(search_string, regex) {
419
- var match;
420
- match = regex.exec(search_string);
421
- if (!this.search_contains && (match != null ? match[1] : void 0)) {
422
- match.index += 1;
423
- }
424
- return match;
425
- };
426
-
427
- AbstractChosen.prototype.choices_count = function() {
428
- var i, len, option, ref;
429
- if (this.selected_option_count != null) {
430
- return this.selected_option_count;
431
- }
432
- this.selected_option_count = 0;
433
- ref = this.form_field.options;
434
- for (i = 0, len = ref.length; i < len; i++) {
435
- option = ref[i];
436
- if (option.selected) {
437
- this.selected_option_count += 1;
438
- }
439
- }
440
- return this.selected_option_count;
441
- };
442
-
443
- AbstractChosen.prototype.choices_click = function(evt) {
444
- evt.preventDefault();
445
- this.activate_field();
446
- if (!(this.results_showing || this.is_disabled)) {
447
- return this.results_show();
448
- }
449
- };
450
-
451
- AbstractChosen.prototype.keydown_checker = function(evt) {
452
- var ref, stroke;
453
- stroke = (ref = evt.which) != null ? ref : evt.keyCode;
454
- this.search_field_scale();
455
- if (stroke !== 8 && this.pending_backstroke) {
456
- this.clear_backstroke();
457
- }
458
- switch (stroke) {
459
- case 8:
460
- this.backstroke_length = this.get_search_field_value().length;
461
- break;
462
- case 9:
463
- if (this.results_showing && !this.is_multiple) {
464
- this.result_select(evt);
465
- }
466
- this.mouse_on_container = false;
467
- break;
468
- case 13:
469
- if (this.results_showing) {
470
- evt.preventDefault();
471
- }
472
- break;
473
- case 27:
474
- if (this.results_showing) {
475
- evt.preventDefault();
476
- }
477
- break;
478
- case 32:
479
- if (this.disable_search) {
480
- evt.preventDefault();
481
- }
482
- break;
483
- case 38:
484
- evt.preventDefault();
485
- this.keyup_arrow();
486
- break;
487
- case 40:
488
- evt.preventDefault();
489
- this.keydown_arrow();
490
- break;
491
- }
492
- };
493
-
494
- AbstractChosen.prototype.keyup_checker = function(evt) {
495
- var ref, stroke;
496
- stroke = (ref = evt.which) != null ? ref : evt.keyCode;
497
- this.search_field_scale();
498
- switch (stroke) {
499
- case 8:
500
- if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
501
- this.keydown_backstroke();
502
- } else if (!this.pending_backstroke) {
503
- this.result_clear_highlight();
504
- this.results_search();
505
- }
506
- break;
507
- case 13:
508
- evt.preventDefault();
509
- if (this.results_showing) {
510
- this.result_select(evt);
511
- }
512
- break;
513
- case 27:
514
- if (this.results_showing) {
515
- this.results_hide();
516
- }
517
- break;
518
- case 9:
519
- case 16:
520
- case 17:
521
- case 18:
522
- case 38:
523
- case 40:
524
- case 91:
525
- break;
526
- default:
527
- this.results_search();
528
- break;
529
- }
530
- };
531
-
532
- AbstractChosen.prototype.clipboard_event_checker = function(evt) {
533
- if (this.is_disabled) {
534
- return;
535
- }
536
- return setTimeout(((function(_this) {
537
- return function() {
538
- return _this.results_search();
539
- };
540
- })(this)), 50);
541
- };
542
-
543
- AbstractChosen.prototype.container_width = function() {
544
- if (this.options.width != null) {
545
- return this.options.width;
546
- } else {
547
- return this.form_field.offsetWidth + "px";
548
- }
549
- };
550
-
551
- AbstractChosen.prototype.include_option_in_results = function(option) {
552
- if (this.is_multiple && (!this.display_selected_options && option.selected)) {
553
- return false;
554
- }
555
- if (!this.display_disabled_options && option.disabled) {
556
- return false;
557
- }
558
- if (option.empty) {
559
- return false;
560
- }
561
- return true;
562
- };
563
-
564
- AbstractChosen.prototype.search_results_touchstart = function(evt) {
565
- this.touch_started = true;
566
- return this.search_results_mouseover(evt);
567
- };
568
-
569
- AbstractChosen.prototype.search_results_touchmove = function(evt) {
570
- this.touch_started = false;
571
- return this.search_results_mouseout(evt);
572
- };
573
-
574
- AbstractChosen.prototype.search_results_touchend = function(evt) {
575
- if (this.touch_started) {
576
- return this.search_results_mouseup(evt);
577
- }
578
- };
579
-
580
- AbstractChosen.prototype.outerHTML = function(element) {
581
- var tmp;
582
- if (element.outerHTML) {
583
- return element.outerHTML;
584
- }
585
- tmp = document.createElement("div");
586
- tmp.appendChild(element);
587
- return tmp.innerHTML;
588
- };
589
-
590
- AbstractChosen.prototype.get_single_html = function() {
591
- return "<a class=\"chosen-single chosen-default\">\n <span>" + this.default_text + "</span>\n <div><b></b></div>\n</a>\n<div class=\"chosen-drop\">\n <div class=\"chosen-search\">\n <input class=\"chosen-search-input\" type=\"text\" autocomplete=\"off\" />\n </div>\n <ul class=\"chosen-results\"></ul>\n</div>";
592
- };
593
-
594
- AbstractChosen.prototype.get_multi_html = function() {
595
- return "<ul class=\"chosen-choices\">\n <li class=\"search-field\">\n <input class=\"chosen-search-input\" type=\"text\" autocomplete=\"off\" value=\"" + this.default_text + "\" />\n </li>\n</ul>\n<div class=\"chosen-drop\">\n <ul class=\"chosen-results\"></ul>\n</div>";
596
- };
597
-
598
- AbstractChosen.prototype.get_no_results_html = function(terms) {
599
- return "<li class=\"no-results\">\n " + this.results_none_found + " <span>" + (this.escape_html(terms)) + "</span>\n</li>";
600
- };
601
-
602
- AbstractChosen.browser_is_supported = function() {
603
- if ("Microsoft Internet Explorer" === window.navigator.appName) {
604
- return document.documentMode >= 8;
605
- }
606
- if (/iP(od|hone)/i.test(window.navigator.userAgent) || /IEMobile/i.test(window.navigator.userAgent) || /Windows Phone/i.test(window.navigator.userAgent) || /BlackBerry/i.test(window.navigator.userAgent) || /BB10/i.test(window.navigator.userAgent) || /Android.*Mobile/i.test(window.navigator.userAgent)) {
607
- return false;
608
- }
609
- return true;
610
- };
611
-
612
- AbstractChosen.default_multiple_text = "Select Some Options";
613
-
614
- AbstractChosen.default_single_text = "Select an Option";
615
-
616
- AbstractChosen.default_no_result_text = "No results match";
617
-
618
- return AbstractChosen;
619
-
620
- })();
621
-
622
- $ = jQuery;
623
-
624
- $.fn.extend({
625
- chosen: function(options) {
626
- if (!AbstractChosen.browser_is_supported()) {
627
- return this;
628
- }
629
- return this.each(function(input_field) {
630
- var $this, chosen;
631
- $this = $(this);
632
- chosen = $this.data('chosen');
633
- if (options === 'destroy') {
634
- if (chosen instanceof Chosen) {
635
- chosen.destroy();
636
- }
637
- return;
638
- }
639
- if (!(chosen instanceof Chosen)) {
640
- $this.data('chosen', new Chosen(this, options));
641
- }
642
- });
643
- }
644
- });
645
-
646
- Chosen = (function(superClass) {
647
- extend(Chosen, superClass);
648
-
649
- function Chosen() {
650
- return Chosen.__super__.constructor.apply(this, arguments);
651
- }
652
-
653
- Chosen.prototype.setup = function() {
654
- this.form_field_jq = $(this.form_field);
655
- return this.current_selectedIndex = this.form_field.selectedIndex;
656
- };
657
-
658
- Chosen.prototype.set_up_html = function() {
659
- var container_classes, container_props;
660
- container_classes = ["chosen-container"];
661
- container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
662
- if (this.inherit_select_classes && this.form_field.className) {
663
- container_classes.push(this.form_field.className);
664
- }
665
- if (this.is_rtl) {
666
- container_classes.push("chosen-rtl");
667
- }
668
- container_props = {
669
- 'class': container_classes.join(' '),
670
- 'title': this.form_field.title
671
- };
672
- if (this.form_field.id.length) {
673
- container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
674
- }
675
- this.container = $("<div />", container_props);
676
- this.container.width(this.container_width());
677
- if (this.is_multiple) {
678
- this.container.html(this.get_multi_html());
679
- } else {
680
- this.container.html(this.get_single_html());
681
- }
682
- this.form_field_jq.hide().after(this.container);
683
- this.dropdown = this.container.find('div.chosen-drop').first();
684
- this.search_field = this.container.find('input').first();
685
- this.search_results = this.container.find('ul.chosen-results').first();
686
- this.search_field_scale();
687
- this.search_no_results = this.container.find('li.no-results').first();
688
- if (this.is_multiple) {
689
- this.search_choices = this.container.find('ul.chosen-choices').first();
690
- this.search_container = this.container.find('li.search-field').first();
691
- } else {
692
- this.search_container = this.container.find('div.chosen-search').first();
693
- this.selected_item = this.container.find('.chosen-single').first();
694
- }
695
- this.results_build();
696
- this.set_tab_index();
697
- return this.set_label_behavior();
698
- };
699
-
700
- Chosen.prototype.on_ready = function() {
701
- return this.form_field_jq.trigger("chosen:ready", {
702
- chosen: this
703
- });
704
- };
705
-
706
- Chosen.prototype.register_observers = function() {
707
- this.container.on('touchstart.chosen', (function(_this) {
708
- return function(evt) {
709
- _this.container_mousedown(evt);
710
- };
711
- })(this));
712
- this.container.on('touchend.chosen', (function(_this) {
713
- return function(evt) {
714
- _this.container_mouseup(evt);
715
- };
716
- })(this));
717
- this.container.on('mousedown.chosen', (function(_this) {
718
- return function(evt) {
719
- _this.container_mousedown(evt);
720
- };
721
- })(this));
722
- this.container.on('mouseup.chosen', (function(_this) {
723
- return function(evt) {
724
- _this.container_mouseup(evt);
725
- };
726
- })(this));
727
- this.container.on('mouseenter.chosen', (function(_this) {
728
- return function(evt) {
729
- _this.mouse_enter(evt);
730
- };
731
- })(this));
732
- this.container.on('mouseleave.chosen', (function(_this) {
733
- return function(evt) {
734
- _this.mouse_leave(evt);
735
- };
736
- })(this));
737
- this.search_results.on('mouseup.chosen', (function(_this) {
738
- return function(evt) {
739
- _this.search_results_mouseup(evt);
740
- };
741
- })(this));
742
- this.search_results.on('mouseover.chosen', (function(_this) {
743
- return function(evt) {
744
- _this.search_results_mouseover(evt);
745
- };
746
- })(this));
747
- this.search_results.on('mouseout.chosen', (function(_this) {
748
- return function(evt) {
749
- _this.search_results_mouseout(evt);
750
- };
751
- })(this));
752
- this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) {
753
- return function(evt) {
754
- _this.search_results_mousewheel(evt);
755
- };
756
- })(this));
757
- this.search_results.on('touchstart.chosen', (function(_this) {
758
- return function(evt) {
759
- _this.search_results_touchstart(evt);
760
- };
761
- })(this));
762
- this.search_results.on('touchmove.chosen', (function(_this) {
763
- return function(evt) {
764
- _this.search_results_touchmove(evt);
765
- };
766
- })(this));
767
- this.search_results.on('touchend.chosen', (function(_this) {
768
- return function(evt) {
769
- _this.search_results_touchend(evt);
770
- };
771
- })(this));
772
- this.form_field_jq.on("chosen:updated.chosen", (function(_this) {
773
- return function(evt) {
774
- _this.results_update_field(evt);
775
- };
776
- })(this));
777
- this.form_field_jq.on("chosen:activate.chosen", (function(_this) {
778
- return function(evt) {
779
- _this.activate_field(evt);
780
- };
781
- })(this));
782
- this.form_field_jq.on("chosen:open.chosen", (function(_this) {
783
- return function(evt) {
784
- _this.container_mousedown(evt);
785
- };
786
- })(this));
787
- this.form_field_jq.on("chosen:close.chosen", (function(_this) {
788
- return function(evt) {
789
- _this.close_field(evt);
790
- };
791
- })(this));
792
- this.search_field.on('blur.chosen', (function(_this) {
793
- return function(evt) {
794
- _this.input_blur(evt);
795
- };
796
- })(this));
797
- this.search_field.on('keyup.chosen', (function(_this) {
798
- return function(evt) {
799
- _this.keyup_checker(evt);
800
- };
801
- })(this));
802
- this.search_field.on('keydown.chosen', (function(_this) {
803
- return function(evt) {
804
- _this.keydown_checker(evt);
805
- };
806
- })(this));
807
- this.search_field.on('focus.chosen', (function(_this) {
808
- return function(evt) {
809
- _this.input_focus(evt);
810
- };
811
- })(this));
812
- this.search_field.on('cut.chosen', (function(_this) {
813
- return function(evt) {
814
- _this.clipboard_event_checker(evt);
815
- };
816
- })(this));
817
- this.search_field.on('paste.chosen', (function(_this) {
818
- return function(evt) {
819
- _this.clipboard_event_checker(evt);
820
- };
821
- })(this));
822
- if (this.is_multiple) {
823
- return this.search_choices.on('click.chosen', (function(_this) {
824
- return function(evt) {
825
- _this.choices_click(evt);
826
- };
827
- })(this));
828
- } else {
829
- return this.container.on('click.chosen', function(evt) {
830
- evt.preventDefault();
831
- });
832
- }
833
- };
834
-
835
- Chosen.prototype.destroy = function() {
836
- $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action);
837
- if (this.form_field_label.length > 0) {
838
- this.form_field_label.off('click.chosen');
839
- }
840
- if (this.search_field[0].tabIndex) {
841
- this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
842
- }
843
- this.container.remove();
844
- this.form_field_jq.removeData('chosen');
845
- return this.form_field_jq.show();
846
- };
847
-
848
- Chosen.prototype.search_field_disabled = function() {
849
- this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled');
850
- this.container.toggleClass('chosen-disabled', this.is_disabled);
851
- this.search_field[0].disabled = this.is_disabled;
852
- if (!this.is_multiple) {
853
- this.selected_item.off('focus.chosen', this.activate_field);
854
- }
855
- if (this.is_disabled) {
856
- return this.close_field();
857
- } else if (!this.is_multiple) {
858
- return this.selected_item.on('focus.chosen', this.activate_field);
859
- }
860
- };
861
-
862
- Chosen.prototype.container_mousedown = function(evt) {
863
- var ref;
864
- if (this.is_disabled) {
865
- return;
866
- }
867
- if (evt && ((ref = evt.type) === 'mousedown' || ref === 'touchstart') && !this.results_showing) {
868
- evt.preventDefault();
869
- }
870
- if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
871
- if (!this.active_field) {
872
- if (this.is_multiple) {
873
- this.search_field.val("");
874
- }
875
- $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action);
876
- this.results_show();
877
- } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
878
- evt.preventDefault();
879
- this.results_toggle();
880
- }
881
- return this.activate_field();
882
- }
883
- };
884
-
885
- Chosen.prototype.container_mouseup = function(evt) {
886
- if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
887
- return this.results_reset(evt);
888
- }
889
- };
890
-
891
- Chosen.prototype.search_results_mousewheel = function(evt) {
892
- var delta;
893
- if (evt.originalEvent) {
894
- delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
895
- }
896
- if (delta != null) {
897
- evt.preventDefault();
898
- if (evt.type === 'DOMMouseScroll') {
899
- delta = delta * 40;
900
- }
901
- return this.search_results.scrollTop(delta + this.search_results.scrollTop());
902
- }
903
- };
904
-
905
- Chosen.prototype.blur_test = function(evt) {
906
- if (!this.active_field && this.container.hasClass("chosen-container-active")) {
907
- return this.close_field();
908
- }
909
- };
910
-
911
- Chosen.prototype.close_field = function() {
912
- $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action);
913
- this.active_field = false;
914
- this.results_hide();
915
- this.container.removeClass("chosen-container-active");
916
- this.clear_backstroke();
917
- this.show_search_field_default();
918
- this.search_field_scale();
919
- return this.search_field.blur();
920
- };
921
-
922
- Chosen.prototype.activate_field = function() {
923
- if (this.is_disabled) {
924
- return;
925
- }
926
- this.container.addClass("chosen-container-active");
927
- this.active_field = true;
928
- this.search_field.val(this.search_field.val());
929
- return this.search_field.focus();
930
- };
931
-
932
- Chosen.prototype.test_active_click = function(evt) {
933
- var active_container;
934
- active_container = $(evt.target).closest('.chosen-container');
935
- if (active_container.length && this.container[0] === active_container[0]) {
936
- return this.active_field = true;
937
- } else {
938
- return this.close_field();
939
- }
940
- };
941
-
942
- Chosen.prototype.results_build = function() {
943
- this.parsing = true;
944
- this.selected_option_count = null;
945
- this.results_data = SelectParser.select_to_array(this.form_field);
946
- if (this.is_multiple) {
947
- this.search_choices.find("li.search-choice").remove();
948
- } else {
949
- this.single_set_selected_text();
950
- if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
951
- this.search_field[0].readOnly = true;
952
- this.container.addClass("chosen-container-single-nosearch");
953
- } else {
954
- this.search_field[0].readOnly = false;
955
- this.container.removeClass("chosen-container-single-nosearch");
956
- }
957
- }
958
- this.update_results_content(this.results_option_build({
959
- first: true
960
- }));
961
- this.search_field_disabled();
962
- this.show_search_field_default();
963
- this.search_field_scale();
964
- return this.parsing = false;
965
- };
966
-
967
- Chosen.prototype.result_do_highlight = function(el) {
968
- var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
969
- if (el.length) {
970
- this.result_clear_highlight();
971
- this.result_highlight = el;
972
- this.result_highlight.addClass("highlighted");
973
- maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
974
- visible_top = this.search_results.scrollTop();
975
- visible_bottom = maxHeight + visible_top;
976
- high_top = this.result_highlight.position().top + this.search_results.scrollTop();
977
- high_bottom = high_top + this.result_highlight.outerHeight();
978
- if (high_bottom >= visible_bottom) {
979
- return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
980
- } else if (high_top < visible_top) {
981
- return this.search_results.scrollTop(high_top);
982
- }
983
- }
984
- };
985
-
986
- Chosen.prototype.result_clear_highlight = function() {
987
- if (this.result_highlight) {
988
- this.result_highlight.removeClass("highlighted");
989
- }
990
- return this.result_highlight = null;
991
- };
992
-
993
- Chosen.prototype.results_show = function() {
994
- if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
995
- this.form_field_jq.trigger("chosen:maxselected", {
996
- chosen: this
997
- });
998
- return false;
999
- }
1000
- this.container.addClass("chosen-with-drop");
1001
- this.results_showing = true;
1002
- this.search_field.focus();
1003
- this.search_field.val(this.get_search_field_value());
1004
- this.winnow_results();
1005
- return this.form_field_jq.trigger("chosen:showing_dropdown", {
1006
- chosen: this
1007
- });
1008
- };
1009
-
1010
- Chosen.prototype.update_results_content = function(content) {
1011
- return this.search_results.html(content);
1012
- };
1013
-
1014
- Chosen.prototype.results_hide = function() {
1015
- if (this.results_showing) {
1016
- this.result_clear_highlight();
1017
- this.container.removeClass("chosen-with-drop");
1018
- this.form_field_jq.trigger("chosen:hiding_dropdown", {
1019
- chosen: this
1020
- });
1021
- }
1022
- return this.results_showing = false;
1023
- };
1024
-
1025
- Chosen.prototype.set_tab_index = function(el) {
1026
- var ti;
1027
- if (this.form_field.tabIndex) {
1028
- ti = this.form_field.tabIndex;
1029
- this.form_field.tabIndex = -1;
1030
- return this.search_field[0].tabIndex = ti;
1031
- }
1032
- };
1033
-
1034
- Chosen.prototype.set_label_behavior = function() {
1035
- this.form_field_label = this.form_field_jq.parents("label");
1036
- if (!this.form_field_label.length && this.form_field.id.length) {
1037
- this.form_field_label = $("label[for='" + this.form_field.id + "']");
1038
- }
1039
- if (this.form_field_label.length > 0) {
1040
- return this.form_field_label.on('click.chosen', this.label_click_handler);
1041
- }
1042
- };
1043
-
1044
- Chosen.prototype.show_search_field_default = function() {
1045
- if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
1046
- this.search_field.val(this.default_text);
1047
- return this.search_field.addClass("default");
1048
- } else {
1049
- this.search_field.val("");
1050
- return this.search_field.removeClass("default");
1051
- }
1052
- };
1053
-
1054
- Chosen.prototype.search_results_mouseup = function(evt) {
1055
- var target;
1056
- target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
1057
- if (target.length) {
1058
- this.result_highlight = target;
1059
- this.result_select(evt);
1060
- return this.search_field.focus();
1061
- }
1062
- };
1063
-
1064
- Chosen.prototype.search_results_mouseover = function(evt) {
1065
- var target;
1066
- target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
1067
- if (target) {
1068
- return this.result_do_highlight(target);
1069
- }
1070
- };
1071
-
1072
- Chosen.prototype.search_results_mouseout = function(evt) {
1073
- if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) {
1074
- return this.result_clear_highlight();
1075
- }
1076
- };
1077
-
1078
- Chosen.prototype.choice_build = function(item) {
1079
- var choice, close_link;
1080
- choice = $('<li />', {
1081
- "class": "search-choice"
1082
- }).html("<span>" + (this.choice_label(item)) + "</span>");
1083
- if (item.disabled) {
1084
- choice.addClass('search-choice-disabled');
1085
- } else {
1086
- close_link = $('<a />', {
1087
- "class": 'search-choice-close',
1088
- 'data-option-array-index': item.array_index
1089
- });
1090
- close_link.on('click.chosen', (function(_this) {
1091
- return function(evt) {
1092
- return _this.choice_destroy_link_click(evt);
1093
- };
1094
- })(this));
1095
- choice.append(close_link);
1096
- }
1097
- return this.search_container.before(choice);
1098
- };
1099
-
1100
- Chosen.prototype.choice_destroy_link_click = function(evt) {
1101
- evt.preventDefault();
1102
- evt.stopPropagation();
1103
- if (!this.is_disabled) {
1104
- return this.choice_destroy($(evt.target));
1105
- }
1106
- };
1107
-
1108
- Chosen.prototype.choice_destroy = function(link) {
1109
- if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
1110
- if (this.active_field) {
1111
- this.search_field.focus();
1112
- } else {
1113
- this.show_search_field_default();
1114
- }
1115
- if (this.is_multiple && this.choices_count() > 0 && this.get_search_field_value().length < 1) {
1116
- this.results_hide();
1117
- }
1118
- link.parents('li').first().remove();
1119
- return this.search_field_scale();
1120
- }
1121
- };
1122
-
1123
- Chosen.prototype.results_reset = function() {
1124
- this.reset_single_select_options();
1125
- this.form_field.options[0].selected = true;
1126
- this.single_set_selected_text();
1127
- this.show_search_field_default();
1128
- this.results_reset_cleanup();
1129
- this.trigger_form_field_change();
1130
- if (this.active_field) {
1131
- return this.results_hide();
1132
- }
1133
- };
1134
-
1135
- Chosen.prototype.results_reset_cleanup = function() {
1136
- this.current_selectedIndex = this.form_field.selectedIndex;
1137
- return this.selected_item.find("abbr").remove();
1138
- };
1139
-
1140
- Chosen.prototype.result_select = function(evt) {
1141
- var high, item;
1142
- if (this.result_highlight) {
1143
- high = this.result_highlight;
1144
- this.result_clear_highlight();
1145
- if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
1146
- this.form_field_jq.trigger("chosen:maxselected", {
1147
- chosen: this
1148
- });
1149
- return false;
1150
- }
1151
- if (this.is_multiple) {
1152
- high.removeClass("active-result");
1153
- } else {
1154
- this.reset_single_select_options();
1155
- }
1156
- high.addClass("result-selected");
1157
- item = this.results_data[high[0].getAttribute("data-option-array-index")];
1158
- item.selected = true;
1159
- this.form_field.options[item.options_index].selected = true;
1160
- this.selected_option_count = null;
1161
- if (this.is_multiple) {
1162
- this.choice_build(item);
1163
- } else {
1164
- this.single_set_selected_text(this.choice_label(item));
1165
- }
1166
- if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) {
1167
- if (evt.metaKey || evt.ctrlKey) {
1168
- this.winnow_results({
1169
- skip_highlight: true
1170
- });
1171
- } else {
1172
- this.search_field.val("");
1173
- this.winnow_results();
1174
- }
1175
- } else {
1176
- this.results_hide();
1177
- this.show_search_field_default();
1178
- }
1179
- if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
1180
- this.trigger_form_field_change({
1181
- selected: this.form_field.options[item.options_index].value
1182
- });
1183
- }
1184
- this.current_selectedIndex = this.form_field.selectedIndex;
1185
- evt.preventDefault();
1186
- return this.search_field_scale();
1187
- }
1188
- };
1189
-
1190
- Chosen.prototype.single_set_selected_text = function(text) {
1191
- if (text == null) {
1192
- text = this.default_text;
1193
- }
1194
- if (text === this.default_text) {
1195
- this.selected_item.addClass("chosen-default");
1196
- } else {
1197
- this.single_deselect_control_build();
1198
- this.selected_item.removeClass("chosen-default");
1199
- }
1200
- return this.selected_item.find("span").html(text);
1201
- };
1202
-
1203
- Chosen.prototype.result_deselect = function(pos) {
1204
- var result_data;
1205
- result_data = this.results_data[pos];
1206
- if (!this.form_field.options[result_data.options_index].disabled) {
1207
- result_data.selected = false;
1208
- this.form_field.options[result_data.options_index].selected = false;
1209
- this.selected_option_count = null;
1210
- this.result_clear_highlight();
1211
- if (this.results_showing) {
1212
- this.winnow_results();
1213
- }
1214
- this.trigger_form_field_change({
1215
- deselected: this.form_field.options[result_data.options_index].value
1216
- });
1217
- this.search_field_scale();
1218
- return true;
1219
- } else {
1220
- return false;
1221
- }
1222
- };
1223
-
1224
- Chosen.prototype.single_deselect_control_build = function() {
1225
- if (!this.allow_single_deselect) {
1226
- return;
1227
- }
1228
- if (!this.selected_item.find("abbr").length) {
1229
- this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
1230
- }
1231
- return this.selected_item.addClass("chosen-single-with-deselect");
1232
- };
1233
-
1234
- Chosen.prototype.get_search_field_value = function() {
1235
- return this.search_field.val();
1236
- };
1237
-
1238
- Chosen.prototype.get_search_text = function() {
1239
- return $.trim(this.get_search_field_value());
1240
- };
1241
-
1242
- Chosen.prototype.escape_html = function(text) {
1243
- return $('<div/>').text(text).html();
1244
- };
1245
-
1246
- Chosen.prototype.winnow_results_set_highlight = function() {
1247
- var do_high, selected_results;
1248
- selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
1249
- do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
1250
- if (do_high != null) {
1251
- return this.result_do_highlight(do_high);
1252
- }
1253
- };
1254
-
1255
- Chosen.prototype.no_results = function(terms) {
1256
- var no_results_html;
1257
- no_results_html = this.get_no_results_html(terms);
1258
- this.search_results.append(no_results_html);
1259
- return this.form_field_jq.trigger("chosen:no_results", {
1260
- chosen: this
1261
- });
1262
- };
1263
-
1264
- Chosen.prototype.no_results_clear = function() {
1265
- return this.search_results.find(".no-results").remove();
1266
- };
1267
-
1268
- Chosen.prototype.keydown_arrow = function() {
1269
- var next_sib;
1270
- if (this.results_showing && this.result_highlight) {
1271
- next_sib = this.result_highlight.nextAll("li.active-result").first();
1272
- if (next_sib) {
1273
- return this.result_do_highlight(next_sib);
1274
- }
1275
- } else {
1276
- return this.results_show();
1277
- }
1278
- };
1279
-
1280
- Chosen.prototype.keyup_arrow = function() {
1281
- var prev_sibs;
1282
- if (!this.results_showing && !this.is_multiple) {
1283
- return this.results_show();
1284
- } else if (this.result_highlight) {
1285
- prev_sibs = this.result_highlight.prevAll("li.active-result");
1286
- if (prev_sibs.length) {
1287
- return this.result_do_highlight(prev_sibs.first());
1288
- } else {
1289
- if (this.choices_count() > 0) {
1290
- this.results_hide();
1291
- }
1292
- return this.result_clear_highlight();
1293
- }
1294
- }
1295
- };
1296
-
1297
- Chosen.prototype.keydown_backstroke = function() {
1298
- var next_available_destroy;
1299
- if (this.pending_backstroke) {
1300
- this.choice_destroy(this.pending_backstroke.find("a").first());
1301
- return this.clear_backstroke();
1302
- } else {
1303
- next_available_destroy = this.search_container.siblings("li.search-choice").last();
1304
- if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
1305
- this.pending_backstroke = next_available_destroy;
1306
- if (this.single_backstroke_delete) {
1307
- return this.keydown_backstroke();
1308
- } else {
1309
- return this.pending_backstroke.addClass("search-choice-focus");
1310
- }
1311
- }
1312
- }
1313
- };
1314
-
1315
- Chosen.prototype.clear_backstroke = function() {
1316
- if (this.pending_backstroke) {
1317
- this.pending_backstroke.removeClass("search-choice-focus");
1318
- }
1319
- return this.pending_backstroke = null;
1320
- };
1321
-
1322
- Chosen.prototype.search_field_scale = function() {
1323
- var div, i, len, style, style_block, styles, width;
1324
- if (!this.is_multiple) {
1325
- return;
1326
- }
1327
- style_block = {
1328
- position: 'absolute',
1329
- left: '-1000px',
1330
- top: '-1000px',
1331
- display: 'none',
1332
- whiteSpace: 'pre'
1333
- };
1334
- styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing'];
1335
- for (i = 0, len = styles.length; i < len; i++) {
1336
- style = styles[i];
1337
- style_block[style] = this.search_field.css(style);
1338
- }
1339
- div = $('<div />').css(style_block);
1340
- div.text(this.get_search_field_value());
1341
- $('body').append(div);
1342
- width = div.width() + 25;
1343
- div.remove();
1344
- if (this.container.is(':visible')) {
1345
- width = Math.min(this.container.outerWidth() - 10, width);
1346
- }
1347
- return this.search_field.width(width);
1348
- };
1349
-
1350
- Chosen.prototype.trigger_form_field_change = function(extra) {
1351
- this.form_field_jq.trigger("input", extra);
1352
- return this.form_field_jq.trigger("change", extra);
1353
- };
1354
-
1355
- return Chosen;
1356
-
1357
- })(AbstractChosen);
1358
-
1359
- }).call(this);