GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 699b70...879176 )
by Chris
13:23
created

vendor/chosen-js/chosen.jquery.js   F

Complexity

Total Complexity 363
Complexity/F 3

Size

Lines of Code 1257
Function Count 121

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 0
dl 0
loc 1257
rs 2.4
c 0
b 0
f 0
wmc 363
mnd 5
bc 302
fnc 121
bpm 2.4958
cpm 3
noi 54

How to fix   Complexity   

Complexity

Complex classes like vendor/chosen-js/chosen.jquery.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
(function() {
2
  var $, AbstractChosen, Chosen, SelectParser, _ref,
3
    __hasProp = {}.hasOwnProperty,
4
    __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; };
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
5
6
  SelectParser = (function() {
7
    function SelectParser() {
8
      this.options_index = 0;
9
      this.parsed = [];
10
    }
11
12
    SelectParser.prototype.add_node = function(child) {
13
      if (child.nodeName.toUpperCase() === "OPTGROUP") {
14
        return this.add_group(child);
15
      } else {
16
        return this.add_option(child);
17
      }
18
    };
19
20
    SelectParser.prototype.add_group = function(group) {
21
      var group_position, option, _i, _len, _ref, _results;
22
      group_position = this.parsed.length;
23
      this.parsed.push({
24
        array_index: group_position,
25
        group: true,
26
        label: this.escapeExpression(group.label),
27
        title: group.title ? group.title : void 0,
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
28
        children: 0,
29
        disabled: group.disabled,
30
        classes: group.className
31
      });
32
      _ref = group.childNodes;
33
      _results = [];
34
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
35
        option = _ref[_i];
36
        _results.push(this.add_option(option, group_position, group.disabled));
37
      }
38
      return _results;
39
    };
40
41
    SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
42
      if (option.nodeName.toUpperCase() === "OPTION") {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if option.nodeName.toUpperCase() === "OPTION" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
43
        if (option.text !== "") {
44
          if (group_position != null) {
45
            this.parsed[group_position].children += 1;
46
          }
47
          this.parsed.push({
48
            array_index: this.parsed.length,
49
            options_index: this.options_index,
50
            value: option.value,
51
            text: option.text,
52
            html: option.innerHTML,
53
            title: option.title ? option.title : void 0,
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
54
            selected: option.selected,
55
            disabled: group_disabled === true ? group_disabled : option.disabled,
56
            group_array_index: group_position,
57
            group_label: group_position != null ? this.parsed[group_position].label : null,
58
            classes: option.className,
59
            style: option.style.cssText
60
          });
61
        } else {
62
          this.parsed.push({
63
            array_index: this.parsed.length,
64
            options_index: this.options_index,
65
            empty: true
66
          });
67
        }
68
        return this.options_index += 1;
69
      }
70
    };
71
72
    SelectParser.prototype.escapeExpression = function(text) {
73
      var map, unsafe_chars;
74
      if ((text == null) || text === false) {
75
        return "";
76
      }
77
      if (!/[\&\<\>\"\'\`]/.test(text)) {
78
        return text;
79
      }
80
      map = {
81
        "<": "&lt;",
82
        ">": "&gt;",
83
        '"': "&quot;",
84
        "'": "&#x27;",
85
        "`": "&#x60;"
86
      };
87
      unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g;
88
      return text.replace(unsafe_chars, function(chr) {
89
        return map[chr] || "&amp;";
90
      });
91
    };
92
93
    return SelectParser;
94
95
  })();
96
97
  SelectParser.select_to_array = function(select) {
98
    var child, parser, _i, _len, _ref;
99
    parser = new SelectParser();
100
    _ref = select.childNodes;
101
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
102
      child = _ref[_i];
103
      parser.add_node(child);
104
    }
105
    return parser.parsed;
106
  };
107
108
  AbstractChosen = (function() {
109
    function AbstractChosen(form_field, options) {
110
      this.form_field = form_field;
111
      this.options = options != null ? options : {};
112
      if (!AbstractChosen.browser_is_supported()) {
113
        return;
114
      }
115
      this.is_multiple = this.form_field.multiple;
116
      this.set_default_text();
117
      this.set_default_values();
118
      this.setup();
119
      this.set_up_html();
120
      this.register_observers();
121
      this.on_ready();
122
    }
123
124
    AbstractChosen.prototype.set_default_values = function() {
125
      var _this = this;
126
      this.click_test_action = function(evt) {
127
        return _this.test_active_click(evt);
128
      };
129
      this.activate_action = function(evt) {
130
        return _this.activate_field(evt);
131
      };
132
      this.active_field = false;
133
      this.mouse_on_container = false;
134
      this.results_showing = false;
135
      this.result_highlighted = null;
136
      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;
137
      this.disable_search_threshold = this.options.disable_search_threshold || 0;
138
      this.disable_search = this.options.disable_search || false;
139
      this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
140
      this.group_search = this.options.group_search != null ? this.options.group_search : true;
141
      this.search_contains = this.options.search_contains || false;
142
      this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
143
      this.max_selected_options = this.options.max_selected_options || Infinity;
144
      this.inherit_select_classes = this.options.inherit_select_classes || false;
145
      this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
146
      this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
147
      this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
148
      this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
149
      return this.case_sensitive_search = this.options.case_sensitive_search || false;
150
    };
151
152
    AbstractChosen.prototype.set_default_text = function() {
153
      if (this.form_field.getAttribute("data-placeholder")) {
154
        this.default_text = this.form_field.getAttribute("data-placeholder");
155
      } else if (this.is_multiple) {
156
        this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
157
      } else {
158
        this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
159
      }
160
      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
161
    };
162
163
    AbstractChosen.prototype.choice_label = function(item) {
164
      if (this.include_group_label_in_selected && (item.group_label != null)) {
165
        return "<b class='group-name'>" + item.group_label + "</b>" + item.html;
166
      } else {
167
        return item.html;
168
      }
169
    };
170
171
    AbstractChosen.prototype.mouse_enter = function() {
172
      return this.mouse_on_container = true;
173
    };
174
175
    AbstractChosen.prototype.mouse_leave = function() {
176
      return this.mouse_on_container = false;
177
    };
178
179
    AbstractChosen.prototype.input_focus = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
180
      var _this = this;
181
      if (this.is_multiple) {
182
        if (!this.active_field) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.active_field is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
183
          return setTimeout((function() {
184
            return _this.container_mousedown();
185
          }), 50);
186
        }
187
      } else {
188
        if (!this.active_field) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.active_field is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
189
          return this.activate_field();
190
        }
191
      }
