tolaria 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +66 -0
  3. data/.yardopts +4 -0
  4. data/CNAME +1 -0
  5. data/CONTRIBUTING.md +32 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.md +9 -0
  8. data/README.md +538 -0
  9. data/Rakefile +52 -0
  10. data/app/assets/fonts/admin/fontawesome.eot +0 -0
  11. data/app/assets/fonts/admin/fontawesome.svg +565 -0
  12. data/app/assets/fonts/admin/fontawesome.ttf +0 -0
  13. data/app/assets/fonts/admin/fontawesome.woff +0 -0
  14. data/app/assets/fonts/admin/fontawesome.woff2 +0 -0
  15. data/app/assets/images/admin/columbia_banner.png +0 -0
  16. data/app/assets/images/admin/favicon.ico +0 -0
  17. data/app/assets/images/admin/noise.png +0 -0
  18. data/app/assets/images/admin/select_arrows.svg +1 -0
  19. data/app/assets/javascripts/admin/admin.js +4 -0
  20. data/app/assets/javascripts/admin/base.js +12 -0
  21. data/app/assets/javascripts/admin/lib/backbone.js +1888 -0
  22. data/app/assets/javascripts/admin/lib/jquery.chosen.js +1272 -0
  23. data/app/assets/javascripts/admin/lib/jquery.js +10361 -0
  24. data/app/assets/javascripts/admin/lib/jquery.selection.js +352 -0
  25. data/app/assets/javascripts/admin/lib/moment.js +3103 -0
  26. data/app/assets/javascripts/admin/lib/no.js +6 -0
  27. data/app/assets/javascripts/admin/lib/underscore.js +1570 -0
  28. data/app/assets/javascripts/admin/models/composer_buttons.js +45 -0
  29. data/app/assets/javascripts/admin/models/rails_meta.js +4 -0
  30. data/app/assets/javascripts/admin/views/field_with_errors.js +19 -0
  31. data/app/assets/javascripts/admin/views/fields/attachment_field.js +32 -0
  32. data/app/assets/javascripts/admin/views/fields/has_many.js +64 -0
  33. data/app/assets/javascripts/admin/views/fields/image_association_select.js +31 -0
  34. data/app/assets/javascripts/admin/views/fields/markdown_composer.js +167 -0
  35. data/app/assets/javascripts/admin/views/fields/searchable_select.js +70 -0
  36. data/app/assets/javascripts/admin/views/fields/slug_field.js +38 -0
  37. data/app/assets/javascripts/admin/views/fields/swatch_field.js +55 -0
  38. data/app/assets/javascripts/admin/views/fields/timestamp_field.js +80 -0
  39. data/app/assets/javascripts/admin/views/flash_message.js +18 -0
  40. data/app/assets/javascripts/admin/views/form_orchestrator.js +41 -0
  41. data/app/assets/javascripts/admin/views/navigation.js +20 -0
  42. data/app/assets/javascripts/admin/views/resource_form.js +18 -0
  43. data/app/assets/javascripts/admin/views/search_form.js +20 -0
  44. data/app/assets/javascripts/admin/views/sessions.js +109 -0
  45. data/app/assets/javascripts/admin/views/virtual_form.js +47 -0
  46. data/app/assets/stylesheets/admin/_base.scss +5 -0
  47. data/app/assets/stylesheets/admin/_reset.scss +149 -0
  48. data/app/assets/stylesheets/admin/_root.scss +63 -0
  49. data/app/assets/stylesheets/admin/admin.scss +4 -0
  50. data/app/assets/stylesheets/admin/components/_blank_slate.scss +44 -0
  51. data/app/assets/stylesheets/admin/components/_buttons.scss +82 -0
  52. data/app/assets/stylesheets/admin/components/_flash_message.scss +64 -0
  53. data/app/assets/stylesheets/admin/components/_footer.scss +9 -0
  54. data/app/assets/stylesheets/admin/components/_header.scss +107 -0
  55. data/app/assets/stylesheets/admin/components/_index_table.scss +120 -0
  56. data/app/assets/stylesheets/admin/components/_main.scss +68 -0
  57. data/app/assets/stylesheets/admin/components/_markdown_body.scss +109 -0
  58. data/app/assets/stylesheets/admin/components/_navigation.scss +110 -0
  59. data/app/assets/stylesheets/admin/components/_pagination.scss +36 -0
  60. data/app/assets/stylesheets/admin/components/_pill.scss +11 -0
  61. data/app/assets/stylesheets/admin/components/_resource_form.scss +222 -0
  62. data/app/assets/stylesheets/admin/components/_search_form.scss +36 -0
  63. data/app/assets/stylesheets/admin/components/_sessions.scss +152 -0
  64. data/app/assets/stylesheets/admin/components/_show_table.scss +67 -0
  65. data/app/assets/stylesheets/admin/components/forms/_attachment_field.scss +59 -0
  66. data/app/assets/stylesheets/admin/components/forms/_chosen.scss +478 -0
  67. data/app/assets/stylesheets/admin/components/forms/_image_association_select.scss +20 -0
  68. data/app/assets/stylesheets/admin/components/forms/_markdown_composer.scss +149 -0
  69. data/app/assets/stylesheets/admin/components/forms/_nested_fields.scss +63 -0
  70. data/app/assets/stylesheets/admin/components/forms/_searchable_select.scss +8 -0
  71. data/app/assets/stylesheets/admin/components/forms/_slug_field.scss +20 -0
  72. data/app/assets/stylesheets/admin/components/forms/_swatch_field.scss +47 -0
  73. data/app/assets/stylesheets/admin/components/forms/_timestamp_field.scss +15 -0
  74. data/app/assets/stylesheets/admin/components/help_link.scss +6 -0
  75. data/app/assets/stylesheets/admin/mixins/_clearfix.scss +18 -0
  76. data/app/assets/stylesheets/admin/mixins/_min_max_width.scss +11 -0
  77. data/app/assets/stylesheets/admin/mixins/_rgbb.scss +7 -0
  78. data/app/assets/stylesheets/admin/mixins/_visuallyhidden.scss +33 -0
  79. data/app/assets/stylesheets/admin/settings/_animations.scss +21 -0
  80. data/app/assets/stylesheets/admin/settings/_breakpoints.scss +2 -0
  81. data/app/assets/stylesheets/admin/settings/_colors.scss +32 -0
  82. data/app/assets/stylesheets/admin/settings/_fonts.scss +31 -0
  83. data/app/assets/stylesheets/admin/settings/_icons.scss +1658 -0
  84. data/app/controllers/admin/admin_controller.rb +21 -0
  85. data/app/controllers/admin/sessions_controller.rb +112 -0
  86. data/app/controllers/tolaria/resource_controller.rb +132 -0
  87. data/app/controllers/tolaria/tolaria_controller.rb +40 -0
  88. data/app/helpers/admin/table_helper.rb +175 -0
  89. data/app/helpers/admin/view_helper.rb +76 -0
  90. data/app/mailers/passcode_mailer.rb +11 -0
  91. data/app/models/administrator.rb +146 -0
  92. data/app/views/admin/administrators/_form.html.erb +16 -0
  93. data/app/views/admin/administrators/_index.html.erb +20 -0
  94. data/app/views/admin/administrators/_search.html.erb +5 -0
  95. data/app/views/admin/administrators/_show.html.erb +14 -0
  96. data/app/views/admin/help/help_link.html.erb +16 -0
  97. data/app/views/admin/session/form.html.erb +52 -0
  98. data/app/views/admin/shared/_flash_messages.html.erb +42 -0
  99. data/app/views/admin/shared/_footer.html.erb +8 -0
  100. data/app/views/admin/shared/_head.html.erb +11 -0
  101. data/app/views/admin/shared/_header.html.erb +43 -0
  102. data/app/views/admin/shared/_navigation.html.erb +47 -0
  103. data/app/views/admin/shared/_skiplinks.html.erb +0 -0
  104. data/app/views/admin/shared/forms/_attachment_field.html.erb +17 -0
  105. data/app/views/admin/shared/forms/_has_many.html.erb +14 -0
  106. data/app/views/admin/shared/forms/_has_many_header.html.erb +19 -0
  107. data/app/views/admin/shared/forms/_image_association_select.html.erb +6 -0
  108. data/app/views/admin/shared/forms/_image_field.html.erb +19 -0
  109. data/app/views/admin/shared/forms/_markdown_composer.html.erb +29 -0
  110. data/app/views/admin/shared/forms/_searchable_select.html.erb +3 -0
  111. data/app/views/admin/shared/forms/_slug_field.html.erb +9 -0
  112. data/app/views/admin/shared/forms/_swatch_field.html.erb +4 -0
  113. data/app/views/admin/shared/forms/_timestamp_field.html.erb +19 -0
  114. data/app/views/admin/tolaria_resource/_form_buttons.html.erb +10 -0
  115. data/app/views/admin/tolaria_resource/_index_table.html.erb +73 -0
  116. data/app/views/admin/tolaria_resource/_search_form.html.erb +32 -0
  117. data/app/views/admin/tolaria_resource/_show_buttons.html.erb +13 -0
  118. data/app/views/admin/tolaria_resource/edit.html.erb +34 -0
  119. data/app/views/admin/tolaria_resource/index.html.erb +36 -0
  120. data/app/views/admin/tolaria_resource/new.html.erb +1 -0
  121. data/app/views/admin/tolaria_resource/show.html.erb +52 -0
  122. data/app/views/kaminari/admin/_first_page.html.erb +9 -0
  123. data/app/views/kaminari/admin/_last_page.html.erb +9 -0
  124. data/app/views/kaminari/admin/_next_page.html.erb +9 -0
  125. data/app/views/kaminari/admin/_page.html.erb +17 -0
  126. data/app/views/kaminari/admin/_paginator.html.erb +21 -0
  127. data/app/views/kaminari/admin/_prev_page.html.erb +9 -0
  128. data/app/views/layouts/admin/admin.html.erb +21 -0
  129. data/app/views/layouts/admin/sessions.html.erb +12 -0
  130. data/app/views/passcode_mailer/passcode.text.erb +5 -0
  131. data/lib/generators/tolaria/install/install_generator.rb +21 -0
  132. data/lib/generators/tolaria/install/templates/administrators_migration.rb +31 -0
  133. data/lib/generators/tolaria/install/templates/tolaria_initializer.rb +93 -0
  134. data/lib/tasks/admin.rake +32 -0
  135. data/lib/tolaria.rb +27 -0
  136. data/lib/tolaria/active_record.rb +55 -0
  137. data/lib/tolaria/admin.rb +4 -0
  138. data/lib/tolaria/categories.rb +21 -0
  139. data/lib/tolaria/config.rb +40 -0
  140. data/lib/tolaria/default_config.rb +74 -0
  141. data/lib/tolaria/engine.rb +23 -0
  142. data/lib/tolaria/form_buildable.rb +203 -0
  143. data/lib/tolaria/help_links.rb +78 -0
  144. data/lib/tolaria/introspection.rb +13 -0
  145. data/lib/tolaria/manage.rb +57 -0
  146. data/lib/tolaria/managed_class.rb +90 -0
  147. data/lib/tolaria/markdown.rb +28 -0
  148. data/lib/tolaria/random_tokens.rb +16 -0
  149. data/lib/tolaria/reload.rb +21 -0
  150. data/lib/tolaria/routes.rb +33 -0
  151. data/lib/tolaria/version.rb +13 -0
  152. data/test/demo/Rakefile +4 -0
  153. data/test/demo/app/assets/javascripts/application.js +1 -0
  154. data/test/demo/app/assets/stylesheets/application.scss +1 -0
  155. data/test/demo/app/controllers/application_controller.rb +5 -0
  156. data/test/demo/app/controllers/concerns/.keep +0 -0
  157. data/test/demo/app/controllers/homepage_controller.rb +4 -0
  158. data/test/demo/app/helpers/application_helper.rb +2 -0
  159. data/test/demo/app/mailers/.keep +0 -0
  160. data/test/demo/app/models/.keep +0 -0
  161. data/test/demo/app/models/blog_post.rb +43 -0
  162. data/test/demo/app/models/footnote.rb +5 -0
  163. data/test/demo/app/models/image.rb +19 -0
  164. data/test/demo/app/models/legal_page.rb +24 -0
  165. data/test/demo/app/models/miscellany.rb +12 -0
  166. data/test/demo/app/models/topic.rb +22 -0
  167. data/test/demo/app/models/video.rb +16 -0
  168. data/test/demo/app/views/admin/blog_posts/_form.html.erb +48 -0
  169. data/test/demo/app/views/admin/blog_posts/_search.html.erb +5 -0
  170. data/test/demo/app/views/admin/help/markdown-help.md +95 -0
  171. data/test/demo/app/views/admin/images/_form.html.erb +26 -0
  172. data/test/demo/app/views/admin/legal_pages/_form.html.erb +15 -0
  173. data/test/demo/app/views/admin/topics/_form.html.erb +3 -0
  174. data/test/demo/app/views/admin/videos/_form.html.erb +11 -0
  175. data/test/demo/app/views/homepage/homepage.html.erb +3 -0
  176. data/test/demo/app/views/layouts/application.html.erb +14 -0
  177. data/test/demo/bin/bundle +3 -0
  178. data/test/demo/bin/rails +4 -0
  179. data/test/demo/bin/rake +4 -0
  180. data/test/demo/bin/setup +29 -0
  181. data/test/demo/config.ru +4 -0
  182. data/test/demo/config/application.rb +26 -0
  183. data/test/demo/config/boot.rb +4 -0
  184. data/test/demo/config/database.yml +18 -0
  185. data/test/demo/config/environment.rb +3 -0
  186. data/test/demo/config/environments/development.rb +43 -0
  187. data/test/demo/config/environments/test.rb +44 -0
  188. data/test/demo/config/initializers/assets.rb +11 -0
  189. data/test/demo/config/initializers/cookies_serializer.rb +2 -0
  190. data/test/demo/config/initializers/filter_parameter_logging.rb +3 -0
  191. data/test/demo/config/initializers/inflections.rb +17 -0
  192. data/test/demo/config/initializers/markdown.rb +44 -0
  193. data/test/demo/config/initializers/secret_token.rb +2 -0
  194. data/test/demo/config/initializers/session_store.rb +2 -0
  195. data/test/demo/config/initializers/tolaria.rb +17 -0
  196. data/test/demo/config/initializers/wrap_parameters.rb +14 -0
  197. data/test/demo/config/routes.rb +4 -0
  198. data/test/demo/db/migrate/20150601202901_create_administrators.rb +31 -0
  199. data/test/demo/db/migrate/20150603204006_add_testing_models.rb +27 -0
  200. data/test/demo/db/migrate/20150609232013_create_footnotes.rb +10 -0
  201. data/test/demo/db/migrate/20150610135235_create_additional_demo_objects.rb +50 -0
  202. data/test/demo/db/schema.rb +112 -0
  203. data/test/demo/log/.keep +0 -0
  204. data/test/demo/public/404.html +67 -0
  205. data/test/demo/public/422.html +67 -0
  206. data/test/demo/public/500.html +66 -0
  207. data/test/demo/public/favicon.ico +0 -0
  208. data/test/integration/help_link_test.rb +73 -0
  209. data/test/integration/interface_test.rb +63 -0
  210. data/test/integration/router_test.rb +73 -0
  211. data/test/integration/session_test.rb +88 -0
  212. data/test/test_helper.rb +58 -0
  213. data/test/unit/configuration_test.rb +21 -0
  214. data/test/unit/managed_classes_test.rb +54 -0
  215. data/test/unit/markdown_test.rb +12 -0
  216. data/test/unit/menu_test.rb +32 -0
  217. data/test/unit/random_tokens_test.rb +13 -0
  218. data/tolaria.gemspec +35 -0
  219. metadata +499 -0
