social_stream 0.11.7 → 0.11.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/{documents → base}/app/assets/images/lightbox-blank.gif +0 -0
  2. data/{documents → base}/app/assets/images/lightbox-btn-close.gif +0 -0
  3. data/{documents → base}/app/assets/images/lightbox-btn-next.gif +0 -0
  4. data/{documents → base}/app/assets/images/lightbox-btn-prev.gif +0 -0
  5. data/{documents → base}/app/assets/images/lightbox-ico-loading.gif +0 -0
  6. data/base/app/assets/javascripts/activities.js.erb +40 -5
  7. data/base/app/assets/javascripts/activities_security_chosen-modified.jquery.js +767 -0
  8. data/base/app/assets/javascripts/messages.js +1 -0
  9. data/base/app/assets/javascripts/social_stream-base.js +1 -0
  10. data/base/app/assets/stylesheets/base.css.scss +1 -1
  11. data/base/app/assets/stylesheets/messages.css.scss +1 -0
  12. data/base/app/controllers/contacts_controller.rb +11 -7
  13. data/base/app/controllers/groups_controller.rb +11 -2
  14. data/base/app/views/activities/_new.html.erb +16 -2
  15. data/base/app/views/activities/index.js.erb +2 -0
  16. data/base/app/views/comments/create.js.erb +2 -0
  17. data/base/app/views/conversations/_conversation_full.html.erb +62 -44
  18. data/base/app/views/conversations/show.html.erb +1 -1
  19. data/base/app/views/conversations/show.js.erb +1 -1
  20. data/base/app/views/home/index.js.erb +3 -0
  21. data/base/app/views/layouts/_header_signed_in.erb +1 -0
  22. data/base/app/views/messages/new.js.erb +1 -1
  23. data/base/app/views/settings/_destroy.html.erb +17 -0
  24. data/base/app/views/settings/_index.html.erb +3 -2
  25. data/base/app/views/subjects/_show.js.erb +3 -0
  26. data/base/config/locales/en.yml +5 -0
  27. data/base/config/locales/es.yml +6 -1
  28. data/base/lib/social_stream/base/version.rb +1 -1
  29. data/base/spec/controllers/contacts_controller_spec.rb +8 -1
  30. data/base/spec/controllers/groups_controller_spec.rb +8 -11
  31. data/base/vendor/assets/javascripts/jquery.ae.image.resize.js +69 -0
  32. data/{documents → base}/vendor/assets/javascripts/jquery.lightbox-with-resize-plugin.js +0 -0
  33. data/documents/app/assets/javascripts/social_stream-documents.js +1 -2
  34. data/documents/lib/social_stream/documents/version.rb +1 -1
  35. data/documents/lib/social_stream/toolbar_config/documents.rb +0 -18
  36. data/documents/social_stream-documents.gemspec +1 -1
  37. data/events/lib/social_stream/events/version.rb +1 -1
  38. data/events/lib/social_stream/toolbar_config/events.rb +0 -12
  39. data/events/social_stream-events.gemspec +1 -1
  40. data/events/vendor/assets/stylesheets/jquery.ad-gallery.css +1 -1
  41. data/lib/social_stream/version.rb +1 -1
  42. data/presence/Rakefile +7 -0
  43. data/presence/app/assets/javascripts/xmpp_client.js +8 -2
  44. data/presence/app/views/xmpp/_chat.html.erb +1 -0
  45. data/presence/app/views/xmpp/_chat_contacts.html.erb +1 -1
  46. data/presence/ejabberd/conf/ejabberd.cfg +2 -2
  47. data/presence/ejabberd/conf/ssconfig.cfg +3 -0
  48. data/presence/ejabberd/ejabberd_scripts/authentication_script +4 -4
  49. data/presence/ejabberd/ejabberd_scripts/emanagement +245 -0
  50. data/presence/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  51. data/presence/ejabberd/mod_sspresence/mod_sspresence.erl +46 -19
  52. data/presence/lib/generators/social_stream/presence/install_generator.rb +28 -0
  53. data/presence/lib/generators/social_stream/presence/templates/initializer.rb +12 -0
  54. data/presence/lib/social_stream/presence/{config.rb → version.rb} +1 -1
  55. data/presence/lib/tasks/presence/synchronize.rake +1 -1
  56. data/presence/social_stream-presence.gemspec +1 -1
  57. data/social_stream.gemspec +3 -3
  58. metadata +27 -23
  59. data/base/app/views/settings/_contacts.html.erb +0 -16
  60. data/base/vendor/assets/javascripts/chosen.jquery.js +0 -755
  61. data/presence/ejabberd/conf/server.pem +0 -37
