PageSourceSearch

https://masharikirpc.org/wp-content/plugins/wp-event-manager/asset…/chosen.jquery.min.js?ver=1.1.0

js masharikirpc.org collected 2026-10-02 19:49:23 UTC 45,589 bytes, 3,685 lines download raw bytes

vendor: 17,233 bytes, lines 1-1396
1/*!
2
3
4Chosen, a Select Box Enhancer for jQuery and Prototype
5
6
7by Patrick Filler for Harvest, http://getharvest.com
8
9
10
11
12
13Version 1.2.0
14
15
16Full source at https://github.com/harvesthq/chosen
17
18
19Copyright (c) 2011-2014 Harvest http://getharvest.com
20
21
22
23
24
25MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
26
27
28This file is generated by `grunt build`, do not edit it by hand.
29
30
31*/
32
33
34
35
36
37(function() {
38
39
40  var $, AbstractChosen, Chosen, SelectParser, _ref,
41
42
43    __hasProp = {}.hasOwnProperty,
44
45
46    __extends = 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; };
47
48
49
50
51
52  SelectParser = (function() {
53
54
55    function SelectParser() {
56
57
58      this.options_index = 0;
59
60
61      this.parsed = [];
62
63
64    }
65
66
67
68
69
70    SelectParser.prototype.add_node = function(child) {
71
72
73      if (child.nodeName.toUpperCase() === "OPTGROUP") {
74
75
76        return this.add_group(child);
77
78
79      } else {
80
81
82        return this.add_option(child);
83
84
85      }
86
87
88    };
89
90
91
92
93
94    SelectParser.prototype.add_group = function(group) {
95
96
97      var group_position, option, _i, _len, _ref, _results;
98
99
100      group_position = this.parsed.length;
101
102
103      this.parsed.push({
104
105
106        array_index: group_position,
107
108
109        group: true,
110
111
112        label: this.escapeExpression(group.label),
113
114
115        children: 0,
116
117
118        disabled: group.disabled
119
120
121      });
122
123
124      _ref = group.childNodes;
125
126
127      _results = [];
128
129
130      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
131
132
133        option = _ref[_i];
134
135
136        _results.push(this.add_option(option, group_position, group.disabled));
137
138
139      }
140
141
142      return _results;
143
144
145    };
146
147
148
149
150
151    SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
152
153
154      if (option.nodeName.toUpperCase() === "OPTION") {
155
156
157        if (option.text !== "") {
158
159
160          if (group_position != null) {
161
162
163            this.parsed[group_position].children += 1;
164
165
166          }
167
168
169          this.parsed.push({
170
171
172            array_index: this.parsed.length,
173
174
175            options_index: this.options_index,
176
177
178            value: option.value,
179
180
181            text: option.text,
182
183
184            html: option.innerHTML,
185
186
187            selected: option.selected,
188
189
190            disabled: group_disabled === true ? group_disabled : option.disabled,
191
192
193            group_array_index: group_position,
194
195
196            classes: option.className,
197
198
199            style: option.style.cssText
200
201
202          });
203
204
205        } else {
206
207
208          this.parsed.push({
209
210
211            array_index: this.parsed.length,
212
213
214            options_index: this.options_index,
215
216
217            empty: true
218
219
220          });
221
222
223        }
224
225
226        return this.options_index += 1;
227
228
229      }
230
231
232    };
233
234
235
236
237
238    SelectParser.prototype.escapeExpression = function(text) {
239
240
241      var map, unsafe_chars;
242
243
244      if ((text == null) || text === false) {
245
246
247        return "";
248
249
250      }
251
252
253      if (!/[\&\<\>\"\'\`]/.test(text)) {
254
255
256        return text;
257
258
259      }
260
261
262      map = {
263
264
265        "<": "&lt;",
266
267
268        ">": "&gt;",
269
270
271        '"': "&quot;",
272
273
274        "'": "&#x27;",
275
276
277        "`": "&#x60;"
278
279
280      };
281
282
283      unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g;
284
285
286      return text.replace(unsafe_chars, function(chr) {
287
288
289        return map[chr] || "&amp;";
290
291
292      });
293
294
295    };
296
297
298
299
300
301    return SelectParser;
302
303
304
305
306
307  })();
308
309
310
311
312
313  SelectParser.select_to_array = function(select) {
314
315
316    var child, parser, _i, _len, _ref;
317
318
319    parser = new SelectParser();
320
321
322    _ref = select.childNodes;
323
324
325    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
326
327
328      child = _ref[_i];
329
330
331      parser.add_node(child);
332
333
334    }
335
336
337    return parser.parsed;
338
339
340  };
341
342
343
344
345
346  AbstractChosen = (function() {
347
348
349    function AbstractChosen(form_field, options) {
350
351
352      this.form_field = form_field;
353
354
355      this.options = options != null ? options : {};
356
357
358      if (!AbstractChosen.browser_is_supported()) {
359
360
361        return;
362
363
364      }
365
366
367      this.is_multiple = this.form_field.multiple;
368
369
370      this.set_default_text();
371
372
373      this.set_default_values();
374
375
376      this.setup();
377
378
379      this.set_up_html();
380
381
382      this.register_observers();
383
384
385    }
386
387
388
389
390
391    AbstractChosen.prototype.set_default_values = function() {
392
393
394      var _this = this;
395
396
397      this.click_test_action = function(evt) {
398
399
400        return _this.test_active_click(evt);
401
402
403      };
404
405
406      this.activate_action = function(evt) {
407
408
409        return _this.activate_field(evt);
410
411
412      };
413
414
415      this.active_field = false;
416
417
418      this.mouse_on_container = false;
419
420
421      this.results_showing = false;
422
423
424      this.result_highlighted = null;
425
426
427      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;
428
429
430      this.disable_search_threshold = this.options.disable_search_threshold || 0;
431
432
433      this.disable_search = this.options.disable_search || false;
434
435
436      this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
437
438
439      this.group_search = this.options.group_search != null ? this.options.group_search : true;
440
441
442      this.search_contains = this.options.search_contains || false;
443
444
445      this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
446
447
448      this.max_selected_options = this.options.max_selected_options || Infinity;
449
450
451      this.inherit_select_classes = this.options.inherit_select_classes || false;
452
453
454      this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
455
456
457      return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
458
459
460    };
461
462
463
464
465
466    AbstractChosen.prototype.set_default_text = function() {
467
468
469      if (this.form_field.getAttribute("data-multiple_text")) {
470
471
472        this.default_text = this.form_field.getAttribute("data-multiple_text");
473
474
475      } else if (this.is_multiple) {
476
477
478        this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
479
480
481      } else {
482
483
484        this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
485
486
487      }
488
489
490      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
491
492
493    };
494
495
496
497
498
499    AbstractChosen.prototype.mouse_enter = function() {
500
501
502      return this.mouse_on_container = true;
503
504
505    };
506
507
508
509
510
511    AbstractChosen.prototype.mouse_leave = function() {
512
513
514      return this.mouse_on_container = false;
515
516
517    };
518
519
520
521
522
523    AbstractChosen.prototype.input_focus = function(evt) {
524
525
526      var _this = this;
527
528
529      if (this.is_multiple) {
530
531
532        if (!this.active_field) {
533
534
535          return setTimeout((function() {
536
537
538            return _this.container_mousedown();
539
540
541          }), 50);
542
543
544        }
545
546
547      } else {
548
549
550        if (!this.active_field) {
551
552
553          return this.activate_field();
554
555
556        }
557
558
559      }
560
561
562    };
563
564
565
566
567
568    AbstractChosen.prototype.input_blur = function(evt) {
569
570
571      var _this = this;
572
573
574      if (!this.mouse_on_container) {
575
576
577        this.active_field = false;
578
579
580        return setTimeout((function() {
581
582
583          return _this.blur_test();
584
585
586        }), 100);
587
588
589      }
590
591
592    };
593
594
595
596
597
598    AbstractChosen.prototype.results_option_build = function(options) {
599
600
601      var content, data, _i, _len, _ref;
602
603
604      content = '';
605
606
607      _ref = this.results_data;
608
609
610      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
611
612
613        data = _ref[_i];
614
615
616        if (data.group) {
617
618
619          content += this.result_add_group(data);
620
621
622        } else {
623
624
625          content += this.result_add_option(data);
626
627
628        }
629
630
631        if (options != null ? options.first : void 0) {
632
633
634          if (data.selected && this.is_multiple) {
635
636
637            this.choice_build(data);
638
639
640          } else if (data.selected && !this.is_multiple) {
641
642
643            this.single_set_selected_text(data.text);
644
645
646          }
647
648
649        }
650
651
652      }
653
654
655      return content;
656
657
658    };
659
660
661
662
663
664    AbstractChosen.prototype.result_add_option = function(option) {
665
666
667      var classes, option_el;
668
669
670      if (!option.search_match) {
671
672
673        return '';
674
675
676      }
677
678
679      if (!this.include_option_in_results(option)) {
680
681
682        return '';
683
684
685      }
686
687
688      classes = [];
689
690
691      if (!option.disabled && !(option.selected && this.is_multiple)) {
692
693
694        classes.push("active-result");
695
696
697      }
698
699
700      if (option.disabled && !(option.selected && this.is_multiple)) {
701
702
703        classes.push("disabled-result");
704
705
706      }
707
708
709      if (option.selected) {
710
711
712        classes.push("result-selected");
713
714
715      }
716
717
718      if (option.group_array_index != null) {
719
720
721        classes.push("group-option");
722
723
724      }
725
726
727      if (option.classes !== "") {
728
729
730        classes.push(option.classes);
731
732
733      }
734
735
736      option_el = document.createElement("li");
737
738
739      option_el.className = classes.join(" ");
740
741
742      option_el.style.cssText = option.style;
743
744
745      option_el.setAttribute("data-option-array-index", option.array_index);
746
747
748      option_el.innerHTML = option.search_text;
749
750
751      return this.outerHTML(option_el);
752
753
754    };
755
756
757
758
759
760    AbstractChosen.prototype.result_add_group = function(group) {
761
762
763      var group_el;
764
765
766      if (!(group.search_match || group.group_match)) {
767
768
769        return '';
770
771
772      }
773
774
775      if (!(group.active_options > 0)) {
776
777
778        return '';
779
780
781      }
782
783
784      group_el = document.createElement("li");
785
786
787      group_el.className = "group-result";
788
789
790      group_el.innerHTML = group.search_text;
791
792
793      return this.outerHTML(group_el);
794
795
796    };
797
798
799
800
801
802    AbstractChosen.prototype.results_update_field = function() {
803
804
805      this.set_default_text();
806
807
808      if (!this.is_multiple) {
809
810
811        this.results_reset_cleanup();
812
813
814      }
815
816
817      this.result_clear_highlight();
818
819
820      this.results_build();
821
822
823      if (this.results_showing) {
824
825
826        return this.winnow_results();
827
828
829      }
830
831
832    };
833
834
835
836
837
838    AbstractChosen.prototype.reset_single_select_options = function() {
839
840
841      var result, _i, _len, _ref, _results;
842
843
844      _ref = this.results_data;
845
846
847      _results = [];
848
849
850      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
851
852
853        result = _ref[_i];
854
855
856        if (result.selected) {
857
858
859          _results.push(result.selected = false);
860
861
862        } else {
863
864
865          _results.push(void 0);
866
867
868        }
869
870
871      }
872
873
874      return _results;
875
876
877    };
878
879
880
881
882
883    AbstractChosen.prototype.results_toggle = function() {
884
885
886      if (this.results_showing) {
887
888
889        return this.results_hide();
890
891
892      } else {
893
894
895        return this.results_show();
896
897
898      }
899
900
901    };
902
903
904
905
906
907    AbstractChosen.prototype.results_search = function(evt) {
908
909
910      if (this.results_showing) {
911
912
913        return this.winnow_results();
914
915
916      } else {
917
918
919        return this.results_show();
920
921
922      }
923
924
925    };
926
927
928
929
930
931    AbstractChosen.prototype.winnow_results = function() {
932
933
934      var escapedSearchText, option, regex, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
935
936
937      this.no_results_clear();
938
939
940      results = 0;
941
942
943      searchText = this.get_search_text();
944
945
946      escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
947
948
949      zregex = new RegExp(escapedSearchText, 'i');
950
951
952      regex = this.get_search_regex(escapedSearchText);
953
954
955      _ref = this.results_data;
956
957
958      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
959
960
961        option = _ref[_i];
962
963
964        option.search_match = false;
965
966
967        results_group = null;
968
969
970        if (this.include_option_in_results(option)) {
971
972
973          if (option.group) {
974
975
976            option.group_match = false;
977
978
979            option.active_options = 0;
980
981
982          }
983
984
985          if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
986
987
988            results_group = this.results_data[option.group_array_index];
989
990
991            if (results_group.active_options === 0 && results_group.search_match) {
992
993
994              results += 1;
995
996
997            }
998
999
1000            results_group.active_options += 1;
1001
1002
1003          }
1004
1005
1006          if (!(option.group && !this.group_search)) {
1007
1008
1009            option.search_text = option.group ? option.label : option.text;
1010
1011
1012            option.search_match = this.search_string_match(option.search_text, regex);
1013
1014
1015            if (option.search_match && !option.group) {
1016
1017
1018              results += 1;
1019
1020
1021            }
1022
1023
1024            if (option.search_match) {
1025
1026
1027              if (searchText.length) {
1028
1029
1030                startpos = option.search_text.search(zregex);
1031
1032
1033                text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
1034
1035
1036                option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
1037
1038
1039              }
1040
1041
1042              if (results_group != null) {
1043
1044
1045                results_group.group_match = true;
1046
1047
1048              }
1049
1050
1051            } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
1052
1053
1054              option.search_match = true;
1055
1056
1057            }
1058
1059
1060          }
1061
1062
1063        }
1064
1065
1066      }
1067
1068
1069      this.result_clear_highlight();
1070
1071
1072      if (results < 1 && searchText.length) {
1073
1074
1075        this.update_results_content("");
1076
1077
1078        return this.no_results(searchText);
1079
1080
1081      } else {
1082
1083
1084        this.update_results_content(this.results_option_build());
1085
1086
1087        return this.winnow_results_set_highlight();
1088
1089
1090      }
1091
1092
1093    };
1094
1095
1096
1097
1098
1099    AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
1100
1101
1102      var regex_anchor;
1103
1104
1105      regex_anchor = this.search_contains ? "" : "^";
1106
1107
1108      return new RegExp(regex_anchor + escaped_search_string, 'i');
1109
1110
1111    };
1112
1113
1114
1115
1116
1117    AbstractChosen.prototype.search_string_match = function(search_string, regex) {
1118
1119
1120      var part, parts, _i, _len;
1121
1122
1123      if (regex.test(search_string)) {
1124
1125
1126        return true;
1127
1128
1129      } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
1130
1131
1132        parts = search_string.replace(/\[|\]/g, "").split(" ");
1133
1134
1135        if (parts.length) {
1136
1137
1138          for (_i = 0, _len = parts.length; _i < _len; _i++) {
1139
1140
1141            part = parts[_i];
1142
1143
1144            if (regex.test(part)) {
1145
1146
1147              return true;
1148
1149
1150            }
1151
1152
1153          }
1154
1155
1156        }
1157
1158
1159      }
1160
1161
1162    };
1163
1164
1165
1166
1167
1168    AbstractChosen.prototype.choices_count = function() {
1169
1170
1171      var option, _i, _len, _ref;
1172
1173
1174      if (this.selected_option_count != null) {
1175
1176
1177        return this.selected_option_count;
1178
1179
1180      }
1181
1182
1183      this.selected_option_count = 0;
1184
1185
1186      _ref = this.form_field.options;
1187
1188
1189      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1190
1191
1192        option = _ref[_i];
1193
1194
1195        if (option.selected) {
1196
1197
1198          this.selected_option_count += 1;
1199
1200
1201        }
1202
1203
1204      }
1205
1206
1207      return this.selected_option_count;
1208
1209
1210    };
1211
1212
1213
1214
1215
1216    AbstractChosen.prototype.choices_click = function(evt) {
1217
1218
1219      evt.preventDefault();
1220
1221
1222      if (!(this.results_showing || this.is_disabled)) {
1223
1224
1225        return this.results_show();
1226
1227
1228      }
1229
1230
1231    };
1232
1233
1234
1235
1236
1237    AbstractChosen.prototype.keyup_checker = function(evt) {
1238
1239
1240      var stroke, _ref;
1241
1242
1243      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
1244
1245
1246      this.search_field_scale();
1247
1248
1249      switch (stroke) {
1250
1251
1252        case 8:
1253
1254
1255          if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
1256
1257
1258            return this.keydown_backstroke();
1259
1260
1261          } else if (!this.pending_backstroke) {
1262
1263
1264            this.result_clear_highlight();
1265
1266
1267            return this.results_search();
1268
1269
1270          }
1271
1272
1273          break;
1274
1275
1276        case 13:
1277
1278
1279          evt.preventDefault();
1280
1281
1282          if (this.results_showing) {
1283
1284
1285            return this.result_select(evt);
1286
1287
1288          }
1289
1290
1291          break;
1292
1293
1294        case 27:
1295
1296
1297          if (this.results_showing) {
1298
1299
1300            this.results_hide();
1301
1302
1303          }
1304
1305
1306          return true;
1307
1308
1309        case 9:
1310
1311
1312        case 38:
1313
1314
1315        case 40:
1316
1317
1318        case 16:
1319
1320
1321        case 91:
1322
1323
1324        case 17:
1325
1326
1327          break;
1328
1329
1330        default:
1331
1332
1333          return this.results_search();
1334
1335
1336      }
1337
1338
1339    };
1340
1341
1342
1343
1344
1345    AbstractChosen.prototype.clipboard_event_checker = function(evt) {
1346
1347
1348      var _this = this;
1349
1350
1351      return setTimeout((function() {
1352
1353
1354        return _this.results_search();
1355
1356
1357      }), 50);
1358
1359
1360    };
1361
1362
1363
1364
1365
1366    AbstractChosen.prototype.container_width = function() {
1367
1368
1369      if (this.options.width != null) {
1370
1371
1372        return this.options.width;
1373
1374
1375      } else {
1376
1377
1378        return "" + this.form_field.offsetWidth + "px";
1379
1380
1381      }
1382
1383
1384    };
1385
1386
1387
1388
1389
1390    AbstractChosen.prototype.include_option_in_results = function(option) {
1391
1392
1393      if (this.is_multiple && (!this.display_selected_options && option.selected)) {
1394
1395
1396        return false;
1397
1398
1399      }
1400
1401
1402      if (!this.display_disabled_options && option.disabled) {
1403
1404
1405        return false;
1406
1407
1408      }
1409
1410
1411      if (option.empty) {
1412
1413
1414        return false;
1415
1416
1417      }
1418
1419
1420      return true;
1421
1422
1423    };
1424
1425
1426
1427
1428
1429    AbstractChosen.prototype.search_results_touchstart = function(evt) {
1430
1431
1432      this.touch_started = true;
1433
1434
1435      return this.search_results_mouseover(evt);
1436
1437
1438    };
1439
1440
1441
1442
1443
1444    AbstractChosen.prototype.search_results_touchmove = function(evt) {
1445
1446
1447      this.touch_started = false;
1448
1449
1450      return this.search_results_mouseout(evt);
1451
1452
1453    };
1454
1455
1456
1457
1458
1459    AbstractChosen.prototype.search_results_touchend = function(evt) {
1460
1461
1462      if (this.touch_started) {
1463
1464
1465        return this.search_results_mouseup(evt);
1466
1467
1468      }
1469
1470
1471    };
1472
1473
1474
1475
1476
1477    AbstractChosen.prototype.outerHTML = function(element) {
1478
1479
1480      var tmp;
1481
1482
1483      if (element.outerHTML) {
1484
1485
1486        return element.outerHTML;
1487
1488
1489      }
1490
1491
1492      tmp = document.createElement("div");
1493
1494
1495      tmp.appendChild(element);
1496
1497
1498      return tmp.innerHTML;
1499
1500
1501    };
1502
1503
1504
1505
1506
1507    AbstractChosen.browser_is_supported = function() {
1508
1509
1510      if (window.navigator.appName === "Microsoft Internet Explorer") {
1511
1512
1513        return document.documentMode >= 8;
1514
1515
1516      }
1517
1518
1519      if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
1520
1521
1522        return false;
1523
1524
1525      }
1526
1527
1528      if (/Android/i.test(window.navigator.userAgent)) {
1529
1530
1531        if (/Mobile/i.test(window.navigator.userAgent)) {
1532
1533
1534          return false;
1535
1536
1537        }
1538
1539
1540      }
1541
1542
1543      return true;
1544
1545
1546    };
1547
1548
1549
1550
1551
1552    AbstractChosen.default_multiple_text = wpem_chosen.multiple_text; 
1553
1554
1555
1556
1557
1558    AbstractChosen.default_single_text = wpem_chosen.single_text;
1559
1560
1561
1562
1563
1564    AbstractChosen.default_no_result_text = wpem_chosen.no_result_text;
1565
1566
1567
1568
1569
1570    return AbstractChosen;
1571
1572
1573
1574
1575
1576  })();
1577
1578
1579
1580
1581
1582  $ = jQuery;
1583
1584
1585
1586
1587
1588  $.fn.extend({
1589
1590
1591    chosen: function(options) {
1592
1593
1594      if (!AbstractChosen.browser_is_supported()) {
1595
1596
1597        return this;
1598
1599
1600      }
1601
1602
1603      return this.each(function(input_field) {
1604
1605
1606        var $this, chosen;
1607
1608
1609        $this = $(this);
1610
1611
1612        chosen = $this.data('chosen');
1613
1614
1615        if (options === 'destroy' && chosen instanceof Chosen) {
1616
1617
1618          chosen.destroy();
1619
1620
1621        } else if (!(chosen instanceof Chosen)) {
1622
1623
1624          $this.data('chosen', new Chosen(this, options));
1625
1626
1627        }
1628
1629
1630      });
1631
1632
1633    }
1634
1635
1636  });
1637
1638
1639
1640
1641
1642  Chosen = (function(_super) {
1643
1644
1645    __extends(Chosen, _super);
1646
1647
1648
1649
1650
1651    function Chosen() {
1652
1653
1654      _ref = Chosen.__super__.constructor.apply(this, arguments);
1655
1656
1657      return _ref;
1658
1659
1660    }
1661
1662
1663
1664
1665
1666    Chosen.prototype.setup = function() {
1667
1668
1669      this.form_field_jq = $(this.form_field);
1670
1671
1672      this.current_selectedIndex = this.form_field.selectedIndex;
1673
1674
1675      return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
1676
1677
1678    };
1679
1680
1681
1682
1683
1684    Chosen.prototype.set_up_html = function() {
1685
1686
vendor: 25,546 bytes, lines 1687-3685
1687      var container_classes, container_props;
1688
1689
1690      container_classes = ["chosen-container"];
1691
1692
1693      container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
1694
1695
1696      if (this.inherit_select_classes && this.form_field.className) {
1697
1698
1699        container_classes.push(this.form_field.className);
1700
1701
1702      }
1703
1704
1705      if (this.is_rtl) {
1706
1707
1708        container_classes.push("chosen-rtl");
1709
1710
1711      }
1712
1713
1714      container_props = {
1715
1716
1717        'class': container_classes.join(' '),
1718
1719
1720        'style': "width: " + (this.container_width()) + ";",
1721
1722
1723        'title': this.form_field.title
1724
1725
1726      };
1727
1728
1729      if (this.form_field.id.length) {
1730
1731
1732        container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
1733
1734
1735      }
1736
1737
1738      this.container = $("<div />", container_props);
1739
1740
1741      if (this.is_multiple) {
1742
1743
1744        this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
1745
1746
1747      } else {
1748
1749
1750        this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.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>');
1751
1752
1753      }
1754
1755
1756      this.form_field_jq.hide().after(this.container);
1757
1758
1759      this.dropdown = this.container.find('div.chosen-drop').first();
1760
1761
1762      this.search_field = this.container.find('input').first();
1763
1764
1765      this.search_results = this.container.find('ul.chosen-results').first();
1766
1767
1768      this.search_field_scale();
1769
1770
1771      this.search_no_results = this.container.find('li.no-results').first();
1772
1773
1774      if (this.is_multiple) {
1775
1776
1777        this.search_choices = this.container.find('ul.chosen-choices').first();
1778
1779
1780        this.search_container = this.container.find('li.search-field').first();
1781
1782
1783      } else {
1784
1785
1786        this.search_container = this.container.find('div.chosen-search').first();
1787
1788
1789        this.selected_item = this.container.find('.chosen-single').first();
1790
1791
1792      }
1793
1794
1795      this.results_build();
1796
1797
1798      this.set_tab_index();
1799
1800
1801      this.set_label_behavior();
1802
1803
1804      return this.form_field_jq.trigger("chosen:ready", {
1805
1806
1807        chosen: this
1808
1809
1810      });
1811
1812
1813    };
1814
1815
1816
1817
1818
1819    Chosen.prototype.register_observers = function() {
1820
1821
1822      var _this = this;
1823
1824
1825      this.container.bind('touchstart.chosen', function(evt) {
1826
1827
1828        _this.container_mousedown(evt);
1829
1830
1831      });
1832
1833
1834      this.container.bind('touchend.chosen', function(evt) {
1835
1836
1837        _this.container_mouseup(evt);
1838
1839
1840      });
1841
1842
1843      this.container.bind('mousedown.chosen', function(evt) {
1844
1845
1846        _this.container_mousedown(evt);
1847
1848
1849      });
1850
1851
1852      this.container.bind('mouseup.chosen', function(evt) {
1853
1854
1855        _this.container_mouseup(evt);
1856
1857
1858      });
1859
1860
1861      this.container.bind('mouseenter.chosen', function(evt) {
1862
1863
1864        _this.mouse_enter(evt);
1865
1866
1867      });
1868
1869
1870      this.container.bind('mouseleave.chosen', function(evt) {
1871
1872
1873        _this.mouse_leave(evt);
1874
1875
1876      });
1877
1878
1879      this.search_results.bind('mouseup.chosen', function(evt) {
1880
1881
1882        _this.search_results_mouseup(evt);
1883
1884
1885      });
1886
1887
1888      this.search_results.bind('mouseover.chosen', function(evt) {
1889
1890
1891        _this.search_results_mouseover(evt);
1892
1893
1894      });
1895
1896
1897      this.search_results.bind('mouseout.chosen', function(evt) {
1898
1899
1900        _this.search_results_mouseout(evt);
1901
1902
1903      });
1904
1905
1906      this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
1907
1908
1909        _this.search_results_mousewheel(evt);
1910
1911
1912      });
1913
1914
1915      this.search_results.bind('touchstart.chosen', function(evt) {
1916
1917
1918        _this.search_results_touchstart(evt);
1919
1920
1921      });
1922
1923
1924      this.search_results.bind('touchmove.chosen', function(evt) {
1925
1926
1927        _this.search_results_touchmove(evt);
1928
1929
1930      });
1931
1932
1933      this.search_results.bind('touchend.chosen', function(evt) {
1934
1935
1936        _this.search_results_touchend(evt);
1937
1938
1939      });
1940
1941
1942      this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
1943
1944
1945        _this.results_update_field(evt);
1946
1947
1948      });
1949
1950
1951      this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
1952
1953
1954        _this.activate_field(evt);
1955
1956
1957      });
1958
1959
1960      this.form_field_jq.bind("chosen:open.chosen", function(evt) {
1961
1962
1963        _this.container_mousedown(evt);
1964
1965
1966      });
1967
1968
1969      this.form_field_jq.bind("chosen:close.chosen", function(evt) {
1970
1971
1972        _this.input_blur(evt);
1973
1974
1975      });
1976
1977
1978      this.search_field.bind('blur.chosen', function(evt) {
1979
1980
1981        _this.input_blur(evt);
1982
1983
1984      });
1985
1986
1987      this.search_field.bind('keyup.chosen', function(evt) {
1988
1989
1990        _this.keyup_checker(evt);
1991
1992
1993      });
1994
1995
1996      this.search_field.bind('keydown.chosen', function(evt) {
1997
1998
1999        _this.keydown_checker(evt);
2000
2001
2002      });
2003
2004
2005      this.search_field.bind('focus.chosen', function(evt) {
2006
2007
2008        _this.input_focus(evt);
2009
2010
2011      });
2012
2013
2014      this.search_field.bind('cut.chosen', function(evt) {
2015
2016
2017        _this.clipboard_event_checker(evt);
2018
2019
2020      });
2021
2022
2023      this.search_field.bind('paste.chosen', function(evt) {
2024
2025
2026        _this.clipboard_event_checker(evt);
2027
2028
2029      });
2030
2031
2032      if (this.is_multiple) {
2033
2034
2035        return this.search_choices.bind('click.chosen', function(evt) {
2036
2037
2038          _this.choices_click(evt);
2039
2040
2041        });
2042
2043
2044      } else {
2045
2046
2047        return this.container.bind('click.chosen', function(evt) {
2048
2049
2050          evt.preventDefault();
2051
2052
2053        });
2054
2055
2056      }
2057
2058
2059    };
2060
2061
2062
2063
2064
2065    Chosen.prototype.destroy = function() {
2066
2067
2068      $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
2069
2070
2071      if (this.search_field[0].tabIndex) {
2072
2073
2074        this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
2075
2076
2077      }
2078
2079
2080      this.container.remove();
2081
2082
2083      this.form_field_jq.removeData('chosen');
2084
2085
2086      return this.form_field_jq.show();
2087
2088
2089    };
2090
2091
2092
2093
2094
2095    Chosen.prototype.search_field_disabled = function() {
2096
2097
2098      this.is_disabled = this.form_field_jq[0].disabled;
2099
2100
2101      if (this.is_disabled) {
2102
2103
2104        this.container.addClass('chosen-disabled');
2105
2106
2107        this.search_field[0].disabled = true;
2108
2109
2110        if (!this.is_multiple) {
2111
2112
2113          this.selected_item.unbind("focus.chosen", this.activate_action);
2114
2115
2116        }
2117
2118
2119        return this.close_field();
2120
2121
2122      } else {
2123
2124
2125        this.container.removeClass('chosen-disabled');
2126
2127
2128        this.search_field[0].disabled = false;
2129
2130
2131        if (!this.is_multiple) {
2132
2133
2134          return this.selected_item.bind("focus.chosen", this.activate_action);
2135
2136
2137        }
2138
2139
2140      }
2141
2142
2143    };
2144
2145
2146
2147
2148
2149    Chosen.prototype.container_mousedown = function(evt) {
2150
2151
2152      if (!this.is_disabled) {
2153
2154
2155        if (evt && evt.type === "mousedown" && !this.results_showing) {
2156
2157
2158          evt.preventDefault();
2159
2160
2161        }
2162
2163
2164        if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
2165
2166
2167          if (!this.active_field) {
2168
2169
2170            if (this.is_multiple) {
2171
2172
2173              this.search_field.val("");
2174
2175
2176            }
2177
2178
2179            $(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action);
2180
2181
2182            this.results_show();
2183
2184
2185          } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
2186
2187
2188            evt.preventDefault();
2189
2190
2191            this.results_toggle();
2192
2193
2194          }
2195
2196
2197          return this.activate_field();
2198
2199
2200        }
2201
2202
2203      }
2204
2205
2206    };
2207
2208
2209
2210
2211
2212    Chosen.prototype.container_mouseup = function(evt) {
2213
2214
2215      if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
2216
2217
2218        return this.results_reset(evt);
2219
2220
2221      }
2222
2223
2224    };
2225
2226
2227
2228
2229
2230    Chosen.prototype.search_results_mousewheel = function(evt) {
2231
2232
2233      var delta;
2234
2235
2236      if (evt.originalEvent) {
2237
2238
2239        delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
2240
2241
2242      }
2243
2244
2245      if (delta != null) {
2246
2247
2248        evt.preventDefault();
2249
2250
2251        if (evt.type === 'DOMMouseScroll') {
2252
2253
2254          delta = delta * 40;
2255
2256
2257        }
2258
2259
2260        return this.search_results.scrollTop(delta + this.search_results.scrollTop());
2261
2262
2263      }
2264
2265
2266    };
2267
2268
2269
2270
2271
2272    Chosen.prototype.blur_test = function(evt) {
2273
2274
2275      if (!this.active_field && this.container.hasClass("chosen-container-active")) {
2276
2277
2278        return this.close_field();
2279
2280
2281      }
2282
2283
2284    };
2285
2286
2287
2288
2289
2290    Chosen.prototype.close_field = function() {
2291
2292
2293      $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
2294
2295
2296      this.active_field = false;
2297
2298
2299      this.results_hide();
2300
2301
2302      this.container.removeClass("chosen-container-active");
2303
2304
2305      this.clear_backstroke();
2306
2307
2308      this.show_search_field_default();
2309
2310
2311      return this.search_field_scale();
2312
2313
2314    };
2315
2316
2317
2318
2319
2320    Chosen.prototype.activate_field = function() {
2321
2322
2323      this.container.addClass("chosen-container-active");
2324
2325
2326      this.active_field = true;
2327
2328
2329      this.search_field.val(this.search_field.val());
2330
2331
2332      return this.search_field.focus();
2333
2334
2335    };
2336
2337
2338
2339
2340
2341    Chosen.prototype.test_active_click = function(evt) {
2342
2343
2344      var active_container;
2345
2346
2347      active_container = $(evt.target).closest('.chosen-container');
2348
2349
2350      if (active_container.length && this.container[0] === active_container[0]) {
2351
2352
2353        return this.active_field = true;
2354
2355
2356      } else {
2357
2358
2359        return this.close_field();
2360
2361
2362      }
2363
2364
2365    };
2366
2367
2368
2369
2370
2371    Chosen.prototype.results_build = function() {
2372
2373
2374      this.parsing = true;
2375
2376
2377      this.selected_option_count = null;
2378
2379
2380      this.results_data = SelectParser.select_to_array(this.form_field);
2381
2382
2383      if (this.is_multiple) {
2384
2385
2386        this.search_choices.find("li.search-choice").remove();
2387
2388
2389      } else if (!this.is_multiple) {
2390
2391
2392        this.single_set_selected_text();
2393
2394
2395        if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
2396
2397
2398          this.search_field[0].readOnly = true;
2399
2400
2401          this.container.addClass("chosen-container-single-nosearch");
2402
2403
2404        } else {
2405
2406
2407          this.search_field[0].readOnly = false;
2408
2409
2410          this.container.removeClass("chosen-container-single-nosearch");
2411
2412
2413        }
2414
2415
2416      }
2417
2418
2419      this.update_results_content(this.results_option_build({
2420
2421
2422        first: true
2423
2424
2425      }));
2426
2427
2428      this.search_field_disabled();
2429
2430
2431      this.show_search_field_default();
2432
2433
2434      this.search_field_scale();
2435
2436
2437      return this.parsing = false;
2438
2439
2440    };
2441
2442
2443
2444
2445
2446    Chosen.prototype.result_do_highlight = function(el) {
2447
2448
2449      var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
2450
2451
2452      if (el.length) {
2453
2454
2455        this.result_clear_highlight();
2456
2457
2458        this.result_highlight = el;
2459
2460
2461        this.result_highlight.addClass("highlighted");
2462
2463
2464        maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
2465
2466
2467        visible_top = this.search_results.scrollTop();
2468
2469
2470        visible_bottom = maxHeight + visible_top;
2471
2472
2473        high_top = this.result_highlight.position().top + this.search_results.scrollTop();
2474
2475
2476        high_bottom = high_top + this.result_highlight.outerHeight();
2477
2478
2479        if (high_bottom >= visible_bottom) {
2480
2481
2482          return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
2483
2484
2485        } else if (high_top < visible_top) {
2486
2487
2488          return this.search_results.scrollTop(high_top);
2489
2490
2491        }
2492
2493
2494      }
2495
2496
2497    };
2498
2499
2500
2501
2502
2503    Chosen.prototype.result_clear_highlight = function() {
2504
2505
2506      if (this.result_highlight) {
2507
2508
2509        this.result_highlight.removeClass("highlighted");
2510
2511
2512      }
2513
2514
2515      return this.result_highlight = null;
2516
2517
2518    };
2519
2520
2521
2522
2523
2524    Chosen.prototype.results_show = function() {
2525
2526
2527      if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
2528
2529
2530        this.form_field_jq.trigger("chosen:maxselected", {
2531
2532
2533          chosen: this
2534
2535
2536        });
2537
2538
2539        return false;
2540
2541
2542      }
2543
2544
2545      this.container.addClass("chosen-with-drop");
2546
2547
2548      this.results_showing = true;
2549
2550
2551      this.search_field.focus();
2552
2553
2554      this.search_field.val(this.search_field.val());
2555
2556
2557      this.winnow_results();
2558
2559
2560      return this.form_field_jq.trigger("chosen:showing_dropdown", {
2561
2562
2563        chosen: this
2564
2565
2566      });
2567
2568
2569    };
2570
2571
2572
2573
2574
2575    Chosen.prototype.update_results_content = function(content) {
2576      var clean = DOMPurify.sanitize(content);
2577      return this.search_results.html(clean);
2578
2579    };
2580
2581
2582
2583
2584
2585    Chosen.prototype.results_hide = function() {
2586
2587
2588      if (this.results_showing) {
2589
2590
2591        this.result_clear_highlight();
2592
2593
2594        this.container.removeClass("chosen-with-drop");
2595
2596
2597        this.form_field_jq.trigger("chosen:hiding_dropdown", {
2598
2599
2600          chosen: this
2601
2602
2603        });
2604
2605
2606      }
2607
2608
2609      return this.results_showing = false;
2610
2611
2612    };
2613
2614
2615
2616
2617
2618    Chosen.prototype.set_tab_index = function(el) {
2619
2620
2621      var ti;
2622
2623
2624      if (this.form_field.tabIndex) {
2625
2626
2627        ti = this.form_field.tabIndex;
2628
2629
2630        this.form_field.tabIndex = -1;
2631
2632
2633        return this.search_field[0].tabIndex = ti;
2634
2635
2636      }
2637
2638
2639    };
2640
2641
2642
2643
2644
2645    Chosen.prototype.set_label_behavior = function() {
2646
2647
2648      var _this = this;
2649
2650
2651      this.form_field_label = this.form_field_jq.parents("label");
2652
2653
2654      if (!this.form_field_label.length && this.form_field.id.length) {
2655
2656
2657        this.form_field_label = $("label[for='" + this.form_field.id + "']");
2658
2659
2660      }
2661
2662
2663      if (this.form_field_label.length > 0) {
2664
2665
2666        return this.form_field_label.bind('click.chosen', function(evt) {
2667
2668
2669          if (_this.is_multiple) {
2670
2671
2672            return _this.container_mousedown(evt);
2673
2674
2675          } else {
2676
2677
2678            return _this.activate_field();
2679
2680
2681          }
2682
2683
2684        });
2685
2686
2687      }
2688
2689
2690    };
2691
2692
2693
2694
2695
2696    Chosen.prototype.show_search_field_default = function() {
2697
2698
2699      if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
2700
2701
2702        this.search_field.val(this.default_text);
2703
2704
2705        return this.search_field.addClass("default");
2706
2707
2708      } else {
2709
2710
2711        this.search_field.val("");
2712
2713
2714        return this.search_field.removeClass("default");
2715
2716
2717      }
2718
2719
2720    };
2721
2722
2723
2724
2725
2726    Chosen.prototype.search_results_mouseup = function(evt) {
2727
2728
2729      var target;
2730
2731
2732      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
2733
2734
2735      if (target.length) {
2736
2737
2738        this.result_highlight = target;
2739
2740
2741        this.result_select(evt);
2742
2743
2744        return this.search_field.focus();
2745
2746
2747      }
2748
2749
2750    };
2751
2752
2753
2754
2755
2756    Chosen.prototype.search_results_mouseover = function(evt) {
2757
2758
2759      var target;
2760
2761
2762      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
2763
2764
2765      if (target) {
2766
2767
2768        return this.result_do_highlight(target);
2769
2770
2771      }
2772
2773
2774    };
2775
2776
2777
2778
2779
2780    Chosen.prototype.search_results_mouseout = function(evt) {
2781
2782
2783      if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
2784
2785
2786        return this.result_clear_highlight();
2787
2788
2789      }
2790
2791
2792    };
2793
2794
2795
2796
2797
2798    Chosen.prototype.choice_build = function(item) {
2799
2800
2801      var choice, close_link,
2802
2803
2804        _this = this;
2805
2806
2807      choice = $('<li />', {
2808
2809
2810        "class": "search-choice"
2811
2812
2813      }).html("<span>" + item.html + "</span>");
2814
2815
2816      if (item.disabled) {
2817
2818
2819        choice.addClass('search-choice-disabled');
2820
2821
2822      } else {
2823
2824
2825        close_link = $('<a />', {
2826
2827
2828          "class": 'search-choice-close',
2829
2830
2831          'data-option-array-index': item.array_index
2832
2833
2834        });
2835
2836
2837        close_link.bind('click.chosen', function(evt) {
2838
2839
2840          return _this.choice_destroy_link_click(evt);
2841
2842
2843        });
2844
2845
2846        choice.append(close_link);
2847
2848
2849      }
2850
2851
2852      return this.search_container.before(choice);
2853
2854
2855    };
2856
2857
2858
2859
2860
2861    Chosen.prototype.choice_destroy_link_click = function(evt) {
2862
2863
2864      evt.preventDefault();
2865
2866
2867      evt.stopPropagation();
2868
2869
2870      if (!this.is_disabled) {
2871
2872
2873        return this.choice_destroy($(evt.target));
2874
2875
2876      }
2877
2878
2879    };
2880
2881
2882
2883
2884
2885    Chosen.prototype.choice_destroy = function(link) {
2886
2887
2888      if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
2889
2890
2891        this.show_search_field_default();
2892
2893
2894        if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
2895
2896
2897          this.results_hide();
2898
2899
2900        }
2901
2902
2903        link.parents('li').first().remove();
2904
2905
2906        return this.search_field_scale();
2907
2908
2909      }
2910
2911
2912    };
2913
2914
2915
2916
2917
2918    Chosen.prototype.results_reset = function() {
2919
2920
2921      this.reset_single_select_options();
2922
2923
2924      this.form_field.options[0].selected = true;
2925
2926
2927      this.single_set_selected_text();
2928
2929
2930      this.show_search_field_default();
2931
2932
2933      this.results_reset_cleanup();
2934
2935
2936      this.form_field_jq.trigger("change");
2937
2938
2939      if (this.active_field) {
2940
2941
2942        return this.results_hide();
2943
2944
2945      }
2946
2947
2948    };
2949
2950
2951
2952
2953
2954    Chosen.prototype.results_reset_cleanup = function() {
2955
2956
2957      this.current_selectedIndex = this.form_field.selectedIndex;
2958
2959
2960      return this.selected_item.find("abbr").remove();
2961
2962
2963    };
2964
2965
2966
2967
2968
2969    Chosen.prototype.result_select = function(evt) {
2970
2971
2972      var high, item;
2973
2974
2975      if (this.result_highlight) {
2976
2977
2978        high = this.result_highlight;
2979
2980
2981        this.result_clear_highlight();
2982
2983
2984        if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
2985
2986
2987          this.form_field_jq.trigger("chosen:maxselected", {
2988
2989
2990            chosen: this
2991
2992
2993          });
2994
2995
2996          return false;
2997
2998
2999        }
3000
3001
3002        if (this.is_multiple) {
3003
3004
3005          high.removeClass("active-result");
3006
3007
3008        } else {
3009
3010
3011          this.reset_single_select_options();
3012
3013
3014        }
3015
3016
3017        item = this.results_data[high[0].getAttribute("data-option-array-index")];
3018
3019
3020        item.selected = true;
3021
3022
3023        this.form_field.options[item.options_index].selected = true;
3024
3025
3026        this.selected_option_count = null;
3027
3028
3029        if (this.is_multiple) {
3030
3031
3032          this.choice_build(item);
3033
3034
3035        } else {
3036
3037
3038          this.single_set_selected_text(item.text);
3039
3040
3041        }
3042
3043
3044        if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
3045
3046
3047          this.results_hide();
3048
3049
3050        }
3051
3052
3053        this.search_field.val("");
3054
3055
3056        if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
3057
3058
3059          this.form_field_jq.trigger("change", {
3060
3061
3062            'selected': this.form_field.options[item.options_index].value
3063
3064
3065          });
3066
3067
3068        }
3069
3070
3071        this.current_selectedIndex = this.form_field.selectedIndex;
3072
3073
3074        return this.search_field_scale();
3075
3076
3077      }
3078
3079
3080    };
3081
3082
3083
3084
3085
3086    Chosen.prototype.single_set_selected_text = function(text) {
3087
3088
3089      if (text == null) {
3090
3091
3092        text = this.default_text;
3093
3094
3095      }
3096
3097
3098      if (text === this.default_text) {
3099
3100
3101        this.selected_item.addClass("chosen-default");
3102
3103
3104      } else {
3105
3106
3107        this.single_deselect_control_build();
3108
3109
3110        this.selected_item.removeClass("chosen-default");
3111
3112
3113      }
3114
3115
3116      return this.selected_item.find("span").text(text);
3117
3118
3119    };
3120
3121
3122
3123
3124
3125    Chosen.prototype.result_deselect = function(pos) {
3126
3127
3128      var result_data;
3129
3130
3131      result_data = this.results_data[pos];
3132
3133
3134      if (!this.form_field.options[result_data.options_index].disabled) {
3135
3136
3137        result_data.selected = false;
3138
3139
3140        this.form_field.options[result_data.options_index].selected = false;
3141
3142
3143        this.selected_option_count = null;
3144
3145
3146        this.result_clear_highlight();
3147
3148
3149        if (this.results_showing) {
3150
3151
3152          this.winnow_results();
3153
3154
3155        }
3156
3157
3158        this.form_field_jq.trigger("change", {
3159
3160
3161          deselected: this.form_field.options[result_data.options_index].value
3162
3163
3164        });
3165
3166
3167        this.search_field_scale();
3168
3169
3170        return true;
3171
3172
3173      } else {
3174
3175
3176        return false;
3177
3178
3179      }
3180
3181
3182    };
3183
3184
3185
3186
3187
3188    Chosen.prototype.single_deselect_control_build = function() {
3189
3190
3191      if (!this.allow_single_deselect) {
3192
3193
3194        return;
3195
3196
3197      }
3198
3199
3200      if (!this.selected_item.find("abbr").length) {
3201
3202
3203        this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
3204
3205
3206      }
3207
3208
3209      return this.selected_item.addClass("chosen-single-with-deselect");
3210
3211
3212    };
3213
3214
3215
3216
3217
3218    Chosen.prototype.get_search_text = function() {
3219
3220
3221      if (this.search_field.val() === this.default_text) {
3222
3223
3224        return "";
3225
3226
3227      } else {
3228
3229
3230        return $('<div/>').text($.trim(this.search_field.val())).html();
3231
3232
3233      }
3234
3235
3236    };
3237
3238
3239
3240
3241
3242    Chosen.prototype.winnow_results_set_highlight = function() {
3243
3244
3245      var do_high, selected_results;
3246
3247
3248      selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
3249
3250
3251      do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
3252
3253
3254      if (do_high != null) {
3255
3256
3257        return this.result_do_highlight(do_high);
3258
3259
3260      }
3261
3262
3263    };
3264
3265
3266
3267
3268
3269    Chosen.prototype.no_results = function(terms) {
3270
3271
3272      var no_results_html;
3273
3274
3275      no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
3276
3277
3278      no_results_html.find("span").first().html(terms);
3279
3280
3281      this.search_results.append(no_results_html);
3282
3283
3284      return this.form_field_jq.trigger("chosen:no_results", {
3285
3286
3287        chosen: this
3288
3289
3290      });
3291
3292
3293    };
3294
3295
3296
3297
3298
3299    Chosen.prototype.no_results_clear = function() {
3300
3301
3302      return this.search_results.find(".no-results").remove();
3303
3304
3305    };
3306
3307
3308
3309
3310
3311    Chosen.prototype.keydown_arrow = function() {
3312
3313
3314      var next_sib;
3315
3316
3317      if (this.results_showing && this.result_highlight) {
3318
3319
3320        next_sib = this.result_highlight.nextAll("li.active-result").first();
3321
3322
3323        if (next_sib) {
3324
3325
3326          return this.result_do_highlight(next_sib);
3327
3328
3329        }
3330
3331
3332      } else {
3333
3334
3335        return this.results_show();
3336
3337
3338      }
3339
3340
3341    };
3342
3343
3344
3345
3346
3347    Chosen.prototype.keyup_arrow = function() {
3348
3349
3350      var prev_sibs;
3351
3352
3353      if (!this.results_showing && !this.is_multiple) {
3354
3355
3356        return this.results_show();
3357
3358
3359      } else if (this.result_highlight) {
3360
3361
3362        prev_sibs = this.result_highlight.prevAll("li.active-result");
3363
3364
3365        if (prev_sibs.length) {
3366
3367
3368          return this.result_do_highlight(prev_sibs.first());
3369
3370
3371        } else {
3372
3373
3374          if (this.choices_count() > 0) {
3375
3376
3377            this.results_hide();
3378
3379
3380          }
3381
3382
3383          return this.result_clear_highlight();
3384
3385
3386        }
3387
3388
3389      }
3390
3391
3392    };
3393
3394
3395
3396
3397
3398    Chosen.prototype.keydown_backstroke = function() {
3399
3400
3401      var next_available_destroy;
3402
3403
3404      if (this.pending_backstroke) {
3405
3406
3407        this.choice_destroy(this.pending_backstroke.find("a").first());
3408
3409
3410        return this.clear_backstroke();
3411
3412
3413      } else {
3414
3415
3416        next_available_destroy = this.search_container.siblings("li.search-choice").last();
3417
3418
3419        if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
3420
3421
3422          this.pending_backstroke = next_available_destroy;
3423
3424
3425          if (this.single_backstroke_delete) {
3426
3427
3428            return this.keydown_backstroke();
3429
3430
3431          } else {
3432
3433
3434            return this.pending_backstroke.addClass("search-choice-focus");
3435
3436
3437          }
3438
3439
3440        }
3441
3442
3443      }
3444
3445
3446    };
3447
3448
3449
3450
3451
3452    Chosen.prototype.clear_backstroke = function() {
3453
3454
3455      if (this.pending_backstroke) {
3456
3457
3458        this.pending_backstroke.removeClass("search-choice-focus");
3459
3460
3461      }
3462
3463
3464      return this.pending_backstroke = null;
3465
3466
3467    };
3468
3469
3470
3471
3472
3473    Chosen.prototype.keydown_checker = function(evt) {
3474
3475
3476      var stroke, _ref1;
3477
3478
3479      stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
3480
3481
3482      this.search_field_scale();
3483
3484
3485      if (stroke !== 8 && this.pending_backstroke) {
3486
3487
3488        this.clear_backstroke();
3489
3490
3491      }
3492
3493
3494      switch (stroke) {
3495
3496
3497        case 8:
3498
3499
3500          this.backstroke_length = this.search_field.val().length;
3501
3502
3503          break;
3504
3505
3506        case 9:
3507
3508
3509          if (this.results_showing && !this.is_multiple) {
3510
3511
3512            this.result_select(evt);
3513
3514
3515          }
3516
3517
3518          this.mouse_on_container = false;
3519
3520
3521          break;
3522
3523
3524        case 13:
3525
3526
3527          if (this.results_showing) {
3528
3529
3530            evt.preventDefault();
3531
3532
3533          }
3534
3535
3536          break;
3537
3538
3539        case 32:
3540
3541
3542          if (this.disable_search) {
3543
3544
3545            evt.preventDefault();
3546
3547
3548          }
3549
3550
3551          break;
3552
3553
3554        case 38:
3555
3556
3557          evt.preventDefault();
3558
3559
3560          this.keyup_arrow();
3561
3562
3563          break;
3564
3565
3566        case 40:
3567
3568
3569          evt.preventDefault();
3570
3571
3572          this.keydown_arrow();
3573
3574
3575          break;
3576
3577
3578      }
3579
3580
3581    };
3582
3583
3584
3585
3586
3587    Chosen.prototype.search_field_scale = function() {
3588
3589
3590      var div, f_width, h, style, style_block, styles, w, _i, _len;
3591
3592
3593      if (this.is_multiple) {
3594
3595
3596        h = 0;
3597
3598
3599        w = 0;
3600
3601
3602        style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
3603
3604
3605        styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
3606
3607
3608        for (_i = 0, _len = styles.length; _i < _len; _i++) {
3609
3610
3611          style = styles[_i];
3612
3613
3614          style_block += style + ":" + this.search_field.css(style) + ";";
3615
3616
3617        }
3618
3619
3620        div = $('<div />', {
3621
3622
3623          'style': style_block
3624
3625
3626        });
3627
3628
3629        div.text(this.search_field.val());
3630
3631
3632        $('body').append(div);
3633
3634
3635        w = div.width() + 25;
3636
3637
3638        div.remove();
3639
3640
3641        f_width = this.container.outerWidth();
3642
3643
3644        if (w > f_width - 10) {
3645
3646
3647          w = f_width - 10;
3648
3649
3650        }
3651
3652
3653        return this.search_field.css({
3654
3655
3656          'width': w + 'px'
3657
3658
3659        });
3660
3661
3662      }
3663
3664
3665    };
3666
3667
3668
3669
3670
3671    return Chosen;
3672
3673
3674
3675
3676
3677  })(AbstractChosen);
3678
3679
3680
3681
3682
3683}).call(this);
3684
3685

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.