192
    };
193
194
    AbstractChosen.prototype.input_blur = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
195
      var _this = this;
196
      if (!this.mouse_on_container) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.mouse_on_container is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
197
        this.active_field = false;
198
        return setTimeout((function() {
199
          return _this.blur_test();
200
        }), 100);
201
      }
202
    };
203
204
    AbstractChosen.prototype.results_option_build = function(options) {
205
      var content, data, data_content, shown_results, _i, _len, _ref;
206
      content = '';
207
      shown_results = 0;
208
      _ref = this.results_data;
209
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
210
        data = _ref[_i];
211
        data_content = '';
0 ignored issues
show
Unused Code introduced by
The assignment to variable data_content seems to be never used. Consider removing it.
Loading history...
212
        if (data.group) {
213
          data_content = this.result_add_group(data);
214
        } else {
215
          data_content = this.result_add_option(data);
216
        }
217
        if (data_content !== '') {
218
          shown_results++;
219
          content += data_content;
220
        }
221
        if (options != null ? options.first : void 0) {
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
222
          if (data.selected && this.is_multiple) {
223
            this.choice_build(data);
224
          } else if (data.selected && !this.is_multiple) {
225
            this.single_set_selected_text(this.choice_label(data));
226
          }
227
        }
228
        if (shown_results >= this.max_shown_results) {
229
          break;
230
        }
231
      }
232
      return content;
233
    };
234
235
    AbstractChosen.prototype.result_add_option = function(option) {
236
      var classes, option_el;
237
      if (!option.search_match) {
238
        return '';
239
      }
240
      if (!this.include_option_in_results(option)) {
241
        return '';
242
      }
243
      classes = [];
244
      if (!option.disabled && !(option.selected && this.is_multiple)) {
245
        classes.push("active-result");
246
      }
247
      if (option.disabled && !(option.selected && this.is_multiple)) {
248
        classes.push("disabled-result");
249
      }
250
      if (option.selected) {
251
        classes.push("result-selected");
252
      }
253
      if (option.group_array_index != null) {
254
        classes.push("group-option");
255
      }
256
      if (option.classes !== "") {
257
        classes.push(option.classes);
258
      }
259
      option_el = document.createElement("li");
260
      option_el.className = classes.join(" ");
261
      option_el.style.cssText = option.style;
262
      option_el.setAttribute("data-option-array-index", option.array_index);
263
      option_el.innerHTML = option.search_text;
264
      if (option.title) {
265
        option_el.title = option.title;
266
      }
267
      return this.outerHTML(option_el);
268
    };
269
270
    AbstractChosen.prototype.result_add_group = function(group) {
271
      var classes, group_el;
272
      if (!(group.search_match || group.group_match)) {
273
        return '';
274
      }
275
      if (!(group.active_options > 0)) {
276
        return '';
277
      }
278
      classes = [];
279
      classes.push("group-result");
280
      if (group.classes) {
281
        classes.push(group.classes);
282
      }
283
      group_el = document.createElement("li");
284
      group_el.className = classes.join(" ");
285
      group_el.innerHTML = group.search_text;
286
      if (group.title) {
287
        group_el.title = group.title;
288
      }
289
      return this.outerHTML(group_el);
290
    };
291
292
    AbstractChosen.prototype.results_update_field = function() {
293
      this.set_default_text();
294
      if (!this.is_multiple) {
295
        this.results_reset_cleanup();
296
      }
297
      this.result_clear_highlight();
298
      this.results_build();
299
      if (this.results_showing) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.results_showing is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
300
        return this.winnow_results();
301
      }
302
    };
303
304
    AbstractChosen.prototype.reset_single_select_options = function() {
305
      var result, _i, _len, _ref, _results;
306
      _ref = this.results_data;
307
      _results = [];
308
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
309
        result = _ref[_i];
310
        if (result.selected) {
311
          _results.push(result.selected = false);
312
        } else {
313
          _results.push(void 0);
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
314
        }
315
      }
316
      return _results;
317
    };
