typus-rails4 4.0.0.beta6

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