PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 2.0.0
Adminify – White Label, Admin Menu Editor, Login Customizer v2.0.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / lib / adminify-framework / assets / js / plugins.js

plugins.js in Adminify – White Label, Admin Menu Editor, Login Customizer 2.0.0, at lib/adminify-framework/assets/js/plugins.js

2,093 lines 65.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 *
3 * jQuery Chosen AJAX Autocomplete Library
4 *
5 * https://github.com/meltingice/ajax-chosen
6 * https://github.com/michaelperrin/ajax-chosen
7 *
8 * MIT License
9 *
10 * Customized by Adminify
11 *
12 */
13 (function($) {
14
15 function ADMINIFYAjaxChosen(element, options) {
16 this.element = $(element);
17 this.options = options;
18 this.init();
19 };
20
21 ADMINIFYAjaxChosen.prototype.init = function() {
22 this.element.chosen(this.options);
23 this.container = this.element.next('.chosen-container');
24 this.search_field = this.container.find('.chosen-search-input');
25 this.is_multiple = this.container.hasClass('chosen-container-multi');
26 this.is_typing = false;
27 this.chosenXhr = null;
28 this.events();
29 };
30
31 ADMINIFYAjaxChosen.prototype.events = function() {
32
33 var _this = this;
34
35 this.search_field.on('compositionstart', function() {
36 _this.is_typing = true;
37 });
38
39 this.search_field.on('compositionend', function() {
40 _this.is_typing = false;
41 _this.update_list();
42 });
43
44 this.search_field.on('keyup', function() {
45 _this.update_list();
46 });
47
48 this.search_field.on('focus', function() {
49 _this.search_field_focused();
50 });
51
52 };
53
54 ADMINIFYAjaxChosen.prototype.search_field_focused = function() {
55 this.search_welcome_message();
56 if ( this.options.min_length === 0 && this.search_field.val().length === 0 ) {
57 this.update_list();
58 }
59 };
60
61 ADMINIFYAjaxChosen.prototype.search_welcome_message = function() {
62
63 var value = $.trim(this.search_field.val());
64 var results = this.container.find('.chosen-results');
65
66 if ( results.children().length === 0 && value.length === 0 ) {
67 results.html('<li class="no-results">' + this.options.typing_text.replace('%s', this.options.min_length - value.length) + '</li>');
68 }
69
70 };
71
72 ADMINIFYAjaxChosen.prototype.update_list = function() {
73
74 var _this = this;
75
76 this.search_welcome_message();
77
78 if ( this.is_typing ) { return; }
79
80 var value = $.trim(this.search_field.val());
81 var message = ( value.length < this.options.min_length ) ? this.options.typing_text.replace('%s', this.options.min_length - value.length) : this.options.searching_text;
82
83 this.container.find('.no-results').text(message);
84
85 if ( value === this.search_field.data('prevVal') ) { return; }
86
87 this.search_field.data('prevVal', value);
88
89 if (this.timer) {
90 clearTimeout(this.timer);
91 }
92
93 if ( value.length < this.options.min_length ) { return; }
94
95 this.timer = setTimeout( function() {
96
97 if ( _this.chosenXhr ) {
98 _this.chosenXhr.abort();
99 }
100
101 _this.options.data['term'] = value;
102
103 _this.chosenXhr = window.wp.ajax.post('adminify-chosen', _this.options.data).done( function( response ) {
104 _this.show_results( response );
105 }).fail( function( response ) {
106 _this.container.find('.no-results').text(response.error);
107 });
108
109 }, this.options.type_delay );
110
111 };
112
113 ADMINIFYAjaxChosen.prototype.show_results = function( items ) {
114
115 var _this = this;
116
117 if ( this.is_typing || items === null ) { return; }
118
119 if ( items.length === 0 ) {
120 this.element.data().chosen.no_results_clear();
121 this.element.data().chosen.no_results(this.search_field.val());
122 return;
123 }
124
125 var selected_values = [];
126
127 this.element.find('option').each(function() {
128 if ( $(this).is(':selected') ) {
129 selected_values.push( $(this).val() + "-" + $(this).text() );
130 } else {
131 if( $(this).attr('value').length ) {
132 $(this).remove();
133 }
134 }
135 });
136
137 $.each(items, function(i, item) {
138 if ( $.inArray( item.value + "-" + item.text, selected_values ) === -1 ) {
139 $('<option />').attr('value', item.value).html(item.text).appendTo(_this.element);
140 }
141 });
142
143 var value_before_trigger = this.search_field.val();
144 var width_before_trigger = this.search_field.innerWidth();
145
146 this.element.trigger('chosen:updated');
147
148 if( this.is_multiple ) {
149
150 var $hidden_select = this.element.parent().find('.adminify-hide-select');
151 var $hidden_value = $hidden_select.val() || [];
152
153 this.element.ADMINIFYChosenOrder($hidden_value, true);
154 this.search_field.css('width', width_before_trigger);
155
156 }
157
158 this.search_field.val(value_before_trigger);
159
160 if ( this.chosenXhr.done !== null ) {
161 this.chosenXhr.done(items);
162 }
163
164 };
165
166 $.fn.ADMINIFYAjaxChosen = function(chosenOptions) {
167 return this.each(function() {
168 new ADMINIFYAjaxChosen(this, chosenOptions);
169 });
170 };
171
172 })(jQuery);
173 ;// Chosen Order v1.2.1
174 // This plugin allows you to handle the order of the selection for Chosen multiple <select> dropdowns
175 // Full source at https://github.com/tristanjahier/chosen-order
176 // Copyright (c) 2013 - Tristan Jahier, http://tristan-jahier.fr
177 (function() {
178 var $, ADMINIFYAbstractChosenOrder, _ref,
179 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
180 __hasProp = {}.hasOwnProperty,
181 __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; };
182
183 ADMINIFYAbstractChosenOrder = (function() {
184
185 function ADMINIFYAbstractChosenOrder() {}
186
187 ADMINIFYAbstractChosenOrder.insertAt = function(node, index, parentNode) {
188 return parentNode.insertBefore(node, parentNode.children[index].nextSibling);
189 };
190
191 ADMINIFYAbstractChosenOrder.getFlattenedOptionsAndGroups = function(select) {
192 var flattened_options, opt, options, sub_opt, sub_options, _i, _j, _len, _len1;
193 options = Array.prototype.filter.call(select.childNodes, function(o) {
194 var _ref;
195 return (_ref = o.nodeName.toUpperCase()) === 'OPTION' || _ref === 'OPTGROUP';
196 });
197 flattened_options = [];
198 for (_i = 0, _len = options.length; _i < _len; _i++) {
199 opt = options[_i];
200 flattened_options.push(opt);
201 if (opt.nodeName.toUpperCase() === 'OPTGROUP') {
202 sub_options = Array.prototype.filter.call(opt.childNodes, function(o) {
203 return o.nodeName.toUpperCase() === 'OPTION';
204 });
205 for (_j = 0, _len1 = sub_options.length; _j < _len1; _j++) {
206 sub_opt = sub_options[_j];
207 flattened_options.push(sub_opt);
208 }
209 }
210 }
211 return flattened_options;
212 };
213
214 ADMINIFYAbstractChosenOrder.isValidMultipleSelectElement = function(element) {
215 return element !== null && typeof element !== "undefined" && element.nodeName === "SELECT" && element.multiple;
216 };
217
218 ADMINIFYAbstractChosenOrder.getChosenUIContainer = function(select) {
219 if (select.id !== "") {
220 return document.getElementById(select.id.replace(/-/g, "_") + "_chosen");
221 } else {
222 return this.searchChosenUIContainer(select);
223 }
224 };
225
226 ADMINIFYAbstractChosenOrder.isChosenified = function(select) {
227 return this.getChosenUIContainer(select) != null;
228 };
229
230 ADMINIFYAbstractChosenOrder.forceSelection = function(select, selection) {
231 var i, opt, options, _ref;
232 options = this.getFlattenedOptionsAndGroups(select);
233 i = 0;
234 while (i < options.length) {
235 opt = options[i];
236 if (_ref = opt.getAttribute("value"), __indexOf.call(selection, _ref) >= 0) {
237 opt.selected = true;
238 opt.setAttribute("selected", "");
239 } else {
240 opt.selected = false;
241 opt.removeAttribute("selected");
242 }
243 i++;
244 }
245 return this.triggerEvent(select, "chosen:updated");
246 };
247
248 ADMINIFYAbstractChosenOrder.ADMINIFYChosenOrder = function(select, order, force) {
249 var chosen_choices, chosen_options, chosen_ui, i, j, opt, opt_val, option, options, rel, relAttributeName, _i, _j, _len, _len1, _results;
250 if (this.getDOMElement != null) {
251 select = this.getDOMElement(select);
252 }
253 if (!this.isValidMultipleSelectElement(select)) {
254 return;
255 }
256 chosen_ui = this.getChosenUIContainer(select);
257 if (chosen_ui == null) {
258 return;
259 }
260 if (order instanceof Array) {
261 order = order.map(Function.prototype.call, String.prototype.trim);
262 options = this.getFlattenedOptionsAndGroups(select);
263 if ((force != null) && force === true) {
264 this.forceSelection(select, order);
265 }
266 _results = [];
267 for (i = _i = 0, _len = order.length; _i < _len; i = ++_i) {
268 opt_val = order[i];
269 rel = null;
270 for (j = _j = 0, _len1 = options.length; _j < _len1; j = ++_j) {
271 opt = options[j];
272 if (opt.value === opt_val) {
273 rel = j;
274 }
275 }
276 chosen_options = chosen_ui.querySelectorAll('.search-choice');
277 relAttributeName = this.relAttributeName;
278 option = Array.prototype.filter.call(chosen_options, function(o) {
279 return o.querySelector("a.search-choice-close[" + relAttributeName + "=\"" + rel + "\"]") != null;
280 })[0];
281 if (option == null) {
282 continue;
283 }
284 chosen_choices = chosen_ui.querySelector("ul.chosen-choices");
285 _results.push(this.insertAt(option, i, chosen_ui.querySelector('ul.chosen-choices')));
286 }
287 return _results;
288 } else {
289 return;
290 }
291 };
292
293 return ADMINIFYAbstractChosenOrder;
294
295 })();
296
297 $ = jQuery;
298
299 $.fn.extend({
300 ADMINIFYChosenOrder: function(order, force) {
301 return _ADMINIFYChosenOrder.ADMINIFYChosenOrder(this, order, force);
302 }
303 });
304
305 this._ADMINIFYChosenOrder = (function(_super) {
306 __extends(_ADMINIFYChosenOrder, _super);
307
308 function _ADMINIFYChosenOrder() {
309 _ref = _ADMINIFYChosenOrder.__super__.constructor.apply(this, arguments);
310 return _ref;
311 }
312
313 _ADMINIFYChosenOrder.relAttributeName = 'data-option-array-index';
314
315 _ADMINIFYChosenOrder.isjQueryObject = function(obj) {
316 return (typeof jQuery !== "undefined" && jQuery !== null) && obj instanceof jQuery;
317 };
318
319 _ADMINIFYChosenOrder.getDOMElement = function(element) {
320 if (this.isjQueryObject(element)) {
321 return element.get(0);
322 } else {
323 return element;
324 }
325 };
326
327 _ADMINIFYChosenOrder.searchChosenUIContainer = function(element) {
328 if ($(element).data("chosen") != null) {
329 return $(element).data("chosen").container[0];
330 } else {
331 return $(element).next(".chosen-container.chosen-container-multi").get(0);
332 }
333 };
334
335 _ADMINIFYChosenOrder.triggerEvent = function(target, event_name) {
336 return $(target).trigger(event_name);
337 };
338
339 return _ADMINIFYChosenOrder;
340
341 })(ADMINIFYAbstractChosenOrder);
342
343 }).call(this);
344 ;(function() {
345 var $, AbstractChosen, Chosen, SelectParser,
346 bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
347 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; },
348 hasProp = {}.hasOwnProperty;
349
350 SelectParser = (function() {
351 function SelectParser() {
352 this.options_index = 0;
353 this.parsed = [];
354 }
355
356 SelectParser.prototype.add_node = function(child) {
357 if (child.nodeName.toUpperCase() === "OPTGROUP") {
358 return this.add_group(child);
359 } else {
360 return this.add_option(child);
361 }
362 };
363
364 SelectParser.prototype.add_group = function(group) {
365 var group_position, i, len, option, ref, results1;
366 group_position = this.parsed.length;
367 this.parsed.push({
368 array_index: group_position,
369 group: true,
370 label: group.label,
371 title: group.title ? group.title : void 0,
372 children: 0,
373 disabled: group.disabled,
374 classes: group.className
375 });
376 ref = group.childNodes;
377 results1 = [];
378 for (i = 0, len = ref.length; i < len; i++) {
379 option = ref[i];
380 results1.push(this.add_option(option, group_position, group.disabled));
381 }
382 return results1;
383 };
384
385 SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
386 if (option.nodeName.toUpperCase() === "OPTION") {
387 if (option.text !== "") {
388 if (group_position != null) {
389 this.parsed[group_position].children += 1;
390 }
391 this.parsed.push({
392 array_index: this.parsed.length,
393 options_index: this.options_index,
394 value: option.value,
395 text: option.text,
396 html: option.innerHTML,
397 title: option.title ? option.title : void 0,
398 selected: option.selected,
399 disabled: group_disabled === true ? group_disabled : option.disabled,
400 group_array_index: group_position,
401 group_label: group_position != null ? this.parsed[group_position].label : null,
402 classes: option.className,
403 style: option.style.cssText
404 });
405 } else {
406 this.parsed.push({
407 array_index: this.parsed.length,
408 options_index: this.options_index,
409 empty: true
410 });
411 }
412 return this.options_index += 1;
413 }
414 };
415
416 return SelectParser;
417
418 })();
419
420 SelectParser.select_to_array = function(select) {
421 var child, i, len, parser, ref;
422 parser = new SelectParser();
423 ref = select.childNodes;
424 for (i = 0, len = ref.length; i < len; i++) {
425 child = ref[i];
426 parser.add_node(child);
427 }
428 return parser.parsed;
429 };
430
431 AbstractChosen = (function() {
432 function AbstractChosen(form_field, options1) {
433 this.form_field = form_field;
434 this.options = options1 != null ? options1 : {};
435 this.label_click_handler = bind(this.label_click_handler, this);
436 if (!AbstractChosen.browser_is_supported()) {
437 return;
438 }
439 this.is_multiple = this.form_field.multiple;
440 this.set_default_text();
441 this.set_default_values();
442 this.setup();
443 this.set_up_html();
444 this.register_observers();
445 this.on_ready();
446 }
447
448 AbstractChosen.prototype.set_default_values = function() {
449 this.click_test_action = (function(_this) {
450 return function(evt) {
451 return _this.test_active_click(evt);
452 };
453 })(this);
454 this.activate_action = (function(_this) {
455 return function(evt) {
456 return _this.activate_field(evt);
457 };
458 })(this);
459 this.active_field = false;
460 this.mouse_on_container = false;
461 this.results_showing = false;
462 this.result_highlighted = null;
463 this.is_rtl = this.options.rtl || /\bchosen-rtl\b/.test(this.form_field.className);
464 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;
465 this.disable_search_threshold = this.options.disable_search_threshold || 0;
466 this.disable_search = this.options.disable_search || false;
467 this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
468 this.group_search = this.options.group_search != null ? this.options.group_search : true;
469 this.search_contains = this.options.search_contains || false;
470 this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
471 this.max_selected_options = this.options.max_selected_options || Infinity;
472 this.inherit_select_classes = this.options.inherit_select_classes || false;
473 this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
474 this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
475 this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
476 this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
477 this.case_sensitive_search = this.options.case_sensitive_search || false;
478 return this.hide_results_on_select = this.options.hide_results_on_select != null ? this.options.hide_results_on_select : true;
479 };
480
481 AbstractChosen.prototype.set_default_text = function() {
482 if (this.form_field.getAttribute("data-placeholder")) {
483 this.default_text = this.form_field.getAttribute("data-placeholder");
484 } else if (this.is_multiple) {
485 this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
486 } else {
487 this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
488 }
489 this.default_text = this.escape_html(this.default_text);
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 AbstractChosen.prototype.choice_label = function(item) {
494 if (this.include_group_label_in_selected && (item.group_label != null)) {
495 return "<b class='group-name'>" + (this.escape_html(item.group_label)) + "</b>" + item.html;
496 } else {
497 return item.html;
498 }
499 };
500
501 AbstractChosen.prototype.mouse_enter = function() {
502 return this.mouse_on_container = true;
503 };
504
505 AbstractChosen.prototype.mouse_leave = function() {
506 return this.mouse_on_container = false;
507 };
508
509 AbstractChosen.prototype.input_focus = function(evt) {
510 if (this.is_multiple) {
511 if (!this.active_field) {
512 return setTimeout(((function(_this) {
513 return function() {
514 return _this.container_mousedown();
515 };
516 })(this)), 50);
517 }
518 } else {
519 if (!this.active_field) {
520 return this.activate_field();
521 }
522 }
523 };
524
525 AbstractChosen.prototype.input_blur = function(evt) {
526 if (!this.mouse_on_container) {
527 this.active_field = false;
528 return setTimeout(((function(_this) {
529 return function() {
530 return _this.blur_test();
531 };
532 })(this)), 100);
533 }
534 };
535
536 AbstractChosen.prototype.label_click_handler = function(evt) {
537 if (this.is_multiple) {
538 return this.container_mousedown(evt);
539 } else {
540 return this.activate_field();
541 }
542 };
543
544 AbstractChosen.prototype.results_option_build = function(options) {
545 var content, data, data_content, i, len, ref, shown_results;
546 content = '';
547 shown_results = 0;
548 ref = this.results_data;
549 for (i = 0, len = ref.length; i < len; i++) {
550 data = ref[i];
551 data_content = '';
552 if (data.group) {
553 data_content = this.result_add_group(data);
554 } else {
555 data_content = this.result_add_option(data);
556 }
557 if (data_content !== '') {
558 shown_results++;
559 content += data_content;
560 }
561 if (options != null ? options.first : void 0) {
562 if (data.selected && this.is_multiple) {
563 this.choice_build(data);
564 } else if (data.selected && !this.is_multiple) {
565 this.single_set_selected_text(this.choice_label(data));
566 }
567 }
568 if (shown_results >= this.max_shown_results) {
569 break;
570 }
571 }
572 return content;
573 };
574
575 AbstractChosen.prototype.result_add_option = function(option) {
576 var classes, option_el;
577 if (!option.search_match) {
578 return '';
579 }
580 if (!this.include_option_in_results(option)) {
581 return '';
582 }
583 classes = [];
584 if (!option.disabled && !(option.selected && this.is_multiple)) {
585 classes.push("active-result");
586 }
587 if (option.disabled && !(option.selected && this.is_multiple)) {
588 classes.push("disabled-result");
589 }
590 if (option.selected) {
591 classes.push("result-selected");
592 }
593 if (option.group_array_index != null) {
594 classes.push("group-option");
595 }
596 if (option.classes !== "") {
597 classes.push(option.classes);
598 }
599 option_el = document.createElement("li");
600 option_el.className = classes.join(" ");
601 if (option.style) {
602 option_el.style.cssText = option.style;
603 }
604 option_el.setAttribute("data-option-array-index", option.array_index);
605 option_el.innerHTML = option.highlighted_html || option.html;
606 if (option.title) {
607 option_el.title = option.title;
608 }
609 return this.outerHTML(option_el);
610 };
611
612 AbstractChosen.prototype.result_add_group = function(group) {
613 var classes, group_el;
614 if (!(group.search_match || group.group_match)) {
615 return '';
616 }
617 if (!(group.active_options > 0)) {
618 return '';
619 }
620 classes = [];
621 classes.push("group-result");
622 if (group.classes) {
623 classes.push(group.classes);
624 }
625 group_el = document.createElement("li");
626 group_el.className = classes.join(" ");
627 group_el.innerHTML = group.highlighted_html || this.escape_html(group.label);
628 if (group.title) {
629 group_el.title = group.title;
630 }
631 return this.outerHTML(group_el);
632 };
633
634 AbstractChosen.prototype.results_update_field = function() {
635 this.set_default_text();
636 if (!this.is_multiple) {
637 this.results_reset_cleanup();
638 }
639 this.result_clear_highlight();
640 this.results_build();
641 if (this.results_showing) {
642 return this.winnow_results();
643 }
644 };
645
646 AbstractChosen.prototype.reset_single_select_options = function() {
647 var i, len, ref, result, results1;
648 ref = this.results_data;
649 results1 = [];
650 for (i = 0, len = ref.length; i < len; i++) {
651 result = ref[i];
652 if (result.selected) {
653 results1.push(result.selected = false);
654 } else {
655 results1.push(void 0);
656 }
657 }
658 return results1;
659 };
660
661 AbstractChosen.prototype.results_toggle = function() {
662 if (this.results_showing) {
663 return this.results_hide();
664 } else {
665 return this.results_show();
666 }
667 };
668
669 AbstractChosen.prototype.results_search = function(evt) {
670 if (this.results_showing) {
671 return this.winnow_results();
672 } else {
673 return this.results_show();
674 }
675 };
676
677 AbstractChosen.prototype.winnow_results = function(options) {
678 var escapedQuery, fix, i, len, option, prefix, query, ref, regex, results, results_group, search_match, startpos, suffix, text;
679 this.no_results_clear();
680 results = 0;
681 query = this.get_search_text();
682 escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
683 regex = this.get_search_regex(escapedQuery);
684 ref = this.results_data;
685 for (i = 0, len = ref.length; i < len; i++) {
686 option = ref[i];
687 option.search_match = false;
688 results_group = null;
689 search_match = null;
690 option.highlighted_html = '';
691 if (this.include_option_in_results(option)) {
692 if (option.group) {
693 option.group_match = false;
694 option.active_options = 0;
695 }
696 if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
697 results_group = this.results_data[option.group_array_index];
698 if (results_group.active_options === 0 && results_group.search_match) {
699 results += 1;
700 }
701 results_group.active_options += 1;
702 }
703 text = option.group ? option.label : option.text;
704 if (!(option.group && !this.group_search)) {
705 search_match = this.search_string_match(text, regex);
706 option.search_match = search_match != null;
707 if (option.search_match && !option.group) {
708 results += 1;
709 }
710 if (option.search_match) {
711 if (query.length) {
712 startpos = search_match.index;
713 prefix = text.slice(0, startpos);
714 fix = text.slice(startpos, startpos + query.length);
715 suffix = text.slice(startpos + query.length);
716 option.highlighted_html = (this.escape_html(prefix)) + "<em>" + (this.escape_html(fix)) + "</em>" + (this.escape_html(suffix));
717 }
718 if (results_group != null) {
719 results_group.group_match = true;
720 }
721 } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
722 option.search_match = true;
723 }
724 }
725 }
726 }
727 this.result_clear_highlight();
728 if (results < 1 && query.length) {
729 this.update_results_content("");
730 return this.no_results(query);
731 } else {
732 this.update_results_content(this.results_option_build());
733 if (!(options != null ? options.skip_highlight : void 0)) {
734 return this.winnow_results_set_highlight();
735 }
736 }
737 };
738
739 AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
740 var regex_flag, regex_string;
741 regex_string = this.search_contains ? escaped_search_string : "(^|\\s|\\b)" + escaped_search_string + "[^\\s]*";
742 if (!(this.enable_split_word_search || this.search_contains)) {
743 regex_string = "^" + regex_string;
744 }
745 regex_flag = this.case_sensitive_search ? "" : "i";
746 return new RegExp(regex_string, regex_flag);
747 };
748
749 AbstractChosen.prototype.search_string_match = function(search_string, regex) {
750 var match;
751 match = regex.exec(search_string);
752 if (!this.search_contains && (match != null ? match[1] : void 0)) {
753 match.index += 1;
754 }
755 return match;
756 };
757
758 AbstractChosen.prototype.choices_count = function() {
759 var i, len, option, ref;
760 if (this.selected_option_count != null) {
761 return this.selected_option_count;
762 }
763 this.selected_option_count = 0;
764 ref = this.form_field.options;
765 for (i = 0, len = ref.length; i < len; i++) {
766 option = ref[i];
767 if (option.selected) {
768 this.selected_option_count += 1;
769 }
770 }
771 return this.selected_option_count;
772 };
773
774 AbstractChosen.prototype.choices_click = function(evt) {
775 evt.preventDefault();
776 this.activate_field();
777 if (!(this.results_showing || this.is_disabled)) {
778 return this.results_show();
779 }
780 };
781
782 AbstractChosen.prototype.keydown_checker = function(evt) {
783 var ref, stroke;
784 stroke = (ref = evt.which) != null ? ref : evt.keyCode;
785 this.search_field_scale();
786 if (stroke !== 8 && this.pending_backstroke) {
787 this.clear_backstroke();
788 }
789 switch (stroke) {
790 case 8:
791 this.backstroke_length = this.get_search_field_value().length;
792 break;
793 case 9:
794 if (this.results_showing && !this.is_multiple) {
795 this.result_select(evt);
796 }
797 this.mouse_on_container = false;
798 break;
799 case 13:
800 if (this.results_showing) {
801 evt.preventDefault();
802 }
803 break;
804 case 27:
805 if (this.results_showing) {
806 evt.preventDefault();
807 }
808 break;
809 case 32:
810 if (this.disable_search) {
811 evt.preventDefault();
812 }
813 break;
814 case 38:
815 evt.preventDefault();
816 this.keyup_arrow();
817 break;
818 case 40:
819 evt.preventDefault();
820 this.keydown_arrow();
821 break;
822 }
823 };
824
825 AbstractChosen.prototype.keyup_checker = function(evt) {
826 var ref, stroke;
827 stroke = (ref = evt.which) != null ? ref : evt.keyCode;
828 this.search_field_scale();
829 switch (stroke) {
830 case 8:
831 if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
832 this.keydown_backstroke();
833 } else if (!this.pending_backstroke) {
834 this.result_clear_highlight();
835 this.results_search();
836 }
837 break;
838 case 13:
839 evt.preventDefault();
840 if (this.results_showing) {
841 this.result_select(evt);
842 }
843 break;
844 case 27:
845 if (this.results_showing) {
846 this.results_hide();
847 }
848 break;
849 case 9:
850 case 16:
851 case 17:
852 case 18:
853 case 38:
854 case 40:
855 case 91:
856 break;
857 default:
858 this.results_search();
859 break;
860 }
861 };
862
863 AbstractChosen.prototype.clipboard_event_checker = function(evt) {
864 if (this.is_disabled) {
865 return;
866 }
867 return setTimeout(((function(_this) {
868 return function() {
869 return _this.results_search();
870 };
871 })(this)), 50);
872 };
873
874 AbstractChosen.prototype.container_width = function() {
875 if (this.options.width != null) {
876 return this.options.width;
877 } else {
878 return this.form_field.offsetWidth + "px";
879 }
880 };
881
882 AbstractChosen.prototype.include_option_in_results = function(option) {
883 if (this.is_multiple && (!this.display_selected_options && option.selected)) {
884 return false;
885 }
886 if (!this.display_disabled_options && option.disabled) {
887 return false;
888 }
889 if (option.empty) {
890 return false;
891 }
892 return true;
893 };
894
895 AbstractChosen.prototype.search_results_touchstart = function(evt) {
896 this.touch_started = true;
897 return this.search_results_mouseover(evt);
898 };
899
900 AbstractChosen.prototype.search_results_touchmove = function(evt) {
901 this.touch_started = false;
902 return this.search_results_mouseout(evt);
903 };
904
905 AbstractChosen.prototype.search_results_touchend = function(evt) {
906 if (this.touch_started) {
907 return this.search_results_mouseup(evt);
908 }
909 };
910
911 AbstractChosen.prototype.outerHTML = function(element) {
912 var tmp;
913 if (element.outerHTML) {
914 return element.outerHTML;
915 }
916 tmp = document.createElement("div");
917 tmp.appendChild(element);
918 return tmp.innerHTML;
919 };
920
921 AbstractChosen.prototype.get_single_html = function() {
922 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>";
923 };
924
925 AbstractChosen.prototype.get_multi_html = function() {
926 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>";
927 };
928
929 AbstractChosen.prototype.get_no_results_html = function(terms) {
930 return "<li class=\"no-results\">\n " + this.results_none_found + " <span>" + (this.escape_html(terms)) + "</span>\n</li>";
931 };
932
933 AbstractChosen.browser_is_supported = function() {
934 if ("Microsoft Internet Explorer" === window.navigator.appName) {
935 return document.documentMode >= 8;
936 }
937 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)) {
938 return false;
939 }
940 return true;
941 };
942
943 AbstractChosen.default_multiple_text = "Select Some Options";
944
945 AbstractChosen.default_single_text = "Select an Option";
946
947 AbstractChosen.default_no_result_text = "No results match";
948
949 return AbstractChosen;
950
951 })();
952
953 $ = jQuery;
954
955 $.fn.extend({
956 chosen: function(options) {
957 if (!AbstractChosen.browser_is_supported()) {
958 return this;
959 }
960 return this.each(function(input_field) {
961 var $this, chosen;
962 $this = $(this);
963 chosen = $this.data('chosen');
964 if (options === 'destroy') {
965 if (chosen instanceof Chosen) {
966 chosen.destroy();
967 }
968 return;
969 }
970 if (!(chosen instanceof Chosen)) {
971 $this.data('chosen', new Chosen(this, options));
972 }
973 });
974 }
975 });
976
977 Chosen = (function(superClass) {
978 extend(Chosen, superClass);
979
980 function Chosen() {
981 return Chosen.__super__.constructor.apply(this, arguments);
982 }
983
984 Chosen.prototype.setup = function() {
985 this.form_field_jq = $(this.form_field);
986 return this.current_selectedIndex = this.form_field.selectedIndex;
987 };
988
989 Chosen.prototype.set_up_html = function() {
990 var container_classes, container_props;
991 container_classes = ["chosen-container"];
992 container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
993 if (this.inherit_select_classes && this.form_field.className) {
994 container_classes.push(this.form_field.className);
995 }
996 if (this.is_rtl) {
997 container_classes.push("chosen-rtl");
998 }
999 container_props = {
1000 'class': container_classes.join(' '),
1001 'title': this.form_field.title
1002 };
1003 if (this.form_field.id.length) {
1004 container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
1005 }
1006 this.container = $("<div />", container_props);
1007 this.container.width(this.container_width());
1008 if (this.is_multiple) {
1009 this.container.html(this.get_multi_html());
1010 } else {
1011 this.container.html(this.get_single_html());
1012 }
1013 this.form_field_jq.hide().after(this.container);
1014 this.dropdown = this.container.find('div.chosen-drop').first();
1015 this.search_field = this.container.find('input').first();
1016 this.search_results = this.container.find('ul.chosen-results').first();
1017 this.search_field_scale();
1018 this.search_no_results = this.container.find('li.no-results').first();
1019 if (this.is_multiple) {
1020 this.search_choices = this.container.find('ul.chosen-choices').first();
1021 this.search_container = this.container.find('li.search-field').first();
1022 } else {
1023 this.search_container = this.container.find('div.chosen-search').first();
1024 this.selected_item = this.container.find('.chosen-single').first();
1025 }
1026 this.results_build();
1027 this.set_tab_index();
1028 return this.set_label_behavior();
1029 };
1030
1031 Chosen.prototype.on_ready = function() {
1032 return this.form_field_jq.trigger("chosen:ready", {
1033 chosen: this
1034 });
1035 };
1036
1037 Chosen.prototype.register_observers = function() {
1038 this.container.on('touchstart.chosen', (function(_this) {
1039 return function(evt) {
1040 _this.container_mousedown(evt);
1041 };
1042 })(this));
1043 this.container.on('touchend.chosen', (function(_this) {
1044 return function(evt) {
1045 _this.container_mouseup(evt);
1046 };
1047 })(this));
1048 this.container.on('mousedown.chosen', (function(_this) {
1049 return function(evt) {
1050 _this.container_mousedown(evt);
1051 };
1052 })(this));
1053 this.container.on('mouseup.chosen', (function(_this) {
1054 return function(evt) {
1055 _this.container_mouseup(evt);
1056 };
1057 })(this));
1058 this.container.on('mouseenter.chosen', (function(_this) {
1059 return function(evt) {
1060 _this.mouse_enter(evt);
1061 };
1062 })(this));
1063 this.container.on('mouseleave.chosen', (function(_this) {
1064 return function(evt) {
1065 _this.mouse_leave(evt);
1066 };
1067 })(this));
1068 this.search_results.on('mouseup.chosen', (function(_this) {
1069 return function(evt) {
1070 _this.search_results_mouseup(evt);
1071 };
1072 })(this));
1073 this.search_results.on('mouseover.chosen', (function(_this) {
1074 return function(evt) {
1075 _this.search_results_mouseover(evt);
1076 };
1077 })(this));
1078 this.search_results.on('mouseout.chosen', (function(_this) {
1079 return function(evt) {
1080 _this.search_results_mouseout(evt);
1081 };
1082 })(this));
1083 this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) {
1084 return function(evt) {
1085 _this.search_results_mousewheel(evt);
1086 };
1087 })(this));
1088 this.search_results.on('touchstart.chosen', (function(_this) {
1089 return function(evt) {
1090 _this.search_results_touchstart(evt);
1091 };
1092 })(this));
1093 this.search_results.on('touchmove.chosen', (function(_this) {
1094 return function(evt) {
1095 _this.search_results_touchmove(evt);
1096 };
1097 })(this));
1098 this.search_results.on('touchend.chosen', (function(_this) {
1099 return function(evt) {
1100 _this.search_results_touchend(evt);
1101 };
1102 })(this));
1103 this.form_field_jq.on("chosen:updated.chosen", (function(_this) {
1104 return function(evt) {
1105 _this.results_update_field(evt);
1106 };
1107 })(this));
1108 this.form_field_jq.on("chosen:activate.chosen", (function(_this) {
1109 return function(evt) {
1110 _this.activate_field(evt);
1111 };
1112 })(this));
1113 this.form_field_jq.on("chosen:open.chosen", (function(_this) {
1114 return function(evt) {
1115 _this.container_mousedown(evt);
1116 };
1117 })(this));
1118 this.form_field_jq.on("chosen:close.chosen", (function(_this) {
1119 return function(evt) {
1120 _this.close_field(evt);
1121 };
1122 })(this));
1123 this.search_field.on('blur.chosen', (function(_this) {
1124 return function(evt) {
1125 _this.input_blur(evt);
1126 };
1127 })(this));
1128 this.search_field.on('keyup.chosen', (function(_this) {
1129 return function(evt) {
1130 _this.keyup_checker(evt);
1131 };
1132 })(this));
1133 this.search_field.on('keydown.chosen', (function(_this) {
1134 return function(evt) {
1135 _this.keydown_checker(evt);
1136 };
1137 })(this));
1138 this.search_field.on('focus.chosen', (function(_this) {
1139 return function(evt) {
1140 _this.input_focus(evt);
1141 };
1142 })(this));
1143 this.search_field.on('cut.chosen', (function(_this) {
1144 return function(evt) {
1145 _this.clipboard_event_checker(evt);
1146 };
1147 })(this));
1148 this.search_field.on('paste.chosen', (function(_this) {
1149 return function(evt) {
1150 _this.clipboard_event_checker(evt);
1151 };
1152 })(this));
1153 if (this.is_multiple) {
1154 return this.search_choices.on('click.chosen', (function(_this) {
1155 return function(evt) {
1156 _this.choices_click(evt);
1157 };
1158 })(this));
1159 } else {
1160 return this.container.on('click.chosen', function(evt) {
1161 evt.preventDefault();
1162 });
1163 }
1164 };
1165
1166 Chosen.prototype.destroy = function() {
1167 $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action);
1168 if (this.form_field_label.length > 0) {
1169 this.form_field_label.off('click.chosen');
1170 }
1171 if (this.search_field[0].tabIndex) {
1172 this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
1173 }
1174 this.container.remove();
1175 this.form_field_jq.removeData('chosen');
1176 return this.form_field_jq.show();
1177 };
1178
1179 Chosen.prototype.search_field_disabled = function() {
1180 this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled');
1181 this.container.toggleClass('chosen-disabled', this.is_disabled);
1182 this.search_field[0].disabled = this.is_disabled;
1183 if (!this.is_multiple) {
1184 this.selected_item.off('focus.chosen', this.activate_field);
1185 }
1186 if (this.is_disabled) {
1187 return this.close_field();
1188 } else if (!this.is_multiple) {
1189 return this.selected_item.on('focus.chosen', this.activate_field);
1190 }
1191 };
1192
1193 Chosen.prototype.container_mousedown = function(evt) {
1194 var ref;
1195 if (this.is_disabled) {
1196 return;
1197 }
1198 if (evt && ((ref = evt.type) === 'mousedown' || ref === 'touchstart') && !this.results_showing) {
1199 evt.preventDefault();
1200 }
1201 if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
1202 if (!this.active_field) {
1203 if (this.is_multiple) {
1204 this.search_field.val("");
1205 }
1206 $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action);
1207 this.results_show();
1208 } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
1209 evt.preventDefault();
1210 this.results_toggle();
1211 }
1212 return this.activate_field();
1213 }
1214 };
1215
1216 Chosen.prototype.container_mouseup = function(evt) {
1217 if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
1218 return this.results_reset(evt);
1219 }
1220 };
1221
1222 Chosen.prototype.search_results_mousewheel = function(evt) {
1223 var delta;
1224 if (evt.originalEvent) {
1225 delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
1226 }
1227 if (delta != null) {
1228 evt.preventDefault();
1229 if (evt.type === 'DOMMouseScroll') {
1230 delta = delta * 40;
1231 }
1232 return this.search_results.scrollTop(delta + this.search_results.scrollTop());
1233 }
1234 };
1235
1236 Chosen.prototype.blur_test = function(evt) {
1237 if (!this.active_field && this.container.hasClass("chosen-container-active")) {
1238 return this.close_field();
1239 }
1240 };
1241
1242 Chosen.prototype.close_field = function() {
1243 $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action);
1244 this.active_field = false;
1245 this.results_hide();
1246 this.container.removeClass("chosen-container-active");
1247 this.clear_backstroke();
1248 this.show_search_field_default();
1249 this.search_field_scale();
1250 return this.search_field.blur();
1251 };
1252
1253 Chosen.prototype.activate_field = function() {
1254 if (this.is_disabled) {
1255 return;
1256 }
1257 this.container.addClass("chosen-container-active");
1258 this.active_field = true;
1259 this.search_field.val(this.search_field.val());
1260 return this.search_field.focus();
1261 };
1262
1263 Chosen.prototype.test_active_click = function(evt) {
1264 var active_container;
1265 active_container = $(evt.target).closest('.chosen-container');
1266 if (active_container.length && this.container[0] === active_container[0]) {
1267 return this.active_field = true;
1268 } else {
1269 return this.close_field();
1270 }
1271 };
1272
1273 Chosen.prototype.results_build = function() {
1274 this.parsing = true;
1275 this.selected_option_count = null;
1276 this.results_data = SelectParser.select_to_array(this.form_field);
1277 if (this.is_multiple) {
1278 this.search_choices.find("li.search-choice").remove();
1279 } else {
1280 this.single_set_selected_text();
1281 if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
1282 this.search_field[0].readOnly = true;
1283 this.container.addClass("chosen-container-single-nosearch");
1284 } else {
1285 this.search_field[0].readOnly = false;
1286 this.container.removeClass("chosen-container-single-nosearch");
1287 }
1288 }
1289 this.update_results_content(this.results_option_build({
1290 first: true
1291 }));
1292 this.search_field_disabled();
1293 this.show_search_field_default();
1294 this.search_field_scale();
1295 return this.parsing = false;
1296 };
1297
1298 Chosen.prototype.result_do_highlight = function(el) {
1299 var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
1300 if (el.length) {
1301 this.result_clear_highlight();
1302 this.result_highlight = el;
1303 this.result_highlight.addClass("highlighted");
1304 maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
1305 visible_top = this.search_results.scrollTop();
1306 visible_bottom = maxHeight + visible_top;
1307 high_top = this.result_highlight.position().top + this.search_results.scrollTop();
1308 high_bottom = high_top + this.result_highlight.outerHeight();
1309 if (high_bottom >= visible_bottom) {
1310 return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
1311 } else if (high_top < visible_top) {
1312 return this.search_results.scrollTop(high_top);
1313 }
1314 }
1315 };
1316
1317 Chosen.prototype.result_clear_highlight = function() {
1318 if (this.result_highlight) {
1319 this.result_highlight.removeClass("highlighted");
1320 }
1321 return this.result_highlight = null;
1322 };
1323
1324 Chosen.prototype.results_show = function() {
1325 if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
1326 this.form_field_jq.trigger("chosen:maxselected", {
1327 chosen: this
1328 });
1329 return false;
1330 }
1331 this.container.addClass("chosen-with-drop");
1332 this.results_showing = true;
1333 this.search_field.focus();
1334 this.search_field.val(this.get_search_field_value());
1335 this.winnow_results();
1336 return this.form_field_jq.trigger("chosen:showing_dropdown", {
1337 chosen: this
1338 });
1339 };
1340
1341 Chosen.prototype.update_results_content = function(content) {
1342 return this.search_results.html(content);
1343 };
1344
1345 Chosen.prototype.results_hide = function() {
1346 if (this.results_showing) {
1347 this.result_clear_highlight();
1348 this.container.removeClass("chosen-with-drop");
1349 this.form_field_jq.trigger("chosen:hiding_dropdown", {
1350 chosen: this
1351 });
1352 }
1353 return this.results_showing = false;
1354 };
1355
1356 Chosen.prototype.set_tab_index = function(el) {
1357 var ti;
1358 if (this.form_field.tabIndex) {
1359 ti = this.form_field.tabIndex;
1360 this.form_field.tabIndex = -1;
1361 return this.search_field[0].tabIndex = ti;
1362 }
1363 };
1364
1365 Chosen.prototype.set_label_behavior = function() {
1366 this.form_field_label = this.form_field_jq.parents("label");
1367 if (!this.form_field_label.length && this.form_field.id.length) {
1368 this.form_field_label = $("label[for='" + this.form_field.id + "']");
1369 }
1370 if (this.form_field_label.length > 0) {
1371 return this.form_field_label.on('click.chosen', this.label_click_handler);
1372 }
1373 };
1374
1375 Chosen.prototype.show_search_field_default = function() {
1376 if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
1377 this.search_field.val(this.default_text);
1378 return this.search_field.addClass("default");
1379 } else {
1380 this.search_field.val("");
1381 return this.search_field.removeClass("default");
1382 }
1383 };
1384
1385 Chosen.prototype.search_results_mouseup = function(evt) {
1386 var target;
1387 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
1388 if (target.length) {
1389 this.result_highlight = target;
1390 this.result_select(evt);
1391 return this.search_field.focus();
1392 }
1393 };
1394
1395 Chosen.prototype.search_results_mouseover = function(evt) {
1396 var target;
1397 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
1398 if (target) {
1399 return this.result_do_highlight(target);
1400 }
1401 };
1402
1403 Chosen.prototype.search_results_mouseout = function(evt) {
1404 if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) {
1405 return this.result_clear_highlight();
1406 }
1407 };
1408
1409 Chosen.prototype.choice_build = function(item) {
1410 var choice, close_link;
1411 choice = $('<li />', {
1412 "class": "search-choice"
1413 }).html("<span>" + (this.choice_label(item)) + "</span>");
1414 if (item.disabled) {
1415 choice.addClass('search-choice-disabled');
1416 } else {
1417 close_link = $('<a />', {
1418 "class": 'search-choice-close',
1419 'data-option-array-index': item.array_index
1420 });
1421 close_link.on('click.chosen', (function(_this) {
1422 return function(evt) {
1423 return _this.choice_destroy_link_click(evt);
1424 };
1425 })(this));
1426 choice.append(close_link);
1427 }
1428 return this.search_container.before(choice);
1429 };
1430
1431 Chosen.prototype.choice_destroy_link_click = function(evt) {
1432 evt.preventDefault();
1433 evt.stopPropagation();
1434 if (!this.is_disabled) {
1435 return this.choice_destroy($(evt.target));
1436 }
1437 };
1438
1439 Chosen.prototype.choice_destroy = function(link) {
1440 if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
1441 if (this.active_field) {
1442 this.search_field.focus();
1443 } else {
1444 this.show_search_field_default();
1445 }
1446 if (this.is_multiple && this.choices_count() > 0 && this.get_search_field_value().length < 1) {
1447 this.results_hide();
1448 }
1449 link.parents('li').first().remove();
1450 return this.search_field_scale();
1451 }
1452 };
1453
1454 Chosen.prototype.results_reset = function() {
1455 this.reset_single_select_options();
1456 this.form_field.options[0].selected = true;
1457 this.single_set_selected_text();
1458 this.show_search_field_default();
1459 this.results_reset_cleanup();
1460 this.trigger_form_field_change();
1461 if (this.active_field) {
1462 return this.results_hide();
1463 }
1464 };
1465
1466 Chosen.prototype.results_reset_cleanup = function() {
1467 this.current_selectedIndex = this.form_field.selectedIndex;
1468 return this.selected_item.find("abbr").remove();
1469 };
1470
1471 Chosen.prototype.result_select = function(evt) {
1472 var high, item;
1473 if (this.result_highlight) {
1474 high = this.result_highlight;
1475 this.result_clear_highlight();
1476 if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
1477 this.form_field_jq.trigger("chosen:maxselected", {
1478 chosen: this
1479 });
1480 return false;
1481 }
1482 if (this.is_multiple) {
1483 high.removeClass("active-result");
1484 } else {
1485 this.reset_single_select_options();
1486 }
1487 high.addClass("result-selected");
1488 item = this.results_data[high[0].getAttribute("data-option-array-index")];
1489 item.selected = true;
1490 this.form_field.options[item.options_index].selected = true;
1491 this.selected_option_count = null;
1492 if (this.is_multiple) {
1493 this.choice_build(item);
1494 } else {
1495 this.single_set_selected_text(this.choice_label(item));
1496 }
1497 if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) {
1498 if (evt.metaKey || evt.ctrlKey) {
1499 this.winnow_results({
1500 skip_highlight: true
1501 });
1502 } else {
1503 this.search_field.val("");
1504 this.winnow_results();
1505 }
1506 } else {
1507 this.results_hide();
1508 this.show_search_field_default();
1509 }
1510 if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
1511 this.trigger_form_field_change({
1512 selected: this.form_field.options[item.options_index].value
1513 });
1514 }
1515 this.current_selectedIndex = this.form_field.selectedIndex;
1516 evt.preventDefault();
1517 return this.search_field_scale();
1518 }
1519 };
1520
1521 Chosen.prototype.single_set_selected_text = function(text) {
1522 if (text == null) {
1523 text = this.default_text;
1524 }
1525 if (text === this.default_text) {
1526 this.selected_item.addClass("chosen-default");
1527 } else {
1528 this.single_deselect_control_build();
1529 this.selected_item.removeClass("chosen-default");
1530 }
1531 return this.selected_item.find("span").html(text);
1532 };
1533
1534 Chosen.prototype.result_deselect = function(pos) {
1535 var result_data;
1536 result_data = this.results_data[pos];
1537 if (!this.form_field.options[result_data.options_index].disabled) {
1538 result_data.selected = false;
1539 this.form_field.options[result_data.options_index].selected = false;
1540 this.selected_option_count = null;
1541 this.result_clear_highlight();
1542 if (this.results_showing) {
1543 this.winnow_results();
1544 }
1545 this.trigger_form_field_change({
1546 deselected: this.form_field.options[result_data.options_index].value
1547 });
1548 this.search_field_scale();
1549 return true;
1550 } else {
1551 return false;
1552 }
1553 };
1554
1555 Chosen.prototype.single_deselect_control_build = function() {
1556 if (!this.allow_single_deselect) {
1557 return;
1558 }
1559 if (!this.selected_item.find("abbr").length) {
1560 this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
1561 }
1562 return this.selected_item.addClass("chosen-single-with-deselect");
1563 };
1564
1565 Chosen.prototype.get_search_field_value = function() {
1566 return this.search_field.val();
1567 };
1568
1569 Chosen.prototype.get_search_text = function() {
1570 return $.trim(this.get_search_field_value());
1571 };
1572
1573 Chosen.prototype.escape_html = function(text) {
1574 return $('<div/>').text(text).html();
1575 };
1576
1577 Chosen.prototype.winnow_results_set_highlight = function() {
1578 var do_high, selected_results;
1579 selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
1580 do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
1581 if (do_high != null) {
1582 return this.result_do_highlight(do_high);
1583 }
1584 };
1585
1586 Chosen.prototype.no_results = function(terms) {
1587 var no_results_html;
1588 no_results_html = this.get_no_results_html(terms);
1589 this.search_results.append(no_results_html);
1590 return this.form_field_jq.trigger("chosen:no_results", {
1591 chosen: this
1592 });
1593 };
1594
1595 Chosen.prototype.no_results_clear = function() {
1596 return this.search_results.find(".no-results").remove();
1597 };
1598
1599 Chosen.prototype.keydown_arrow = function() {
1600 var next_sib;
1601 if (this.results_showing && this.result_highlight) {
1602 next_sib = this.result_highlight.nextAll("li.active-result").first();
1603 if (next_sib) {
1604 return this.result_do_highlight(next_sib);
1605 }
1606 } else {
1607 return this.results_show();
1608 }
1609 };
1610
1611 Chosen.prototype.keyup_arrow = function() {
1612 var prev_sibs;
1613 if (!this.results_showing && !this.is_multiple) {
1614 return this.results_show();
1615 } else if (this.result_highlight) {
1616 prev_sibs = this.result_highlight.prevAll("li.active-result");
1617 if (prev_sibs.length) {
1618 return this.result_do_highlight(prev_sibs.first());
1619 } else {
1620 if (this.choices_count() > 0) {
1621 this.results_hide();
1622 }
1623 return this.result_clear_highlight();
1624 }
1625 }
1626 };
1627
1628 Chosen.prototype.keydown_backstroke = function() {
1629 var next_available_destroy;
1630 if (this.pending_backstroke) {
1631 this.choice_destroy(this.pending_backstroke.find("a").first());
1632 return this.clear_backstroke();
1633 } else {
1634 next_available_destroy = this.search_container.siblings("li.search-choice").last();
1635 if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
1636 this.pending_backstroke = next_available_destroy;
1637 if (this.single_backstroke_delete) {
1638 return this.keydown_backstroke();
1639 } else {
1640 return this.pending_backstroke.addClass("search-choice-focus");
1641 }
1642 }
1643 }
1644 };
1645
1646 Chosen.prototype.clear_backstroke = function() {
1647 if (this.pending_backstroke) {
1648 this.pending_backstroke.removeClass("search-choice-focus");
1649 }
1650 return this.pending_backstroke = null;
1651 };
1652
1653 Chosen.prototype.search_field_scale = function() {
1654 var div, i, len, style, style_block, styles, width;
1655 if (!this.is_multiple) {
1656 return;
1657 }
1658 style_block = {
1659 position: 'absolute',
1660 left: '-1000px',
1661 top: '-1000px',
1662 display: 'none',
1663 whiteSpace: 'pre'
1664 };
1665 styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing'];
1666 for (i = 0, len = styles.length; i < len; i++) {
1667 style = styles[i];
1668 style_block[style] = this.search_field.css(style);
1669 }
1670 div = $('<div />').css(style_block);
1671 div.text(this.get_search_field_value());
1672 $('body').append(div);
1673 width = div.width() + 25;
1674 div.remove();
1675 if (this.container.is(':visible')) {
1676 width = Math.min(this.container.outerWidth() - 10, width);
1677 }
1678 return this.search_field.width(width);
1679 };
1680
1681 Chosen.prototype.trigger_form_field_change = function(extra) {
1682 this.form_field_jq.trigger("input", extra);
1683 return this.form_field_jq.trigger("change", extra);
1684 };
1685
1686 return Chosen;
1687
1688 })(AbstractChosen);
1689
1690 }).call(this);
1691 ;/**
1692 *
1693 * jQuery Interdependencies library
1694 * http://miohtama.github.com/jquery-interdependencies/
1695 * Copyright 2012-2013 Mikko Ohtamaa, others
1696 *
1697 * Customized by Adminify
1698 *
1699 */
1700 (function($) {
1701
1702 'use strict';
1703
1704 function Rule(controller, condition, value) {
1705 this.init(controller, condition, value);
1706 }
1707
1708 $.extend(Rule.prototype, {
1709
1710 init: function(controller, condition, value) {
1711
1712 this.controller = controller;
1713 this.condition = condition;
1714 this.value = value;
1715 this.rules = [];
1716 this.controls = [];
1717
1718 },
1719
1720 evalCondition: function(context, control, condition, val1, val2) {
1721
1722 if( condition == '==' ) {
1723
1724 return this.checkBoolean(val1) == this.checkBoolean(val2);
1725
1726 } else if( condition == '!=' ) {
1727
1728 return this.checkBoolean(val1) != this.checkBoolean(val2);
1729
1730 } else if( condition == '>=' ) {
1731
1732 return Number(val2) >= Number(val1);
1733
1734 } else if( condition == '<=' ) {
1735
1736 return Number(val2) <= Number(val1);
1737
1738 } else if( condition == '>' ) {
1739
1740 return Number(val2) > Number(val1);
1741
1742 } else if( condition == '<' ) {
1743
1744 return Number(val2) < Number(val1);
1745
1746 } else if( condition == '()' ) {
1747
1748 return window[val1](context, control, val2);
1749
1750 } else if( condition == 'any' ) {
1751
1752 if( $.isArray( val2 ) ) {
1753 for (var i = val2.length - 1; i >= 0; i--) {
1754 if( $.inArray( val2[i], val1.split(',') ) !== -1 ) {
1755 return true;
1756 }
1757 }
1758 } else {
1759 if( $.inArray( val2, val1.split(',') ) !== -1 ) {
1760 return true;
1761 }
1762 }
1763
1764 } else if( condition == 'not-any' ) {
1765
1766 if( $.isArray( val2 ) ) {
1767 for (var i = val2.length - 1; i >= 0; i--) {
1768 if( $.inArray( val2[i], val1.split(',') ) == -1 ) {
1769 return true;
1770 }
1771 }
1772 } else {
1773 if( $.inArray( val2, val1.split(',') ) == -1 ) {
1774 return true;
1775 }
1776 }
1777
1778 }
1779
1780 return false;
1781
1782 },
1783
1784 checkBoolean: function(value) {
1785
1786 switch( value ) {
1787
1788 case true:
1789 case 'true':
1790 case 1:
1791 case '1':
1792 value = true;
1793 break;
1794
1795 case null:
1796 case false:
1797 case 'false':
1798 case 0:
1799 case '0':
1800 value = false;
1801 break;
1802
1803 }
1804
1805 return value;
1806 },
1807
1808 checkCondition: function( context ) {
1809
1810 if( !this.condition ) {
1811 return true;
1812 }
1813
1814 var control = context.find(this.controller);
1815
1816 var control_value = this.getControlValue(context, control);
1817
1818 if( control_value === undefined ) {
1819 return false;
1820 }
1821
1822 control_value = this.normalizeValue(control, this.value, control_value);
1823
1824 return this.evalCondition(context, control, this.condition, this.value, control_value);
1825 },
1826
1827 normalizeValue: function( control, baseValue, control_value ) {
1828
1829 if( typeof baseValue == 'number' ) {
1830 return parseFloat( control_value );
1831 }
1832
1833 return control_value;
1834 },
1835
1836 getControlValue: function(context, control) {
1837
1838 if( control.length > 1 && ( control.attr('type') == 'radio' || control.attr('type') == 'checkbox' ) ) {
1839
1840 return control.filter(':checked').map(function() { return this.value; }).get();
1841
1842 } else if ( control.attr('type') == 'checkbox' || control.attr('type') == 'radio' ) {
1843
1844 return control.is(':checked');
1845
1846 }
1847
1848 return control.val();
1849
1850 },
1851
1852 createRule: function(controller, condition, value) {
1853 var rule = new Rule(controller, condition, value);
1854 this.rules.push(rule);
1855 return rule;
1856 },
1857
1858 include: function(input) {
1859 this.controls.push(input);
1860 },
1861
1862 applyRule: function(context, enforced) {
1863
1864 var result;
1865
1866 if( typeof( enforced ) == 'undefined' ) {
1867 result = this.checkCondition(context);
1868 } else {
1869 result = enforced;
1870 }
1871
1872 var controls = $.map(this.controls, function(elem, idx) {
1873 return context.find(elem);
1874 });
1875
1876 if( result ) {
1877
1878 $(controls).each(function() {
1879 $(this).removeClass('adminify-depend-on');
1880 });
1881
1882 $(this.rules).each(function() {
1883 this.applyRule(context);
1884 });
1885
1886 } else {
1887
1888 $(controls).each(function() {
1889 $(this).addClass('adminify-depend-on');
1890 });
1891
1892 $(this.rules).each(function() {
1893 this.applyRule(context, false);
1894 });
1895
1896 }
1897 }
1898 });
1899
1900 function Ruleset() {
1901 this.rules = [];
1902 };
1903
1904 $.extend(Ruleset.prototype, {
1905
1906 createRule: function(controller, condition, value) {
1907 var rule = new Rule(controller, condition, value);
1908 this.rules.push(rule);
1909 return rule;
1910 },
1911
1912 applyRules: function(context) {
1913 $(this.rules).each(function() {
1914 this.applyRule(context);
1915 });
1916 }
1917 });
1918
1919 $.adminify_deps = {
1920
1921 createRuleset: function() {
1922 return new Ruleset();
1923 },
1924
1925 enable: function(selection, ruleset, depends) {
1926
1927 selection.on('change keyup', function(elem) {
1928
1929 var depend_id = elem.target.getAttribute('data-depend-id') || elem.target.getAttribute('data-sub-depend-id');
1930
1931 if( depends.indexOf( depend_id ) !== -1 ) {
1932 ruleset.applyRules(selection);
1933 }
1934
1935 });
1936
1937 ruleset.applyRules(selection);
1938
1939 return true;
1940 }
1941 };
1942
1943 })(jQuery);
1944 ;/**
1945 *
1946 * jQuery serializeObject
1947 *
1948 * @copyright 2014, macek <paulmacek@gmail.com>
1949 * @link https://github.com/macek/jquery-serialize-object
1950 * @license BSD
1951 * @version 2.5.0
1952 *
1953 * Customized by Adminify
1954 *
1955 */
1956 (function(root, factory) {
1957
1958 // AMD
1959 if (typeof define === "function" && define.amd) {
1960 define(["exports", "jquery"], function(exports, $) {
1961 return factory(exports, $);
1962 });
1963 }
1964
1965 // CommonJS
1966 else if (typeof exports !== "undefined") {
1967 var $ = require("jquery");
1968 factory(exports, $);
1969 }
1970
1971 // Browser
1972 else {
1973 factory(root, (root.jQuery || root.Zepto || root.ender || root.$));
1974 }
1975
1976 }(this, function(exports, $) {
1977
1978 //
1979 // Adminify: Added custom patterns for spesific validate
1980 //
1981 var patterns = {
1982 validate: /^(?!(_nonce|_pseudo))[a-zA-Z0-9_-]*(?:\[(?:\d*|(?!(_nonce|_pseudo))[a-zA-Z0-9_-]+)\])*$/i,
1983 key: /[a-zA-Z0-9_-]+|(?=\[\])/g,
1984 named: /^[a-zA-Z0-9_-]+$/,
1985 push: /^$/,
1986 fixed: /^\d+$/
1987 };
1988
1989 function FormSerializer(helper, $form) {
1990
1991 // private variables
1992 var data = {},
1993 pushes = {};
1994
1995 // private API
1996 function build(base, key, value) {
1997 base[key] = value;
1998 return base;
1999 }
2000
2001 function makeObject(root, value) {
2002
2003 var keys = root.match(patterns.key), k;
2004
2005 // nest, nest, ..., nest
2006 while ((k = keys.pop()) !== undefined) {
2007 // foo[]
2008 if (patterns.push.test(k)) {
2009 var idx = incrementPush(root.replace(/\[\]$/, ''));
2010 value = build([], idx, value);
2011 }
2012
2013 // foo[n]
2014 else if (patterns.fixed.test(k)) {
2015 value = build([], k, value);
2016 }
2017
2018 // foo; foo[bar]
2019 else if (patterns.named.test(k)) {
2020 value = build({}, k, value);
2021 }
2022 }
2023
2024 return value;
2025 }
2026
2027 function incrementPush(key) {
2028 if (pushes[key] === undefined) {
2029 pushes[key] = 0;
2030 }
2031 return pushes[key]++;
2032 }
2033
2034 function addPair(pair) {
2035 if (!patterns.validate.test(pair.name)) return this;
2036 var obj = makeObject(pair.name, pair.value);
2037 data = helper.extend(true, data, obj);
2038 return this;
2039 }
2040
2041 function addPairs(pairs) {
2042 if (!helper.isArray(pairs)) {
2043 throw new Error("formSerializer.addPairs expects an Array");
2044 }
2045 for (var i=0, len=pairs.length; i<len; i++) {
2046 this.addPair(pairs[i]);
2047 }
2048 return this;
2049 }
2050
2051 function serialize() {
2052 return data;
2053 }
2054
2055 function serializeJSON() {
2056 return JSON.stringify(serialize());
2057 }
2058
2059 // public API
2060 this.addPair = addPair;
2061 this.addPairs = addPairs;
2062 this.serialize = serialize;
2063 this.serializeJSON = serializeJSON;
2064 }
2065
2066 FormSerializer.patterns = patterns;
2067
2068 FormSerializer.serializeObject = function serializeObject() {
2069 return new FormSerializer($, this).
2070 addPairs(this.serializeArray()).
2071 serialize();
2072 };
2073
2074 FormSerializer.serializeJSON = function serializeJSON() {
2075 return new FormSerializer($, this).
2076 addPairs(this.serializeArray()).
2077 serializeJSON();
2078 };
2079
2080 //
2081 // Adminify: Renamed function names for avoid conflicts
2082 //
2083
2084 if (typeof $.fn !== "undefined") {
2085 $.fn.serializeObjectADMINIFY = FormSerializer.serializeObject;
2086 $.fn.serializeJSONADMINIFY = FormSerializer.serializeJSON;
2087 }
2088
2089 exports.FormSerializer = FormSerializer;
2090
2091 return FormSerializer;
2092 }));
2093