318
319
    AbstractChosen.prototype.results_toggle = function() {
320
      if (this.results_showing) {
321
        return this.results_hide();
322
      } else {
323
        return this.results_show();
324
      }
325
    };
326
327
    AbstractChosen.prototype.results_search = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
328
      if (this.results_showing) {
329
        return this.winnow_results();
330
      } else {
331
        return this.results_show();
332
      }
333
    };
334
335
    AbstractChosen.prototype.winnow_results = function() {
336
      var escapedSearchText, option, regex, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
337
      this.no_results_clear();
338
      results = 0;
339
      searchText = this.get_search_text();
340
      escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
341
      zregex = new RegExp(escapedSearchText, 'i');
342
      regex = this.get_search_regex(escapedSearchText);
343
      _ref = this.results_data;
344
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
345
        option = _ref[_i];
346
        option.search_match = false;
347
        results_group = null;
348
        if (this.include_option_in_results(option)) {
349
          if (option.group) {
350
            option.group_match = false;
351
            option.active_options = 0;
352
          }
353
          if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
354
            results_group = this.results_data[option.group_array_index];
355
            if (results_group.active_options === 0 && results_group.search_match) {
356
              results += 1;
357
            }
358
            results_group.active_options += 1;
359
          }
360
          option.search_text = option.group ? option.label : option.html;
361
          if (!(option.group && !this.group_search)) {
362
            option.search_match = this.search_string_match(option.search_text, regex);
363
            if (option.search_match && !option.group) {
364
              results += 1;
365
            }
366
            if (option.search_match) {
367
              if (searchText.length) {
368
                startpos = option.search_text.search(zregex);
369
                text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
370
                option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
371
              }
372
              if (results_group != null) {
373
                results_group.group_match = true;
374
              }
375
            } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
376
              option.search_match = true;
377
            }
378
          }
379
        }
380
      }
381
      this.result_clear_highlight();
382
      if (results < 1 && searchText.length) {
383
        this.update_results_content("");
384
        return this.no_results(searchText);
385
      } else {
386
        this.update_results_content(this.results_option_build());
387
        return this.winnow_results_set_highlight();
388
      }
389
    };
390
391
    AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
392
      var regex_anchor, regex_flag;
393
      regex_anchor = this.search_contains ? "" : "^";
394
      regex_flag = this.case_sensitive_search ? "" : "i";
395
      return new RegExp(regex_anchor + escaped_search_string, regex_flag);
396
    };
397
398
    AbstractChosen.prototype.search_string_match = function(search_string, regex) {
399
      var part, parts, _i, _len;
400
      if (regex.test(search_string)) {
401
        return true;
402
      } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.enable_split_word_s...ring.indexOf("[") === 0 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
403
        parts = search_string.replace(/\[|\]/g, "").split(" ");
404
        if (parts.length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if parts.length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
405
          for (_i = 0, _len = parts.length; _i < _len; _i++) {
406
            part = parts[_i];
407
            if (regex.test(part)) {
408
              return true;
409
            }
410
          }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
411
        }
412
      }
413
    };
414
415
    AbstractChosen.prototype.choices_count = function() {
416
      var option, _i, _len, _ref;
417
      if (this.selected_option_count != null) {
418
        return this.selected_option_count;
419
      }
420
      this.selected_option_count = 0;
421
      _ref = this.form_field.options;
422
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
423
        option = _ref[_i];
424
        if (option.selected) {
425
          this.selected_option_count += 1;
426
        }
427
      }
428
      return this.selected_option_count;
429
    };
430
431
    AbstractChosen.prototype.choices_click = function(evt) {
432
      evt.preventDefault();
433
      if (!(this.results_showing || this.is_disabled)) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !(this.results_showing || this.is_disabled) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
434
        return this.results_show();
435
      }
436
    };
437
438
    AbstractChosen.prototype.keyup_checker = function(evt) {
439
      var stroke, _ref;
440
      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
441
      this.search_field_scale();
442
      switch (stroke) {
443
        case 8:
444
          if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
445
            return this.keydown_backstroke();
446
          } else if (!this.pending_backstroke) {
447
            this.result_clear_highlight();
448
            return this.results_search();
449
          }
450
          break;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
451
        case 13:
452
          evt.preventDefault();
453
          if (this.results_showing) {
454
            return this.result_select(evt);
455
          }
456
          break;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
457
        case 27:
458
          if (this.results_showing) {
459
            this.results_hide();
460
          }
461
          return true;
462
        case 9:
463
        case 38:
464
        case 40:
465
        case 16:
466
        case 91:
467
        case 17:
468
        case 18:
469
          break;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
470
        default:
471
          return this.results_search();
472
      }
473
    };
474
475
    AbstractChosen.prototype.clipboard_event_checker = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
476
      var _this = this;
477
      return setTimeout((function() {
478
        return _this.results_search();
479
      }), 50);
480
    };
481
482
    AbstractChosen.prototype.container_width = function() {
483
      if (this.options.width != null) {
484
        return this.options.width;
485
      } else {
486
        return "" + this.form_field.offsetWidth + "px";
487
      }
488
    };
489
490
    AbstractChosen.prototype.include_option_in_results = function(option) {
491
      if (this.is_multiple && (!this.display_selected_options && option.selected)) {
492
        return false;
493
      }
494
      if (!this.display_disabled_options && option.disabled) {
495
        return false;
496
      }
497
      if (option.empty) {
498
        return false;
499
      }
500
      return true;
501
    };
