tentd-admin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +201 -0
  4. data/LICENSE.txt +22 -0
  5. data/Procfile +1 -0
  6. data/README.md +104 -0
  7. data/Rakefile +30 -0
  8. data/assets/images/chosen-sprite.png +0 -0
  9. data/assets/images/glyphicons-halflings-white.png +0 -0
  10. data/assets/images/glyphicons-halflings.png +0 -0
  11. data/assets/javascripts/application.js.coffee +24 -0
  12. data/assets/javascripts/bootstrap.js +2027 -0
  13. data/assets/javascripts/chosen.jquery.js +1129 -0
  14. data/assets/javascripts/jquery.js +9301 -0
  15. data/assets/stylesheets/application.css.sass +34 -0
  16. data/assets/stylesheets/bootstrap-responsive.css +1040 -0
  17. data/assets/stylesheets/bootstrap.css +5624 -0
  18. data/assets/stylesheets/chosen.css.erb +397 -0
  19. data/config.ru +36 -0
  20. data/config/asset_sync.rb +12 -0
  21. data/lib/tentd-admin.rb +7 -0
  22. data/lib/tentd-admin/app.rb +242 -0
  23. data/lib/tentd-admin/set_entity.rb +10 -0
  24. data/lib/tentd-admin/setup_tent.rb +54 -0
  25. data/lib/tentd-admin/sprockets/environment.rb +23 -0
  26. data/lib/tentd-admin/sprockets/helpers.rb +5 -0
  27. data/lib/tentd-admin/version.rb +5 -0
  28. data/lib/tentd-admin/views/_profile_type_fields.slim +20 -0
  29. data/lib/tentd-admin/views/_profile_type_section.slim +4 -0
  30. data/lib/tentd-admin/views/apps.slim +39 -0
  31. data/lib/tentd-admin/views/auth_confirm.slim +34 -0
  32. data/lib/tentd-admin/views/dashboard.slim +53 -0
  33. data/lib/tentd-admin/views/followers.slim +12 -0
  34. data/lib/tentd-admin/views/followings.slim +22 -0
  35. data/lib/tentd-admin/views/layout.slim +15 -0
  36. data/lib/tentd-admin/views/profile.slim +11 -0
  37. data/lib/tentd-admin/views/setup.slim +20 -0
  38. data/tentd-admin.gemspec +32 -0
  39. metadata +252 -0
