typus 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGELOG +23 -0
  2. data/Gemfile +5 -5
  3. data/README.md +8 -8
  4. data/app/assets/javascripts/typus/application.js +1 -1
  5. data/app/assets/javascripts/typus/jquery.application.js +25 -28
  6. data/app/controllers/admin/resources_controller.rb +1 -1
  7. data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +3 -1
  8. data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +1 -1
  9. data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +3 -3
  10. data/app/helpers/admin/resources/data_types/has_many_helper.rb +2 -2
  11. data/app/helpers/admin/resources/data_types/has_one_helper.rb +1 -1
  12. data/app/helpers/admin/resources/data_types/paperclip_helper.rb +2 -2
  13. data/app/helpers/admin/resources/form_helper.rb +1 -1
  14. data/app/helpers/admin/resources/table_helper.rb +2 -2
  15. data/app/views/admin/dashboard/styles.html.erb +94 -90
  16. data/app/views/admin/dashboard/widgets/_applications.html.erb +1 -1
  17. data/app/views/admin/dashboard/widgets/_models.html.erb +1 -1
  18. data/app/views/admin/dashboard/widgets/_models_extended.html.erb +1 -1
  19. data/app/views/admin/resources/_form.html.erb +1 -1
  20. data/app/views/admin/resources/edit.html.erb +7 -5
  21. data/app/views/admin/templates/_belongs_to.html.erb +8 -2
  22. data/app/views/admin/templates/_date.html.erb +0 -5
  23. data/app/views/admin/templates/_datetime.html.erb +0 -5
  24. data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +14 -12
  25. data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +1 -1
  26. data/config/routes.rb +2 -2
  27. data/lib/generators/typus/config_generator.rb +14 -9
  28. data/lib/support/string.rb +1 -1
  29. data/lib/typus.rb +3 -2
  30. data/lib/typus/configuration.rb +3 -3
  31. data/lib/typus/controller/autocomplete.rb +13 -0
  32. data/lib/typus/controller/format.rb +1 -1
  33. data/lib/typus/controller/headless.rb +3 -1
  34. data/lib/typus/i18n.rb +3 -4
  35. data/lib/typus/orm/active_record/class_methods.rb +4 -4
  36. data/lib/typus/orm/base.rb +2 -2
  37. data/lib/typus/resources.rb +1 -1
  38. data/lib/typus/version.rb +1 -1
  39. data/typus.gemspec +3 -2
  40. data/vendor/assets/chosen/LICENSE.md +24 -0
  41. data/vendor/assets/chosen/chosen.css +58 -24
  42. data/vendor/assets/chosen/chosen.jquery.js +888 -0
  43. data/vendor/assets/chosen/typus/chosen-sprite.png +0 -0
  44. metadata +27 -14
  45. data/vendor/assets/chosen/chosen-sprite.png +0 -0
  46. data/vendor/assets/chosen/chosen.jquery.min.js +0 -10