502
503
    AbstractChosen.prototype.search_results_touchstart = function(evt) {
504
      this.touch_started = true;
505
      return this.search_results_mouseover(evt);
506
    };
507
508
    AbstractChosen.prototype.search_results_touchmove = function(evt) {
509
      this.touch_started = false;
510
      return this.search_results_mouseout(evt);
511
    };
512
513
    AbstractChosen.prototype.search_results_touchend = function(evt) {
514
      if (this.touch_started) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.touch_started is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
515
        return this.search_results_mouseup(evt);
516
      }
517
    };
518
519
    AbstractChosen.prototype.outerHTML = function(element) {
520
      var tmp;
521
      if (element.outerHTML) {
522
        return element.outerHTML;
523
      }
524
      tmp = document.createElement("div");
525
      tmp.appendChild(element);
526
      return tmp.innerHTML;
527
    };
528
529
    AbstractChosen.browser_is_supported = function() {
530
      if ("Microsoft Internet Explorer" === window.navigator.appName) {
531
        return document.documentMode >= 8;
532
      }
533
      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)) {
534
        return false;
535
      }
536
      return true;
537
    };
538
539
    AbstractChosen.default_multiple_text = "Select Some Options";
540
541
    AbstractChosen.default_single_text = "Select an Option";
542
543
    AbstractChosen.default_no_result_text = "No results match";
544
545
    return AbstractChosen;
546
547
  })();
548
549
  $ = jQuery;
550
551
  $.fn.extend({
552
    chosen: function(options) {
553
      if (!AbstractChosen.browser_is_supported()) {
554
        return this;
555
      }
556
      return this.each(function(input_field) {
0 ignored issues
show
Unused Code introduced by
The parameter input_field is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
557
        var $this, chosen;
558
        $this = $(this);
559
        chosen = $this.data('chosen');
560
        if (options === 'destroy') {
561
          if (chosen instanceof Chosen) {
562
            chosen.destroy();
563
          }
564
          return;
565
        }
566
        if (!(chosen instanceof Chosen)) {
567
          $this.data('chosen', new Chosen(this, options));
568
        }
569
      });
570
    }
571
  });
572
573
  Chosen = (function(_super) {
574
    __extends(Chosen, _super);
575
576
    function Chosen() {
577
      _ref = Chosen.__super__.constructor.apply(this, arguments);
578
      return _ref;
579
    }
580
581
    Chosen.prototype.setup = function() {
582
      this.form_field_jq = $(this.form_field);
583
      this.current_selectedIndex = this.form_field.selectedIndex;
584
      return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
585
    };
586
587
    Chosen.prototype.set_up_html = function() {
588
      var container_classes, container_props;
589
      container_classes = ["chosen-container"];
590
      container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
591
      if (this.inherit_select_classes && this.form_field.className) {
592
        container_classes.push(this.form_field.className);
593
      }
594
      if (this.is_rtl) {
595
        container_classes.push("chosen-rtl");
596
      }
597
      container_props = {
598
        'class': container_classes.join(' '),
599
        'style': "width: " + (this.container_width()) + ";",
600
        'title': this.form_field.title
601
      };
602
      if (this.form_field.id.length) {
603
        container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
604
      }
605
      this.container = $("<div />", container_props);
606
      if (this.is_multiple) {
607
        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>');
608
      } else {
609
        this.container.html('<a class="chosen-single chosen-default"><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>');
610
      }
611
      this.form_field_jq.hide().after(this.container);
612
      this.dropdown = this.container.find('div.chosen-drop').first();
613
      this.search_field = this.container.find('input').first();
614
      this.search_results = this.container.find('ul.chosen-results').first();
615
      this.search_field_scale();
616
      this.search_no_results = this.container.find('li.no-results').first();
617
      if (this.is_multiple) {
618
        this.search_choices = this.container.find('ul.chosen-choices').first();
619
        this.search_container = this.container.find('li.search-field').first();
620
      } else {
621
        this.search_container = this.container.find('div.chosen-search').first();
622
        this.selected_item = this.container.find('.chosen-single').first();
623
      }
624
      this.results_build();
625
      this.set_tab_index();
626
      return this.set_label_behavior();
627
    };
628
629
    Chosen.prototype.on_ready = function() {
630
      return this.form_field_jq.trigger("chosen:ready", {
631
        chosen: this
632
      });
633
    };
634
635
    Chosen.prototype.register_observers = function() {
636
      var _this = this;
637
      this.container.bind('touchstart.chosen', function(evt) {
638
        _this.container_mousedown(evt);
639
        return evt.preventDefault();
640
      });
641
      this.container.bind('touchend.chosen', function(evt) {
642
        _this.container_mouseup(evt);
643
        return evt.preventDefault();
644
      });
645
      this.container.bind('mousedown.chosen', function(evt) {
646
        _this.container_mousedown(evt);
647
      });
648
      this.container.bind('mouseup.chosen', function(evt) {
649
        _this.container_mouseup(evt);
650
      });
651
      this.container.bind('mouseenter.chosen', function(evt) {
652
        _this.mouse_enter(evt);
653
      });
654
      this.container.bind('mouseleave.chosen', function(evt) {
655
        _this.mouse_leave(evt);
656
      });
657
      this.search_results.bind('mouseup.chosen', function(evt) {
658
        _this.search_results_mouseup(evt);
659
      });
660
      this.search_results.bind('mouseover.chosen', function(evt) {
661
        _this.search_results_mouseover(evt);
662
      });
663
      this.search_results.bind('mouseout.chosen', function(evt) {
664
        _this.search_results_mouseout(evt);
665
      });
666
      this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
667
        _this.search_results_mousewheel(evt);
668
      });
669
      this.search_results.bind('touchstart.chosen', function(evt) {
670
        _this.search_results_touchstart(evt);
671
      });
672
      this.search_results.bind('touchmove.chosen', function(evt) {
673
        _this.search_results_touchmove(evt);
674
      });
675
      this.search_results.bind('touchend.chosen', function(evt) {
676
        _this.search_results_touchend(evt);
677
      });
678
      this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
679
        _this.results_update_field(evt);
680
      });