@@ -0,0 +1,1272 @@
1
+ // Chosen 1.4.2
2
+ // https://github.com/harvesthq/chosen
3
+ //
4
+ // Copyright (c) 2011-2015 Harvest
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person
7
+ // obtaining a copy of this software and associated documentation
8
+ // files (the "Software"), to deal in the Software without
9
+ // restriction, including without limitation the rights to use,
10
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the
12
+ // Software is furnished to do so, subject to the following
13
+ // conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be
16
+ // included in all copies or substantial portions of the Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ // OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ (function() {
28
+ var $, AbstractChosen, Chosen, SelectParser, _ref,
29
+ __hasProp = {}.hasOwnProperty,
30
+ __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; };
31
+
32
+ SelectParser = (function() {
33
+ function SelectParser() {
34
+ this.options_index = 0;
35
+ this.parsed = [];
36
+ }
37
+
38
+ SelectParser.prototype.add_node = function(child) {
39
+ if (child.nodeName.toUpperCase() === "OPTGROUP") {
40
+ return this.add_group(child);
41
+ } else {
42
+ return this.add_option(child);
43
+ }
44
+ };
45
+
46
+ SelectParser.prototype.add_group = function(group) {
47
+ var group_position, option, _i, _len, _ref, _results;
48
+ group_position = this.parsed.length;
49
+ this.parsed.push({
50
+ array_index: group_position,
51
+ group: true,
52
+ label: this.escapeExpression(group.label),
53
+ title: group.title ? group.title : void 0,
54
+ children: 0,
55
+ disabled: group.disabled,
56
+ classes: group.className
57
+ });
58
+ _ref = group.childNodes;
59
+ _results = [];
60
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
61
+ option = _ref[_i];
62
+ _results.push(this.add_option(option, group_position, group.disabled));
63
+ }
64
+ return _results;
65
+ };
66
+
67
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
68
+ if (option.nodeName.toUpperCase() === "OPTION") {
69
+ if (option.text !== "") {
70
+ if (group_position != null) {
71
+ this.parsed[group_position].children += 1;
72
+ }
73
+ this.parsed.push({
74
+ array_index: this.parsed.length,
75
+ options_index: this.options_index,
76
+ value: option.value,
77
+ text: option.text,
78
+ html: option.innerHTML,
79
+ title: option.title ? option.title : void 0,
80
+ selected: option.selected,
81
+ disabled: group_disabled === true ? group_disabled : option.disabled,
82
+ group_array_index: group_position,
83
+ group_label: group_position != null ? this.parsed[group_position].label : null,
84
+ classes: option.className,
85
+ style: option.style.cssText
86
+ });
87
+ } else {
88
+ this.parsed.push({
89
+ array_index: this.parsed.length,
90
+ options_index: this.options_index,
91
+ empty: true
92
+ });
93
+ }
94
+ return this.options_index += 1;
95
+ }
96
+ };
97
+
98
+ SelectParser.prototype.escapeExpression = function(text) {
99
+ var map, unsafe_chars;
100
+ if ((text == null) || text === false) {
101
+ return "";
102
+ }
103
+ if (!/[\&\<\>\"\'\`]/.test(text)) {
104
+ return text;
105
+ }
106
+ map = {
107
+ "<": "&lt;",
108
+ ">": "&gt;",
109
+ '"': "&quot;",
110
+ "'": "&#x27;",
111
+ "`": "&#x60;"
112
+ };
113
+ unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g;
114
+ return text.replace(unsafe_chars, function(chr) {
115
+ return map[chr] || "&amp;";
116
+ });
117
+ };
118
+
119
+ return SelectParser;
120
+
121
+ })();
122
+
123
+ SelectParser.select_to_array = function(select) {
124
+ var child, parser, _i, _len, _ref;
125
+ parser = new SelectParser();
126
+ _ref = select.childNodes;
127
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
128
+ child = _ref[_i];
129
+ parser.add_node(child);
130
+ }
131
+ return parser.parsed;
132
+ };
133
+
134
+ AbstractChosen = (function() {
135
+ function AbstractChosen(form_field, options) {
136
+ this.form_field = form_field;
137
+ this.options = options != null ? options : {};
138
+ if (!AbstractChosen.browser_is_supported()) {
139
+ return;
140
+ }
141
+ this.is_multiple = this.form_field.multiple;
142
+ this.set_default_text();
143
+ this.set_default_values();
144
+ this.setup();
145
+ this.set_up_html();
146
+ this.register_observers();
147
+ this.on_ready();
148
+ }
149
+
150
+ AbstractChosen.prototype.set_default_values = function() {
151
+ var _this = this;
152
+ this.click_test_action = function(evt) {
153
+ return _this.test_active_click(evt);
154
+ };
155
+ this.activate_action = function(evt) {
156
+ return _this.activate_field(evt);
157
+ };
158
+ this.active_field = false;
159
+ this.mouse_on_container = false;
160
+ this.results_showing = false;
161
+ this.result_highlighted = null;
162
+ 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;
163
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
164
+ this.disable_search = this.options.disable_search || false;
165
+ this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
166
+ this.group_search = this.options.group_search != null ? this.options.group_search : true;
167
+ this.search_contains = this.options.search_contains || false;
168
+ this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
169
+ this.max_selected_options = this.options.max_selected_options || Infinity;
170
+ this.inherit_select_classes = this.options.inherit_select_classes || false;
171
+ this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
172
+ this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
173
+ return this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
174
+ };
175
+
176
+ AbstractChosen.prototype.set_default_text = function() {
177
+ if (this.form_field.getAttribute("data-placeholder")) {
178
+ this.default_text = this.form_field.getAttribute("data-placeholder");
179
+ } else if (this.is_multiple) {
180
+ this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
181
+ } else {
182
+ this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
183
+ }
184
+ return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
185
+ };
186
+
187
+ AbstractChosen.prototype.choice_label = function(item) {
188
+ if (this.include_group_label_in_selected && (item.group_label != null)) {
189
+ return "<b class='group-name'>" + item.group_label + "</b>" + item.html;
190
+ } else {
191
+ return item.html;
192
+ }
193
+ };
194
+
195
+ AbstractChosen.prototype.mouse_enter = function() {
196
+ return this.mouse_on_container = true;
197
+ };
198
+
199
+ AbstractChosen.prototype.mouse_leave = function() {
200
+ return this.mouse_on_container = false;
201
+ };
202
+
203
+ AbstractChosen.prototype.input_focus = function(evt) {
204
+ var _this = this;
205
+ if (this.is_multiple) {
206
+ if (!this.active_field) {
207
+ return setTimeout((function() {
208
+ return _this.container_mousedown();
209
+ }), 50);
210
+ }
211
+ } else {
212
+ if (!this.active_field) {
213
+ return this.activate_field();
214
+ }
215
+ }
216
+ };
217
+
218
+ AbstractChosen.prototype.input_blur = function(evt) {
219
+ var _this = this;
220
+ if (!this.mouse_on_container) {
221
+ this.active_field = false;
222
+ return setTimeout((function() {
223
+ return _this.blur_test();
224
+ }), 100);
225
+ }
226
+ };
227
+
228
+ AbstractChosen.prototype.results_option_build = function(options) {
229
+ var content, data, _i, _len, _ref;
230
+ content = '';
231
+ _ref = this.results_data;
232
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
233
+ data = _ref[_i];
234
+ if (data.group) {
235
+ content += this.result_add_group(data);
236
+ } else {
237
+ content += this.result_add_option(data);
238
+ }
239
+ if (options != null ? options.first : void 0) {
240
+ if (data.selected && this.is_multiple) {
241
+ this.choice_build(data);
242
+ } else if (data.selected && !this.is_multiple) {
243
+ this.single_set_selected_text(this.choice_label(data));
244
+ }
245
+ }
246
+ }
247
+ return content;
248
+ };
249
+
250
+ AbstractChosen.prototype.result_add_option = function(option) {
251
+ var classes, option_el;
252
+ if (!option.search_match) {
253
+ return '';
254
+ }
255
+ if (!this.include_option_in_results(option)) {
256
+ return '';
257
+ }
258
+ classes = [];
259
+ if (!option.disabled && !(option.selected && this.is_multiple)) {
260
+ classes.push("active-result");
261
+ }
262
+ if (option.disabled && !(option.selected && this.is_multiple)) {
263
+ classes.push("disabled-result");
264
+ }
265
+ if (option.selected) {
266
+ classes.push("result-selected");
267
+ }
268
+ if (option.group_array_index != null) {
269
+ classes.push("group-option");
270
+ }
271
+ if (option.classes !== "") {
272
+ classes.push(option.classes);
273
+ }
274
+ option_el = document.createElement("li");
275
+ option_el.className = classes.join(" ");
276
+ option_el.style.cssText = option.style;
277
+ option_el.setAttribute("data-option-array-index", option.array_index);
278
+ option_el.innerHTML = option.search_text;
279
+ if (option.title) {
280
+ option_el.title = option.title;
281
+ }
282
+ return this.outerHTML(option_el);
283
+ };
284
+
285
+ AbstractChosen.prototype.result_add_group = function(group) {
286
+ var classes, group_el;
287
+ if (!(group.search_match || group.group_match)) {
288
+ return '';
289
+ }
290
+ if (!(group.active_options > 0)) {
291
+ return '';
292
+ }
293
+ classes = [];
294
+ classes.push("group-result");
295
+ if (group.classes) {
296
+ classes.push(group.classes);
297
+ }
298
+ group_el = document.createElement("li");
299
+ group_el.className = classes.join(" ");
300
+ group_el.innerHTML = group.search_text;
301
+ if (group.title) {
302
+ group_el.title = group.title;
303
+ }
304
+ return this.outerHTML(group_el);
305
+ };
306
+
307
+ AbstractChosen.prototype.results_update_field = function() {
308
+ this.set_default_text();
309
+ if (!this.is_multiple) {
310
+ this.results_reset_cleanup();
311
+ }
312
+ this.result_clear_highlight();
313
+ this.results_build();
314
+ if (this.results_showing) {
315
+ return this.winnow_results();
316
+ }
317
+ };
318
+
319
+ AbstractChosen.prototype.reset_single_select_options = function() {
320
+ var result, _i, _len, _ref, _results;
321
+ _ref = this.results_data;
322
+ _results = [];
323
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
324
+ result = _ref[_i];
325
+ if (result.selected) {
326
+ _results.push(result.selected = false);
327
+ } else {
328
+ _results.push(void 0);
329
+ }
330
+ }
331
+ return _results;
332
+ };
333
+
334
+ AbstractChosen.prototype.results_toggle = function() {
335
+ if (this.results_showing) {
336
+ return this.results_hide();
337
+ } else {
338
+ return this.results_show();
339
+ }
340
+ };
341
+
342
+ AbstractChosen.prototype.results_search = function(evt) {
343
+ if (this.results_showing) {
344
+ return this.winnow_results();
345
+ } else {
346
+ return this.results_show();
347
+ }
348
+ };
349
+
350
+ AbstractChosen.prototype.winnow_results = function() {
351
+ var escapedSearchText, option, regex, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
352
+ this.no_results_clear();
353
+ results = 0;
354
+ searchText = this.get_search_text();
355
+ escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
356
+ zregex = new RegExp(escapedSearchText, 'i');
357
+ regex = this.get_search_regex(escapedSearchText);
358
+ _ref = this.results_data;
359
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
360
+ option = _ref[_i];
361
+ option.search_match = false;
362
+ results_group = null;
363
+ if (this.include_option_in_results(option)) {
364
+ if (option.group) {
365
+ option.group_match = false;
366
+ option.active_options = 0;
367
+ }
368
+ if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
369
+ results_group = this.results_data[option.group_array_index];
370
+ if (results_group.active_options === 0 && results_group.search_match) {
371
+ results += 1;
372
+ }
373
+ results_group.active_options += 1;
374
+ }
375
+ option.search_text = option.group ? option.label : option.html;
376
+ if (!(option.group && !this.group_search)) {
377
+ option.search_match = this.search_string_match(option.search_text, regex);
378
+ if (option.search_match && !option.group) {
379
+ results += 1;
380
+ }
381
+ if (option.search_match) {
382
+ if (searchText.length) {
383
+ startpos = option.search_text.search(zregex);
384
+ text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
385
+ option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
386
+ }
387
+ if (results_group != null) {
388
+ results_group.group_match = true;
389
+ }
390
+ } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
391
+ option.search_match = true;
392
+ }
393
+ }
394
+ }
395
+ }
396
+ this.result_clear_highlight();
397
+ if (results < 1 && searchText.length) {
398
+ this.update_results_content("");
399
+ return this.no_results(searchText);
400
+ } else {
401
+ this.update_results_content(this.results_option_build());
402
+ return this.winnow_results_set_highlight();
403
+ }
404
+ };
405
+
406
+ AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
407
+ var regex_anchor;
408
+ regex_anchor = this.search_contains ? "" : "^";
409
+ return new RegExp(regex_anchor + escaped_search_string, 'i');
410
+ };
411
+
412
+ AbstractChosen.prototype.search_string_match = function(search_string, regex) {
413
+ var part, parts, _i, _len;
414
+ if (regex.test(search_string)) {
415
+ return true;
416
+ } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
417
+ parts = search_string.replace(/\[|\]/g, "").split(" ");
418
+ if (parts.length) {
419
+ for (_i = 0, _len = parts.length; _i < _len; _i++) {
420
+ part = parts[_i];
421
+ if (regex.test(part)) {
422
+ return true;
423
+ }
424
+ }
425
+ }
426
+ }
427
+ };
428
+
429
+ AbstractChosen.prototype.choices_count = function() {
430
+ var option, _i, _len, _ref;
431
+ if (this.selected_option_count != null) {
432
+ return this.selected_option_count;
433
+ }
434
+ this.selected_option_count = 0;
435
+ _ref = this.form_field.options;
436
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
437
+ option = _ref[_i];
438
+ if (option.selected) {
439
+ this.selected_option_count += 1;
440
+ }
441
+ }
442
+ return this.selected_option_count;
443
+ };
444
+
445
+ AbstractChosen.prototype.choices_click = function(evt) {
446
+ evt.preventDefault();
447
+ if (!(this.results_showing || this.is_disabled)) {
448
+ return this.results_show();
449
+ }
450
+ };
451
+
452
+ AbstractChosen.prototype.keyup_checker = function(evt) {
453
+ var stroke, _ref;
454
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
455
+ this.search_field_scale();
456
+ switch (stroke) {
457
+ case 8:
458
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
459
+ return this.keydown_backstroke();
460
+ } else if (!this.pending_backstroke) {
461
+ this.result_clear_highlight();
462
+ return this.results_search();
463
+ }
464
+ break;
465
+ case 13:
466
+ evt.preventDefault();
467
+ if (this.results_showing) {
468
+ return this.result_select(evt);
469
+ }
470
+ break;
471
+ case 27:
472
+ if (this.results_showing) {
473
+ this.results_hide();
474
+ }
475
+ return true;
476
+ case 9:
477
+ case 38:
478
+ case 40:
479
+ case 16:
480
+ case 91:
481
+ case 17:
482
+ break;
483
+ default:
484
+ return this.results_search();
485
+ }
486
+ };
487
+
488
+ AbstractChosen.prototype.clipboard_event_checker = function(evt) {
489
+ var _this = this;
490
+ return setTimeout((function() {
491
+ return _this.results_search();
492
+ }), 50);
493
+ };
494
+
495
+ AbstractChosen.prototype.container_width = function() {
496
+ if (this.options.width != null) {
497
+ return this.options.width;
498
+ } else {
499
+ return "" + this.form_field.offsetWidth + "px";
500
+ }
501
+ };
502
+
503
+ AbstractChosen.prototype.include_option_in_results = function(option) {
504
+ if (this.is_multiple && (!this.display_selected_options && option.selected)) {
505
+ return false;
506
+ }
507
+ if (!this.display_disabled_options && option.disabled) {
508
+ return false;
509
+ }
510
+ if (option.empty) {
511
+ return false;
512
+ }
513
+ return true;
514
+ };
515
+
516
+ AbstractChosen.prototype.search_results_touchstart = function(evt) {
517
+ this.touch_started = true;
518
+ return this.search_results_mouseover(evt);
519
+ };
520
+
521
+ AbstractChosen.prototype.search_results_touchmove = function(evt) {
522
+ this.touch_started = false;
523
+ return this.search_results_mouseout(evt);
524
+ };
525
+
526
+ AbstractChosen.prototype.search_results_touchend = function(evt) {
527
+ if (this.touch_started) {
528
+ return this.search_results_mouseup(evt);
529
+ }
530
+ };
531
+
532
+ AbstractChosen.prototype.outerHTML = function(element) {
533
+ var tmp;
534
+ if (element.outerHTML) {
535
+ return element.outerHTML;
536
+ }
537
+ tmp = document.createElement("div");
538
+ tmp.appendChild(element);
539
+ return tmp.innerHTML;
540
+ };
541
+
542
+ AbstractChosen.browser_is_supported = function() {
543
+ if (window.navigator.appName === "Microsoft Internet Explorer") {
544
+ return document.documentMode >= 8;
545
+ }
546
+ if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
547
+ return false;
548
+ }
549
+ if (/Android/i.test(window.navigator.userAgent)) {
550
+ if (/Mobile/i.test(window.navigator.userAgent)) {
551
+ return false;
552
+ }
553
+ }
554
+ return true;
555
+ };
556
+
557
+ AbstractChosen.default_multiple_text = "Select Some Options";
558
+
559
+ AbstractChosen.default_single_text = "Select an Option";
560
+
561
+ AbstractChosen.default_no_result_text = "No results match";
562
+
563
+ return AbstractChosen;
564
+
565
+ })();
566
+
567
+ $ = jQuery;
568
+
569
+ $.fn.extend({
570
+ chosen: function(options) {
571
+ if (!AbstractChosen.browser_is_supported()) {
572
+ return this;
573
+ }
574
+ return this.each(function(input_field) {
575
+ var $this, chosen;
576
+ $this = $(this);
577
+ chosen = $this.data('chosen');
578
+ if (options === 'destroy' && chosen instanceof Chosen) {
579
+ chosen.destroy();
580
+ } else if (!(chosen instanceof Chosen)) {
581
+ $this.data('chosen', new Chosen(this, options));
582
+ }
583
+ });
584
+ }
585
+ });
586
+
587
+ Chosen = (function(_super) {
588
+ __extends(Chosen, _super);
589
+
590
+ function Chosen() {
591
+ _ref = Chosen.__super__.constructor.apply(this, arguments);
592
+ return _ref;
593
+ }
594
+
595
+ Chosen.prototype.setup = function() {
596
+ this.form_field_jq = $(this.form_field);
597
+ this.current_selectedIndex = this.form_field.selectedIndex;
598
+ return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
599
+ };
600
+
601
+ Chosen.prototype.set_up_html = function() {
602
+ var container_classes, container_props;
603
+ container_classes = ["chosen-container"];
604
+ container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
605
+ if (this.inherit_select_classes && this.form_field.className) {
606
+ container_classes.push(this.form_field.className);
607
+ }
608
+ if (this.is_rtl) {
609
+ container_classes.push("chosen-rtl");
610
+ }
611
+ container_props = {
612
+ 'class': container_classes.join(' '),
613
+ 'style': "width: " + (this.container_width()) + ";",
614
+ 'title': this.form_field.title
615
+ };
616
+ if (this.form_field.id.length) {
617
+ container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
618
+ }
619
+ this.container = $("<div />", container_props);
620
+ if (this.is_multiple) {
621
+ 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>');
622
+ } else {
623
+ this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
624
+ }
625
+ this.form_field_jq.hide().after(this.container);
626
+ this.dropdown = this.container.find('div.chosen-drop').first();
627
+ this.search_field = this.container.find('input').first();
628
+ this.search_results = this.container.find('ul.chosen-results').first();
629
+ this.search_field_scale();
630
+ this.search_no_results = this.container.find('li.no-results').first();
631
+ if (this.is_multiple) {
632
+ this.search_choices = this.container.find('ul.chosen-choices').first();
633
+ this.search_container = this.container.find('li.search-field').first();
634
+ } else {
635
+ this.search_container = this.container.find('div.chosen-search').first();
636
+ this.selected_item = this.container.find('.chosen-single').first();
637
+ }
638
+ this.results_build();
639
+ this.set_tab_index();
640
+ return this.set_label_behavior();
641
+ };
642
+
643
+ Chosen.prototype.on_ready = function() {
644
+ return this.form_field_jq.trigger("chosen:ready", {
645
+ chosen: this
646
+ });
647
+ };
648
+
649
+ Chosen.prototype.register_observers = function() {
650
+ var _this = this;
651
+ this.container.bind('touchstart.chosen', function(evt) {
652
+ _this.container_mousedown(evt);
653
+ return evt.preventDefault();
654
+ });
655
+ this.container.bind('touchend.chosen', function(evt) {
656
+ _this.container_mouseup(evt);
657
+ return evt.preventDefault();
658
+ });
659
+ this.container.bind('mousedown.chosen', function(evt) {
660
+ _this.container_mousedown(evt);
661
+ });
662
+ this.container.bind('mouseup.chosen', function(evt) {
663
+ _this.container_mouseup(evt);
664
+ });
665
+ this.container.bind('mouseenter.chosen', function(evt) {
666
+ _this.mouse_enter(evt);
667
+ });
668
+ this.container.bind('mouseleave.chosen', function(evt) {
669
+ _this.mouse_leave(evt);
670
+ });
671
+ this.search_results.bind('mouseup.chosen', function(evt) {
672
+ _this.search_results_mouseup(evt);
673
+ });
674
+ this.search_results.bind('mouseover.chosen', function(evt) {
675
+ _this.search_results_mouseover(evt);
676
+ });
677
+ this.search_results.bind('mouseout.chosen', function(evt) {
678
+ _this.search_results_mouseout(evt);
679
+ });
680
+ this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
681
+ _this.search_results_mousewheel(evt);
682
+ });
683
+ this.search_results.bind('touchstart.chosen', function(evt) {
684
+ _this.search_results_touchstart(evt);
685
+ });
686
+ this.search_results.bind('touchmove.chosen', function(evt) {
687
+ _this.search_results_touchmove(evt);
688
+ });
689
+ this.search_results.bind('touchend.chosen', function(evt) {
690
+ _this.search_results_touchend(evt);
691
+ });
692
+ this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
693
+ _this.results_update_field(evt);
694
+ });
695
+ this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
696
+ _this.activate_field(evt);
697
+ });
698
+ this.form_field_jq.bind("chosen:open.chosen", function(evt) {
699
+ _this.container_mousedown(evt);
700
+ });
701
+ this.form_field_jq.bind("chosen:close.chosen", function(evt) {
702
+ _this.input_blur(evt);
703
+ });
704
+ this.search_field.bind('blur.chosen', function(evt) {
705
+ _this.input_blur(evt);
706
+ });
707
+ this.search_field.bind('keyup.chosen', function(evt) {
708
+ _this.keyup_checker(evt);
709
+ });
710
+ this.search_field.bind('keydown.chosen', function(evt) {
711
+ _this.keydown_checker(evt);
712
+ });
713
+ this.search_field.bind('focus.chosen', function(evt) {
714
+ _this.input_focus(evt);
715
+ });
716
+ this.search_field.bind('cut.chosen', function(evt) {
717
+ _this.clipboard_event_checker(evt);
718
+ });
719
+ this.search_field.bind('paste.chosen', function(evt) {
720
+ _this.clipboard_event_checker(evt);
721
+ });
722
+ if (this.is_multiple) {
723
+ return this.search_choices.bind('click.chosen', function(evt) {
724
+ _this.choices_click(evt);
725
+ });
726
+ } else {
727
+ return this.container.bind('click.chosen', function(evt) {
728
+ evt.preventDefault();
729
+ });
730
+ }
731
+ };
732
+
733
+ Chosen.prototype.destroy = function() {
734
+ $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
735
+ if (this.search_field[0].tabIndex) {
736
+ this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
737
+ }
738
+ this.container.remove();
739
+ this.form_field_jq.removeData('chosen');
740
+ return this.form_field_jq.show();
741
+ };
742
+
743
+ Chosen.prototype.search_field_disabled = function() {
744
+ this.is_disabled = this.form_field_jq[0].disabled;
745
+ if (this.is_disabled) {
746
+ this.container.addClass('chosen-disabled');
747
+ this.search_field[0].disabled = true;
748
+ if (!this.is_multiple) {
749
+ this.selected_item.unbind("focus.chosen", this.activate_action);
750
+ }
751
+ return this.close_field();
752
+ } else {
753
+ this.container.removeClass('chosen-disabled');
754
+ this.search_field[0].disabled = false;
755
+ if (!this.is_multiple) {
756
+ return this.selected_item.bind("focus.chosen", this.activate_action);
757
+ }
758
+ }
759
+ };
760
+
761
+ Chosen.prototype.container_mousedown = function(evt) {
762
+ if (!this.is_disabled) {
763
+ if (evt && evt.type === "mousedown" && !this.results_showing) {
764
+ evt.preventDefault();
765
+ }
766
+ if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
767
+ if (!this.active_field) {
768
+ if (this.is_multiple) {
769
+ this.search_field.val("");
770
+ }
771
+ $(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action);
772
+ this.results_show();
773
+ } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
774
+ evt.preventDefault();
775
+ this.results_toggle();
776
+ }
777
+ return this.activate_field();
778
+ }
779
+ }
780
+ };
781
+
782
+ Chosen.prototype.container_mouseup = function(evt) {
783
+ if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
784
+ return this.results_reset(evt);
785
+ }
786
+ };
787
+
788
+ Chosen.prototype.search_results_mousewheel = function(evt) {
789
+ var delta;
790
+ if (evt.originalEvent) {
791
+ delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
792
+ }
793
+ if (delta != null) {
794
+ evt.preventDefault();
795
+ if (evt.type === 'DOMMouseScroll') {
796
+ delta = delta * 40;
797
+ }
798
+ return this.search_results.scrollTop(delta + this.search_results.scrollTop());
799
+ }
800
+ };
801
+
802
+ Chosen.prototype.blur_test = function(evt) {
803
+ if (!this.active_field && this.container.hasClass("chosen-container-active")) {
804
+ return this.close_field();
805
+ }
806
+ };
807
+
808
+ Chosen.prototype.close_field = function() {
809
+ $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
810
+ this.active_field = false;
811
+ this.results_hide();
812
+ this.container.removeClass("chosen-container-active");
813
+ this.clear_backstroke();
814
+ this.show_search_field_default();
815
+ return this.search_field_scale();
816
+ };
817
+
818
+ Chosen.prototype.activate_field = function() {
819
+ this.container.addClass("chosen-container-active");
820
+ this.active_field = true;
821
+ this.search_field.val(this.search_field.val());
822
+ return this.search_field.focus();
823
+ };
824
+
825
+ Chosen.prototype.test_active_click = function(evt) {
826
+ var active_container;
827
+ active_container = $(evt.target).closest('.chosen-container');
828
+ if (active_container.length && this.container[0] === active_container[0]) {
829
+ return this.active_field = true;
830
+ } else {
831
+ return this.close_field();
832
+ }
833
+ };
834
+
835
+ Chosen.prototype.results_build = function() {
836
+ this.parsing = true;
837
+ this.selected_option_count = null;
838
+ this.results_data = SelectParser.select_to_array(this.form_field);
839
+ if (this.is_multiple) {
840
+ this.search_choices.find("li.search-choice").remove();
841
+ } else if (!this.is_multiple) {
842
+ this.single_set_selected_text();
843
+ if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
844
+ this.search_field[0].readOnly = true;
845
+ this.container.addClass("chosen-container-single-nosearch");
846
+ } else {
847
+ this.search_field[0].readOnly = false;
848
+ this.container.removeClass("chosen-container-single-nosearch");
849
+ }
850
+ }
851
+ this.update_results_content(this.results_option_build({
852
+ first: true
853
+ }));
854
+ this.search_field_disabled();
855
+ this.show_search_field_default();
856
+ this.search_field_scale();
857
+ return this.parsing = false;
858
+ };
859
+
860
+ Chosen.prototype.result_do_highlight = function(el) {
861
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
862
+ if (el.length) {
863
+ this.result_clear_highlight();
864
+ this.result_highlight = el;
865
+ this.result_highlight.addClass("highlighted");
866
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
867
+ visible_top = this.search_results.scrollTop();
868
+ visible_bottom = maxHeight + visible_top;
869
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
870
+ high_bottom = high_top + this.result_highlight.outerHeight();
871
+ if (high_bottom >= visible_bottom) {
872
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
873
+ } else if (high_top < visible_top) {
874
+ return this.search_results.scrollTop(high_top);
875
+ }
876
+ }
877
+ };
878
+
879
+ Chosen.prototype.result_clear_highlight = function() {
880
+ if (this.result_highlight) {
881
+ this.result_highlight.removeClass("highlighted");
882
+ }
883
+ return this.result_highlight = null;
884
+ };
885
+
886
+ Chosen.prototype.results_show = function() {
887
+ if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
888
+ this.form_field_jq.trigger("chosen:maxselected", {
889
+ chosen: this
890
+ });
891
+ return false;
892
+ }
893
+ this.container.addClass("chosen-with-drop");
894
+ this.results_showing = true;
895
+ this.search_field.focus();
896
+ this.search_field.val(this.search_field.val());
897
+ this.winnow_results();
898
+ return this.form_field_jq.trigger("chosen:showing_dropdown", {
899
+ chosen: this
900
+ });
901
+ };
902
+
903
+ Chosen.prototype.update_results_content = function(content) {
904
+ return this.search_results.html(content);
905
+ };
906
+
907
+ Chosen.prototype.results_hide = function() {
908
+ if (this.results_showing) {
909
+ this.result_clear_highlight();
910
+ this.container.removeClass("chosen-with-drop");
911
+ this.form_field_jq.trigger("chosen:hiding_dropdown", {
912
+ chosen: this
913
+ });
914
+ }
915
+ return this.results_showing = false;
916
+ };
917
+
918
+ Chosen.prototype.set_tab_index = function(el) {
919
+ var ti;
920
+ if (this.form_field.tabIndex) {
921
+ ti = this.form_field.tabIndex;
922
+ this.form_field.tabIndex = -1;
923
+ return this.search_field[0].tabIndex = ti;
924
+ }
925
+ };
926
+
927
+ Chosen.prototype.set_label_behavior = function() {
928
+ var _this = this;
929
+ this.form_field_label = this.form_field_jq.parents("label");
930
+ if (!this.form_field_label.length && this.form_field.id.length) {
931
+ this.form_field_label = $("label[for='" + this.form_field.id + "']");
932
+ }
933
+ if (this.form_field_label.length > 0) {
934
+ return this.form_field_label.bind('click.chosen', function(evt) {
935
+ if (_this.is_multiple) {
936
+ return _this.container_mousedown(evt);
937
+ } else {
938
+ return _this.activate_field();
939
+ }
940
+ });
941
+ }
942
+ };
943
+
944
+ Chosen.prototype.show_search_field_default = function() {
945
+ if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
946
+ this.search_field.val(this.default_text);
947
+ return this.search_field.addClass("default");
948
+ } else {
949
+ this.search_field.val("");
950
+ return this.search_field.removeClass("default");
951
+ }
952
+ };
953
+
954
+ Chosen.prototype.search_results_mouseup = function(evt) {
955
+ var target;
956
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
957
+ if (target.length) {
958
+ this.result_highlight = target;
959
+ this.result_select(evt);
960
+ return this.search_field.focus();
961
+ }
962
+ };
963
+
964
+ Chosen.prototype.search_results_mouseover = function(evt) {
965
+ var target;
966
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
967
+ if (target) {
968
+ return this.result_do_highlight(target);
969
+ }
970
+ };
971
+
972
+ Chosen.prototype.search_results_mouseout = function(evt) {
973
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
974
+ return this.result_clear_highlight();
975
+ }
976
+ };
977
+
978
+ Chosen.prototype.choice_build = function(item) {
979
+ var choice, close_link,
980
+ _this = this;
981
+ choice = $('<li />', {
982
+ "class": "search-choice"
983
+ }).html("<span>" + (this.choice_label(item)) + "</span>");
984
+ if (item.disabled) {
985
+ choice.addClass('search-choice-disabled');
986
+ } else {
987
+ close_link = $('<a />', {
988
+ "class": 'search-choice-close',
989
+ 'data-option-array-index': item.array_index
990
+ });
991
+ close_link.bind('click.chosen', function(evt) {
992
+ return _this.choice_destroy_link_click(evt);
993
+ });
994
+ choice.append(close_link);
995
+ }
996
+ return this.search_container.before(choice);
997
+ };
998
+
999
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
1000
+ evt.preventDefault();
1001
+ evt.stopPropagation();
1002
+ if (!this.is_disabled) {
1003
+ return this.choice_destroy($(evt.target));
1004
+ }
1005
+ };
1006
+
1007
+ Chosen.prototype.choice_destroy = function(link) {
1008
+ if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
1009
+ this.show_search_field_default();
1010
+ if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
1011
+ this.results_hide();
1012
+ }
1013
+ link.parents('li').first().remove();
1014
+ return this.search_field_scale();
1015
+ }
1016
+ };
1017
+
1018
+ Chosen.prototype.results_reset = function() {
1019
+ this.reset_single_select_options();
1020
+ this.form_field.options[0].selected = true;
1021
+ this.single_set_selected_text();
1022
+ this.show_search_field_default();
1023
+ this.results_reset_cleanup();
1024
+ this.form_field_jq.trigger("change");
1025
+ if (this.active_field) {
1026
+ return this.results_hide();
1027
+ }
1028
+ };
1029
+
1030
+ Chosen.prototype.results_reset_cleanup = function() {
1031
+ this.current_selectedIndex = this.form_field.selectedIndex;
1032
+ return this.selected_item.find("abbr").remove();
1033
+ };
1034
+
1035
+ Chosen.prototype.result_select = function(evt) {
1036
+ var high, item;
1037
+ if (this.result_highlight) {
1038
+ high = this.result_highlight;
1039
+ this.result_clear_highlight();
1040
+ if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
1041
+ this.form_field_jq.trigger("chosen:maxselected", {
1042
+ chosen: this
1043
+ });
1044
+ return false;
1045
+ }
1046
+ if (this.is_multiple) {
1047
+ high.removeClass("active-result");
1048
+ } else {
1049
+ this.reset_single_select_options();
1050
+ }
1051
+ high.addClass("result-selected");
1052
+ item = this.results_data[high[0].getAttribute("data-option-array-index")];
1053
+ item.selected = true;
1054
+ this.form_field.options[item.options_index].selected = true;
1055
+ this.selected_option_count = null;
1056
+ if (this.is_multiple) {
1057
+ this.choice_build(item);
1058
+ } else {
1059
+ this.single_set_selected_text(this.choice_label(item));
1060
+ }
1061
+ if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
1062
+ this.results_hide();
1063
+ }
1064
+ this.search_field.val("");
1065
+ if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
1066
+ this.form_field_jq.trigger("change", {
1067
+ 'selected': this.form_field.options[item.options_index].value
1068
+ });
1069
+ }
1070
+ this.current_selectedIndex = this.form_field.selectedIndex;
1071
+ evt.preventDefault();
1072
+ return this.search_field_scale();
1073
+ }
1074
+ };
1075
+
1076
+ Chosen.prototype.single_set_selected_text = function(text) {
1077
+ if (text == null) {
1078
+ text = this.default_text;
1079
+ }
1080
+ if (text === this.default_text) {
1081
+ this.selected_item.addClass("chosen-default");
1082
+ } else {
1083
+ this.single_deselect_control_build();
1084
+ this.selected_item.removeClass("chosen-default");
1085
+ }
1086
+ return this.selected_item.find("span").html(text);
1087
+ };
1088
+
1089
+ Chosen.prototype.result_deselect = function(pos) {
1090
+ var result_data;
1091
+ result_data = this.results_data[pos];
1092
+ if (!this.form_field.options[result_data.options_index].disabled) {
1093
+ result_data.selected = false;
1094
+ this.form_field.options[result_data.options_index].selected = false;
1095
+ this.selected_option_count = null;
1096
+ this.result_clear_highlight();
1097
+ if (this.results_showing) {
1098
+ this.winnow_results();
1099
+ }
1100
+ this.form_field_jq.trigger("change", {
1101
+ deselected: this.form_field.options[result_data.options_index].value
1102
+ });
1103
+ this.search_field_scale();
1104
+ return true;
1105
+ } else {
1106
+ return false;
1107
+ }
1108
+ };
1109
+
1110
+ Chosen.prototype.single_deselect_control_build = function() {
1111
+ if (!this.allow_single_deselect) {
1112
+ return;
1113
+ }
1114
+ if (!this.selected_item.find("abbr").length) {
1115
+ this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
1116
+ }
1117
+ return this.selected_item.addClass("chosen-single-with-deselect");
1118
+ };
1119
+
1120
+ Chosen.prototype.get_search_text = function() {
1121
+ return $('<div/>').text($.trim(this.search_field.val())).html();
1122
+ };
1123
+
1124
+ Chosen.prototype.winnow_results_set_highlight = function() {
1125
+ var do_high, selected_results;
1126
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
1127
+ do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
1128
+ if (do_high != null) {
1129
+ return this.result_do_highlight(do_high);
1130
+ }
1131
+ };
1132
+
1133
+ Chosen.prototype.no_results = function(terms) {
1134
+ var no_results_html;
1135
+ no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
1136
+ no_results_html.find("span").first().html(terms);
1137
+ this.search_results.append(no_results_html);
1138
+ return this.form_field_jq.trigger("chosen:no_results", {
1139
+ chosen: this
1140
+ });
1141
+ };
1142
+
1143
+ Chosen.prototype.no_results_clear = function() {
1144
+ return this.search_results.find(".no-results").remove();
1145
+ };
1146
+
1147
+ Chosen.prototype.keydown_arrow = function() {
1148
+ var next_sib;
1149
+ if (this.results_showing && this.result_highlight) {
1150
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
1151
+ if (next_sib) {
1152
+ return this.result_do_highlight(next_sib);
1153
+ }
1154
+ } else {
1155
+ return this.results_show();
1156
+ }
1157
+ };
1158
+
1159
+ Chosen.prototype.keyup_arrow = function() {
1160
+ var prev_sibs;
1161
+ if (!this.results_showing && !this.is_multiple) {
1162
+ return this.results_show();
1163
+ } else if (this.result_highlight) {
1164
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
1165
+ if (prev_sibs.length) {
1166
+ return this.result_do_highlight(prev_sibs.first());
1167
+ } else {
1168
+ if (this.choices_count() > 0) {
1169
+ this.results_hide();
1170
+ }
1171
+ return this.result_clear_highlight();
1172
+ }
1173
+ }
1174
+ };
1175
+
1176
+ Chosen.prototype.keydown_backstroke = function() {
1177
+ var next_available_destroy;
1178
+ if (this.pending_backstroke) {
1179
+ this.choice_destroy(this.pending_backstroke.find("a").first());
1180
+ return this.clear_backstroke();
1181
+ } else {
1182
+ next_available_destroy = this.search_container.siblings("li.search-choice").last();
1183
+ if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
1184
+ this.pending_backstroke = next_available_destroy;
1185
+ if (this.single_backstroke_delete) {
1186
+ return this.keydown_backstroke();
1187
+ } else {
1188
+ return this.pending_backstroke.addClass("search-choice-focus");
1189
+ }
1190
+ }
1191
+ }
1192
+ };
1193
+
1194
+ Chosen.prototype.clear_backstroke = function() {
1195
+ if (this.pending_backstroke) {
1196
+ this.pending_backstroke.removeClass("search-choice-focus");
1197
+ }
1198
+ return this.pending_backstroke = null;
1199
+ };
1200
+
1201
+ Chosen.prototype.keydown_checker = function(evt) {
1202
+ var stroke, _ref1;
1203
+ stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
1204
+ this.search_field_scale();
1205
+ if (stroke !== 8 && this.pending_backstroke) {
1206
+ this.clear_backstroke();
1207
+ }
1208
+ switch (stroke) {
1209
+ case 8:
1210
+ this.backstroke_length = this.search_field.val().length;
1211
+ break;
1212
+ case 9:
1213
+ if (this.results_showing && !this.is_multiple) {
1214
+ this.result_select(evt);
1215
+ }
1216
+ this.mouse_on_container = false;
1217
+ break;
1218
+ case 13:
1219
+ if (this.results_showing) {
1220
+ evt.preventDefault();
1221
+ }
1222
+ break;
1223
+ case 32:
1224
+ if (this.disable_search) {
1225
+ evt.preventDefault();
1226
+ }
1227
+ break;
1228
+ case 38:
1229
+ evt.preventDefault();
1230
+ this.keyup_arrow();
1231
+ break;
1232
+ case 40:
1233
+ evt.preventDefault();
1234
+ this.keydown_arrow();
1235
+ break;
1236
+ }
1237
+ };
1238
+
1239
+ Chosen.prototype.search_field_scale = function() {
1240
+ var div, f_width, h, style, style_block, styles, w, _i, _len;
1241
+ if (this.is_multiple) {
1242
+ h = 0;
1243
+ w = 0;
1244
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
1245
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
1246
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
1247
+ style = styles[_i];
1248
+ style_block += style + ":" + this.search_field.css(style) + ";";
1249
+ }
1250
+ div = $('<div />', {
1251
+ 'style': style_block
1252
+ });
1253
+ div.text(this.search_field.val());
1254
+ $('body').append(div);
1255
+ w = div.width() + 25;
1256
+ div.remove();
1257
+ f_width = this.container.outerWidth();
1258
+ if (w > f_width - 10) {
1259
+ w = f_width - 10;
1260
+ }
1261
+ return this.search_field.css({
1262
+ 'width': w + 'px'
1263
+ });
1264
+ }
1265
+ };
1266
+
1267
+ return Chosen;
1268
+
1269
+ })(AbstractChosen);
1270
+
1271
+ }).call(this);
1272
+