atrium 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/.gitignore +13 -0
  2. data/.gitmodules +3 -0
  3. data/.rvmrc +32 -0
  4. data/GETTING_STARTED.textile +109 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +320 -0
  7. data/Guardfile +10 -0
  8. data/README.mkd +56 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/images/atrium/ajax-loader.gif +0 -0
  11. data/app/assets/images/atrium/lightbox-ico-loading.gif +0 -0
  12. data/app/assets/images/atrium/logo.png +0 -0
  13. data/app/assets/javascripts/atrium/atrium.js +281 -0
  14. data/app/assets/javascripts/chosen.jquery.js +899 -0
  15. data/app/assets/javascripts/ckeditor.warning.js +65 -0
  16. data/app/assets/javascripts/ckeditor/config.js.coffee +6 -0
  17. data/app/assets/javascripts/ckeditor/jquery.generateId.js +13 -0
  18. data/app/assets/javascripts/ckeditor/jquery.jeditable.ckeditor.js +59 -0
  19. data/app/assets/javascripts/ckeditor/plugins/linkItem/application_link.png +0 -0
  20. data/app/assets/javascripts/ckeditor/plugins/linkItem/dialogs/linkItem.js +1470 -0
  21. data/app/assets/javascripts/ckeditor/plugins/linkItem/plugin.js +16 -0
  22. data/app/assets/javascripts/ckeditor/plugins/linkItem/ui_toolbar_pencil.png +0 -0
  23. data/app/assets/javascripts/jquery.colorbox.js +864 -0
  24. data/app/assets/javascripts/jquery.jeditable.js +543 -0
  25. data/app/assets/stylesheets/atrium/atrium.css +216 -0
  26. data/app/assets/stylesheets/atrium/chosen-sprite.png +0 -0
  27. data/app/assets/stylesheets/atrium/chosen.css +367 -0
  28. data/app/assets/stylesheets/colorbox.css +42 -0
  29. data/app/assets/stylesheets/controls.png +0 -0
  30. data/app/assets/stylesheets/loading.gif +0 -0
  31. data/app/controllers/atrium/base_controller.rb +25 -0
  32. data/app/controllers/atrium/collection_exhibit_order_controller.rb +21 -0
  33. data/app/controllers/atrium/collections_controller.rb +165 -0
  34. data/app/controllers/atrium/customization_controller.rb +41 -0
  35. data/app/controllers/atrium/descriptions_controller.rb +177 -0
  36. data/app/controllers/atrium/exhibit_facet_order_controller.rb +19 -0
  37. data/app/controllers/atrium/exhibits_controller.rb +108 -0
  38. data/app/controllers/atrium/showcases_controller.rb +193 -0
  39. data/app/helpers/atrium/base_helper.rb +6 -0
  40. data/app/models/ability.rb +14 -0
  41. data/app/models/atrium/browse_level.rb +41 -0
  42. data/app/models/atrium/collection.rb +121 -0
  43. data/app/models/atrium/description.rb +128 -0
  44. data/app/models/atrium/essay.rb +21 -0
  45. data/app/models/atrium/exhibit.rb +58 -0
  46. data/app/models/atrium/search/facet.rb +29 -0
  47. data/app/models/atrium/search/facet_selection.rb +17 -0
  48. data/app/models/atrium/showcase.rb +173 -0
  49. data/app/models/atrium/showcase/facet_selection.rb +21 -0
  50. data/app/models/atrium/showcase/item.rb +19 -0
  51. data/app/models/role_mapper.rb +23 -0
  52. data/app/views/_user_util_links.html.erb +25 -0
  53. data/app/views/atrium/collections/_bookmark_control.html.erb +25 -0
  54. data/app/views/atrium/collections/_browse_index.html.erb +20 -0
  55. data/app/views/atrium/collections/_collection_items_index.html.erb +10 -0
  56. data/app/views/atrium/collections/_document.html.erb +24 -0
  57. data/app/views/atrium/collections/_document_list.html.erb +6 -0
  58. data/app/views/atrium/collections/_edit_navigation.html.erb +20 -0
  59. data/app/views/atrium/collections/_folder_control.html.erb +12 -0
  60. data/app/views/atrium/collections/_form.html.erb +93 -0
  61. data/app/views/atrium/collections/_listing.html.erb +18 -0
  62. data/app/views/atrium/collections/_navigation.html.erb +45 -0
  63. data/app/views/atrium/collections/_results_pagination.html.erb +9 -0
  64. data/app/views/atrium/collections/_sort_and_per_page.html.erb +23 -0
  65. data/app/views/atrium/collections/edit.html.erb +5 -0
  66. data/app/views/atrium/collections/new.html.erb +6 -0
  67. data/app/views/atrium/collections/show.html.erb +22 -0
  68. data/app/views/atrium/descriptions/_form.html.erb +64 -0
  69. data/app/views/atrium/descriptions/edit.html.erb +4 -0
  70. data/app/views/atrium/descriptions/index.html.erb +4 -0
  71. data/app/views/atrium/descriptions/new.html.erb +2 -0
  72. data/app/views/atrium/descriptions/show.html.erb +20 -0
  73. data/app/views/atrium/exhibits/_bookmark_control.html.erb +25 -0
  74. data/app/views/atrium/exhibits/_folder_control.html.erb +12 -0
  75. data/app/views/atrium/exhibits/_form.html.erb +108 -0
  76. data/app/views/atrium/exhibits/edit.html.erb +9 -0
  77. data/app/views/atrium/exhibits/new.html.erb +6 -0
  78. data/app/views/atrium/exhibits/show.html.erb +26 -0
  79. data/app/views/atrium/showcases/_showcase_navigation.html.erb +23 -0
  80. data/app/views/atrium/showcases/show.html.erb +1 -0
  81. data/app/views/catalog/_collection_home_text.html.erb +6 -0
  82. data/app/views/catalog/_constraints.html.erb +9 -0
  83. data/app/views/catalog/_default_collection_text.html.erb +18 -0
  84. data/app/views/catalog/_default_home_text.html.erb +6 -0
  85. data/app/views/catalog/_home_text.html.erb +6 -0
  86. data/app/views/catalog/_index_partials/_description.html.erb +8 -0
  87. data/app/views/catalog/_search_form.html.erb +66 -0
  88. data/app/views/catalog/_show_partials/_description.html.erb +15 -0
  89. data/app/views/catalog/browse_show.html.erb +18 -0
  90. data/app/views/catalog/index.html.erb +35 -0
  91. data/app/views/catalog/list_description.html.erb +24 -0
  92. data/app/views/catalog/list_item.html.erb +3 -0
  93. data/app/views/layouts/atrium.html.erb +86 -0
  94. data/app/views/layouts/atrium_themes/default.html.erb +4 -0
  95. data/app/views/layouts/item_listing.html.erb +36 -0
  96. data/app/views/listing/_document.html.erb +27 -0
  97. data/app/views/listing/_document_list.html.erb +3 -0
  98. data/app/views/listing/_item_search.html.erb +27 -0
  99. data/app/views/shared/_banner.html.erb +5 -0
  100. data/app/views/shared/_collection_complete_list.html.erb +33 -0
  101. data/app/views/shared/_collection_search_form.html.erb +12 -0
  102. data/app/views/shared/_collection_title_header.html.erb +3 -0
  103. data/app/views/shared/_featured_sources.html.erb +20 -0
  104. data/app/views/shared/_list_descriptions.html.erb +38 -0
  105. data/app/views/shared/_navigation_browse_levels.html.erb +34 -0
  106. data/app/views/shared/_showcase_configure_menu.html.erb +22 -0
  107. data/app/views/shared/_top_navigation.html.erb +9 -0
  108. data/atrium.gemspec +76 -0
  109. data/config/routes.rb +12 -0
  110. data/init.rb +3 -0
  111. data/lib/application_controller.rb +24 -0
  112. data/lib/atrium.rb +42 -0
  113. data/lib/atrium/application_helper.rb +24 -0
  114. data/lib/atrium/atrium_helper_behavior.rb +162 -0
  115. data/lib/atrium/catalog.rb +203 -0
  116. data/lib/atrium/collections_helper.rb +139 -0
  117. data/lib/atrium/controller.rb +10 -0
  118. data/lib/atrium/descriptions_helper.rb +23 -0
  119. data/lib/atrium/engine.rb +12 -0
  120. data/lib/atrium/layout_helper.rb +13 -0
  121. data/lib/atrium/routes.rb +99 -0
  122. data/lib/atrium/solr_helper.rb +440 -0
  123. data/lib/atrium/version.rb +3 -0
  124. data/lib/generators/atrium/assets_generator.rb +44 -0
  125. data/lib/generators/atrium/atrium_generator.rb +149 -0
  126. data/lib/generators/atrium/cucumber_support_generator.rb +29 -0
  127. data/lib/generators/atrium/templates/config/role_map_cucumber.yml +2 -0
  128. data/lib/generators/atrium/templates/config/role_map_development.yml +2 -0
  129. data/lib/generators/atrium/templates/config/role_map_production.yml +2 -0
  130. data/lib/generators/atrium/templates/config/role_map_test.yml +2 -0
  131. data/lib/generators/atrium/templates/config/solr.yml +10 -0
  132. data/lib/generators/atrium/templates/db/seeds.rb +87 -0
  133. data/lib/generators/atrium/templates/migrations/create_atrium_browse_levels.rb +18 -0
  134. data/lib/generators/atrium/templates/migrations/create_atrium_collections.rb +20 -0
  135. data/lib/generators/atrium/templates/migrations/create_atrium_descriptions.rb +16 -0
  136. data/lib/generators/atrium/templates/migrations/create_atrium_essays.rb +15 -0
  137. data/lib/generators/atrium/templates/migrations/create_atrium_exhibits.rb +16 -0
  138. data/lib/generators/atrium/templates/migrations/create_atrium_search_facets.rb +14 -0
  139. data/lib/generators/atrium/templates/migrations/create_atrium_showcase_facet_selections.rb +15 -0
  140. data/lib/generators/atrium/templates/migrations/create_atrium_showcase_items.rb +17 -0
  141. data/lib/generators/atrium/templates/migrations/create_atrium_showcases.rb +16 -0
  142. data/lib/generators/atrium/templates/themes/example.html.erb +21 -0
  143. data/lib/railties/all_tests.rake +23 -0
  144. data/lib/railties/atrium_cucumber.rake +121 -0
  145. data/lib/railties/index.rake +37 -0
  146. data/tasks/atrium.rake +268 -0
  147. data/tasks/atrium_rspec.rake +91 -0
  148. data/test_support/etc/Gemfile +33 -0
  149. data/test_support/etc/bundle_config +3 -0
  150. data/test_support/etc/rvmrc +32 -0
  151. data/test_support/features/atrium_collections.feature +162 -0
  152. data/test_support/features/atrium_exhibits.feature +164 -0
  153. data/test_support/features/step_definitions/atrium_collection_steps.rb +102 -0
  154. data/test_support/features/step_definitions/atrium_exhibit_steps.rb +53 -0
  155. data/test_support/features/step_definitions/bookmarks_steps.rb +6 -0
  156. data/test_support/features/step_definitions/error_steps.rb +5 -0
  157. data/test_support/features/step_definitions/folder_steps.rb +27 -0
  158. data/test_support/features/step_definitions/general_steps.rb +50 -0
  159. data/test_support/features/step_definitions/record_view_steps.rb +12 -0
  160. data/test_support/features/step_definitions/saved_searches_steps.rb +22 -0
  161. data/test_support/features/step_definitions/search_facets_steps.rb +29 -0
  162. data/test_support/features/step_definitions/search_history_steps.rb +9 -0
  163. data/test_support/features/step_definitions/search_result_steps.rb +114 -0
  164. data/test_support/features/step_definitions/search_steps.rb +103 -0
  165. data/test_support/features/step_definitions/user_steps.rb +5 -0
  166. data/test_support/features/step_definitions/web_steps.rb +213 -0
  167. data/test_support/features/support/env.rb +67 -0
  168. data/test_support/features/support/paths.rb +76 -0
  169. data/test_support/features/support/selectors.rb +40 -0
  170. data/test_support/fixtures/atrium_exhibits.yml +3 -0
  171. data/test_support/spec/controllers/atrium/base_controller_spec.rb +13 -0
  172. data/test_support/spec/controllers/atrium/collection_exhibit_order_controller_spec.rb +29 -0
  173. data/test_support/spec/controllers/atrium/collections_controller_spec.rb +185 -0
  174. data/test_support/spec/controllers/atrium/customization_controller_spec.rb +38 -0
  175. data/test_support/spec/controllers/atrium/descriptions_controller_spec.rb +150 -0
  176. data/test_support/spec/controllers/atrium/exhibit_facet_order_controller_spec.rb +36 -0
  177. data/test_support/spec/controllers/atrium/exhibits_controller_spec.rb +192 -0
  178. data/test_support/spec/controllers/atrium/showcases_controller_spec.rb +185 -0
  179. data/test_support/spec/helpers/atrium_collections_helper_spec.rb +147 -0
  180. data/test_support/spec/helpers/atrium_description_helper_spec.rb +47 -0
  181. data/test_support/spec/helpers/atrium_solr_helper_spec.rb +512 -0
  182. data/test_support/spec/models/atrium/browse_level_spec.rb +31 -0
  183. data/test_support/spec/models/atrium/collection_spec.rb +30 -0
  184. data/test_support/spec/models/atrium/description_spec.rb +67 -0
  185. data/test_support/spec/models/atrium/essay_spec.rb +12 -0
  186. data/test_support/spec/models/atrium/exhibit_spec.rb +76 -0
  187. data/test_support/spec/models/atrium/search/facet_selection_spec.rb +24 -0
  188. data/test_support/spec/models/atrium/search/facet_spec.rb +11 -0
  189. data/test_support/spec/models/atrium/search_facet_spec.rb +54 -0
  190. data/test_support/spec/models/atrium/showcase/facet_selection_spec.rb +15 -0
  191. data/test_support/spec/models/atrium/showcase/item_spec.rb +12 -0
  192. data/test_support/spec/models/atrium/showcase_facet_selection_spec.rb +65 -0
  193. data/test_support/spec/models/atrium/showcase_spec.rb +134 -0
  194. data/test_support/spec/rcov.opts +3 -0
  195. data/test_support/spec/routing/atrium/collections_routing_spec.rb +33 -0
  196. data/test_support/spec/spec.opts +4 -0
  197. data/test_support/spec/spec_helper.rb +47 -0
  198. data/test_support/spec/support/be_accessible_matcher.rb +8 -0
  199. data/test_support/spec/support/be_routed_mixin.rb +7 -0
  200. data/test_support/tmp/step_definitions/catalog_index_steps.rb +14 -0
  201. data/test_support/tmp/step_definitions/edit_document_steps.rb +67 -0
  202. data/test_support/tmp/step_definitions/hydra_metadata_steps.rb +3 -0
  203. data/test_support/tmp/step_definitions/hydra_steps.rb +8 -0
  204. data/test_support/tmp/step_definitions/search_steps.rb +86 -0
  205. data/test_support/tmp/step_definitions/searching_steps.rb +22 -0
  206. data/test_support/tmp/step_definitions/select_steps.rb +8 -0
  207. data/test_support/tmp/step_definitions/show_document_steps.rb +73 -0
  208. data/test_support/tmp/step_definitions/user_steps.rb +15 -0
  209. data/test_support/tmp/step_definitions/web_steps.rb +273 -0
  210. data/test_support/tmp/support/env.rb +54 -0
  211. data/test_support/tmp/support/paths.rb +57 -0
  212. metadata +1047 -0
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ notification :gntp
4
+ guard 'rspec', :notrify => 'true', :cli => '--color', :spec_paths => 'test_support/spec' do
5
+ watch(%r|^app/(.*)\.rb|) { |m|
6
+ "test_support/spec/#{m[1]}_spec.rb"
7
+ }
8
+ watch(%r|^test_support/spec/(.*)_spec\.rb|)
9
+ watch('test_support/spec/spec_helper.rb') { 'test_support/spec' }
10
+ end
@@ -0,0 +1,56 @@
1
+ # Atrium
2
+
3
+ __Atrium is still a work in progress. Do not count on any of the present or
4
+ promised functionality to exist.__
5
+
6
+
7
+ ## What it's for
8
+
9
+ Atrium is a tool for:
10
+
11
+ - grouping items
12
+ - adding context
13
+
14
+ to an index in a [Blacklight][1]-enabled application.
15
+
16
+ Atrium provides three mechanisms to achieve this end:
17
+
18
+ - Collections
19
+ - Exhibits
20
+ - Showcases
21
+
22
+
23
+ ### Collections
24
+
25
+ A collection contains a subset of the items in the complete index as defined by
26
+ a Solr query. An explicitly declared subset of the total facets can be applied
27
+ to these items. A collection description and or featured items form the
28
+ collection can be displayed at the top level collection page. Collections can be
29
+ themed independently of the base application and other collections.
30
+
31
+
32
+ ### Exhibits
33
+
34
+ An exhibit is a customizable view of a single topic (as defined by a facet),
35
+ further scoped by an optional Solr query. An exhibit defines it's own
36
+ hierarchical list of facets. An exhibit may also have a description and a list
37
+ of featured items.
38
+
39
+
40
+ ### Showcases
41
+
42
+ A showcase is a container for storing feature items and descriptions. A showcase
43
+ can be attached to a collection, exhibit, or to specific combinations of
44
+ selected facets and facet values within an exhibit. There can be multiple
45
+ showcases in an exhibit.
46
+
47
+
48
+ ## Acknowledgements
49
+
50
+ Thanks to [Hiten Parmar][2] for the gem name. The [origional atirum gem][3] was
51
+ an instant web server.
52
+
53
+
54
+ [1]: https://github.com/projectblacklight/blacklight
55
+ [2]: http://www.hitenparmar.com/
56
+ [3]: https://github.com/hrp/atrium
@@ -0,0 +1,6 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Dir.glob('tasks/*.rake').each { |r| import r }
@@ -0,0 +1,281 @@
1
+ //= require chosen.jquery
2
+ //= require ckeditor-jquery
3
+ //= include jquery.colorbox
4
+ //= require jquery.jeditable
5
+ //= require ckeditor/jquery.generateId
6
+ //= require ckeditor/jquery.jeditable.ckeditor
7
+
8
+
9
+
10
+ (function($){
11
+
12
+ $.fn.outerHTML = function() {
13
+ return $(this).clone().wrap('<p></p>').parent().html();
14
+ }
15
+
16
+ $(document).ready(function(){
17
+
18
+ CKEDITOR.config.toolbar_Basic = [[ 'Source', '-', 'Bold', 'Italic' ] ];
19
+ CKEDITOR.config.toolbar_full = [ ['Cut','Copy','Paste','PasteText','PasteFromWord'],
20
+ ['Bold','Italic','Underline','Strike'],
21
+ ['Format','-','NumberedList','BulletedList','Blockquote'],
22
+ ['Link','Unlink','Anchor','-','SelectAll','RemoveFormat'],
23
+ ['Source','ShowBlocks','Maximize'],
24
+ ['Button','Button','linkItem'] ]
25
+ //CKEDITOR.config.menu_groups = 'googlemaps';
26
+ CKEDITOR.config.extraPlugins = 'linkItem';
27
+ // CKEDITOR.config.toolbar_map = [ ['Button','Button','linkItem'] ];
28
+
29
+ $('select.chosen').chosen();
30
+
31
+ $('.jquery-ckeditor').ckeditor(
32
+ {
33
+ toolbar:'full'
34
+ }
35
+ );
36
+
37
+ $('.sortable').sortable({
38
+ update: function(e, ui){
39
+ var $target = $(e.target).closest('ol'),
40
+ orderedItems = {},
41
+ resourceURL = $target.attr('data-resource'),
42
+ childTag = $target.children().first()[0].nodeName.toLowerCase(),
43
+ primaryLabel = $target.attr('data-primary-label'),
44
+ secondaryLabel = $target.attr('data-secondary-label');
45
+ $(childTag, $(e.target).closest('ol')).each(function(index, element){
46
+ var objectId = $(element).attr('data-id');
47
+ orderedItems[objectId] = (index + 1);
48
+ });
49
+ $.ajax({
50
+ type: 'POST',
51
+ url: resourceURL,
52
+ data: {collection: orderedItems},
53
+ success: function(data, statusCode){
54
+ if (childTag == 'li'){
55
+ $target.effect('highlight', {}, 1500);
56
+ } else {
57
+ $target.parents('fieldset').effect('highlight', {}, 1500);
58
+ }
59
+ if (primaryLabel !== undefined){
60
+ $('td.label', $target).text(secondaryLabel); // This could be implemented better
61
+ $('td.label', $target).first().text(primaryLabel); //
62
+ }
63
+ }
64
+ });
65
+ }
66
+ });
67
+
68
+ $('.select_colorbox').colorbox({
69
+ width:'880px',
70
+ height:'80%',
71
+ iframe:true,
72
+ onClosed:function(){
73
+ var url = $(this).attr('action');
74
+ $.ajax({
75
+ type: 'GET',
76
+ url: url,
77
+ dataType: 'html',
78
+ cache: true,
79
+ beforeSend: function() {
80
+ $('#cboxLoadedContent').empty();
81
+ $('#cboxLoadingGraphic').show();
82
+ },
83
+ complete: function() {
84
+ $('#cboxLoadingGraphic').hide();
85
+ },
86
+ success: function(data) {
87
+ $('#show-selected').html(data);
88
+ $('#catalog-form').show();
89
+ }
90
+ });
91
+ }
92
+ });
93
+
94
+ $('.description_colorbox').colorbox({
95
+ width:'880px',
96
+ height:'80%',
97
+ iframe:true,
98
+ onClosed:function(){
99
+ var url = $(this).attr('action');
100
+ $.ajax({
101
+ type: 'GET',
102
+ url: url,
103
+ cache: true,
104
+ beforeSend: function() {
105
+ $('#cboxLoadedContent').empty();
106
+ $('#cboxLoadingGraphic').show();
107
+ },
108
+ complete: function() {
109
+ $('#cboxLoadingGraphic').hide();
110
+ },
111
+ success: function(data) {
112
+ var html= loadMore(data);
113
+ $('#show-description').html(html);
114
+ $('#catalog-form').show();
115
+
116
+
117
+ }
118
+ });
119
+ }
120
+ });
121
+
122
+ function getParams() {
123
+ var $html = $(response);
124
+ $html.find('a.description_colorbox').colorbox({ width: '960px', height: '90%', iframe: true });
125
+ return $html;
126
+ }
127
+
128
+ function loadMore(response) {
129
+ var $html = $(response);
130
+ $html.find('a.description_colorbox').colorbox({ width: '960px', height: '90%', iframe: true });
131
+ return $html;
132
+ }
133
+
134
+
135
+ //$('.description').hide();
136
+ $('.add_description').click(function(){
137
+ var $this = $(this);
138
+ $this.parent()
139
+ .children('.description')
140
+ .slideToggle(300, function(){
141
+ if ($this.text() == 'Add Description'){
142
+ $this.text('Hide Description');
143
+ }else{
144
+ $this.text('Add Description');
145
+ }
146
+ });
147
+ });
148
+
149
+ $("a.destroy_description", this).live("click", function(e) {
150
+ var $descNode = $(this).closest('dl')
151
+ var url = $(this).attr('action');
152
+ $.ajax({
153
+ type: "DELETE",
154
+ url: url,
155
+ dataType: "html",
156
+ beforeSend: function() {
157
+ $descNode.animate({'backgroundColor':'#fb6c6c'},300);
158
+ },
159
+ success: function() {
160
+ $descNode.slideUp(300,function() {
161
+ $descNode.remove();
162
+ });
163
+ }
164
+ });
165
+ });
166
+
167
+ $('.edit-text').editable(submitEditableText,{
168
+ indicator : 'Saving...',
169
+ tooltip : 'Click to edit...'
170
+ });
171
+
172
+ function submitEditableText(value, settings) {
173
+ var edits = new Object();
174
+ var result = value;
175
+ edits[settings.name] = [value];
176
+ var params = $('div.edit-text').attr("data-column-name")+"="+value;
177
+ var returned = $.ajax({
178
+ type: "PUT",
179
+ url: $('div.edit-text').attr("data-update-uri"),
180
+ dataType: "html",
181
+ data: params,
182
+ success: function(data){
183
+ $(".div.edit-text").text(value)
184
+ },
185
+ error: function(xhr, textStatus, errorThrown){
186
+ $.noticeAdd({
187
+ inEffect: {opacity: 'show'}, // in effect
188
+ inEffectDuration: 600, // in effect duration in milliseconds
189
+ stayTime: 6000, // time in milliseconds before the item has to disappear
190
+ text: 'Your changes failed'+ xhr.statusText + ': '+ xhr.responseText,
191
+ stay: true, // should the notice item stay or not?
192
+ type: 'error' // could also be error, success
193
+ });
194
+ }
195
+ });
196
+ return value;
197
+ }
198
+
199
+ function submitEditableTextArea(value, settings) {
200
+ var edits = new Object();
201
+ var result = value;
202
+ edits[settings.name] = [value];
203
+ var params = $('div.edit-textarea').attr("data-column-name")+"="+value;
204
+ var returned = $.ajax({
205
+ type: "PUT",
206
+ url: $('div.edit-textarea').attr("data-update-uri"),
207
+ dataType: "html",
208
+ data: params,
209
+ success: function(data){
210
+ $(".div.edit-text").text(value)
211
+ },
212
+ error: function(xhr, textStatus, errorThrown){
213
+ $.noticeAdd({
214
+ inEffect: {opacity: 'show'}, // in effect
215
+ inEffectDuration: 600, // in effect duration in milliseconds
216
+ stayTime: 6000, // time in milliseconds before the item has to disappear
217
+ text: 'Your changes failed'+ xhr.statusText + ': '+ xhr.responseText,
218
+ stay: true, // should the notice item stay or not?
219
+ type: 'error' // could also be error, success
220
+ });
221
+ }
222
+ });
223
+ return value;
224
+ }
225
+
226
+ $('.edit-textarea').editable(submitEditableTextArea, {
227
+ method : "PUT",
228
+ type : "ckeditor",
229
+ submit : "OK",
230
+ cancel : "Cancel",
231
+ placeholder : "click to edit description",
232
+ onblur : "ignore",
233
+ name : "textarea",
234
+ id : "field_id",
235
+ indicator : 'Saving...',
236
+ tooltip : 'Click to edit...',
237
+ height : "100",
238
+ ckeditor : { toolbar:'full'
239
+ }
240
+ });
241
+
242
+ $("div.content").hide();
243
+
244
+ $("a.heading").click(function(){
245
+ $(this).siblings(".intro").toggle()
246
+ $(this).next("div.content").slideToggle(300);
247
+ $(this).text($(this).text() == '[Read the complete essay]' ? '[Hide essay]' : '[Read the complete essay]');
248
+ });
249
+
250
+ $("div.ckeditor h3.index_title a").click( function(){
251
+ var href = $(this).attr('href');
252
+ var dialog = window.opener.CKEDITOR.dialog.getCurrent();
253
+ var parent = window.opener.document;
254
+ dialog.setValueOf('info','url',href); // Populates the URL field in the Links dialogue.
255
+ dialog.setValueOf('info','protocol',''); // This sets the Link's Protocol to Other which loads the file from the same folder the link is on
256
+ dialog.setValueOf('info','displayField',$(this).html()); // Populates the display field in the Links dialogue
257
+ window.close(); // closes the popup window
258
+ return false;
259
+ });
260
+
261
+ $(".add_description h3.index_title a").click( function(){
262
+ var href = $(this).attr('href');
263
+ alert(href)
264
+ $.ajax({
265
+ type: "GET",
266
+ url: url,
267
+ dataType: "html",
268
+ beforeSend: function() {
269
+ $descNode.animate({'backgroundColor':'#fb6c6c'},300);
270
+ },
271
+ success: function() {
272
+ $descNode.slideUp(300,function() {
273
+ $descNode.remove();
274
+ });
275
+ }
276
+ });
277
+ return false;
278
+ });
279
+
280
+ });
281
+ })(jQuery);
@@ -0,0 +1,899 @@
1
+ // Chosen, a Select Box Enhancer for jQuery and Protoype
2
+ // by Patrick Filler for Harvest, http://getharvest.com
3
+ //
4
+ // Version 0.9.5
5
+ // Full source at https://github.com/harvesthq/chosen
6
+ // Copyright (c) 2011 Harvest http://getharvest.com
7
+
8
+ // MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
9
+ // This file is generated by `cake build`, do not edit it by hand.
10
+ (function() {
11
+ var SelectParser;
12
+ SelectParser = (function() {
13
+ function SelectParser() {
14
+ this.options_index = 0;
15
+ this.parsed = [];
16
+ }
17
+ SelectParser.prototype.add_node = function(child) {
18
+ if (child.nodeName === "OPTGROUP") {
19
+ return this.add_group(child);
20
+ } else {
21
+ return this.add_option(child);
22
+ }
23
+ };
24
+ SelectParser.prototype.add_group = function(group) {
25
+ var group_position, option, _i, _len, _ref, _results;
26
+ group_position = this.parsed.length;
27
+ this.parsed.push({
28
+ array_index: group_position,
29
+ group: true,
30
+ label: group.label,
31
+ children: 0,
32
+ disabled: group.disabled
33
+ });
34
+ _ref = group.childNodes;
35
+ _results = [];
36
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
37
+ option = _ref[_i];
38
+ _results.push(this.add_option(option, group_position, group.disabled));
39
+ }
40
+ return _results;
41
+ };
42
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
43
+ if (option.nodeName === "OPTION") {
44
+ if (option.text !== "") {
45
+ if (group_position != null) {
46
+ this.parsed[group_position].children += 1;
47
+ }
48
+ this.parsed.push({
49
+ array_index: this.parsed.length,
50
+ options_index: this.options_index,
51
+ value: option.value,
52
+ text: option.text,
53
+ html: option.innerHTML,
54
+ selected: option.selected,
55
+ disabled: group_disabled === true ? group_disabled : option.disabled,
56
+ group_array_index: group_position,
57
+ classes: option.className,
58
+ style: option.style.cssText
59
+ });
60
+ } else {
61
+ this.parsed.push({
62
+ array_index: this.parsed.length,
63
+ options_index: this.options_index,
64
+ empty: true
65
+ });
66
+ }
67
+ return this.options_index += 1;
68
+ }
69
+ };
70
+ return SelectParser;
71
+ })();
72
+ SelectParser.select_to_array = function(select) {
73
+ var child, parser, _i, _len, _ref;
74
+ parser = new SelectParser();
75
+ _ref = select.childNodes;
76
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
77
+ child = _ref[_i];
78
+ parser.add_node(child);
79
+ }
80
+ return parser.parsed;
81
+ };
82
+ this.SelectParser = SelectParser;
83
+ }).call(this);
84
+ (function() {
85
+ /*
86
+ Chosen source: generate output using 'cake build'
87
+ Copyright (c) 2011 by Harvest
88
+ */
89
+ var AbstractChosen, root;
90
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
91
+ root = this;
92
+ AbstractChosen = (function() {
93
+ function AbstractChosen(form_field, options) {
94
+ this.form_field = form_field;
95
+ this.options = options != null ? options : {};
96
+ this.set_default_values();
97
+ this.is_multiple = this.form_field.multiple;
98
+ this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
99
+ this.setup();
100
+ this.set_up_html();
101
+ this.register_observers();
102
+ this.finish_setup();
103
+ }
104
+ AbstractChosen.prototype.set_default_values = function() {
105
+ this.click_test_action = __bind(function(evt) {
106
+ return this.test_active_click(evt);
107
+ }, this);
108
+ this.activate_action = __bind(function(evt) {
109
+ return this.activate_field(evt);
110
+ }, this);
111
+ this.active_field = false;
112
+ this.mouse_on_container = false;
113
+ this.results_showing = false;
114
+ this.result_highlighted = null;
115
+ this.result_single_selected = null;
116
+ this.allow_single_deselect = (this.options.allow_single_deselect != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
117
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
118
+ this.choices = 0;
119
+ return this.results_none_found = this.options.no_results_text || "No results match";
120
+ };
121
+ AbstractChosen.prototype.mouse_enter = function() {
122
+ return this.mouse_on_container = true;
123
+ };
124
+ AbstractChosen.prototype.mouse_leave = function() {
125
+ return this.mouse_on_container = false;
126
+ };
127
+ AbstractChosen.prototype.input_focus = function(evt) {
128
+ if (!this.active_field) {
129
+ return setTimeout((__bind(function() {
130
+ return this.container_mousedown();
131
+ }, this)), 50);
132
+ }
133
+ };
134
+ AbstractChosen.prototype.input_blur = function(evt) {
135
+ if (!this.mouse_on_container) {
136
+ this.active_field = false;
137
+ return setTimeout((__bind(function() {
138
+ return this.blur_test();
139
+ }, this)), 100);
140
+ }
141
+ };
142
+ AbstractChosen.prototype.result_add_option = function(option) {
143
+ var classes, style;
144
+ if (!option.disabled) {
145
+ option.dom_id = this.container_id + "_o_" + option.array_index;
146
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
147
+ if (option.selected) {
148
+ classes.push("result-selected");
149
+ }
150
+ if (option.group_array_index != null) {
151
+ classes.push("group-option");
152
+ }
153
+ if (option.classes !== "") {
154
+ classes.push(option.classes);
155
+ }
156
+ style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
157
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
158
+ } else {
159
+ return "";
160
+ }
161
+ };
162
+ AbstractChosen.prototype.results_update_field = function() {
163
+ this.result_clear_highlight();
164
+ this.result_single_selected = null;
165
+ return this.results_build();
166
+ };
167
+ AbstractChosen.prototype.results_toggle = function() {
168
+ if (this.results_showing) {
169
+ return this.results_hide();
170
+ } else {
171
+ return this.results_show();
172
+ }
173
+ };
174
+ AbstractChosen.prototype.results_search = function(evt) {
175
+ if (this.results_showing) {
176
+ return this.winnow_results();
177
+ } else {
178
+ return this.results_show();
179
+ }
180
+ };
181
+ AbstractChosen.prototype.keyup_checker = function(evt) {
182
+ var stroke, _ref;
183
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
184
+ this.search_field_scale();
185
+ switch (stroke) {
186
+ case 8:
187
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
188
+ return this.keydown_backstroke();
189
+ } else if (!this.pending_backstroke) {
190
+ this.result_clear_highlight();
191
+ return this.results_search();
192
+ }
193
+ break;
194
+ case 13:
195
+ evt.preventDefault();
196
+ if (this.results_showing) {
197
+ return this.result_select(evt);
198
+ }
199
+ break;
200
+ case 27:
201
+ if (this.results_showing) {
202
+ return this.results_hide();
203
+ }
204
+ break;
205
+ case 9:
206
+ case 38:
207
+ case 40:
208
+ case 16:
209
+ case 91:
210
+ case 17:
211
+ break;
212
+ default:
213
+ return this.results_search();
214
+ }
215
+ };
216
+ AbstractChosen.prototype.generate_field_id = function() {
217
+ var new_id;
218
+ new_id = this.generate_random_id();
219
+ this.form_field.id = new_id;
220
+ return new_id;
221
+ };
222
+ AbstractChosen.prototype.generate_random_char = function() {
223
+ var chars, newchar, rand;
224
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
225
+ rand = Math.floor(Math.random() * chars.length);
226
+ return newchar = chars.substring(rand, rand + 1);
227
+ };
228
+ return AbstractChosen;
229
+ })();
230
+ root.AbstractChosen = AbstractChosen;
231
+ }).call(this);
232
+ (function() {
233
+ /*
234
+ Chosen source: generate output using 'cake build'
235
+ Copyright (c) 2011 by Harvest
236
+ */
237
+ var $, Chosen, get_side_border_padding, root;
238
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
239
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
240
+ function ctor() { this.constructor = child; }
241
+ ctor.prototype = parent.prototype;
242
+ child.prototype = new ctor;
243
+ child.__super__ = parent.prototype;
244
+ return child;
245
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
246
+ root = this;
247
+ $ = jQuery;
248
+ $.fn.extend({
249
+ chosen: function(options) {
250
+ if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
251
+ return this;
252
+ }
253
+ return $(this).each(function(input_field) {
254
+ if (!($(this)).hasClass("chzn-done")) {
255
+ return new Chosen(this, options);
256
+ }
257
+ });
258
+ }
259
+ });
260
+ Chosen = (function() {
261
+ __extends(Chosen, AbstractChosen);
262
+ function Chosen() {
263
+ Chosen.__super__.constructor.apply(this, arguments);
264
+ }
265
+ Chosen.prototype.setup = function() {
266
+ this.form_field_jq = $(this.form_field);
267
+ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
268
+ };
269
+ Chosen.prototype.finish_setup = function() {
270
+ return this.form_field_jq.addClass("chzn-done");
271
+ };
272
+ Chosen.prototype.set_up_html = function() {
273
+ var container_div, dd_top, dd_width, sf_width;
274
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
275
+ this.container_id += "_chzn";
276
+ this.f_width = this.form_field_jq.outerWidth();
277
+ this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
278
+ container_div = $("<div />", {
279
+ id: this.container_id,
280
+ "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
281
+ style: 'width: ' + this.f_width + 'px;'
282
+ });
283
+ if (this.is_multiple) {
284
+ container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
285
+ } else {
286
+ container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
287
+ }
288
+ this.form_field_jq.hide().after(container_div);
289
+ this.container = $('#' + this.container_id);
290
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
291
+ if (!this.is_multiple && this.form_field.options.length <= this.disable_search_threshold) {
292
+ this.container.addClass("chzn-container-single-nosearch");
293
+ }
294
+ this.dropdown = this.container.find('div.chzn-drop').first();
295
+ dd_top = this.container.height();
296
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
297
+ this.dropdown.css({
298
+ "width": dd_width + "px",
299
+ "top": dd_top + "px"
300
+ });
301
+ this.search_field = this.container.find('input').first();
302
+ this.search_results = this.container.find('ul.chzn-results').first();
303
+ this.search_field_scale();
304
+ this.search_no_results = this.container.find('li.no-results').first();
305
+ if (this.is_multiple) {
306
+ this.search_choices = this.container.find('ul.chzn-choices').first();
307
+ this.search_container = this.container.find('li.search-field').first();
308
+ } else {
309
+ this.search_container = this.container.find('div.chzn-search').first();
310
+ this.selected_item = this.container.find('.chzn-single').first();
311
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
312
+ this.search_field.css({
313
+ "width": sf_width + "px"
314
+ });
315
+ }
316
+ this.results_build();
317
+ this.set_tab_index();
318
+ return this.form_field_jq.trigger("liszt:ready", {
319
+ chosen: this
320
+ });
321
+ };
322
+ Chosen.prototype.register_observers = function() {
323
+ this.container.mousedown(__bind(function(evt) {
324
+ return this.container_mousedown(evt);
325
+ }, this));
326
+ this.container.mouseup(__bind(function(evt) {
327
+ return this.container_mouseup(evt);
328
+ }, this));
329
+ this.container.mouseenter(__bind(function(evt) {
330
+ return this.mouse_enter(evt);
331
+ }, this));
332
+ this.container.mouseleave(__bind(function(evt) {
333
+ return this.mouse_leave(evt);
334
+ }, this));
335
+ this.search_results.mouseup(__bind(function(evt) {
336
+ return this.search_results_mouseup(evt);
337
+ }, this));
338
+ this.search_results.mouseover(__bind(function(evt) {
339
+ return this.search_results_mouseover(evt);
340
+ }, this));
341
+ this.search_results.mouseout(__bind(function(evt) {
342
+ return this.search_results_mouseout(evt);
343
+ }, this));
344
+ this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
345
+ return this.results_update_field(evt);
346
+ }, this));
347
+ this.search_field.blur(__bind(function(evt) {
348
+ return this.input_blur(evt);
349
+ }, this));
350
+ this.search_field.keyup(__bind(function(evt) {
351
+ return this.keyup_checker(evt);
352
+ }, this));
353
+ this.search_field.keydown(__bind(function(evt) {
354
+ return this.keydown_checker(evt);
355
+ }, this));
356
+ if (this.is_multiple) {
357
+ this.search_choices.click(__bind(function(evt) {
358
+ return this.choices_click(evt);
359
+ }, this));
360
+ return this.search_field.focus(__bind(function(evt) {
361
+ return this.input_focus(evt);
362
+ }, this));
363
+ }
364
+ };
365
+ Chosen.prototype.search_field_disabled = function() {
366
+ this.is_disabled = this.form_field_jq.attr('disabled');
367
+ if (this.is_disabled) {
368
+ this.container.addClass('chzn-disabled');
369
+ this.search_field.attr('disabled', true);
370
+ if (!this.is_multiple) {
371
+ this.selected_item.unbind("focus", this.activate_action);
372
+ }
373
+ return this.close_field();
374
+ } else {
375
+ this.container.removeClass('chzn-disabled');
376
+ this.search_field.attr('disabled', false);
377
+ if (!this.is_multiple) {
378
+ return this.selected_item.bind("focus", this.activate_action);
379
+ }
380
+ }
381
+ };
382
+ Chosen.prototype.container_mousedown = function(evt) {
383
+ var target_closelink;
384
+ if (!this.is_disabled) {
385
+ target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
386
+ if (evt && evt.type === "mousedown") {
387
+ evt.stopPropagation();
388
+ }
389
+ if (!this.pending_destroy_click && !target_closelink) {
390
+ if (!this.active_field) {
391
+ if (this.is_multiple) {
392
+ this.search_field.val("");
393
+ }
394
+ $(document).click(this.click_test_action);
395
+ this.results_show();
396
+ } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
397
+ evt.preventDefault();
398
+ this.results_toggle();
399
+ }
400
+ return this.activate_field();
401
+ } else {
402
+ return this.pending_destroy_click = false;
403
+ }
404
+ }
405
+ };
406
+ Chosen.prototype.container_mouseup = function(evt) {
407
+ if (evt.target.nodeName === "ABBR") {
408
+ return this.results_reset(evt);
409
+ }
410
+ };
411
+ Chosen.prototype.blur_test = function(evt) {
412
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
413
+ return this.close_field();
414
+ }
415
+ };
416
+ Chosen.prototype.close_field = function() {
417
+ $(document).unbind("click", this.click_test_action);
418
+ if (!this.is_multiple) {
419
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
420
+ this.search_field.attr("tabindex", -1);
421
+ }
422
+ this.active_field = false;
423
+ this.results_hide();
424
+ this.container.removeClass("chzn-container-active");
425
+ this.winnow_results_clear();
426
+ this.clear_backstroke();
427
+ this.show_search_field_default();
428
+ return this.search_field_scale();
429
+ };
430
+ Chosen.prototype.activate_field = function() {
431
+ if (!this.is_multiple && !this.active_field) {
432
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
433
+ this.selected_item.attr("tabindex", -1);
434
+ }
435
+ this.container.addClass("chzn-container-active");
436
+ this.active_field = true;
437
+ this.search_field.val(this.search_field.val());
438
+ return this.search_field.focus();
439
+ };
440
+ Chosen.prototype.test_active_click = function(evt) {
441
+ if ($(evt.target).parents('#' + this.container_id).length) {
442
+ return this.active_field = true;
443
+ } else {
444
+ return this.close_field();
445
+ }
446
+ };
447
+ Chosen.prototype.results_build = function() {
448
+ var content, data, startTime, _i, _len, _ref;
449
+ startTime = new Date();
450
+ this.parsing = true;
451
+ this.results_data = root.SelectParser.select_to_array(this.form_field);
452
+ if (this.is_multiple && this.choices > 0) {
453
+ this.search_choices.find("li.search-choice").remove();
454
+ this.choices = 0;
455
+ } else if (!this.is_multiple) {
456
+ this.selected_item.find("span").text(this.default_text);
457
+ }
458
+ content = '';
459
+ _ref = this.results_data;
460
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
461
+ data = _ref[_i];
462
+ if (data.group) {
463
+ content += this.result_add_group(data);
464
+ } else if (!data.empty) {
465
+ content += this.result_add_option(data);
466
+ if (data.selected && this.is_multiple) {
467
+ this.choice_build(data);
468
+ } else if (data.selected && !this.is_multiple) {
469
+ this.selected_item.find("span").text(data.text);
470
+ if (this.allow_single_deselect) {
471
+ this.single_deselect_control_build();
472
+ }
473
+ }
474
+ }
475
+ }
476
+ this.search_field_disabled();
477
+ this.show_search_field_default();
478
+ this.search_field_scale();
479
+ this.search_results.html(content);
480
+ return this.parsing = false;
481
+ };
482
+ Chosen.prototype.result_add_group = function(group) {
483
+ if (!group.disabled) {
484
+ group.dom_id = this.container_id + "_g_" + group.array_index;
485
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
486
+ } else {
487
+ return "";
488
+ }
489
+ };
490
+ Chosen.prototype.result_do_highlight = function(el) {
491
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
492
+ if (el.length) {
493
+ this.result_clear_highlight();
494
+ this.result_highlight = el;
495
+ this.result_highlight.addClass("highlighted");
496
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
497
+ visible_top = this.search_results.scrollTop();
498
+ visible_bottom = maxHeight + visible_top;
499
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
500
+ high_bottom = high_top + this.result_highlight.outerHeight();
501
+ if (high_bottom >= visible_bottom) {
502
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
503
+ } else if (high_top < visible_top) {
504
+ return this.search_results.scrollTop(high_top);
505
+ }
506
+ }
507
+ };
508
+ Chosen.prototype.result_clear_highlight = function() {
509
+ if (this.result_highlight) {
510
+ this.result_highlight.removeClass("highlighted");
511
+ }
512
+ return this.result_highlight = null;
513
+ };
514
+ Chosen.prototype.results_show = function() {
515
+ var dd_top;
516
+ if (!this.is_multiple) {
517
+ this.selected_item.addClass("chzn-single-with-drop");
518
+ if (this.result_single_selected) {
519
+ this.result_do_highlight(this.result_single_selected);
520
+ }
521
+ }
522
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
523
+ this.dropdown.css({
524
+ "top": dd_top + "px",
525
+ "left": 0
526
+ });
527
+ this.results_showing = true;
528
+ this.search_field.focus();
529
+ this.search_field.val(this.search_field.val());
530
+ return this.winnow_results();
531
+ };
532
+ Chosen.prototype.results_hide = function() {
533
+ if (!this.is_multiple) {
534
+ this.selected_item.removeClass("chzn-single-with-drop");
535
+ }
536
+ this.result_clear_highlight();
537
+ this.dropdown.css({
538
+ "left": "-9000px"
539
+ });
540
+ return this.results_showing = false;
541
+ };
542
+ Chosen.prototype.set_tab_index = function(el) {
543
+ var ti;
544
+ if (this.form_field_jq.attr("tabindex")) {
545
+ ti = this.form_field_jq.attr("tabindex");
546
+ this.form_field_jq.attr("tabindex", -1);
547
+ if (this.is_multiple) {
548
+ return this.search_field.attr("tabindex", ti);
549
+ } else {
550
+ this.selected_item.attr("tabindex", ti);
551
+ return this.search_field.attr("tabindex", -1);
552
+ }
553
+ }
554
+ };
555
+ Chosen.prototype.show_search_field_default = function() {
556
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
557
+ this.search_field.val(this.default_text);
558
+ return this.search_field.addClass("default");
559
+ } else {
560
+ this.search_field.val("");
561
+ return this.search_field.removeClass("default");
562
+ }
563
+ };
564
+ Chosen.prototype.search_results_mouseup = function(evt) {
565
+ var target;
566
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
567
+ if (target.length) {
568
+ this.result_highlight = target;
569
+ return this.result_select(evt);
570
+ }
571
+ };
572
+ Chosen.prototype.search_results_mouseover = function(evt) {
573
+ var target;
574
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
575
+ if (target) {
576
+ return this.result_do_highlight(target);
577
+ }
578
+ };
579
+ Chosen.prototype.search_results_mouseout = function(evt) {
580
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
581
+ return this.result_clear_highlight();
582
+ }
583
+ };
584
+ Chosen.prototype.choices_click = function(evt) {
585
+ evt.preventDefault();
586
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
587
+ return this.results_show();
588
+ }
589
+ };
590
+ Chosen.prototype.choice_build = function(item) {
591
+ var choice_id, link;
592
+ choice_id = this.container_id + "_c_" + item.array_index;
593
+ this.choices += 1;
594
+ this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
595
+ link = $('#' + choice_id).find("a").first();
596
+ return link.click(__bind(function(evt) {
597
+ return this.choice_destroy_link_click(evt);
598
+ }, this));
599
+ };
600
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
601
+ evt.preventDefault();
602
+ if (!this.is_disabled) {
603
+ this.pending_destroy_click = true;
604
+ return this.choice_destroy($(evt.target));
605
+ } else {
606
+ return evt.stopPropagation;
607
+ }
608
+ };
609
+ Chosen.prototype.choice_destroy = function(link) {
610
+ this.choices -= 1;
611
+ this.show_search_field_default();
612
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
613
+ this.results_hide();
614
+ }
615
+ this.result_deselect(link.attr("rel"));
616
+ return link.parents('li').first().remove();
617
+ };
618
+ Chosen.prototype.results_reset = function(evt) {
619
+ this.form_field.options[0].selected = true;
620
+ this.selected_item.find("span").text(this.default_text);
621
+ this.show_search_field_default();
622
+ $(evt.target).remove();
623
+ this.form_field_jq.trigger("change");
624
+ if (this.active_field) {
625
+ return this.results_hide();
626
+ }
627
+ };
628
+ Chosen.prototype.result_select = function(evt) {
629
+ var high, high_id, item, position;
630
+ if (this.result_highlight) {
631
+ high = this.result_highlight;
632
+ high_id = high.attr("id");
633
+ this.result_clear_highlight();
634
+ if (this.is_multiple) {
635
+ this.result_deactivate(high);
636
+ } else {
637
+ this.search_results.find(".result-selected").removeClass("result-selected");
638
+ this.result_single_selected = high;
639
+ }
640
+ high.addClass("result-selected");
641
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
642
+ item = this.results_data[position];
643
+ item.selected = true;
644
+ this.form_field.options[item.options_index].selected = true;
645
+ if (this.is_multiple) {
646
+ this.choice_build(item);
647
+ } else {
648
+ this.selected_item.find("span").first().text(item.text);
649
+ if (this.allow_single_deselect) {
650
+ this.single_deselect_control_build();
651
+ }
652
+ }
653
+ if (!(evt.metaKey && this.is_multiple)) {
654
+ this.results_hide();
655
+ }
656
+ this.search_field.val("");
657
+ this.form_field_jq.trigger("change");
658
+ return this.search_field_scale();
659
+ }
660
+ };
661
+ Chosen.prototype.result_activate = function(el) {
662
+ return el.addClass("active-result");
663
+ };
664
+ Chosen.prototype.result_deactivate = function(el) {
665
+ return el.removeClass("active-result");
666
+ };
667
+ Chosen.prototype.result_deselect = function(pos) {
668
+ var result, result_data;
669
+ result_data = this.results_data[pos];
670
+ result_data.selected = false;
671
+ this.form_field.options[result_data.options_index].selected = false;
672
+ result = $("#" + this.container_id + "_o_" + pos);
673
+ result.removeClass("result-selected").addClass("active-result").show();
674
+ this.result_clear_highlight();
675
+ this.winnow_results();
676
+ this.form_field_jq.trigger("change");
677
+ return this.search_field_scale();
678
+ };
679
+ Chosen.prototype.single_deselect_control_build = function() {
680
+ if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
681
+ return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
682
+ }
683
+ };
684
+ Chosen.prototype.winnow_results = function() {
685
+ var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
686
+ startTime = new Date();
687
+ this.no_results_clear();
688
+ results = 0;
689
+ searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
690
+ regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
691
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
692
+ _ref = this.results_data;
693
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
694
+ option = _ref[_i];
695
+ if (!option.disabled && !option.empty) {
696
+ if (option.group) {
697
+ $('#' + option.dom_id).hide();
698
+ } else if (!(this.is_multiple && option.selected)) {
699
+ found = false;
700
+ result_id = option.dom_id;
701
+ if (regex.test(option.html)) {
702
+ found = true;
703
+ results += 1;
704
+ } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
705
+ parts = option.html.replace(/\[|\]/g, "").split(" ");
706
+ if (parts.length) {
707
+ for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
708
+ part = parts[_j];
709
+ if (regex.test(part)) {
710
+ found = true;
711
+ results += 1;
712
+ }
713
+ }
714
+ }
715
+ }
716
+ if (found) {
717
+ if (searchText.length) {
718
+ startpos = option.html.search(zregex);
719
+ text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
720
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
721
+ } else {
722
+ text = option.html;
723
+ }
724
+ if ($("#" + result_id).html !== text) {
725
+ $("#" + result_id).html(text);
726
+ }
727
+ this.result_activate($("#" + result_id));
728
+ if (option.group_array_index != null) {
729
+ $("#" + this.results_data[option.group_array_index].dom_id).show();
730
+ }
731
+ } else {
732
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
733
+ this.result_clear_highlight();
734
+ }
735
+ this.result_deactivate($("#" + result_id));
736
+ }
737
+ }
738
+ }
739
+ }
740
+ if (results < 1 && searchText.length) {
741
+ return this.no_results(searchText);
742
+ } else {
743
+ return this.winnow_results_set_highlight();
744
+ }
745
+ };
746
+ Chosen.prototype.winnow_results_clear = function() {
747
+ var li, lis, _i, _len, _results;
748
+ this.search_field.val("");
749
+ lis = this.search_results.find("li");
750
+ _results = [];
751
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
752
+ li = lis[_i];
753
+ li = $(li);
754
+ _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
755
+ }
756
+ return _results;
757
+ };
758
+ Chosen.prototype.winnow_results_set_highlight = function() {
759
+ var do_high, selected_results;
760
+ if (!this.result_highlight) {
761
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
762
+ do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
763
+ if (do_high != null) {
764
+ return this.result_do_highlight(do_high);
765
+ }
766
+ }
767
+ };
768
+ Chosen.prototype.no_results = function(terms) {
769
+ var no_results_html;
770
+ no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
771
+ no_results_html.find("span").first().html(terms);
772
+ return this.search_results.append(no_results_html);
773
+ };
774
+ Chosen.prototype.no_results_clear = function() {
775
+ return this.search_results.find(".no-results").remove();
776
+ };
777
+ Chosen.prototype.keydown_arrow = function() {
778
+ var first_active, next_sib;
779
+ if (!this.result_highlight) {
780
+ first_active = this.search_results.find("li.active-result").first();
781
+ if (first_active) {
782
+ this.result_do_highlight($(first_active));
783
+ }
784
+ } else if (this.results_showing) {
785
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
786
+ if (next_sib) {
787
+ this.result_do_highlight(next_sib);
788
+ }
789
+ }
790
+ if (!this.results_showing) {
791
+ return this.results_show();
792
+ }
793
+ };
794
+ Chosen.prototype.keyup_arrow = function() {
795
+ var prev_sibs;
796
+ if (!this.results_showing && !this.is_multiple) {
797
+ return this.results_show();
798
+ } else if (this.result_highlight) {
799
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
800
+ if (prev_sibs.length) {
801
+ return this.result_do_highlight(prev_sibs.first());
802
+ } else {
803
+ if (this.choices > 0) {
804
+ this.results_hide();
805
+ }
806
+ return this.result_clear_highlight();
807
+ }
808
+ }
809
+ };
810
+ Chosen.prototype.keydown_backstroke = function() {
811
+ if (this.pending_backstroke) {
812
+ this.choice_destroy(this.pending_backstroke.find("a").first());
813
+ return this.clear_backstroke();
814
+ } else {
815
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
816
+ return this.pending_backstroke.addClass("search-choice-focus");
817
+ }
818
+ };
819
+ Chosen.prototype.clear_backstroke = function() {
820
+ if (this.pending_backstroke) {
821
+ this.pending_backstroke.removeClass("search-choice-focus");
822
+ }
823
+ return this.pending_backstroke = null;
824
+ };
825
+ Chosen.prototype.keydown_checker = function(evt) {
826
+ var stroke, _ref;
827
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
828
+ this.search_field_scale();
829
+ if (stroke !== 8 && this.pending_backstroke) {
830
+ this.clear_backstroke();
831
+ }
832
+ switch (stroke) {
833
+ case 8:
834
+ this.backstroke_length = this.search_field.val().length;
835
+ break;
836
+ case 9:
837
+ if (this.results_showing && !this.is_multiple) {
838
+ this.result_select(evt);
839
+ }
840
+ this.mouse_on_container = false;
841
+ break;
842
+ case 13:
843
+ evt.preventDefault();
844
+ break;
845
+ case 38:
846
+ evt.preventDefault();
847
+ this.keyup_arrow();
848
+ break;
849
+ case 40:
850
+ this.keydown_arrow();
851
+ break;
852
+ }
853
+ };
854
+ Chosen.prototype.search_field_scale = function() {
855
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
856
+ if (this.is_multiple) {
857
+ h = 0;
858
+ w = 0;
859
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
860
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
861
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
862
+ style = styles[_i];
863
+ style_block += style + ":" + this.search_field.css(style) + ";";
864
+ }
865
+ div = $('<div />', {
866
+ 'style': style_block
867
+ });
868
+ div.text(this.search_field.val());
869
+ $('body').append(div);
870
+ w = div.width() + 25;
871
+ div.remove();
872
+ if (w > this.f_width - 10) {
873
+ w = this.f_width - 10;
874
+ }
875
+ this.search_field.css({
876
+ 'width': w + 'px'
877
+ });
878
+ dd_top = this.container.height();
879
+ return this.dropdown.css({
880
+ "top": dd_top + "px"
881
+ });
882
+ }
883
+ };
884
+ Chosen.prototype.generate_random_id = function() {
885
+ var string;
886
+ string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
887
+ while ($("#" + string).length > 0) {
888
+ string += this.generate_random_char();
889
+ }
890
+ return string;
891
+ };
892
+ return Chosen;
893
+ })();
894
+ get_side_border_padding = function(elmt) {
895
+ var side_border_padding;
896
+ return side_border_padding = elmt.outerWidth() - elmt.width();
897
+ };
898
+ root.get_side_border_padding = get_side_border_padding;
899
+ }).call(this);