681
      this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
682
        _this.activate_field(evt);
683
      });
684
      this.form_field_jq.bind("chosen:open.chosen", function(evt) {
685
        _this.container_mousedown(evt);
686
      });
687
      this.form_field_jq.bind("chosen:close.chosen", function(evt) {
688
        _this.input_blur(evt);
689
      });
690
      this.search_field.bind('blur.chosen', function(evt) {
691
        _this.input_blur(evt);
692
      });
693
      this.search_field.bind('keyup.chosen', function(evt) {
694
        _this.keyup_checker(evt);
695
      });
696
      this.search_field.bind('keydown.chosen', function(evt) {
697
        _this.keydown_checker(evt);
698
      });
699
      this.search_field.bind('focus.chosen', function(evt) {
700
        _this.input_focus(evt);
701
      });
702
      this.search_field.bind('cut.chosen', function(evt) {
703
        _this.clipboard_event_checker(evt);
704
      });
705
      this.search_field.bind('paste.chosen', function(evt) {
706
        _this.clipboard_event_checker(evt);
707
      });
708
      if (this.is_multiple) {
709
        return this.search_choices.bind('click.chosen', function(evt) {
710
          _this.choices_click(evt);
711
        });
712
      } else {
713
        return this.container.bind('click.chosen', function(evt) {
714
          evt.preventDefault();
715
        });
716
      }
717
    };
718
719
    Chosen.prototype.destroy = function() {
720
      $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
721
      if (this.search_field[0].tabIndex) {
722
        this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
723
      }
724
      this.container.remove();
725
      this.form_field_jq.removeData('chosen');
726
      return this.form_field_jq.show();
727
    };
728
729
    Chosen.prototype.search_field_disabled = function() {
730
      this.is_disabled = this.form_field_jq[0].disabled;
731
      if (this.is_disabled) {
732
        this.container.addClass('chosen-disabled');
733
        this.search_field[0].disabled = true;
734
        if (!this.is_multiple) {
735
          this.selected_item.unbind("focus.chosen", this.activate_action);
736
        }
737
        return this.close_field();
738
      } else {
739
        this.container.removeClass('chosen-disabled');
740
        this.search_field[0].disabled = false;
741
        if (!this.is_multiple) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.is_multiple is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
742
          return this.selected_item.bind("focus.chosen", this.activate_action);
743
        }
744
      }
745
    };
746
747
    Chosen.prototype.container_mousedown = function(evt) {
748
      if (!this.is_disabled) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.is_disabled is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
749
        if (evt && evt.type === "mousedown" && !this.results_showing) {
750
          evt.preventDefault();
751
        }
752
        if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !(evt != null && $(evt.t..."search-choice-close")) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
753
          if (!this.active_field) {
754
            if (this.is_multiple) {
755
              this.search_field.val("");
756
            }
757
            $(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action);
758
            this.results_show();
759
          } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
760
            evt.preventDefault();
761
            this.results_toggle();
762
          }
763
          return this.activate_field();
764
        }
765
      }
766
    };
767
768
    Chosen.prototype.container_mouseup = function(evt) {
769
      if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if evt.target.nodeName === ...R" && !this.is_disabled is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
770
        return this.results_reset(evt);
771
      }
772
    };
773
774
    Chosen.prototype.search_results_mousewheel = function(evt) {
775
      var delta;
776
      if (evt.originalEvent) {
777
        delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
778
      }
779
      if (delta != null) {
0 ignored issues
show
Bug introduced by
The variable delta does not seem to be initialized in case evt.originalEvent on line 776 is false. Are you sure this can never be the case?
Loading history...
Complexity Best Practice introduced by
There is no return statement if delta != null is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
780
        evt.preventDefault();
781
        if (evt.type === 'DOMMouseScroll') {
782
          delta = delta * 40;
783
        }
784
        return this.search_results.scrollTop(delta + this.search_results.scrollTop());
785
      }
786
    };
787
788
    Chosen.prototype.blur_test = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
789
      if (!this.active_field && this.container.hasClass("chosen-container-active")) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.active_field && th...osen-container-active") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
790
        return this.close_field();
791
      }
792
    };
793
794
    Chosen.prototype.close_field = function() {
795
      $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
796
      this.active_field = false;
797
      this.results_hide();
798
      this.container.removeClass("chosen-container-active");
799
      this.clear_backstroke();
800
      this.show_search_field_default();
801
      return this.search_field_scale();
802
    };