@@ -0,0 +1,888 @@
1
+ // Chosen, a Select Box Enhancer for jQuery and Protoype
2
+ // by Patrick Filler for Harvest, http://getharvest.com
3
+ //
4
+ // Version 0.9.5
5
+ // Full source at https://github.com/harvesthq/chosen
6
+ // Copyright (c) 2011 Harvest http://getharvest.com
7
+
8
+ // MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
9
+ // This file is generated by `cake build`, do not edit it by hand.
10
+ (function() {
11
+ var SelectParser;
12
+ SelectParser = (function() {
13
+ function SelectParser() {
14
+ this.options_index = 0;
15
+ this.parsed = [];
16
+ }
17
+ SelectParser.prototype.add_node = function(child) {
18
+ if (child.nodeName === "OPTGROUP") {
19
+ return this.add_group(child);
20
+ } else {
21
+ return this.add_option(child);
22
+ }
23
+ };
24
+ SelectParser.prototype.add_group = function(group) {
25
+ var group_position, option, _i, _len, _ref, _results;
26
+ group_position = this.parsed.length;
27
+ this.parsed.push({
28
+ array_index: group_position,
29
+ group: true,
30
+ label: group.label,
31
+ children: 0,
32
+ disabled: group.disabled
33
+ });
34
+ _ref = group.childNodes;
35
+ _results = [];
36
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
37
+ option = _ref[_i];
38
+ _results.push(this.add_option(option, group_position, group.disabled));
39
+ }
40
+ return _results;
41
+ };
42
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
43
+ if (option.nodeName === "OPTION") {
44
+ if (option.text !== "") {
45
+ if (group_position != null) {
46
+ this.parsed[group_position].children += 1;
47
+ }
48
+ this.parsed.push({
49
+ array_index: this.parsed.length,
50
+ options_index: this.options_index,
51
+ value: option.value,
52
+ text: option.text,
53
+ html: option.innerHTML,
54
+ selected: option.selected,
55
+ disabled: group_disabled === true ? group_disabled : option.disabled,
56
+ group_array_index: group_position,
57
+ classes: option.className,
58
+ style: option.style.cssText
59
+ });
60
+ } else {
61
+ this.parsed.push({
62
+ array_index: this.parsed.length,
63
+ options_index: this.options_index,
64
+ empty: true
65
+ });
66
+ }
67
+ return this.options_index += 1;
68
+ }
69
+ };
70
+ return SelectParser;
71
+ })();
72
+ SelectParser.select_to_array = function(select) {
73
+ var child, parser, _i, _len, _ref;
74
+ parser = new SelectParser();
75
+ _ref = select.childNodes;
76
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
77
+ child = _ref[_i];
78
+ parser.add_node(child);
79
+ }
80
+ return parser.parsed;
81
+ };
82
+ this.SelectParser = SelectParser;
83
+ }).call(this);
84
+ (function() {
85
+ /*
86
+ Chosen source: generate output using 'cake build'
87
+ Copyright (c) 2011 by Harvest
88
+ */
89
+ var AbstractChosen, root;
90
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
91
+ root = this;
92
+ AbstractChosen = (function() {
93
+ function AbstractChosen(form_field, options) {
94
+ this.form_field = form_field;
95
+ this.options = options != null ? options : {};
96
+ this.set_default_values();
97
+ this.is_multiple = this.form_field.multiple;
98
+ this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
99
+ this.setup();
100
+ this.set_up_html();
101
+ this.register_observers();
102
+ this.finish_setup();
103
+ }
104
+ AbstractChosen.prototype.set_default_values = function() {
105
+ this.click_test_action = __bind(function(evt) {
106
+ return this.test_active_click(evt);
107
+ }, this);
108
+ this.activate_action = __bind(function(evt) {
109
+ return this.activate_field(evt);
110
+ }, this);
111
+ this.active_field = false;
112
+ this.mouse_on_container = false;
113
+ this.results_showing = false;
114
+ this.result_highlighted = null;
115
+ this.result_single_selected = null;
116
+ this.allow_single_deselect = (this.options.allow_single_deselect != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
117
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
118
+ this.choices = 0;
119
+ return this.results_none_found = this.options.no_results_text || "No results match";
120
+ };
121
+ AbstractChosen.prototype.mouse_enter = function() {
122
+ return this.mouse_on_container = true;
123
+ };
124
+ AbstractChosen.prototype.mouse_leave = function() {
125
+ return this.mouse_on_container = false;
126
+ };
127
+ AbstractChosen.prototype.input_focus = function(evt) {
128
+ if (!this.active_field) {
129
+ return setTimeout((__bind(function() {
130
+ return this.container_mousedown();
131
+ }, this)), 50);
132
+ }
133
+ };
134
+ AbstractChosen.prototype.input_blur = function(evt) {
135
+ if (!this.mouse_on_container) {
136
+ this.active_field = false;
137
+ return setTimeout((__bind(function() {
138
+ return this.blur_test();
139
+ }, this)), 100);
140
+ }
141
+ };
142
+ AbstractChosen.prototype.result_add_option = function(option) {
143
+ var classes, style;
144
+ if (!option.disabled) {
145
+ option.dom_id = this.container_id + "_o_" + option.array_index;
146
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
147
+ if (option.selected) {
148
+ classes.push("result-selected");
149
+ }
150
+ if (option.group_array_index != null) {
151
+ classes.push("group-option");
152
+ }
153
+ if (option.classes !== "") {
154
+ classes.push(option.classes);
155
+ }
156
+ style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
157
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
158
+ } else {
159
+ return "";
160
+ }
161
+ };
162
+ AbstractChosen.prototype.results_update_field = function() {
163
+ this.result_clear_highlight();
164
+ this.result_single_selected = null;
165
+ return this.results_build();
166
+ };
167
+ AbstractChosen.prototype.results_toggle = function() {
168
+ if (this.results_showing) {
169
+ return this.results_hide();
170
+ } else {
171
+ return this.results_show();
172
+ }
173
+ };
174
+ AbstractChosen.prototype.results_search = function(evt) {
175
+ if (this.results_showing) {
176
+ return this.winnow_results();
177
+ } else {
178
+ return this.results_show();
179
+ }
180
+ };
181
+ AbstractChosen.prototype.keyup_checker = function(evt) {
182
+ var stroke, _ref;
183
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
184
+ this.search_field_scale();
185
+ switch (stroke) {
186
+ case 8:
187
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
188
+ return this.keydown_backstroke();
189
+ } else if (!this.pending_backstroke) {
190
+ this.result_clear_highlight();
191
+ return this.results_search();
192
+ }
193
+ break;
194
+ case 13:
195
+ evt.preventDefault();
196
+ if (this.results_showing) {
197
+ return this.result_select(evt);
198
+ }
199
+ break;
200
+ case 27:
201
+ if (this.results_showing) {
202
+ return this.results_hide();
203
+ }
204
+ break;
205
+ case 9:
206
+ case 38:
207
+ case 40:
208
+ case 16:
209
+ case 91:
210
+ case 17:
211
+ break;
212
+ default:
213
+ return this.results_search();
214
+ }
215
+ };
216
+ AbstractChosen.prototype.generate_field_id = function() {
217
+ var new_id;
218
+ new_id = this.generate_random_id();
219
+ this.form_field.id = new_id;
220
+ return new_id;
221
+ };
222
+ AbstractChosen.prototype.generate_random_char = function() {
223
+ var chars, newchar, rand;
224
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
225
+ rand = Math.floor(Math.random() * chars.length);
226
+ return newchar = chars.substring(rand, rand + 1);
227
+ };
228
+ return AbstractChosen;
229
+ })();
230
+ root.AbstractChosen = AbstractChosen;
231
+ }).call(this);
232
+ (function() {
233
+ /*
234
+ Chosen source: generate output using 'cake build'
235
+ Copyright (c) 2011 by Harvest
236
+ */
237
+ var $, Chosen, get_side_border_padding, root;
238
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
239
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
240
+ function ctor() { this.constructor = child; }
241
+ ctor.prototype = parent.prototype;
242
+ child.prototype = new ctor;
243
+ child.__super__ = parent.prototype;
244
+ return child;
245
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
246
+ root = this;
247
+ $ = jQuery;
248
+ $.fn.extend({
249
+ chosen: function(options) {
250
+ if ($.browser === "msie" && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
251
+ return this;
252
+ }
253
+ return $(this).each(function(input_field) {
254
+ if (!($(this)).hasClass("chzn-done")) {
255
+ return new Chosen(this, options);
256
+ }
257
+ });
258
+ }
259
+ });
260
+ Chosen = (function() {
261
+ __extends(Chosen, AbstractChosen);
262
+ function Chosen() {
263
+ Chosen.__super__.constructor.apply(this, arguments);
264
+ }
265
+ Chosen.prototype.setup = function() {
266
+ this.form_field_jq = $(this.form_field);
267
+ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
268
+ };
269
+ Chosen.prototype.finish_setup = function() {
270
+ return this.form_field_jq.addClass("chzn-done");
271
+ };
272
+ Chosen.prototype.set_up_html = function() {
273
+ var container_div, dd_top, dd_width, sf_width;
274
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
275
+ this.container_id += "_chzn";
276
+ this.f_width = this.form_field_jq.outerWidth();
277
+ this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
278
+ container_div = $("<div />", {
279
+ id: this.container_id,
280
+ "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
281
+ style: 'width: ' + this.f_width + 'px;'
282
+ });
283
+ if (this.is_multiple) {
284
+ container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
285
+ } else {
286
+ container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
287
+ }
288
+ this.form_field_jq.hide().after(container_div);
289
+ this.container = $('#' + this.container_id);
290
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
291
+ if (!this.is_multiple && this.form_field.options.length <= this.disable_search_threshold) {
292
+ this.container.addClass("chzn-container-single-nosearch");
293
+ }
294
+ this.dropdown = this.container.find('div.chzn-drop').first();
295
+ dd_top = this.container.height();
296
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
297
+ this.dropdown.css({
298
+ "width": dd_width + "px",
299
+ "top": dd_top + "px"
300
+ });
301
+ this.search_field = this.container.find('input').first();
302
+ this.search_results = this.container.find('ul.chzn-results').first();
303
+ this.search_field_scale();
304
+ this.search_no_results = this.container.find('li.no-results').first();
305
+ if (this.is_multiple) {
306
+ this.search_choices = this.container.find('ul.chzn-choices').first();
307
+ this.search_container = this.container.find('li.search-field').first();
308
+ } else {
309
+ this.search_container = this.container.find('div.chzn-search').first();
310
+ this.selected_item = this.container.find('.chzn-single').first();
311
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
312
+ this.search_field.css({
313
+ "width": sf_width + "px"
314
+ });
315
+ }
316
+ this.results_build();
317
+ return this.set_tab_index();
318
+ };
319
+ Chosen.prototype.register_observers = function() {
320
+ this.container.mousedown(__bind(function(evt) {
321
+ return this.container_mousedown(evt);
322
+ }, this));
323
+ this.container.mouseup(__bind(function(evt) {
324
+ return this.container_mouseup(evt);
325
+ }, this));
326
+ this.container.mouseenter(__bind(function(evt) {
327
+ return this.mouse_enter(evt);
328
+ }, this));
329
+ this.container.mouseleave(__bind(function(evt) {
330
+ return this.mouse_leave(evt);
331
+ }, this));
332
+ this.search_results.mouseup(__bind(function(evt) {
333
+ return this.search_results_mouseup(evt);
334
+ }, this));
335
+ this.search_results.mouseover(__bind(function(evt) {
336
+ return this.search_results_mouseover(evt);
337
+ }, this));
338
+ this.search_results.mouseout(__bind(function(evt) {
339
+ return this.search_results_mouseout(evt);
340
+ }, this));
341
+ this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
342
+ return this.results_update_field(evt);
343
+ }, this));
344
+ this.search_field.blur(__bind(function(evt) {
345
+ return this.input_blur(evt);
346
+ }, this));
347
+ this.search_field.keyup(__bind(function(evt) {
348
+ return this.keyup_checker(evt);
349
+ }, this));
350
+ this.search_field.keydown(__bind(function(evt) {
351
+ return this.keydown_checker(evt);
352
+ }, this));
353
+ if (this.is_multiple) {
354
+ this.search_choices.click(__bind(function(evt) {
355
+ return this.choices_click(evt);
356
+ }, this));
357
+ return this.search_field.focus(__bind(function(evt) {
358
+ return this.input_focus(evt);
359
+ }, this));
360
+ }
361
+ };
362
+ Chosen.prototype.search_field_disabled = function() {
363
+ this.is_disabled = this.form_field_jq.attr('disabled');
364
+ if (this.is_disabled) {
365
+ this.container.addClass('chzn-disabled');
366
+ this.search_field.attr('disabled', true);
367
+ if (!this.is_multiple) {
368
+ this.selected_item.unbind("focus", this.activate_action);
369
+ }
370
+ return this.close_field();
371
+ } else {
372
+ this.container.removeClass('chzn-disabled');
373
+ this.search_field.attr('disabled', false);
374
+ if (!this.is_multiple) {
375
+ return this.selected_item.bind("focus", this.activate_action);
376
+ }
377
+ }
378
+ };
379
+ Chosen.prototype.container_mousedown = function(evt) {
380
+ var target_closelink;
381
+ if (!this.is_disabled) {
382
+ target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
383
+ if (evt && evt.type === "mousedown") {
384
+ evt.stopPropagation();
385
+ }
386
+ if (!this.pending_destroy_click && !target_closelink) {
387
+ if (!this.active_field) {
388
+ if (this.is_multiple) {
389
+ this.search_field.val("");
390
+ }
391
+ $(document).click(this.click_test_action);
392
+ this.results_show();
393
+ } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
394
+ evt.preventDefault();
395
+ this.results_toggle();
396
+ }
397
+ return this.activate_field();
398
+ } else {
399
+ return this.pending_destroy_click = false;
400
+ }
401
+ }
402
+ };
403
+ Chosen.prototype.container_mouseup = function(evt) {
404
+ if (evt.target.nodeName === "ABBR") {
405
+ return this.results_reset(evt);
406
+ }
407
+ };
408
+ Chosen.prototype.blur_test = function(evt) {
409
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
410
+ return this.close_field();
411
+ }
412
+ };
413
+ Chosen.prototype.close_field = function() {
414
+ $(document).unbind("click", this.click_test_action);
415
+ if (!this.is_multiple) {
416
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
417
+ this.search_field.attr("tabindex", -1);
418
+ }
419
+ this.active_field = false;
420
+ this.results_hide();
421
+ this.container.removeClass("chzn-container-active");
422
+ this.winnow_results_clear();
423
+ this.clear_backstroke();
424
+ this.show_search_field_default();
425
+ return this.search_field_scale();
426
+ };
427
+ Chosen.prototype.activate_field = function() {
428
+ if (!this.is_multiple && !this.active_field) {
429
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
430
+ this.selected_item.attr("tabindex", -1);
431
+ }
432
+ this.container.addClass("chzn-container-active");
433
+ this.active_field = true;
434
+ this.search_field.val(this.search_field.val());
435
+ return this.search_field.focus();
436
+ };
437
+ Chosen.prototype.test_active_click = function(evt) {
438
+ if ($(evt.target).parents('#' + this.container_id).length) {
439
+ return this.active_field = true;
440
+ } else {
441
+ return this.close_field();
442
+ }
443
+ };
444
+ Chosen.prototype.results_build = function() {
445
+ var content, data, startTime, _i, _len, _ref;
446
+ startTime = new Date();
447
+ this.parsing = true;
448
+ this.results_data = root.SelectParser.select_to_array(this.form_field);
449
+ if (this.is_multiple && this.choices > 0) {
450
+ this.search_choices.find("li.search-choice").remove();
451
+ this.choices = 0;
452
+ } else if (!this.is_multiple) {
453
+ this.selected_item.find("span").text(this.default_text);
454
+ }
455
+ content = '';
456
+ _ref = this.results_data;
457
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
458
+ data = _ref[_i];
459
+ if (data.group) {
460
+ content += this.result_add_group(data);
461
+ } else if (!data.empty) {
462
+ content += this.result_add_option(data);
463
+ if (data.selected && this.is_multiple) {
464
+ this.choice_build(data);
465
+ } else if (data.selected && !this.is_multiple) {
466
+ this.selected_item.find("span").text(data.text);
467
+ if (this.allow_single_deselect) {
468
+ this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
469
+ }
470
+ }
471
+ }
472
+ }
473
+ this.search_field_disabled();
474
+ this.show_search_field_default();
475
+ this.search_field_scale();
476
+ this.search_results.html(content);
477
+ return this.parsing = false;
478
+ };
479
+ Chosen.prototype.result_add_group = function(group) {
480
+ if (!group.disabled) {
481
+ group.dom_id = this.container_id + "_g_" + group.array_index;
482
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
483
+ } else {
484
+ return "";
485
+ }
486
+ };
487
+ Chosen.prototype.result_do_highlight = function(el) {
488
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
489
+ if (el.length) {
490
+ this.result_clear_highlight();
491
+ this.result_highlight = el;
492
+ this.result_highlight.addClass("highlighted");
493
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
494
+ visible_top = this.search_results.scrollTop();
495
+ visible_bottom = maxHeight + visible_top;
496
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
497
+ high_bottom = high_top + this.result_highlight.outerHeight();
498
+ if (high_bottom >= visible_bottom) {
499
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
500
+ } else if (high_top < visible_top) {
501
+ return this.search_results.scrollTop(high_top);
502
+ }
503
+ }
504
+ };
505
+ Chosen.prototype.result_clear_highlight = function() {
506
+ if (this.result_highlight) {
507
+ this.result_highlight.removeClass("highlighted");
508
+ }
509
+ return this.result_highlight = null;
510
+ };
511
+ Chosen.prototype.results_show = function() {
512
+ var dd_top;
513
+ if (!this.is_multiple) {
514
+ this.selected_item.addClass("chzn-single-with-drop");
515
+ if (this.result_single_selected) {
516
+ this.result_do_highlight(this.result_single_selected);
517
+ }
518
+ }
519
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
520
+ this.dropdown.css({
521
+ "top": dd_top + "px",
522
+ "left": 0
523
+ });
524
+ this.results_showing = true;
525
+ this.search_field.focus();
526
+ this.search_field.val(this.search_field.val());
527
+ return this.winnow_results();
528
+ };
529
+ Chosen.prototype.results_hide = function() {
530
+ if (!this.is_multiple) {
531
+ this.selected_item.removeClass("chzn-single-with-drop");
532
+ }
533
+ this.result_clear_highlight();
534
+ this.dropdown.css({
535
+ "left": "-9000px"
536
+ });
537
+ return this.results_showing = false;
538
+ };
539
+ Chosen.prototype.set_tab_index = function(el) {
540
+ var ti;
541
+ if (this.form_field_jq.attr("tabindex")) {
542
+ ti = this.form_field_jq.attr("tabindex");
543
+ this.form_field_jq.attr("tabindex", -1);
544
+ if (this.is_multiple) {
545
+ return this.search_field.attr("tabindex", ti);
546
+ } else {
547
+ this.selected_item.attr("tabindex", ti);
548
+ return this.search_field.attr("tabindex", -1);
549
+ }
550
+ }
551
+ };
552
+ Chosen.prototype.show_search_field_default = function() {
553
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
554
+ this.search_field.val(this.default_text);
555
+ return this.search_field.addClass("default");
556
+ } else {
557
+ this.search_field.val("");
558
+ return this.search_field.removeClass("default");
559
+ }
560
+ };
561
+ Chosen.prototype.search_results_mouseup = function(evt) {
562
+ var target;
563
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
564
+ if (target.length) {
565
+ this.result_highlight = target;
566
+ return this.result_select(evt);
567
+ }
568
+ };
569
+ Chosen.prototype.search_results_mouseover = function(evt) {
570
+ var target;
571
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
572
+ if (target) {
573
+ return this.result_do_highlight(target);
574
+ }
575
+ };
576
+ Chosen.prototype.search_results_mouseout = function(evt) {
577
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
578
+ return this.result_clear_highlight();
579
+ }
580
+ };
581
+ Chosen.prototype.choices_click = function(evt) {
582
+ evt.preventDefault();
583
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
584
+ return this.results_show();
585
+ }
586
+ };
587
+ Chosen.prototype.choice_build = function(item) {
588
+ var choice_id, link;
589
+ choice_id = this.container_id + "_c_" + item.array_index;
590
+ this.choices += 1;
591
+ this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
592
+ link = $('#' + choice_id).find("a").first();
593
+ return link.click(__bind(function(evt) {
594
+ return this.choice_destroy_link_click(evt);
595
+ }, this));
596
+ };
597
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
598
+ evt.preventDefault();
599
+ if (!this.is_disabled) {
600
+ this.pending_destroy_click = true;
601
+ return this.choice_destroy($(evt.target));
602
+ } else {
603
+ return evt.stopPropagation;
604
+ }
605
+ };
606
+ Chosen.prototype.choice_destroy = function(link) {
607
+ this.choices -= 1;
608
+ this.show_search_field_default();
609
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
610
+ this.results_hide();
611
+ }
612
+ this.result_deselect(link.attr("rel"));
613
+ return link.parents('li').first().remove();
614
+ };
615
+ Chosen.prototype.results_reset = function(evt) {
616
+ this.form_field.options[0].selected = true;
617
+ this.selected_item.find("span").text(this.default_text);
618
+ this.show_search_field_default();
619
+ $(evt.target).remove();
620
+ this.form_field_jq.trigger("change");
621
+ if (this.active_field) {
622
+ return this.results_hide();
623
+ }
624
+ };
625
+ Chosen.prototype.result_select = function(evt) {
626
+ var high, high_id, item, position;
627
+ if (this.result_highlight) {
628
+ high = this.result_highlight;
629
+ high_id = high.attr("id");
630
+ this.result_clear_highlight();
631
+ if (this.is_multiple) {
632
+ this.result_deactivate(high);
633
+ } else {
634
+ this.search_results.find(".result-selected").removeClass("result-selected");
635
+ this.result_single_selected = high;
636
+ }
637
+ high.addClass("result-selected");
638
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
639
+ item = this.results_data[position];
640
+ item.selected = true;
641
+ this.form_field.options[item.options_index].selected = true;
642
+ if (this.is_multiple) {
643
+ this.choice_build(item);
644
+ } else {
645
+ this.selected_item.find("span").first().text(item.text);
646
+ if (this.allow_single_deselect) {
647
+ this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
648
+ }
649
+ }
650
+ if (!(evt.metaKey && this.is_multiple)) {
651
+ this.results_hide();
652
+ }
653
+ this.search_field.val("");
654
+ this.form_field_jq.trigger("change");
655
+ return this.search_field_scale();
656
+ }
657
+ };
658
+ Chosen.prototype.result_activate = function(el) {
659
+ return el.addClass("active-result");
660
+ };
661
+ Chosen.prototype.result_deactivate = function(el) {
662
+ return el.removeClass("active-result");
663
+ };
664
+ Chosen.prototype.result_deselect = function(pos) {
665
+ var result, result_data;
666
+ result_data = this.results_data[pos];
667
+ result_data.selected = false;
668
+ this.form_field.options[result_data.options_index].selected = false;
669
+ result = $("#" + this.container_id + "_o_" + pos);
670
+ result.removeClass("result-selected").addClass("active-result").show();
671
+ this.result_clear_highlight();
672
+ this.winnow_results();
673
+ this.form_field_jq.trigger("change");
674
+ return this.search_field_scale();
675
+ };
676
+ Chosen.prototype.winnow_results = function() {
677
+ var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
678
+ startTime = new Date();
679
+ this.no_results_clear();
680
+ results = 0;
681
+ searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
682
+ regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
683
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
684
+ _ref = this.results_data;
685
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
686
+ option = _ref[_i];
687
+ if (!option.disabled && !option.empty) {
688
+ if (option.group) {
689
+ $('#' + option.dom_id).hide();
690
+ } else if (!(this.is_multiple && option.selected)) {
691
+ found = false;
692
+ result_id = option.dom_id;
693
+ if (regex.test(option.html)) {
694
+ found = true;
695
+ results += 1;
696
+ } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
697
+ parts = option.html.replace(/\[|\]/g, "").split(" ");
698
+ if (parts.length) {
699
+ for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
700
+ part = parts[_j];
701
+ if (regex.test(part)) {
702
+ found = true;
703
+ results += 1;
704
+ }
705
+ }
706
+ }
707
+ }
708
+ if (found) {
709
+ if (searchText.length) {
710
+ startpos = option.html.search(zregex);
711
+ text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
712
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
713
+ } else {
714
+ text = option.html;
715
+ }
716
+ if ($("#" + result_id).html !== text) {
717
+ $("#" + result_id).html(text);
718
+ }
719
+ this.result_activate($("#" + result_id));
720
+ if (option.group_array_index != null) {
721
+ $("#" + this.results_data[option.group_array_index].dom_id).show();
722
+ }
723
+ } else {
724
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
725
+ this.result_clear_highlight();
726
+ }
727
+ this.result_deactivate($("#" + result_id));
728
+ }
729
+ }
730
+ }
731
+ }
732
+ if (results < 1 && searchText.length) {
733
+ return this.no_results(searchText);
734
+ } else {
735
+ return this.winnow_results_set_highlight();
736
+ }
737
+ };
738
+ Chosen.prototype.winnow_results_clear = function() {
739
+ var li, lis, _i, _len, _results;
740
+ this.search_field.val("");
741
+ lis = this.search_results.find("li");
742
+ _results = [];
743
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
744
+ li = lis[_i];
745
+ li = $(li);
746
+ _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
747
+ }
748
+ return _results;
749
+ };
750
+ Chosen.prototype.winnow_results_set_highlight = function() {
751
+ var do_high, selected_results;
752
+ if (!this.result_highlight) {
753
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
754
+ do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
755
+ if (do_high != null) {
756
+ return this.result_do_highlight(do_high);
757
+ }
758
+ }
759
+ };
760
+ Chosen.prototype.no_results = function(terms) {
761
+ var no_results_html;
762
+ no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
763
+ no_results_html.find("span").first().html(terms);
764
+ return this.search_results.append(no_results_html);
765
+ };
766
+ Chosen.prototype.no_results_clear = function() {
767
+ return this.search_results.find(".no-results").remove();
768
+ };
769
+ Chosen.prototype.keydown_arrow = function() {
770
+ var first_active, next_sib;
771
+ if (!this.result_highlight) {
772
+ first_active = this.search_results.find("li.active-result").first();
773
+ if (first_active) {
774
+ this.result_do_highlight($(first_active));
775
+ }
776
+ } else if (this.results_showing) {
777
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
778
+ if (next_sib) {
779
+ this.result_do_highlight(next_sib);
780
+ }
781
+ }
782
+ if (!this.results_showing) {
783
+ return this.results_show();
784
+ }
785
+ };
786
+ Chosen.prototype.keyup_arrow = function() {
787
+ var prev_sibs;
788
+ if (!this.results_showing && !this.is_multiple) {
789
+ return this.results_show();
790
+ } else if (this.result_highlight) {
791
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
792
+ if (prev_sibs.length) {
793
+ return this.result_do_highlight(prev_sibs.first());
794
+ } else {
795
+ if (this.choices > 0) {
796
+ this.results_hide();
797
+ }
798
+ return this.result_clear_highlight();
799
+ }
800
+ }
801
+ };
802
+ Chosen.prototype.keydown_backstroke = function() {
803
+ if (this.pending_backstroke) {
804
+ this.choice_destroy(this.pending_backstroke.find("a").first());
805
+ return this.clear_backstroke();
806
+ } else {
807
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
808
+ return this.pending_backstroke.addClass("search-choice-focus");
809
+ }
810
+ };
811
+ Chosen.prototype.clear_backstroke = function() {
812
+ if (this.pending_backstroke) {
813
+ this.pending_backstroke.removeClass("search-choice-focus");
814
+ }
815
+ return this.pending_backstroke = null;
816
+ };
817
+ Chosen.prototype.keydown_checker = function(evt) {
818
+ var stroke, _ref;
819
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
820
+ this.search_field_scale();
821
+ if (stroke !== 8 && this.pending_backstroke) {
822
+ this.clear_backstroke();
823
+ }
824
+ switch (stroke) {
825
+ case 8:
826
+ this.backstroke_length = this.search_field.val().length;
827
+ break;
828
+ case 9:
829
+ this.mouse_on_container = false;
830
+ break;
831
+ case 13:
832
+ evt.preventDefault();
833
+ break;
834
+ case 38:
835
+ evt.preventDefault();
836
+ this.keyup_arrow();
837
+ break;
838
+ case 40:
839
+ this.keydown_arrow();
840
+ break;
841
+ }
842
+ };
843
+ Chosen.prototype.search_field_scale = function() {
844
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
845
+ if (this.is_multiple) {
846
+ h = 0;
847
+ w = 0;
848
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
849
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
850
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
851
+ style = styles[_i];
852
+ style_block += style + ":" + this.search_field.css(style) + ";";
853
+ }
854
+ div = $('<div />', {
855
+ 'style': style_block
856
+ });
857
+ div.text(this.search_field.val());
858
+ $('body').append(div);
859
+ w = div.width() + 25;
860
+ div.remove();
861
+ if (w > this.f_width - 10) {
862
+ w = this.f_width - 10;
863
+ }
864
+ this.search_field.css({
865
+ 'width': w + 'px'
866
+ });
867
+ dd_top = this.container.height();
868
+ return this.dropdown.css({
869
+ "top": dd_top + "px"
870
+ });
871
+ }
872
+ };
873
+ Chosen.prototype.generate_random_id = function() {
874
+ var string;
875
+ string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
876
+ while ($("#" + string).length > 0) {
877
+ string += this.generate_random_char();
878
+ }
879
+ return string;
880
+ };
881
+ return Chosen;
882
+ })();
883
+ get_side_border_padding = function(elmt) {
884
+ var side_border_padding;
885
+ return side_border_padding = elmt.outerWidth() - elmt.width();
886
+ };
887
+ root.get_side_border_padding = get_side_border_padding;
888
+ }).call(this);