@@ -1,16 +1,51 @@
1
1
  //= require jquery.livequery
2
- //= require chosen.jquery
3
2
  //= require jquery.tipsy
4
3
  //
5
4
  //initial state
5
+ var default_security_width = '100px';
6
6
  $(function() {
7
7
  $('#wrapper_activities_header form').hide();
8
8
  $('#new_<%= SocialStream.activity_forms.first %>').show();
9
9
  $('#select_<%= SocialStream.activity_forms.first %>').addClass('selected');
10
- $('#security').chosen();
10
+ chosen = $('#security').security_chosen();
11
+ $('#security').change(function() {
12
+ $(this).children("option:selected").each(function(i,opt){
13
+ if(opt.value==relation_public){
14
+ if(public_selected==false){
15
+ public_selected = true;
16
+ for(id in relation_options){
17
+ if(id==relation_public_pos){
18
+ $("#securitychzn_o_" + relation_public_pos).click();
19
+ }else{
20
+ chosen.result_deselect(id);
21
+ }
22
+ }
23
+ chosen.results_update_field();
24
+ }else{
25
+ if($('#security').children("option:selected").size()>1){
26
+ public_selected = false;
27
+ chosen.result_deselect(relation_public_pos);
28
+ chosen.results_update_field();
29
+ }
30
+ }
31
+ }
32
+ });
33
+
34
+ $('#securities .search-choice a').click(function(){
35
+ console.log($('#security').children("option:selected").size());
36
+ if($('#security').children("option:selected").size()==0){
37
+ $('#securities input').css('width', default_security_width)
38
+ }
39
+ });
40
+ });
41
+ $('#securities input').blur(function(){
42
+ console.log($('#security').children("option:selected").size());
43
+ if($('#security').children("option:selected").size()==0){
44
+ $('#securities input').css('width', default_security_width)
45
+ }
46
+ });
11
47
  // Remove width calculation
12
- $('#securities input.default').css('width', '');
13
-
48
+ $('#securities input.default').css('width', default_security_width);
14
49
  setActivityPrivacyTooltips();
15
50
  });
16
51
 
@@ -64,7 +99,7 @@ unblock_all_forms = function() {
64
99
  $(this).removeAttr("readonly").val("").blur();
65
100
  });
66
101
  //New comments