803
804
    Chosen.prototype.activate_field = function() {
805
      this.container.addClass("chosen-container-active");
806
      this.active_field = true;
807
      this.search_field.val(this.search_field.val());
808
      return this.search_field.focus();
809
    };
810
811
    Chosen.prototype.test_active_click = function(evt) {
812
      var active_container;
813
      active_container = $(evt.target).closest('.chosen-container');
814
      if (active_container.length && this.container[0] === active_container[0]) {
815
        return this.active_field = true;
816
      } else {
817
        return this.close_field();
818
      }
819
    };
820
821
    Chosen.prototype.results_build = function() {
822
      this.parsing = true;
823
      this.selected_option_count = null;
824
      this.results_data = SelectParser.select_to_array(this.form_field);
825
      if (this.is_multiple) {
826
        this.search_choices.find("li.search-choice").remove();
827
      } else if (!this.is_multiple) {
828
        this.single_set_selected_text();
829
        if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
830
          this.search_field[0].readOnly = true;
831
          this.container.addClass("chosen-container-single-nosearch");
832
        } else {
833
          this.search_field[0].readOnly = false;
834
          this.container.removeClass("chosen-container-single-nosearch");
835
        }
836
      }
837
      this.update_results_content(this.results_option_build({
838
        first: true
839
      }));
840
      this.search_field_disabled();
841
      this.show_search_field_default();
842
      this.search_field_scale();
843
      return this.parsing = false;
844
    };
845
846
    Chosen.prototype.result_do_highlight = function(el) {
847
      var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
848
      if (el.length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if el.length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
849
        this.result_clear_highlight();
850
        this.result_highlight = el;
851
        this.result_highlight.addClass("highlighted");
852
        maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
853
        visible_top = this.search_results.scrollTop();
854
        visible_bottom = maxHeight + visible_top;
855
        high_top = this.result_highlight.position().top + this.search_results.scrollTop();
856
        high_bottom = high_top + this.result_highlight.outerHeight();
857
        if (high_bottom >= visible_bottom) {
858
          return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
859
        } else if (high_top < visible_top) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if high_top < visible_top is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
860
          return this.search_results.scrollTop(high_top);
861
        }
862
      }
863
    };
864
865
    Chosen.prototype.result_clear_highlight = function() {
866
      if (this.result_highlight) {
867
        this.result_highlight.removeClass("highlighted");
868
      }
869
      return this.result_highlight = null;
870
    };
871
872
    Chosen.prototype.results_show = function() {
873
      if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
874
        this.form_field_jq.trigger("chosen:maxselected", {
875
          chosen: this
876
        });
877
        return false;
878
      }
879
      this.container.addClass("chosen-with-drop");
880
      this.results_showing = true;
881
      this.search_field.focus();
882
      this.search_field.val(this.search_field.val());
883
      this.winnow_results();
884
      return this.form_field_jq.trigger("chosen:showing_dropdown", {
885
        chosen: this
886
      });
887
    };
888
889
    Chosen.prototype.update_results_content = function(content) {
890
      return this.search_results.html(content);
891
    };
892
893
    Chosen.prototype.results_hide = function() {
894
      if (this.results_showing) {
895
        this.result_clear_highlight();
896
        this.container.removeClass("chosen-with-drop");
897
        this.form_field_jq.trigger("chosen:hiding_dropdown", {
898
          chosen: this
899
        });
900
      }
901
      return this.results_showing = false;
902
    };
903
904
    Chosen.prototype.set_tab_index = function(el) {
0 ignored issues
show
Unused Code introduced by
The parameter el is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
905
      var ti;
906
      if (this.form_field.tabIndex) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.form_field.tabIndex is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
907
        ti = this.form_field.tabIndex;
908
        this.form_field.tabIndex = -1;
909
        return this.search_field[0].tabIndex = ti;
910
      }
911
    };
912
913
    Chosen.prototype.set_label_behavior = function() {
914
      var _this = this;
915
      this.form_field_label = this.form_field_jq.parents("label");
916
      if (!this.form_field_label.length && this.form_field.id.length) {
917
        this.form_field_label = $("label[for='" + this.form_field.id + "']");
918
      }
919
      if (this.form_field_label.length > 0) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.form_field_label.length > 0 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
920
        return this.form_field_label.bind('click.chosen', function(evt) {
921
          if (_this.is_multiple) {
922
            return _this.container_mousedown(evt);
923
          } else {
924
            return _this.activate_field();
925
          }
926
        });
927
      }
928
    };
929
930
    Chosen.prototype.show_search_field_default = function() {
931
      if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
932
        this.search_field.val(this.default_text);
933
        return this.search_field.addClass("default");
934
      } else {
935
        this.search_field.val("");
936
        return this.search_field.removeClass("default");
937
      }
938
    };
939
940
    Chosen.prototype.search_results_mouseup = function(evt) {
941
      var target;
942
      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
943
      if (target.length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if target.length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
944
        this.result_highlight = target;
945
        this.result_select(evt);
946
        return this.search_field.focus();
947
      }
948
    };
949
950
    Chosen.prototype.search_results_mouseover = function(evt) {
951
      var target;
952
      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
953
      if (target) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if target is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
954
        return this.result_do_highlight(target);
955
      }