@@ -0,0 +1,1129 @@
1
+ // Chosen, a Select Box Enhancer for jQuery and Protoype
2
+ // by Patrick Filler for Harvest, http://getharvest.com
3
+ //
4
+ // Version 0.9.8
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
+
13
+ SelectParser = (function() {
14
+
15
+ function SelectParser() {
16
+ this.options_index = 0;
17
+ this.parsed = [];
18
+ }
19
+
20
+ SelectParser.prototype.add_node = function(child) {
21
+ if (child.nodeName === "OPTGROUP") {
22
+ return this.add_group(child);
23
+ } else {
24
+ return this.add_option(child);
25
+ }
26
+ };
27
+
28
+ SelectParser.prototype.add_group = function(group) {
29
+ var group_position, option, _i, _len, _ref, _results;
30
+ group_position = this.parsed.length;
31
+ this.parsed.push({
32
+ array_index: group_position,
33
+ group: true,
34
+ label: group.label,
35
+ children: 0,
36
+ disabled: group.disabled
37
+ });
38
+ _ref = group.childNodes;
39
+ _results = [];
40
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
41
+ option = _ref[_i];
42
+ _results.push(this.add_option(option, group_position, group.disabled));
43
+ }
44
+ return _results;
45
+ };
46
+
47
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
48
+ if (option.nodeName === "OPTION") {
49
+ if (option.text !== "") {
50
+ if (group_position != null) {
51
+ this.parsed[group_position].children += 1;
52
+ }
53
+ this.parsed.push({
54
+ array_index: this.parsed.length,
55
+ options_index: this.options_index,
56
+ value: option.value,
57
+ text: option.text,
58
+ html: option.innerHTML,
59
+ selected: option.selected,
60
+ disabled: group_disabled === true ? group_disabled : option.disabled,
61
+ group_array_index: group_position,
62
+ classes: option.className,
63
+ style: option.style.cssText
64
+ });
65
+ } else {
66
+ this.parsed.push({
67
+ array_index: this.parsed.length,
68
+ options_index: this.options_index,
69
+ empty: true
70
+ });
71
+ }
72
+ return this.options_index += 1;
73
+ }
74
+ };
75
+
76
+ return SelectParser;
77
+
78
+ })();
79
+
80
+ SelectParser.select_to_array = function(select) {
81
+ var child, parser, _i, _len, _ref;
82
+ parser = new SelectParser();
83
+ _ref = select.childNodes;
84
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
85
+ child = _ref[_i];
86
+ parser.add_node(child);
87
+ }
88
+ return parser.parsed;
89
+ };
90
+
91
+ this.SelectParser = SelectParser;
92
+
93
+ }).call(this);
94
+
95
+ /*
96
+ Chosen source: generate output using 'cake build'
97
+ Copyright (c) 2011 by Harvest
98
+ */
99
+
100
+
101
+ (function() {
102
+ var AbstractChosen, root;
103
+
104
+ root = this;
105
+
106
+ AbstractChosen = (function() {
107
+
108
+ function AbstractChosen(form_field, options) {
109
+ this.form_field = form_field;
110
+ this.options = options != null ? options : {};
111
+ this.set_default_values();
112
+ this.is_multiple = this.form_field.multiple;
113
+ this.set_default_text();
114
+ this.setup();
115
+ this.set_up_html();
116
+ this.register_observers();
117
+ this.finish_setup();
118
+ }
119
+
120
+ AbstractChosen.prototype.set_default_values = function() {
121
+ var _this = this;
122
+ this.click_test_action = function(evt) {
123
+ return _this.test_active_click(evt);
124
+ };
125
+ this.activate_action = function(evt) {
126
+ return _this.activate_field(evt);
127
+ };
128
+ this.active_field = false;
129
+ this.mouse_on_container = false;
130
+ this.results_showing = false;
131
+ this.result_highlighted = null;
132
+ this.result_single_selected = null;
133
+ this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
134
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
135
+ this.search_contains = this.options.search_contains || false;
136
+ this.choices = 0;
137
+ this.single_backstroke_delete = this.options.single_backstroke_delete || false;
138
+ this.max_selected_options = this.options.max_selected_options || Infinity;
139
+ this.create_option = this.options.create_option || false;
140
+ return this.persistent_create_option = this.options.persistent_create_option || false;
141
+ };
142
+
143
+ AbstractChosen.prototype.set_default_text = function() {
144
+ if (this.form_field.getAttribute("data-placeholder")) {
145
+ this.default_text = this.form_field.getAttribute("data-placeholder");
146
+ } else if (this.is_multiple) {
147
+ this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options";
148
+ } else {
149
+ this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Select an Option";
150
+ }
151
+ this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match";
152
+ return this.create_option_text = this.form_field.getAttribute("data-create_option_text") || this.options.create_option_text || "Add option";
153
+ };
154
+
155
+ AbstractChosen.prototype.mouse_enter = function() {
156
+ return this.mouse_on_container = true;
157
+ };
158
+
159
+ AbstractChosen.prototype.mouse_leave = function() {
160
+ return this.mouse_on_container = false;
161
+ };
162
+
163
+ AbstractChosen.prototype.input_focus = function(evt) {
164
+ var _this = this;
165
+ if (!this.active_field) {
166
+ return setTimeout((function() {
167
+ return _this.container_mousedown();
168
+ }), 50);
169
+ }
170
+ };
171
+
172
+ AbstractChosen.prototype.input_blur = function(evt) {
173
+ var _this = this;
174
+ if (!this.mouse_on_container) {
175
+ this.active_field = false;
176
+ return setTimeout((function() {
177
+ return _this.blur_test();
178
+ }), 100);
179
+ }
180
+ };
181
+
182
+ AbstractChosen.prototype.result_add_option = function(option) {
183
+ var classes, style;
184
+ if (!option.disabled) {
185
+ option.dom_id = this.container_id + "_o_" + option.array_index;
186
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
187
+ if (option.selected) {
188
+ classes.push("result-selected");
189
+ }
190
+ if (option.group_array_index != null) {
191
+ classes.push("group-option");
192
+ }
193
+ if (option.classes !== "") {
194
+ classes.push(option.classes);
195
+ }
196
+ style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
197
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
198
+ } else {
199
+ return "";
200
+ }
201
+ };
202
+
203
+ AbstractChosen.prototype.append_option = function(option) {
204
+ return this.select_append_option(option);
205
+ };
206
+
207
+ AbstractChosen.prototype.results_update_field = function() {
208
+ if (!this.is_multiple) {
209
+ this.results_reset_cleanup();
210
+ }
211
+ this.result_clear_highlight();
212
+ this.result_single_selected = null;
213
+ return this.results_build();
214
+ };
215
+
216
+ AbstractChosen.prototype.results_toggle = function() {
217
+ if (this.results_showing) {
218
+ return this.results_hide();
219
+ } else {
220
+ return this.results_show();
221
+ }
222
+ };
223
+
224
+ AbstractChosen.prototype.results_search = function(evt) {
225
+ if (this.results_showing) {
226
+ return this.winnow_results();
227
+ } else {
228
+ return this.results_show();
229
+ }
230
+ };
231
+
232
+ AbstractChosen.prototype.keyup_checker = function(evt) {
233
+ var stroke, _ref;
234
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
235
+ this.search_field_scale();
236
+ switch (stroke) {
237
+ case 8:
238
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
239
+ return this.keydown_backstroke();
240
+ } else if (!this.pending_backstroke) {
241
+ this.result_clear_highlight();
242
+ return this.results_search();
243
+ }
244
+ break;
245
+ case 13:
246
+ evt.preventDefault();
247
+ if (this.results_showing) {
248
+ return this.result_select(evt);
249
+ }
250
+ break;
251
+ case 27:
252
+ if (this.results_showing) {
253
+ this.results_hide();
254
+ }
255
+ return true;
256
+ case 9:
257
+ case 38:
258
+ case 40:
259
+ case 16:
260
+ case 91:
261
+ case 17:
262
+ break;
263
+ default:
264
+ return this.results_search();
265
+ }
266
+ };
267
+
268
+ AbstractChosen.prototype.generate_field_id = function() {
269
+ var new_id;
270
+ new_id = this.generate_random_id();
271
+ this.form_field.id = new_id;
272
+ return new_id;
273
+ };
274
+
275
+ AbstractChosen.prototype.generate_random_char = function() {
276
+ var chars, newchar, rand;
277
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
278
+ rand = Math.floor(Math.random() * chars.length);
279
+ return newchar = chars.substring(rand, rand + 1);
280
+ };
281
+
282
+ return AbstractChosen;
283
+
284
+ })();
285
+
286
+ root.AbstractChosen = AbstractChosen;
287
+
288
+ }).call(this);
289
+
290
+ /*
291
+ Chosen source: generate output using 'cake build'
292
+ Copyright (c) 2011 by Harvest
293
+ */
294
+
295
+
296
+ (function() {
297
+ var $, Chosen, get_side_border_padding, root,
298
+ __hasProp = {}.hasOwnProperty,
299
+ __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; };
300
+
301
+ root = this;
302
+
303
+ $ = jQuery;
304
+
305
+ $.fn.extend({
306
+ chosen: function(options) {
307
+ if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
308
+ return this;
309
+ }
310
+ return this.each(function(input_field) {
311
+ var $this;
312
+ $this = $(this);
313
+ if (!$this.hasClass("chzn-done")) {
314
+ return $this.data('chosen', new Chosen(this, options));
315
+ }
316
+ });
317
+ }
318
+ });
319
+
320
+ Chosen = (function(_super) {
321
+
322
+ __extends(Chosen, _super);
323
+
324
+ function Chosen() {
325
+ return Chosen.__super__.constructor.apply(this, arguments);
326
+ }
327
+
328
+ Chosen.prototype.setup = function() {
329
+ this.form_field_jq = $(this.form_field);
330
+ this.current_value = this.form_field_jq.val();
331
+ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
332
+ };
333
+
334
+ Chosen.prototype.finish_setup = function() {
335
+ return this.form_field_jq.addClass("chzn-done");
336
+ };
337
+
338
+ Chosen.prototype.set_up_html = function() {
339
+ var container_div, dd_top, dd_width, sf_width;
340
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
341
+ this.container_id += "_chzn";
342
+ this.f_width = this.form_field_jq.outerWidth();
343
+ container_div = $("<div />", {
344
+ id: this.container_id,
345
+ "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
346
+ style: 'width: ' + this.f_width + 'px;'
347
+ });
348
+ if (this.is_multiple) {
349
+ 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>');
350
+ } else {
351
+ container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><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>');
352
+ }
353
+ this.form_field_jq.hide().after(container_div);
354
+ this.container = $('#' + this.container_id);
355
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
356
+ this.dropdown = this.container.find('div.chzn-drop').first();
357
+ dd_top = this.container.height();
358
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
359
+ this.dropdown.css({
360
+ "width": dd_width + "px",
361
+ "top": dd_top + "px"
362
+ });
363
+ this.search_field = this.container.find('input').first();
364
+ this.search_results = this.container.find('ul.chzn-results').first();
365
+ this.search_field_scale();
366
+ this.search_no_results = this.container.find('li.no-results').first();
367
+ if (this.is_multiple) {
368
+ this.search_choices = this.container.find('ul.chzn-choices').first();
369
+ this.search_container = this.container.find('li.search-field').first();
370
+ } else {
371
+ this.search_container = this.container.find('div.chzn-search').first();
372
+ this.selected_item = this.container.find('.chzn-single').first();
373
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
374
+ this.search_field.css({
375
+ "width": sf_width + "px"
376
+ });
377
+ }
378
+ this.results_build();
379
+ this.set_tab_index();
380
+ return this.form_field_jq.trigger("liszt:ready", {
381
+ chosen: this
382
+ });
383
+ };
384
+
385
+ Chosen.prototype.register_observers = function() {
386
+ var _this = this;
387
+ this.container.mousedown(function(evt) {
388
+ return _this.container_mousedown(evt);
389
+ });
390
+ this.container.mouseup(function(evt) {
391
+ return _this.container_mouseup(evt);
392
+ });
393
+ this.container.mouseenter(function(evt) {
394
+ return _this.mouse_enter(evt);
395
+ });
396
+ this.container.mouseleave(function(evt) {
397
+ return _this.mouse_leave(evt);
398
+ });
399
+ this.search_results.mouseup(function(evt) {
400
+ return _this.search_results_mouseup(evt);
401
+ });
402
+ this.search_results.mouseover(function(evt) {
403
+ return _this.search_results_mouseover(evt);
404
+ });
405
+ this.search_results.mouseout(function(evt) {
406
+ return _this.search_results_mouseout(evt);
407
+ });
408
+ this.form_field_jq.bind("liszt:updated", function(evt) {
409
+ return _this.results_update_field(evt);
410
+ });
411
+ this.search_field.blur(function(evt) {
412
+ return _this.input_blur(evt);
413
+ });
414
+ this.search_field.keyup(function(evt) {
415
+ return _this.keyup_checker(evt);
416
+ });
417
+ this.search_field.keydown(function(evt) {
418
+ return _this.keydown_checker(evt);
419
+ });
420
+ if (this.is_multiple) {
421
+ this.search_choices.click(function(evt) {
422
+ return _this.choices_click(evt);
423
+ });
424
+ return this.search_field.focus(function(evt) {
425
+ return _this.input_focus(evt);
426
+ });
427
+ } else {
428
+ return this.container.click(function(evt) {
429
+ return evt.preventDefault();
430
+ });
431
+ }
432
+ };
433
+
434
+ Chosen.prototype.search_field_disabled = function() {
435
+ this.is_disabled = this.form_field_jq[0].disabled;
436
+ if (this.is_disabled) {
437
+ this.container.addClass('chzn-disabled');
438
+ this.search_field[0].disabled = true;
439
+ if (!this.is_multiple) {
440
+ this.selected_item.unbind("focus", this.activate_action);
441
+ }
442
+ return this.close_field();
443
+ } else {
444
+ this.container.removeClass('chzn-disabled');
445
+ this.search_field[0].disabled = false;
446
+ if (!this.is_multiple) {
447
+ return this.selected_item.bind("focus", this.activate_action);
448
+ }
449
+ }
450
+ };
451
+
452
+ Chosen.prototype.container_mousedown = function(evt) {
453
+ var target_closelink;
454
+ if (!this.is_disabled) {
455
+ target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
456
+ if (evt && evt.type === "mousedown" && !this.results_showing) {
457
+ evt.stopPropagation();
458
+ }
459
+ if (!this.pending_destroy_click && !target_closelink) {
460
+ if (!this.active_field) {
461
+ if (this.is_multiple) {
462
+ this.search_field.val("");
463
+ }
464
+ $(document).click(this.click_test_action);
465
+ this.results_show();
466
+ } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
467
+ evt.preventDefault();
468
+ this.results_toggle();
469
+ }
470
+ return this.activate_field();
471
+ } else {
472
+ return this.pending_destroy_click = false;
473
+ }
474
+ }
475
+ };
476
+
477
+ Chosen.prototype.container_mouseup = function(evt) {
478
+ if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
479
+ return this.results_reset(evt);
480
+ }
481
+ };
482
+
483
+ Chosen.prototype.blur_test = function(evt) {
484
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
485
+ return this.close_field();
486
+ }
487
+ };
488
+
489
+ Chosen.prototype.close_field = function() {
490
+ $(document).unbind("click", this.click_test_action);
491
+ if (!this.is_multiple) {
492
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
493
+ this.search_field.attr("tabindex", -1);
494
+ }
495
+ this.active_field = false;
496
+ this.results_hide();
497
+ this.container.removeClass("chzn-container-active");
498
+ this.winnow_results_clear();
499
+ this.clear_backstroke();
500
+ this.show_search_field_default();
501
+ return this.search_field_scale();
502
+ };
503
+
504
+ Chosen.prototype.activate_field = function() {
505
+ if (!this.is_multiple && !this.active_field) {
506
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
507
+ this.selected_item.attr("tabindex", -1);
508
+ }
509
+ this.container.addClass("chzn-container-active");
510
+ this.active_field = true;
511
+ this.search_field.val(this.search_field.val());
512
+ return this.search_field.focus();
513
+ };
514
+
515
+ Chosen.prototype.test_active_click = function(evt) {
516
+ if ($(evt.target).parents('#' + this.container_id).length) {
517
+ return this.active_field = true;
518
+ } else {
519
+ return this.close_field();
520
+ }
521
+ };
522
+
523
+ Chosen.prototype.results_build = function() {
524
+ var content, data, _i, _len, _ref;
525
+ this.parsing = true;
526
+ this.results_data = root.SelectParser.select_to_array(this.form_field);
527
+ if (this.is_multiple && this.choices > 0) {
528
+ this.search_choices.find("li.search-choice").remove();
529
+ this.choices = 0;
530
+ } else if (!this.is_multiple) {
531
+ this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
532
+ if (this.form_field.options.length <= this.disable_search_threshold) {
533
+ this.container.addClass("chzn-container-single-nosearch");
534
+ } else {
535
+ this.container.removeClass("chzn-container-single-nosearch");
536
+ }
537
+ }
538
+ content = '';
539
+ _ref = this.results_data;
540
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
541
+ data = _ref[_i];
542
+ if (data.group) {
543
+ content += this.result_add_group(data);
544
+ } else if (!data.empty) {
545
+ content += this.result_add_option(data);
546
+ if (data.selected && this.is_multiple) {
547
+ this.choice_build(data);
548
+ } else if (data.selected && !this.is_multiple) {
549
+ this.selected_item.removeClass("chzn-default").find("span").text(data.text);
550
+ if (this.allow_single_deselect) {
551
+ this.single_deselect_control_build();
552
+ }
553
+ }
554
+ }
555
+ }
556
+ this.search_field_disabled();
557
+ this.show_search_field_default();
558
+ this.search_field_scale();
559
+ this.search_results.html(content);
560
+ return this.parsing = false;
561
+ };
562
+
563
+ Chosen.prototype.result_add_group = function(group) {
564
+ if (!group.disabled) {
565
+ group.dom_id = this.container_id + "_g_" + group.array_index;
566
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
567
+ } else {
568
+ return "";
569
+ }
570
+ };
571
+
572
+ Chosen.prototype.result_add_option = function(option) {
573
+ var classes;
574
+ if (!option.disabled) {
575
+ option.dom_id = this.container_id + "_o_" + option.array_index;
576
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
577
+ if (option.selected) {
578
+ classes.push("result-selected");
579
+ }
580
+ if (option.group_array_index != null) {
581
+ classes.push("group-option");
582
+ }
583
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + option.html + '</li>';
584
+ } else {
585
+ return "";
586
+ }
587
+ };
588
+
589
+ Chosen.prototype.results_update_field = function() {
590
+ this.result_clear_highlight();
591
+ this.result_single_selected = null;
592
+ return this.results_build();
593
+ };
594
+
595
+ Chosen.prototype.result_do_highlight = function(el) {
596
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
597
+ if (el.length) {
598
+ this.result_clear_highlight();
599
+ this.result_highlight = el;
600
+ this.result_highlight.addClass("highlighted");
601
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
602
+ visible_top = this.search_results.scrollTop();
603
+ visible_bottom = maxHeight + visible_top;
604
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
605
+ high_bottom = high_top + this.result_highlight.outerHeight();
606
+ if (high_bottom >= visible_bottom) {
607
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
608
+ } else if (high_top < visible_top) {
609
+ return this.search_results.scrollTop(high_top);
610
+ }
611
+ }
612
+ };
613
+
614
+ Chosen.prototype.result_clear_highlight = function() {
615
+ if (this.result_highlight) {
616
+ this.result_highlight.removeClass("highlighted");
617
+ }
618
+ return this.result_highlight = null;
619
+ };
620
+
621
+ Chosen.prototype.results_show = function() {
622
+ var dd_top;
623
+ if (!this.is_multiple) {
624
+ this.selected_item.addClass("chzn-single-with-drop");
625
+ if (this.result_single_selected) {
626
+ this.result_do_highlight(this.result_single_selected);
627
+ }
628
+ } else if (this.max_selected_options <= this.choices) {
629
+ this.form_field_jq.trigger("liszt:maxselected", {
630
+ chosen: this
631
+ });
632
+ return false;
633
+ }
634
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
635
+ this.form_field_jq.trigger("liszt:showing_dropdown", {
636
+ chosen: this
637
+ });
638
+ this.dropdown.css({
639
+ "top": dd_top + "px",
640
+ "left": 0
641
+ });
642
+ this.results_showing = true;
643
+ this.search_field.focus();
644
+ this.search_field.val(this.search_field.val());
645
+ return this.winnow_results();
646
+ };
647
+
648
+ Chosen.prototype.results_hide = function() {
649
+ if (!this.is_multiple) {
650
+ this.selected_item.removeClass("chzn-single-with-drop");
651
+ }
652
+ this.result_clear_highlight();
653
+ this.form_field_jq.trigger("liszt:hiding_dropdown", {
654
+ chosen: this
655
+ });
656
+ this.dropdown.css({
657
+ "left": "-9000px"
658
+ });
659
+ return this.results_showing = false;
660
+ };
661
+
662
+ Chosen.prototype.set_tab_index = function(el) {
663
+ var ti;
664
+ if (this.form_field_jq.attr("tabindex")) {
665
+ ti = this.form_field_jq.attr("tabindex");
666
+ this.form_field_jq.attr("tabindex", -1);
667
+ if (this.is_multiple) {
668
+ return this.search_field.attr("tabindex", ti);
669
+ } else {
670
+ this.selected_item.attr("tabindex", ti);
671
+ return this.search_field.attr("tabindex", -1);
672
+ }
673
+ }
674
+ };
675
+
676
+ Chosen.prototype.show_search_field_default = function() {
677
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
678
+ this.search_field.val(this.default_text);
679
+ return this.search_field.addClass("default");
680
+ } else {
681
+ this.search_field.val("");
682
+ return this.search_field.removeClass("default");
683
+ }
684
+ };
685
+
686
+ Chosen.prototype.search_results_mouseup = function(evt) {
687
+ var target;
688
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
689
+ if (target.length) {
690
+ this.result_highlight = target;
691
+ return this.result_select(evt);
692
+ }
693
+ };
694
+
695
+ Chosen.prototype.search_results_mouseover = function(evt) {
696
+ var target;
697
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
698
+ if (target) {
699
+ return this.result_do_highlight(target);
700
+ }
701
+ };
702
+
703
+ Chosen.prototype.search_results_mouseout = function(evt) {
704
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
705
+ return this.result_clear_highlight();
706
+ }
707
+ };
708
+
709
+ Chosen.prototype.choices_click = function(evt) {
710
+ evt.preventDefault();
711
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
712
+ return this.results_show();
713
+ }
714
+ };
715
+
716
+ Chosen.prototype.choice_build = function(item) {
717
+ var choice_id, link,
718
+ _this = this;
719
+ if (this.is_multiple && this.max_selected_options <= this.choices) {
720
+ this.form_field_jq.trigger("liszt:maxselected", {
721
+ chosen: this
722
+ });
723
+ return false;
724
+ }
725
+ choice_id = this.container_id + "_c_" + item.array_index;
726
+ this.choices += 1;
727
+ 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>');
728
+ link = $('#' + choice_id).find("a").first();
729
+ return link.click(function(evt) {
730
+ return _this.choice_destroy_link_click(evt);
731
+ });
732
+ };
733
+
734
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
735
+ evt.preventDefault();
736
+ if (!this.is_disabled) {
737
+ this.pending_destroy_click = true;
738
+ return this.choice_destroy($(evt.target));
739
+ } else {
740
+ return evt.stopPropagation;
741
+ }
742
+ };
743
+
744
+ Chosen.prototype.choice_destroy = function(link) {
745
+ this.choices -= 1;
746
+ this.show_search_field_default();
747
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
748
+ this.results_hide();
749
+ }
750
+ this.result_deselect(link.attr("rel"));
751
+ return link.parents('li').first().remove();
752
+ };
753
+
754
+ Chosen.prototype.results_reset = function() {
755
+ this.form_field.options[0].selected = true;
756
+ this.selected_item.find("span").text(this.default_text);
757
+ if (!this.is_multiple) {
758
+ this.selected_item.addClass("chzn-default");
759
+ }
760
+ this.show_search_field_default();
761
+ this.results_reset_cleanup();
762
+ this.form_field_jq.trigger("change");
763
+ if (this.active_field) {
764
+ return this.results_hide();
765
+ }
766
+ };
767
+
768
+ Chosen.prototype.results_reset_cleanup = function() {
769
+ return this.selected_item.find("abbr").remove();
770
+ };
771
+
772
+ Chosen.prototype.result_select = function(evt) {
773
+ var high, high_id, item, position;
774
+ if (this.result_highlight) {
775
+ high = this.result_highlight;
776
+ if (high.hasClass('create-option')) {
777
+ this.select_create_option(this.search_field.val());
778
+ return this.results_hide();
779
+ }
780
+ high_id = high.attr("id");
781
+ this.result_clear_highlight();
782
+ if (this.is_multiple) {
783
+ this.result_deactivate(high);
784
+ } else {
785
+ this.search_results.find(".result-selected").removeClass("result-selected");
786
+ this.result_single_selected = high;
787
+ this.selected_item.removeClass("chzn-default");
788
+ }
789
+ high.addClass("result-selected");
790
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
791
+ item = this.results_data[position];
792
+ item.selected = true;
793
+ this.form_field.options[item.options_index].selected = true;
794
+ if (this.is_multiple) {
795
+ this.choice_build(item);
796
+ } else {
797
+ this.selected_item.find("span").first().text(item.text);
798
+ if (this.allow_single_deselect) {
799
+ this.single_deselect_control_build();
800
+ }
801
+ }
802
+ if (!(evt.metaKey && this.is_multiple)) {
803
+ this.results_hide();
804
+ }
805
+ this.search_field.val("");
806
+ if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
807
+ this.form_field_jq.trigger("change", {
808
+ 'selected': this.form_field.options[item.options_index].value
809
+ });
810
+ }
811
+ this.current_value = this.form_field_jq.val();
812
+ return this.search_field_scale();
813
+ }
814
+ };
815
+
816
+ Chosen.prototype.result_activate = function(el) {
817
+ return el.addClass("active-result");
818
+ };
819
+
820
+ Chosen.prototype.result_deactivate = function(el) {
821
+ return el.removeClass("active-result");
822
+ };
823
+
824
+ Chosen.prototype.result_deselect = function(pos) {
825
+ var result, result_data;
826
+ result_data = this.results_data[pos];
827
+ result_data.selected = false;
828
+ this.form_field.options[result_data.options_index].selected = false;
829
+ result = $("#" + this.container_id + "_o_" + pos);
830
+ result.removeClass("result-selected").addClass("active-result").show();
831
+ this.result_clear_highlight();
832
+ this.winnow_results();
833
+ this.form_field_jq.trigger("change", {
834
+ deselected: this.form_field.options[result_data.options_index].value
835
+ });
836
+ return this.search_field_scale();
837
+ };
838
+
839
+ Chosen.prototype.single_deselect_control_build = function() {
840
+ if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
841
+ return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
842
+ }
843
+ };
844
+
845
+ Chosen.prototype.winnow_results = function() {
846
+ var eregex, exact_result, found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
847
+ this.no_results_clear();
848
+ this.create_option_clear();
849
+ results = 0;
850
+ searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
851
+ regexAnchor = this.search_contains ? "" : "^";
852
+ regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
853
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
854
+ eregex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + '$', 'i');
855
+ exact_result = false;
856
+ _ref = this.results_data;
857
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
858
+ option = _ref[_i];
859
+ if (!option.disabled && !option.empty) {
860
+ if (option.group) {
861
+ $('#' + option.dom_id).css('display', 'none');
862
+ } else if (!(this.is_multiple && option.selected)) {
863
+ found = false;
864
+ result_id = option.dom_id;
865
+ result = $("#" + result_id);
866
+ if (regex.test(option.html)) {
867
+ found = true;
868
+ results += 1;
869
+ if (eregex.test(option.html)) {
870
+ exact_result = true;
871
+ }
872
+ } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
873
+ parts = option.html.replace(/\[|\]/g, "").split(" ");
874
+ if (parts.length) {
875
+ for (_j = 0, _len1 = parts.length; _j < _len1; _j++) {
876
+ part = parts[_j];
877
+ if (regex.test(part)) {
878
+ found = true;
879
+ results += 1;
880
+ }
881
+ }
882
+ }
883
+ }
884
+ if (found) {
885
+ if (searchText.length) {
886
+ startpos = option.html.search(zregex);
887
+ text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
888
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
889
+ } else {
890
+ text = option.html;
891
+ }
892
+ result.html(text);
893
+ this.result_activate(result);
894
+ if (option.group_array_index != null) {
895
+ $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
896
+ }
897
+ } else {
898
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
899
+ this.result_clear_highlight();
900
+ }
901
+ this.result_deactivate(result);
902
+ }
903
+ }
904
+ }
905
+ }
906
+ if (results < 1 && searchText.length) {
907
+ return this.no_results(searchText);
908
+ } else {
909
+ if (this.create_option && !exact_result && this.persistent_create_option && searchText.length) {
910
+ this.show_create_option(searchText);
911
+ }
912
+ return this.winnow_results_set_highlight();
913
+ }
914
+ };
915
+
916
+ Chosen.prototype.winnow_results_clear = function() {
917
+ var li, lis, _i, _len, _results;
918
+ this.search_field.val("");
919
+ lis = this.search_results.find("li");
920
+ _results = [];
921
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
922
+ li = lis[_i];
923
+ li = $(li);
924
+ if (li.hasClass("group-result")) {
925
+ _results.push(li.css('display', 'auto'));
926
+ } else if (!this.is_multiple || !li.hasClass("result-selected")) {
927
+ _results.push(this.result_activate(li));
928
+ } else {
929
+ _results.push(void 0);
930
+ }
931
+ }
932
+ return _results;
933
+ };
934
+
935
+ Chosen.prototype.winnow_results_set_highlight = function() {
936
+ var do_high, selected_results;
937
+ if (!this.result_highlight) {
938
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
939
+ do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
940
+ if (do_high != null) {
941
+ return this.result_do_highlight(do_high);
942
+ }
943
+ }
944
+ };
945
+
946
+ Chosen.prototype.no_results = function(terms) {
947
+ var no_results_html;
948
+ no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
949
+ no_results_html.find("span").first().html(terms);
950
+ this.search_results.append(no_results_html);
951
+ if (this.create_option) {
952
+ return this.show_create_option(terms);
953
+ }
954
+ };
955
+
956
+ Chosen.prototype.show_create_option = function(terms) {
957
+ var create_option_html,
958
+ _this = this;
959
+ create_option_html = $('<li class="create-option active-result"><a href="javascript:void(0);">' + this.create_option_text + '</a>: "' + terms + '"</li>').bind("click", function(evt) {
960
+ return _this.select_create_option(terms);
961
+ });
962
+ return this.search_results.append(create_option_html);
963
+ };
964
+
965
+ Chosen.prototype.create_option_clear = function() {
966
+ return this.search_results.find(".create-option").remove();
967
+ };
968
+
969
+ Chosen.prototype.select_create_option = function(terms) {
970
+ if ($.isFunction(this.create_option)) {
971
+ return this.create_option.call(this, terms);
972
+ } else {
973
+ return this.select_append_option({
974
+ value: terms,
975
+ text: terms
976
+ });
977
+ }
978
+ };
979
+
980
+ Chosen.prototype.select_append_option = function(options) {
981
+ var option;
982
+ option = $('<option />', options).attr('selected', 'selected');
983
+ this.form_field_jq.append(option);
984
+ this.form_field_jq.trigger("liszt:updated");
985
+ return this.search_field.trigger('focus');
986
+ };
987
+
988
+ Chosen.prototype.no_results_clear = function() {
989
+ return this.search_results.find(".no-results").remove();
990
+ };
991
+
992
+ Chosen.prototype.keydown_arrow = function() {
993
+ var first_active, next_sib;
994
+ if (!this.result_highlight) {
995
+ first_active = this.search_results.find("li.active-result").first();
996
+ if (first_active) {
997
+ this.result_do_highlight($(first_active));
998
+ }
999
+ } else if (this.results_showing) {
1000
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
1001
+ if (next_sib) {
1002
+ this.result_do_highlight(next_sib);
1003
+ }
1004
+ }
1005
+ if (!this.results_showing) {
1006
+ return this.results_show();
1007
+ }
1008
+ };
1009
+
1010
+ Chosen.prototype.keyup_arrow = function() {
1011
+ var prev_sibs;
1012
+ if (!this.results_showing && !this.is_multiple) {
1013
+ return this.results_show();
1014
+ } else if (this.result_highlight) {
1015
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
1016
+ if (prev_sibs.length) {
1017
+ return this.result_do_highlight(prev_sibs.first());
1018
+ } else {
1019
+ if (this.choices > 0) {
1020
+ this.results_hide();
1021
+ }
1022
+ return this.result_clear_highlight();
1023
+ }
1024
+ }
1025
+ };
1026
+
1027
+ Chosen.prototype.keydown_backstroke = function() {
1028
+ if (this.pending_backstroke) {
1029
+ this.choice_destroy(this.pending_backstroke.find("a").first());
1030
+ return this.clear_backstroke();
1031
+ } else {
1032
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
1033
+ if (this.single_backstroke_delete) {
1034
+ return this.keydown_backstroke();
1035
+ } else {
1036
+ return this.pending_backstroke.addClass("search-choice-focus");
1037
+ }
1038
+ }
1039
+ };
1040
+
1041
+ Chosen.prototype.clear_backstroke = function() {
1042
+ if (this.pending_backstroke) {
1043
+ this.pending_backstroke.removeClass("search-choice-focus");
1044
+ }
1045
+ return this.pending_backstroke = null;
1046
+ };
1047
+
1048
+ Chosen.prototype.keydown_checker = function(evt) {
1049
+ var stroke, _ref;
1050
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
1051
+ this.search_field_scale();
1052
+ if (stroke !== 8 && this.pending_backstroke) {
1053
+ this.clear_backstroke();
1054
+ }
1055
+ switch (stroke) {
1056
+ case 8:
1057
+ this.backstroke_length = this.search_field.val().length;
1058
+ break;
1059
+ case 9:
1060
+ if (this.results_showing && !this.is_multiple) {
1061
+ this.result_select(evt);
1062
+ }
1063
+ this.mouse_on_container = false;
1064
+ break;
1065
+ case 13:
1066
+ evt.preventDefault();
1067
+ break;
1068
+ case 38:
1069
+ evt.preventDefault();
1070
+ this.keyup_arrow();
1071
+ break;
1072
+ case 40:
1073
+ this.keydown_arrow();
1074
+ break;
1075
+ }
1076
+ };
1077
+
1078
+ Chosen.prototype.search_field_scale = function() {
1079
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
1080
+ if (this.is_multiple) {
1081
+ h = 0;
1082
+ w = 0;
1083
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
1084
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
1085
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
1086
+ style = styles[_i];
1087
+ style_block += style + ":" + this.search_field.css(style) + ";";
1088
+ }
1089
+ div = $('<div />', {
1090
+ 'style': style_block
1091
+ });
1092
+ div.text(this.search_field.val());
1093
+ $('body').append(div);
1094
+ w = div.width() + 25;
1095
+ div.remove();
1096
+ if (w > this.f_width - 10) {
1097
+ w = this.f_width - 10;
1098
+ }
1099
+ this.search_field.css({
1100
+ 'width': w + 'px'
1101
+ });
1102
+ dd_top = this.container.height();
1103
+ return this.dropdown.css({
1104
+ "top": dd_top + "px"
1105
+ });
1106
+ }
1107
+ };
1108
+
1109
+ Chosen.prototype.generate_random_id = function() {
1110
+ var string;
1111
+ string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
1112
+ while ($("#" + string).length > 0) {
1113
+ string += this.generate_random_char();
1114
+ }
1115
+ return string;
1116
+ };
1117
+
1118
+ return Chosen;
1119
+
1120
+ })(AbstractChosen);
1121
+
1122
+ get_side_border_padding = function(elmt) {
1123
+ var side_border_padding;
1124
+ return side_border_padding = elmt.outerWidth() - elmt.width();
1125
+ };
1126
+
1127
+ root.get_side_border_padding = get_side_border_padding;
1128
+
1129
+ }).call(this);