67
- $('.input_new_comments').each(function() {
102
+ $('.input_new_comments').each(function() {chosen.result_deselect(0)
68
103
  $(this).removeAttr("readonly").val("");
69
104
  });
70
105
  }
@@ -0,0 +1,767 @@
1
+ (function() {
2
+ /*
3
+ Chosen, a Select Box Enhancer for jQuery and Protoype
4
+ by Patrick Filler for Harvest, http://getharvest.com
5
+
6
+ Available for use under the MIT License, http://en.wikipedia.org/wiki/MIT_License
7
+
8
+ Copyright (c) 2011 by Harvest
9
+ */
10
+ var $, SecurityChosen, SelectParser, get_side_border_padding, root;
11
+ var __bind = function(fn, me) {
12
+ return function() {
13
+ return fn.apply(me, arguments);
14
+ };
15
+ };
16
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
17
+ $ = jQuery;
18
+ $.fn.extend({
19
+ security_chosen : function(data, options) {
20
+ var last_chosen;
21
+ $(this).each(function(input_field) {
22
+ if(!($(this)).hasClass("chzn-done")) {
23
+ last_chosen = new SecurityChosen(this, data, options);
24
+ }
25
+ });
26
+ return last_chosen;
27
+ }
28
+ });
29
+ SecurityChosen = (function() {
30
+ function Chosen(elmn) {
31
+ this.set_default_values();
32
+ this.form_field = elmn;
33
+ this.form_field_jq = $(this.form_field);
34
+ this.is_multiple = this.form_field.multiple;
35
+ this.default_text_default = this.form_field.multiple ? "Select Some Options" : "Select an Option";
36
+ this.set_up_html();
37
+ this.register_observers();
38
+ this.form_field_jq.addClass("chzn-done");
39
+ }
40
+
41
+
42
+ Chosen.prototype.set_default_values = function() {
43
+ this.click_test_action = __bind(function(evt) {
44
+ return this.test_active_click(evt);
45
+ }, this);
46
+ this.active_field = false;
47
+ this.mouse_on_container = false;
48
+ this.results_showing = false;
49
+ this.result_highlighted = null;
50
+ this.result_single_selected = null;
51
+ return this.choices = 0;
52
+ };
53
+ Chosen.prototype.set_up_html = function() {
54
+ var container_div, dd_top, dd_width, sf_width;
55
+ this.container_id = this.form_field.id + "_chzn";
56
+ this.f_width = this.form_field_jq.width();
57
+ this.default_text = this.form_field_jq.attr('title') ? this.form_field_jq.attr('title') : this.default_text_default;
58
+ container_div = $("<div />", {
59
+ id : this.container_id,
60
+ "class" : 'chzn-container'
61
+ // style: 'width: ' + this.f_width + 'px;'
62
+ });
63
+ if(this.is_multiple) {
64
+ container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
65
+ } else {
66
+ 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" /></div><ul class="chzn-results"></ul></div>');
67
+ }
68
+ this.form_field_jq.hide().after(container_div);
69
+ this.container = $('#' + this.container_id);
70
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
71
+ this.dropdown = this.container.find('div.chzn-drop').first();
72
+ dd_top = this.container.height();
73
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
74
+ this.dropdown.css({
75
+ "width" : dd_width + "px",
76
+ "top" : dd_top + "px"
77
+ });
78
+ this.search_field = this.container.find('input').first();
79
+ this.search_results = this.container.find('ul.chzn-results').first();
80
+ this.search_field_scale();
81
+ this.search_no_results = this.container.find('li.no-results').first();
82
+ if(this.is_multiple) {
83
+ this.search_choices = this.container.find('ul.chzn-choices').first();
84
+ this.search_container = this.container.find('li.search-field').first();
85
+ } else {
86
+ this.search_container = this.container.find('div.chzn-search').first();
87
+ this.selected_item = this.container.find('.chzn-single').first();
88
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
89
+ this.search_field.css({
90
+ "width" : sf_width + "px"
91
+ });
92
+ }
93
+ this.results_build();
94
+ return this.set_tab_index();
95
+ };
96
+ Chosen.prototype.register_observers = function() {
97
+ this.container.click(__bind(function(evt) {
98
+ return this.container_click(evt);
99
+ }, this));
100
+ this.container.mouseenter(__bind(function(evt) {
101
+ return this.mouse_enter(evt);
102
+ }, this));
103
+ this.container.mouseleave(__bind(function(evt) {
104
+ return this.mouse_leave(evt);
105
+ }, this));
106
+ this.search_results.click(__bind(function(evt) {
107
+ return this.search_results_click(evt);
108
+ }, this));
109
+ this.search_results.mouseover(__bind(function(evt) {
110
+ return this.search_results_mouseover(evt);
111
+ }, this));
112
+ this.search_results.mouseout(__bind(function(evt) {
113
+ return this.search_results_mouseout(evt);
114
+ }, this));
115
+ this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
116
+ return this.results_update_field(evt);
117
+ }, this));
118
+ this.search_field.blur(__bind(function(evt) {
119
+ return this.input_blur(evt);
120
+ }, this));
121
+ this.search_field.keyup(__bind(function(evt) {
122
+ return this.keyup_checker(evt);
123
+ }, this));
124
+ this.search_field.keydown(__bind(function(evt) {
125
+ return this.keydown_checker(evt);
126
+ }, this));
127
+ if(this.is_multiple) {
128
+ this.search_choices.click(__bind(function(evt) {
129
+ return this.choices_click(evt);
130
+ }, this));
131
+ return this.search_field.focus(__bind(function(evt) {
132
+ return this.input_focus(evt);
133
+ }, this));
134
+ } else {
135
+ return this.selected_item.focus(__bind(function(evt) {
136
+ return this.activate_field(evt);
137
+ }, this));
138
+ }
139
+ };
140
+ Chosen.prototype.container_click = function(evt) {
141
+ if(evt && evt.type === "click") {
142
+ evt.stopPropagation();
143
+ }
144
+ if(!this.pending_destroy_click) {
145
+ if(!this.active_field) {
146
+ if(this.is_multiple) {
147
+ this.search_field.val("");
148
+ }
149
+ $(document).click(this.click_test_action);
150
+ this.results_show();
151
+ } else if(!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
152
+ evt.preventDefault();
153
+ this.results_toggle();
154
+ }
155
+ return this.activate_field();
156
+ } else {
157
+ return this.pending_destroy_click = false;
158
+ }
159
+ };
160
+ Chosen.prototype.mouse_enter = function() {
161
+ return this.mouse_on_container = true;
162
+ };
163
+ Chosen.prototype.mouse_leave = function() {
164
+ return this.mouse_on_container = false;
165
+ };
166
+ Chosen.prototype.input_focus = function(evt) {
167
+ if(!this.active_field) {
168
+ return setTimeout((__bind(function() {
169
+ return this.container_click();
170
+ }, this)), 50);
171
+ }
172
+ };
173
+ Chosen.prototype.input_blur = function(evt) {
174
+ if(!this.mouse_on_container) {
175
+ this.active_field = false;
176
+ return setTimeout((__bind(function() {
177
+ return this.blur_test();
178
+ }, this)), 100);
179
+ }
180
+ };
181
+ Chosen.prototype.blur_test = function(evt) {
182
+ if(!this.active_field && this.container.hasClass("chzn-container-active")) {
183
+ return this.close_field();
184
+ }
185
+ };
186
+ Chosen.prototype.close_field = function() {
187
+ $(document).unbind("click", this.click_test_action);
188
+ if(!this.is_multiple) {
189
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
190
+ this.search_field.attr("tabindex", -1);
191
+ }
192
+ this.active_field = false;
193
+ this.results_hide();
194
+ this.container.removeClass("chzn-container-active");
195
+ this.winnow_results_clear();
196
+ this.clear_backstroke();
197
+ this.show_search_field_default();
198
+ //return this.search_field_scale();
199
+ };
200
+ Chosen.prototype.activate_field = function() {
201
+ if(!this.is_multiple && !this.active_field) {
202
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
203
+ this.selected_item.attr("tabindex", -1);
204
+ }
205
+ this.container.addClass("chzn-container-active");
206
+ this.active_field = true;
207
+ this.search_field.val(this.search_field.val());
208
+ return this.search_field.focus();
209
+ };
210
+ Chosen.prototype.test_active_click = function(evt) {
211
+ if($(evt.target).parents('#' + this.container.id).length) {
212
+ return this.active_field = true;
213
+ } else {
214
+ return this.close_field();
215
+ }
216
+ };
217
+ Chosen.prototype.results_build = function() {
218
+ var content, data, startTime, _i, _len, _ref;
219
+ startTime = new Date();
220
+ this.parsing = true;
221
+ this.results_data = SelectParser.select_to_array(this.form_field);
222
+ if(this.is_multiple && this.choices > 0) {
223
+ this.search_choices.find("li.search-choice").remove();
224
+ this.choices = 0;
225
+ } else if(!this.is_multiple) {
226
+ this.selected_item.find("span").text(this.default_text);
227
+ }
228
+ content = '';
229
+ _ref = this.results_data;
230
+ for( _i = 0, _len = _ref.length; _i < _len; _i++) {
231
+ data = _ref[_i];
232
+ if(data.group) {
233
+ content += this.result_add_group(data);
234
+ } else if(!data.empty) {
235
+ content += this.result_add_option(data);
236
+ if(data.selected && this.is_multiple) {
237
+ this.choice_build(data);
238
+ } else if(data.selected && !this.is_multiple) {
239
+ this.selected_item.find("span").text(data.text);
240
+ }
241
+ }
242
+ }
243
+ this.show_search_field_default();
244
+ this.search_field_scale();
245
+ this.search_results.html(content);
246
+ return this.parsing = false;
247
+ };
248
+ Chosen.prototype.result_add_group = function(group) {
249
+ if(!group.disabled) {
250
+ group.dom_id = this.form_field.id + "chzn_g_" + group.array_index;
251
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
252
+ } else {
253
+ return "";
254
+ }
255
+ };
256
+ Chosen.prototype.result_add_option = function(option) {
257
+ var classes;
258
+ if(!option.disabled) {
259
+ option.dom_id = this.form_field.id + "chzn_o_" + option.array_index;
260
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
261
+ if(option.selected) {
262
+ classes.push("result-selected");
263
+ }
264
+ if(option.group_array_index != null) {
265
+ classes.push("group-option");
266
+ }
267
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + $("<div />").text(option.text).html() + '</li>';
268
+ } else {
269
+ return "";
270
+ }
271
+ };
272
+ Chosen.prototype.results_update_field = function() {
273
+ this.result_clear_highlight();
274
+ this.result_single_selected = null;
275
+ return this.results_build();
276
+ };
277
+ Chosen.prototype.result_do_highlight = function(el) {
278
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
279
+ if(el.length) {
280
+ this.result_clear_highlight();
281
+ this.result_highlight = el;
282
+ this.result_highlight.addClass("highlighted");
283
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
284
+ visible_top = this.search_results.scrollTop();
285
+ visible_bottom = maxHeight + visible_top;
286
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
287
+ high_bottom = high_top + this.result_highlight.outerHeight();
288
+ if(high_bottom >= visible_bottom) {
289
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
290
+ } else if(high_top < visible_top) {
291
+ return this.search_results.scrollTop(high_top);
292
+ }
293
+ }
294
+ };
295
+ Chosen.prototype.result_clear_highlight = function() {
296
+ if(this.result_highlight) {
297
+ this.result_highlight.removeClass("highlighted");
298
+ }
299
+ return this.result_highlight = null;
300
+ };
301
+ Chosen.prototype.results_toggle = function() {
302
+ if(this.results_showing) {
303
+ return this.results_hide();
304
+ } else {
305
+ return this.results_show();
306
+ }
307
+ };
308
+ Chosen.prototype.results_show = function() {
309
+ var dd_top;
310
+ if(!this.is_multiple) {
311
+ this.selected_item.addClass("chzn-single-with-drop");
312
+ if(this.result_single_selected) {
313
+ this.result_do_highlight(this.result_single_selected);
314
+ }
315
+ }
316
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
317
+ this.dropdown.css({
318
+ "top" : dd_top + "px",
319
+ "left" : 0
320
+ });
321
+ this.results_showing = true;
322
+ this.search_field.focus();
323
+ this.search_field.val(this.search_field.val());
324
+ return this.winnow_results();
325
+ };
326
+ Chosen.prototype.results_hide = function() {
327
+ if(!this.is_multiple) {
328
+ this.selected_item.removeClass("chzn-single-with-drop");
329
+ }
330
+ this.result_clear_highlight();
331
+ this.dropdown.css({
332
+ "left" : "-9000px"
333
+ });
334
+ return this.results_showing = false;
335
+ };
336
+ Chosen.prototype.set_tab_index = function(el) {
337
+ var ti;
338
+ if(this.form_field_jq.attr("tabindex")) {
339
+ ti = this.form_field_jq.attr("tabindex");
340
+ this.form_field_jq.attr("tabindex", -1);
341
+ if(this.is_multiple) {
342
+ return this.search_field.attr("tabindex", ti);
343
+ } else {
344
+ this.selected_item.attr("tabindex", ti);
345
+ return this.search_field.attr("tabindex", -1);
346
+ }
347
+ }
348
+ };
349
+ Chosen.prototype.show_search_field_default = function() {
350
+ if(this.is_multiple && this.choices < 1 && !this.active_field) {
351
+ this.search_field.val(this.default_text);
352
+ return this.search_field.addClass("default");
353
+ } else {
354
+ this.search_field.val("");
355
+ return this.search_field.removeClass("default");
356
+ }
357
+ };
358
+ Chosen.prototype.search_results_click = function(evt) {
359
+ var target;
360
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
361
+ if(target.length) {
362
+ this.result_highlight = target;
363
+ return this.result_select();
364
+ }
365
+ };
366
+ Chosen.prototype.search_results_mouseover = function(evt) {
367
+ var target;
368
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
369
+ if(target) {
370
+ return this.result_do_highlight(target);
371
+ }
372
+ };
373
+ Chosen.prototype.search_results_mouseout = function(evt) {
374
+ if($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
375
+ return this.result_clear_highlight();
376
+ }
377
+ };
378
+ Chosen.prototype.choices_click = function(evt) {
379
+ evt.preventDefault();
380
+ if(this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
381
+ return this.results_show();
382
+ }
383
+ };
384
+ Chosen.prototype.choice_build = function(item) {
385
+ var choice_id, link;
386
+ choice_id = this.form_field.id + "_chzn_c_" + item.array_index;
387
+ this.choices += 1;
388
+ this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.text + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
389
+ link = $('#' + choice_id).find("a").first();
390
+ return link.click(__bind(function(evt) {
391
+ return this.choice_destroy_link_click(evt);
392
+ }, this));
393
+ };
394
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
395
+ evt.preventDefault();
396
+ this.pending_destroy_click = true;
397
+ return this.choice_destroy($(evt.target));
398
+ };
399
+ Chosen.prototype.choice_destroy = function(link) {
400
+ this.choices -= 1;
401
+ this.show_search_field_default();
402
+ if(this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
403
+ this.results_hide();
404
+ }
405
+ this.result_deselect(link.attr("rel"));
406
+ return link.parents('li').first().remove();
407
+ };
408
+ Chosen.prototype.result_select = function() {
409
+ var high, high_id, item, position;
410
+ if(this.result_highlight) {
411
+ high = this.result_highlight;
412
+ high_id = high.attr("id");
413
+ this.result_clear_highlight();
414
+ high.addClass("result-selected");
415
+ if(this.is_multiple) {
416
+ this.result_deactivate(high);
417
+ } else {
418
+ this.result_single_selected = high;
419
+ }
420
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
421
+ item = this.results_data[position];
422
+ item.selected = true;
423
+ this.form_field.options[item.options_index].selected = true;
424
+ if(this.is_multiple) {
425
+ this.choice_build(item);
426
+ } else {
427
+ this.selected_item.find("span").first().text(item.text);
428
+ }
429
+ this.results_hide();
430
+ this.search_field.val("");
431
+ this.form_field_jq.trigger("change");
432
+ return this.search_field_scale();
433
+ }
434
+ };
435
+ Chosen.prototype.result_activate = function(el) {
436
+ return el.addClass("active-result").show();
437
+ };
438
+ Chosen.prototype.result_deactivate = function(el) {
439
+ return el.removeClass("active-result").hide();
440
+ };
441
+ Chosen.prototype.result_deselect = function(pos) {
442
+ var result, result_data;
443
+ result_data = this.results_data[pos];
444
+ result_data.selected = false;
445
+ this.form_field.options[result_data.options_index].selected = false;
446
+ result = $("#" + this.form_field.id + "chzn_o_" + pos);
447
+ result.removeClass("result-selected").addClass("active-result").show();
448
+ this.result_clear_highlight();
449
+ this.winnow_results();
450
+ this.form_field_jq.trigger("change");
451
+ return this.search_field_scale();
452
+ };
453
+ Chosen.prototype.results_search = function(evt) {
454
+ if(this.results_showing) {
455
+ return this.winnow_results();
456
+ } else {
457
+ return this.results_show();
458
+ }
459
+ };
460
+ Chosen.prototype.winnow_results = function() {
461
+ var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
462
+ startTime = new Date();
463
+ this.no_results_clear();
464
+ results = 0;
465
+ searchText = this.search_field.val() === this.default_text ? "" : $.trim(this.search_field.val());
466
+ regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
467
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
468
+ _ref = this.results_data;
469
+ for( _i = 0, _len = _ref.length; _i < _len; _i++) {
470
+ option = _ref[_i];
471
+ if(!option.disabled && !option.empty) {
472
+ if(option.group) {
473
+ $('#' + option.dom_id).hide();
474
+ } else if(!(this.is_multiple && option.selected)) {
475
+ found = false;
476
+ result_id = option.dom_id;
477
+ if(regex.test(option.text)) {
478
+ found = true;
479
+ results += 1;
480
+ } else if(option.text.indexOf(" ") >= 0 || option.text.indexOf("[") === 0) {
481
+ parts = option.text.replace(/\[|\]/g, "").split(" ");
482
+ if(parts.length) {
483
+ for( _j = 0, _len2 = parts.length; _j < _len2; _j++) {
484
+ part = parts[_j];
485
+ if(regex.test(part)) {
486
+ found = true;
487
+ results += 1;
488
+ }
489
+ }
490
+ }
491
+ }
492
+ if(found) {
493
+ if(searchText.length) {
494
+ startpos = option.text.search(zregex);
495
+ text = option.text.substr(0, startpos + searchText.length) + '</em>' + option.text.substr(startpos + searchText.length);
496
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
497
+ } else {
498
+ text = option.text;
499
+ }
500
+ if($("#" + result_id).html !== text) {
501
+ $("#" + result_id).html(text);
502
+ }
503
+ this.result_activate($("#" + result_id));
504
+ if(option.group_array_index != null) {
505
+ $("#" + this.results_data[option.group_array_index].dom_id).show();
506
+ }
507
+ } else {
508
+ if(this.result_highlight && result_id === this.result_highlight.attr('id')) {
509
+ this.result_clear_highlight();
510
+ }
511
+ this.result_deactivate($("#" + result_id));
512
+ }
513
+ }
514
+ }
515
+ }
516
+ if(results < 1 && searchText.length) {
517
+ return this.no_results(searchText);
518
+ } else {
519
+ return this.winnow_results_set_highlight();
520
+ }
521
+ };
522
+ Chosen.prototype.winnow_results_clear = function() {
523
+ var li, lis, _i, _len, _results;
524
+ this.search_field.val("");
525
+ lis = this.search_results.find("li");
526
+ _results = [];
527
+ for( _i = 0, _len = lis.length; _i < _len; _i++) {
528
+ li = lis[_i];
529
+ li = $(li);
530
+ _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) :
531
+ void 0);
532
+ }
533
+ return _results;
534
+ };
535
+ Chosen.prototype.winnow_results_set_highlight = function() {
536
+ var do_high;
537
+ if(!this.result_highlight) {
538
+ do_high = this.search_results.find(".active-result").first();
539
+ if(do_high) {
540
+ return this.result_do_highlight(do_high);
541
+ }
542
+ }
543
+ };
544
+ Chosen.prototype.no_results = function(terms) {
545
+ var no_results_html;
546
+ no_results_html = $('<li class="no-results">No results match "<span></span>"</li>');
547
+ no_results_html.find("span").first().text(terms);
548
+ return this.search_results.append(no_results_html);
549
+ };
550
+ Chosen.prototype.no_results_clear = function() {
551
+ return this.search_results.find(".no-results").remove();
552
+ };
553
+ Chosen.prototype.keydown_arrow = function() {
554
+ var first_active, next_sib;
555
+ if(!this.result_highlight) {
556
+ first_active = this.search_results.find("li.active-result").first();
557
+ if(first_active) {
558
+ this.result_do_highlight($(first_active));
559
+ }
560
+ } else if(this.results_showing) {
561
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
562
+ if(next_sib) {
563
+ this.result_do_highlight(next_sib);
564
+ }
565
+ }
566
+ if(!this.results_showing) {
567
+ return this.results_show();
568
+ }
569
+ };
570
+ Chosen.prototype.keyup_arrow = function() {
571
+ var prev_sibs;
572
+ if(!this.results_showing && !this.is_multiple) {
573
+ return this.results_show();
574
+ } else if(this.result_highlight) {
575
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
576
+ if(prev_sibs.length) {
577
+ return this.result_do_highlight(prev_sibs.first());
578
+ } else {
579
+ if(this.choices > 0) {
580
+ this.results_hide();
581
+ }
582
+ return this.result_clear_highlight();
583
+ }
584
+ }
585
+ };
586
+ Chosen.prototype.keydown_backstroke = function() {
587
+ if(this.pending_backstroke) {
588
+ this.choice_destroy(this.pending_backstroke.find("a").first());
589
+ return this.clear_backstroke();
590
+ } else {
591
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
592
+ return this.pending_backstroke.addClass("search-choice-focus");
593
+ }
594
+ };
595
+ Chosen.prototype.clear_backstroke = function() {
596
+ if(this.pending_backstroke) {
597
+ this.pending_backstroke.removeClass("search-choice-focus");
598
+ }
599
+ return this.pending_backstroke = null;
600
+ };
601
+ Chosen.prototype.keyup_checker = function(evt) {
602
+ var stroke, _ref;
603
+ stroke = ( _ref = evt.which) != null ? _ref : evt.keyCode;
604
+ this.search_field_scale();
605
+ switch (stroke) {
606
+ case 8:
607
+ if(this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
608
+ return this.keydown_backstroke();
609
+ } else if(!this.pending_backstroke) {
610
+ this.result_clear_highlight();
611
+ return this.results_search();
612
+ }
613
+ break;
614
+ case 13:
615
+ evt.preventDefault();
616
+ if(this.results_showing) {
617
+ return this.result_select();
618
+ }
619
+ break;
620
+ case 27:
621
+ if(this.results_showing) {
622
+ return this.results_hide();
623
+ }
624
+ break;
625
+ case 9:
626
+ case 38:
627
+ case 40:
628
+ case 16:
629
+ break;
630
+ default:
631
+ return this.results_search();
632
+ }
633
+ };
634
+ Chosen.prototype.keydown_checker = function(evt) {
635
+ var stroke, _ref;
636
+ stroke = ( _ref = evt.which) != null ? _ref : evt.keyCode;
637
+ this.search_field_scale();
638
+ if(stroke !== 8 && this.pending_backstroke) {
639
+ this.clear_backstroke();
640
+ }
641
+ switch (stroke) {
642
+ case 8:
643
+ this.backstroke_length = this.search_field.val().length;
644
+ break;
645
+ case 9:
646
+ this.mouse_on_container = false;
647
+ break;
648
+ case 13:
649
+ evt.preventDefault();
650
+ break;
651
+ case 38:
652
+ evt.preventDefault();
653
+ this.keyup_arrow();
654
+ break;
655
+ case 40:
656
+ this.keydown_arrow();
657
+ break;
658
+ }
659
+ };
660
+ Chosen.prototype.search_field_scale = function() {
661
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
662
+ if(this.is_multiple) {
663
+ h = 0;
664
+ w = 0;
665
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
666
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
667
+ for( _i = 0, _len = styles.length; _i < _len; _i++) {
668
+ style = styles[_i];
669
+ style_block += style + ":" + this.search_field.css(style) + ";";
670
+ }
671
+ div = $('<div />', {
672
+ 'style' : style_block
673
+ });
674
+ div.text(this.search_field.val());
675
+ $('body').append(div);
676
+ w = div.width() + 25;
677
+ div.remove();
678
+ if(w > this.f_width - 10) {
679
+ w = this.f_width - 10;
680
+ }
681
+ this.search_field.css({
682
+ 'width' : w + 'px'
683
+ });
684
+ dd_top = this.container.height();
685
+ return this.dropdown.css({
686
+ "top" : dd_top + "px"
687
+ });
688
+ }
689
+ };
690
+ return Chosen;
691
+ })();
692
+ get_side_border_padding = function(elmt) {
693
+ var side_border_padding;
694
+ return side_border_padding = elmt.outerWidth() - elmt.width();
695
+ };
696
+ root.get_side_border_padding = get_side_border_padding;
697
+ SelectParser = (function() {
698
+ function SelectParser() {
699
+ this.options_index = 0;
700
+ this.parsed = [];
701
+ }
702
+
703
+
704
+ SelectParser.prototype.add_node = function(child) {
705
+ if(child.nodeName === "OPTGROUP") {
706
+ return this.add_group(child);
707
+ } else {
708
+ return this.add_option(child);
709
+ }
710
+ };
711
+ SelectParser.prototype.add_group = function(group) {
712
+ var group_position, option, _i, _len, _ref, _results;
713
+ group_position = this.parsed.length;
714
+ this.parsed.push({
715
+ array_index : group_position,
716
+ group : true,
717
+ label : group.label,
718
+ children : 0,
719
+ disabled : group.disabled
720
+ });
721
+ _ref = group.childNodes;
722
+ _results = [];
723
+ for( _i = 0, _len = _ref.length; _i < _len; _i++) {
724
+ option = _ref[_i];
725
+ _results.push(this.add_option(option, group_position, group.disabled));
726
+ }
727
+ return _results;
728
+ };
729
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
730
+ if(option.nodeName === "OPTION") {
731
+ if(option.text !== "") {
732
+ if(group_position != null) {
733
+ this.parsed[group_position].children += 1;
734
+ }
735
+ this.parsed.push({
736
+ array_index : this.parsed.length,
737
+ options_index : this.options_index,
738
+ value : option.value,
739
+ text : option.text,
740
+ selected : option.selected,
741
+ disabled : group_disabled === true ? group_disabled : option.disabled,
742
+ group_array_index : group_position
743
+ });
744
+ } else {
745
+ this.parsed.push({
746
+ array_index : this.parsed.length,
747
+ options_index : this.options_index,
748
+ empty : true
749
+ });
750
+ }
751
+ return this.options_index += 1;
752
+ }
753
+ };
754
+ return SelectParser;
755
+ })();
756
+ SelectParser.select_to_array = function(select) {
757
+ var child, parser, _i, _len, _ref;
758
+ parser = new SelectParser();
759
+ _ref = select.childNodes;
760
+ for( _i = 0, _len = _ref.length; _i < _len; _i++) {
761
+ child = _ref[_i];
762
+ parser.add_node(child);
763
+ }
764
+ return parser.parsed;
765
+ };
766
+ root.SelectParser = SelectParser;
767
+ }).call(this);