956
    };
957
958
    Chosen.prototype.search_results_mouseout = function(evt) {
959
      if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if $(evt.target).hasClass("...ctive-result").first()) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
960
        return this.result_clear_highlight();
961
      }
962
    };
963
964
    Chosen.prototype.choice_build = function(item) {
965
      var choice, close_link,
966
        _this = this;
967
      choice = $('<li />', {
968
        "class": "search-choice"
969
      }).html("<span>" + (this.choice_label(item)) + "</span>");
970
      if (item.disabled) {
971
        choice.addClass('search-choice-disabled');
972
      } else {
973
        close_link = $('<a />', {
974
          "class": 'search-choice-close',
975
          'data-option-array-index': item.array_index
976
        });
977
        close_link.bind('click.chosen', function(evt) {
978
          return _this.choice_destroy_link_click(evt);
979
        });
980
        choice.append(close_link);
981
      }
982
      return this.search_container.before(choice);
983
    };
984
985
    Chosen.prototype.choice_destroy_link_click = function(evt) {
986
      evt.preventDefault();
987
      evt.stopPropagation();
988
      if (!this.is_disabled) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !this.is_disabled is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
989
        return this.choice_destroy($(evt.target));
990
      }
991
    };
992
993
    Chosen.prototype.choice_destroy = function(link) {
994
      if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.result_deselect(lin...a-option-array-index")) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
995
        this.show_search_field_default();
996
        if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
997
          this.results_hide();
998
        }
999
        link.parents('li').first().remove();
1000
        return this.search_field_scale();
1001
      }
1002
    };
1003
1004
    Chosen.prototype.results_reset = function() {
1005
      this.reset_single_select_options();
1006
      this.form_field.options[0].selected = true;
1007
      this.single_set_selected_text();
1008
      this.show_search_field_default();
1009
      this.results_reset_cleanup();
1010
      this.form_field_jq.trigger("change");
1011
      if (this.active_field) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.active_field is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1012
        return this.results_hide();
1013
      }
1014
    };
1015
1016
    Chosen.prototype.results_reset_cleanup = function() {
1017
      this.current_selectedIndex = this.form_field.selectedIndex;
1018
      return this.selected_item.find("abbr").remove();
1019
    };
1020
1021
    Chosen.prototype.result_select = function(evt) {
1022
      var high, item;
1023
      if (this.result_highlight) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.result_highlight is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1024
        high = this.result_highlight;
1025
        this.result_clear_highlight();
1026
        if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
1027
          this.form_field_jq.trigger("chosen:maxselected", {
1028
            chosen: this
1029
          });
1030
          return false;
1031
        }
1032
        if (this.is_multiple) {
1033
          high.removeClass("active-result");
1034
        } else {
1035
          this.reset_single_select_options();
1036
        }
1037
        high.addClass("result-selected");
1038
        item = this.results_data[high[0].getAttribute("data-option-array-index")];
1039
        item.selected = true;
1040
        this.form_field.options[item.options_index].selected = true;
1041
        this.selected_option_count = null;
1042
        if (this.is_multiple) {
1043
          this.choice_build(item);
1044
        } else {
1045
          this.single_set_selected_text(this.choice_label(item));
1046
        }
1047
        if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
1048
          this.results_hide();
1049
        }
1050
        this.show_search_field_default();
1051
        if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
1052
          this.form_field_jq.trigger("change", {
1053
            'selected': this.form_field.options[item.options_index].value
1054
          });
1055
        }
1056
        this.current_selectedIndex = this.form_field.selectedIndex;
1057
        evt.preventDefault();
1058
        return this.search_field_scale();
1059
      }
1060
    };
1061
1062
    Chosen.prototype.single_set_selected_text = function(text) {
1063
      if (text == null) {
1064
        text = this.default_text;
1065
      }
1066
      if (text === this.default_text) {
1067
        this.selected_item.addClass("chosen-default");
1068
      } else {
1069
        this.single_deselect_control_build();
1070
        this.selected_item.removeClass("chosen-default");
1071
      }
1072
      return this.selected_item.find("span").html(text);
1073
    };
1074
1075
    Chosen.prototype.result_deselect = function(pos) {
1076
      var result_data;
1077
      result_data = this.results_data[pos];
1078
      if (!this.form_field.options[result_data.options_index].disabled) {
1079
        result_data.selected = false;
1080
        this.form_field.options[result_data.options_index].selected = false;
1081
        this.selected_option_count = null;
1082
        this.result_clear_highlight();
1083
        if (this.results_showing) {
1084
          this.winnow_results();
1085
        }
1086
        this.form_field_jq.trigger("change", {
1087
          deselected: this.form_field.options[result_data.options_index].value
1088
        });
1089
        this.search_field_scale();
1090
        return true;
1091
      } else {
1092
        return false;
1093
      }
1094
    };
1095
1096
    Chosen.prototype.single_deselect_control_build = function() {
1097
      if (!this.allow_single_deselect) {
1098
        return;
1099
      }
1100
      if (!this.selected_item.find("abbr").length) {
1101
        this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
1102
      }
1103
      return this.selected_item.addClass("chosen-single-with-deselect");
1104
    };
1105
1106
    Chosen.prototype.get_search_text = function() {
1107
      return $('<div/>').text($.trim(this.search_field.val())).html();
1108
    };
1109
1110
    Chosen.prototype.winnow_results_set_highlight = function() {
1111
      var do_high, selected_results;
1112
      selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
1113
      do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
1114
      if (do_high != null) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if do_high != null is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1115
        return this.result_do_highlight(do_high);
1116
      }
1117
    };
1118
1119
    Chosen.prototype.no_results = function(terms) {
1120
      var no_results_html;
1121
      no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
1122
      no_results_html.find("span").first().html(terms);
1123
      this.search_results.append(no_results_html);
1124
      return this.form_field_jq.trigger("chosen:no_results", {
1125
        chosen: this
1126
      });
1127
    };
1128
1129
    Chosen.prototype.no_results_clear = function() {
1130
      return this.search_results.find(".no-results").remove();
1131
    };
1132
1133
    Chosen.prototype.keydown_arrow = function() {
1134
      var next_sib;
1135
      if (this.results_showing && this.result_highlight) {
1136
        next_sib = this.result_highlight.nextAll("li.active-result").first();
1137
        if (next_sib) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if next_sib is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1138
          return this.result_do_highlight(next_sib);
1139
        }
1140
      } else {
1141
        return this.results_show();
1142
      }
1143
    };
1144
1145
    Chosen.prototype.keyup_arrow = function() {
1146
      var prev_sibs;
1147
      if (!this.results_showing && !this.is_multiple) {
1148
        return this.results_show();
1149
      } else if (this.result_highlight) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.result_highlight is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1150
        prev_sibs = this.result_highlight.prevAll("li.active-result");
1151
        if (prev_sibs.length) {
1152
          return this.result_do_highlight(prev_sibs.first());
1153
        } else {
1154
          if (this.choices_count() > 0) {
1155
            this.results_hide();
1156
          }
1157
          return this.result_clear_highlight();
1158
        }
1159
      }
1160
    };
1161
1162
    Chosen.prototype.keydown_backstroke = function() {
1163
      var next_available_destroy;
1164
      if (this.pending_backstroke) {
1165
        this.choice_destroy(this.pending_backstroke.find("a").first());
1166
        return this.clear_backstroke();
1167
      } else {
1168
        next_available_destroy = this.search_container.siblings("li.search-choice").last();
1169
        if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if next_available_destroy.l...earch-choice-disabled") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1170
          this.pending_backstroke = next_available_destroy;
1171
          if (this.single_backstroke_delete) {
1172
            return this.keydown_backstroke();
1173
          } else {
1174
            return this.pending_backstroke.addClass("search-choice-focus");
1175
          }
1176
        }
1177
      }
1178
    };
1179
1180
    Chosen.prototype.clear_backstroke = function() {
1181
      if (this.pending_backstroke) {
1182
        this.pending_backstroke.removeClass("search-choice-focus");
1183
      }
1184
      return this.pending_backstroke = null;
1185
    };
1186
1187
    Chosen.prototype.keydown_checker = function(evt) {
1188
      var stroke, _ref1;
1189
      stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
1190
      this.search_field_scale();
1191
      if (stroke !== 8 && this.pending_backstroke) {
1192
        this.clear_backstroke();
1193
      }
1194
      switch (stroke) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1195
        case 8:
1196
          this.backstroke_length = this.search_field.val().length;
1197
          break;
1198
        case 9:
1199
          if (this.results_showing && !this.is_multiple) {
1200
            this.result_select(evt);
1201
          }
1202
          this.mouse_on_container = false;
1203
          break;
1204
        case 13:
1205
          if (this.results_showing) {
1206
            evt.preventDefault();
1207
          }
1208
          break;
1209
        case 32:
1210
          if (this.disable_search) {
1211
            evt.preventDefault();
1212
          }
1213
          break;
1214
        case 38:
1215
          evt.preventDefault();
1216
          this.keyup_arrow();
1217
          break;
1218
        case 40:
1219
          evt.preventDefault();
1220
          this.keydown_arrow();
1221
          break;
1222
      }
1223
    };
1224
1225
    Chosen.prototype.search_field_scale = function() {
1226
      var div, f_width, h, style, style_block, styles, w, _i, _len;
1227
      if (this.is_multiple) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.is_multiple is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1228
        h = 0;
0 ignored issues
show
Unused Code introduced by
The variable h seems to be never used. Consider removing it.
Loading history...
1229
        w = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to variable w seems to be never used. Consider removing it.
Loading history...
1230
        style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
1231
        styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
1232
        for (_i = 0, _len = styles.length; _i < _len; _i++) {
1233
          style = styles[_i];
1234
          style_block += style + ":" + this.search_field.css(style) + ";";
1235
        }
1236
        div = $('<div />', {
1237
          'style': style_block
1238
        });
1239
        div.text(this.search_field.val());
1240
        $('body').append(div);
1241
        w = div.width() + 25;
1242
        div.remove();
1243
        f_width = this.container.outerWidth();
1244
        if (w > f_width - 10) {
1245
          w = f_width - 10;
1246
        }
1247
        return this.search_field.css({
1248
          'width': w + 'px'
1249
        });
1250
      }
1251
    };
1252
1253
    return Chosen;
1254
1255
  })(AbstractChosen);
1256
1257
}).call(this);
1258