social_stream-base 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,15 @@
1
1
  //= require jquery.livequery
2
+ //= require chosen.jquery
2
3
  //
3
4
  //initial state
4
5
  $(function() {
5
6
  $('#wrapper_activities_header form').hide();
6
7
  $('#new_<%= SocialStream.activity_forms.first %>').show();
7
8
  $('#select_<%= SocialStream.activity_forms.first %>').addClass('selected');
9
+ $('#security').chosen();
8
10
  });
9
11
 
10
- //clicks on headers
12
+ //clicks form selector
11
13
  $('.activity_form_selector').live('click',function(){
12
14
  $('.activity_form_selector').removeClass('selected');
13
15
  $(this).addClass('selected');
@@ -18,13 +20,15 @@ $('.activity_form_selector').live('click',function(){
18
20
  //submit
19
21
  $('#masterSubmitButton').live('click',function(){
20
22
  $('.liveAdded').remove();
21
- $('#wrapper_activities_header form:visible').append(
22
- $('<input/>')
23
- .addClass('liveAdded')
24
- .attr('type', 'hidden')
25
- .attr('name', $('#wrapper_activities_header form:visible')
26
- .attr('id').split('_')[1]+'[_relation_ids][]')
27
- .val($('#security option:selected').attr('value')));
23
+ $('#security option:selected').each(function() {
24
+ $('#wrapper_activities_header form:visible').append(
25
+ $('<input/>')
26
+ .addClass('liveAdded')
27
+ .attr('type', 'hidden')
28
+ .attr('name', $('#wrapper_activities_header form:visible')
29
+ .attr('id').split('_')[1]+'[_relation_ids][]')
30
+ .val($(this).attr('value')));
31
+ });
28
32
  $('#wrapper_activities_header form:visible').submit();
29
33
  });
30
34
 
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  *= require jquery-ui
3
+ *= require chosen
3
4
  */
4
5
 
5
6
 
@@ -15,7 +16,7 @@
15
16
  #input_activities { border-color: #0656a4; color: #2A3890; padding: 5px 5px 5px 5px;
16
17
  border:1px solid #BDC7D8; width:95%;}
17
18
  #activities_share_btn { text-align: right; padding: 5px 16px 0px 10px; vertical-align: middle;}
18
- #securities{ display:inline-block; text-align:left;}
19
+ #securities{ display:inline-block; text-align:left; float: left;}
19
20
 
20
21
  /******************* WALL - ACTIVITY ***************/
21
22
  .activity { text-align:left; display: block; vertical-align: top; padding: 2px 0px 0px 0px;
@@ -69,10 +70,7 @@
69
70
 
70
71
 
71
72
  /*********** DROP DOWN**********/
72
- /** Simple modifications needed for DropDownCheckList to take advantage of ThemeRoller settings */
73
- .ui-dropdownchecklist .ui-widget-content,.ui-dropdownchecklist-selector .ui-state-default { border: none; vertical-align:middle;}
74
- .ui-dropdownchecklist-selector-wrapper { vertical-align: middle;}
75
- .ui-dropdownchecklist-selector {}
76
- .ui-dropdownchecklist-group {}
77
- .ui-dropdownchecklist-text{ padding:3px 3px 0px;}
78
-
73
+ #security_chzn .chzn-choices {
74
+ padding-left: 20px;
75
+ background: url('btn/btn_security.png') no-repeat 10px center;
76
+ }
@@ -14,7 +14,7 @@
14
14
  #sponsor{background-color:#fff}
15
15
  #toolbar { width: 160px; border-color: #000; vertical-align: top; display: table-cell;padding: 5px 5px 5px 5px;}
16
16
  #toolbarContent{}
17
- #wrapper_body{background-color:#fff;}
17
+ #wrapper_body{}
18
18
  #content_logo{/*width: 779px*/}
19
19
 
20
20
 
@@ -49,7 +49,7 @@ span.ui-radio-state-checked-hover {
49
49
  form {
50
50
  overflow: hidden;
51
51
  height: 1%;
52
- margin: 20px 0;
52
+ margin: 0px 0;
53
53
  }
54
54
 
55
55
  .ui-helper-hidden-accessible {
@@ -6,7 +6,7 @@ module NotificationsHelper
6
6
  notification_text = notification_text.gsub(/\%\{sender\}/, link_to(truncate_name(activity.sender.name),
7
7
  url_for(:controller=> activity.sender.subject.class.to_s.downcase.pluralize,
8
8
  :action=> :show, :id=> activity.sender.subject.slug, :only_path => false)))
9
- notification_text = notification_text.gsub(/\%\{confirm\}/,link_to(t('notification.confirm'),edit_contact_url(activity.receiver.contact_to!(activity.sender))))
9
+ notification_text = notification_text.gsub(/\%\{confirm\}/,link_to(t('notification.confirm'),edit_contact_url(activity.receiver.contact_to!(activity.sender), :s => activity.sender.slug)))
10
10
  notification_text = notification_text.gsub(/\%\{look\}/,link_to(t('notification.look'),
11
11
  url_for(:controller=> activity.sender.subject.class.to_s.downcase.pluralize,
12
12
  :action=> :show, :id=> activity.sender.subject.slug, :only_path => false)))
@@ -187,7 +187,13 @@ class Activity < ActiveRecord::Base
187
187
  :subject => view.link_name(sender_subject),
188
188
  :contact => view.link_name(receiver_subject)
189
189
  when "post"
190
- view.link_name sender_subject
190
+ if sender == receiver
191
+ view.link_name sender_subject
192
+ else
193
+ I18n.t "activity.verb.post.title.other_wall",
194
+ :sender => view.link_name(sender_subject),
195
+ :receiver => view.link_name(receiver_subject)
196
+ end
191
197
  end.html_safe
192
198
  end
193
199
 
data/app/models/actor.rb CHANGED
@@ -317,7 +317,7 @@ class Actor < ActiveRecord::Base
317
317
 
318
318
  # Build a new {Contact} from each that has not inverse
319
319
  def pending_contacts
320
- received_contacts.not_reflexive.pending.includes(:inverse).all.map do |c|
320
+ received_contacts.pending.includes(:inverse).all.map do |c|
321
321
  c.inverse ||
322
322
  c.receiver.contact_to!(c.sender)
323
323
  end
@@ -45,13 +45,16 @@ class Contact < ActiveRecord::Base
45
45
 
46
46
  scope :recent, order("contacts.created_at DESC")
47
47
 
48
- scope :pending, joins("LEFT JOIN contacts AS inverse_contacts ON inverse_contacts.id = contacts.inverse_id").
49
- where(arel_table[:inverse_id].eq(nil).or(arel_table.alias("inverse_contacts")[:ties_count].eq(0)))
50
-
51
48
  scope :active, where(arel_table[:ties_count].gt(0))
52
49
 
53
50
  scope :not_reflexive, where(arel_table[:sender_id].not_eq(arel_table[:receiver_id]))
54
51
 
52
+ scope :pending, active.
53
+ not_reflexive.
54
+ joins("LEFT JOIN contacts AS inverse_contacts ON inverse_contacts.id = contacts.inverse_id").
55
+ where(arel_table[:inverse_id].eq(nil).or(arel_table.alias("inverse_contacts")[:ties_count].eq(0)))
56
+
57
+
55
58
  validates_presence_of :sender_id, :receiver_id
56
59
  validates_uniqueness_of :sender_id, :scope => :receiver_id
57
60
  validates_uniqueness_of :receiver_id, :scope => :sender_id
@@ -41,6 +41,8 @@ class Relation::Custom < Relation
41
41
 
42
42
  if (ps = cfg_rel['permissions']).present?
43
43
  ps.each do |p|
44
+ p.push(nil) if p.size == 1
45
+
44
46
  rels[name].permissions <<
45
47
  Permission.find_or_create_by_action_and_object(*p)
46
48
  end
data/app/models/user.rb CHANGED
@@ -49,7 +49,10 @@ class User < ActiveRecord::Base
49
49
  private
50
50
 
51
51
  def email_must_be_uniq
52
- errors.add(:email, "is already taken") if User.find_by_email(email).present?
52
+ user = User.find_by_email(email)
53
+ if user.present? && user.id =! self.id
54
+ errors.add(:email, "is already taken")
55
+ end
53
56
  end
54
57
 
55
58
  class << self
@@ -1,14 +1,4 @@
1
1
  <% if can? :create, new_activity(receiver) %>
2
- <% content_for :javascript do %>
3
-
4
- securityImage = "<%= escape_javascript(image_tag('btn/btn_security.png', :id => 'security_image', :alt => 'security')) %>";
5
- downImage = "<%= escape_javascript(image_tag('btn/btn_down.png')) %>";
6
-
7
- $("#security").dropdownchecklist( { closeRadioOnClick: true, forceMultiple: false } );
8
- $("#security_image").parent().width(28);
9
- $("#security_image").parent().parent().width(28);
10
- <% end %>
11
-
12
2
  <div id="activities_header" class="content_size">
13
3
  <% SocialStream.activity_forms.each do |element| %>
14
4
  <%= render :partial => element.to_s.pluralize+'/new',
@@ -26,11 +16,11 @@
26
16
  <% end %>
27
17
  </div>
28
18
 
29
- <div id="activities_share_btn">
30
19
  <% if current_subject == receiver %>
31
- <div id="securities"><%= select_tag :_relation_ids, options_for_select(current_subject.activity_relations(receiver).sort.map{ |r| [ r.name, r.id ] }), :id => 'security', :multiple => nil %></div>
20
+ <div id="securities"><%= select_tag :_relation_ids, options_for_select(current_subject.activity_relations(receiver).sort.map{ |r| [ r.name, r.id ] }), :id => 'security', :multiple => true, :title => t('activity.new.security.title') %></div>
32
21
  <% end %>
33
22
 
23
+ <div id="activities_share_btn">
34
24
  <%= submit_tag(t('share'), :class => "myButtonBlue", :id => "masterSubmitButton") %>
35
25
  </div>
36
26
  <% end %>
@@ -3,5 +3,3 @@ $("#input_activities").val("<%= t('activity.input') %>");
3
3
  //Display the new post
4
4
  $("#wall").prepend("<%= escape_javascript(render @post.post_activity) %>");
5
5
 
6
- // TEMPORARY FIX
7
- //$("#activities_share_btn").hide();
@@ -14,6 +14,9 @@ en:
14
14
  input: "What are you doing?"
15
15
  last: "Last Activities"
16
16
  like: "I like"
17
+ new:
18
+ security:
19
+ title: "Share with..."
17
20
  one: "Activity"
18
21
  other: "Activities"
19
22
  title: "Activities"
@@ -41,6 +44,9 @@ en:
41
44
  Group:
42
45
  title: "%{subject} added %{contact} as contact."
43
46
  message: "%{name} added you as contact."
47
+ post:
48
+ title:
49
+ other_wall: "%{sender} → %{receiver}"
44
50
  avatar:
45
51
  crop_image: "Crop the uploaded image"
46
52
  crop_submit: "Crop image"
@@ -280,7 +286,7 @@ en:
280
286
  represent:
281
287
  nil: "Represent me/us in the website"
282
288
  of_relation:
283
- choose: "2. Permissions in <strong>%{name}</strong> level"
289
+ choose: "2. Permissions in <strong>%{name}</strong> sphere"
284
290
  privacy:
285
291
  intro: "Contacts at <strong>%{relation}</strong> level are only allowed to:"
286
292
  rule:
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.7.6".freeze
3
+ VERSION = "0.7.7".freeze
4
4
  end
5
5
  end
@@ -99,7 +99,7 @@ module SocialStream
99
99
  :url => "#",
100
100
  :options => {:link => {:id => "resources_menu"}},
101
101
  :items => [
102
- {:key => :resources_documents,:name => image_tag("btn/btn_documents.png")+t('document.title'),:url => polymorphic_path([subject, Document.new])},
102
+ {:key => :resources_documents,:name => image_tag("btn/btn_document.png")+t('document.title'),:url => polymorphic_path([subject, Document.new])},
103
103
  {:key => :resources_pictures,:name => image_tag("btn/btn_gallery.png")+t('picture.title'),:url => polymorphic_path([subject, Picture.new])},
104
104
  {:key => :resources_videos,:name => image_tag("btn/btn_video.png")+t('video.title'),:url => polymorphic_path([subject, Video.new])},
105
105
  {:key => :resources_audios,:name => image_tag("btn/btn_audio.png")+t('audio.title'),:url => polymorphic_path([subject, Audio.new])}
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  # Modernizr.js javascript library
50
50
  s.add_runtime_dependency('modernizr-rails', '~> 2.0.6')
51
51
 
52
- s.add_runtime_dependency('rails', '3.1.0.rc4')
52
+ s.add_runtime_dependency('rails', '3.1.0.rc5')
53
53
 
54
54
  # Development Gem dependencies
55
55
  # Integration testing
@@ -72,7 +72,7 @@ describe Relation::CustomsController do
72
72
  actor = Factory(:user).actor
73
73
  count = Relation.count
74
74
  begin
75
- post :create, :custom => Factory.attributes_for(:relation_custom, :actor => actor)
75
+ post :create, :custom => { :name => 'Test', :actor_id => actor.id }
76
76
 
77
77
  assert false
78
78
  rescue CanCan::AccessDenied
@@ -24,4 +24,14 @@ describe Contact do
24
24
  end
25
25
  end
26
26
 
27
+ context "spurious" do
28
+ before do
29
+ @contact = Factory(:contact)
30
+ @contact.inverse!
31
+ end
32
+
33
+ it "should not appear as pending" do
34
+ @contact.sender.pending_contacts.should_not include(@contact)
35
+ end
36
+ end
27
37
  end
@@ -81,5 +81,13 @@ describe User do
81
81
  it "should have activity object" do
82
82
  Factory(:user).activity_object.should be_present
83
83
  end
84
+
85
+ it "should update password" do
86
+ user = Factory(:user)
87
+ user.password = "testing"
88
+ user.password_confirmation = "testing"
89
+
90
+ assert user.save
91
+ end
84
92
  end
85
93
 
@@ -0,0 +1,755 @@
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
+ */ var $, Chosen, SelectParser, get_side_border_padding, root;
10
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
11
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
12
+ $ = jQuery;
13
+ $.fn.extend({
14
+ chosen: function(data, options) {
15
+ return $(this).each(function(input_field) {
16
+ if (!($(this)).hasClass("chzn-done")) {
17
+ return new Chosen(this, data, options);
18
+ }
19
+ });
20
+ }
21
+ });
22
+ Chosen = (function() {
23
+ function Chosen(elmn) {
24
+ this.set_default_values();
25
+ this.form_field = elmn;
26
+ this.form_field_jq = $(this.form_field);
27
+ this.is_multiple = this.form_field.multiple;
28
+ this.default_text_default = this.form_field.multiple ? "Select Some Options" : "Select an Option";
29
+ this.set_up_html();
30
+ this.register_observers();
31
+ this.form_field_jq.addClass("chzn-done");
32
+ }
33
+ Chosen.prototype.set_default_values = function() {
34
+ this.click_test_action = __bind(function(evt) {
35
+ return this.test_active_click(evt);
36
+ }, this);
37
+ this.active_field = false;
38
+ this.mouse_on_container = false;
39
+ this.results_showing = false;
40
+ this.result_highlighted = null;
41
+ this.result_single_selected = null;
42
+ return this.choices = 0;
43
+ };
44
+ Chosen.prototype.set_up_html = function() {
45
+ var container_div, dd_top, dd_width, sf_width;
46
+ this.container_id = this.form_field.id + "_chzn";
47
+ this.f_width = this.form_field_jq.width();
48
+ this.default_text = this.form_field_jq.attr('title') ? this.form_field_jq.attr('title') : this.default_text_default;
49
+ container_div = $("<div />", {
50
+ id: this.container_id,
51
+ "class": 'chzn-container'
52
+ // style: 'width: ' + this.f_width + 'px;'
53
+ });
54
+ if (this.is_multiple) {
55
+ 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>');
56
+ } else {
57
+ 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>');
58
+ }
59
+ this.form_field_jq.hide().after(container_div);
60
+ this.container = $('#' + this.container_id);
61
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
62
+ this.dropdown = this.container.find('div.chzn-drop').first();
63
+ dd_top = this.container.height();
64
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
65
+ this.dropdown.css({
66
+ "width": dd_width + "px",
67
+ "top": dd_top + "px"
68
+ });
69
+ this.search_field = this.container.find('input').first();
70
+ this.search_results = this.container.find('ul.chzn-results').first();
71
+ this.search_field_scale();
72
+ this.search_no_results = this.container.find('li.no-results').first();
73
+ if (this.is_multiple) {
74
+ this.search_choices = this.container.find('ul.chzn-choices').first();
75
+ this.search_container = this.container.find('li.search-field').first();
76
+ } else {
77
+ this.search_container = this.container.find('div.chzn-search').first();
78
+ this.selected_item = this.container.find('.chzn-single').first();
79
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
80
+ this.search_field.css({
81
+ "width": sf_width + "px"
82
+ });
83
+ }
84
+ this.results_build();
85
+ return this.set_tab_index();
86
+ };
87
+ Chosen.prototype.register_observers = function() {
88
+ this.container.click(__bind(function(evt) {
89
+ return this.container_click(evt);
90
+ }, this));
91
+ this.container.mouseenter(__bind(function(evt) {
92
+ return this.mouse_enter(evt);
93
+ }, this));
94
+ this.container.mouseleave(__bind(function(evt) {
95
+ return this.mouse_leave(evt);
96
+ }, this));
97
+ this.search_results.click(__bind(function(evt) {
98
+ return this.search_results_click(evt);
99
+ }, this));
100
+ this.search_results.mouseover(__bind(function(evt) {
101
+ return this.search_results_mouseover(evt);
102
+ }, this));
103
+ this.search_results.mouseout(__bind(function(evt) {
104
+ return this.search_results_mouseout(evt);
105
+ }, this));
106
+ this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
107
+ return this.results_update_field(evt);
108
+ }, this));
109
+ this.search_field.blur(__bind(function(evt) {
110
+ return this.input_blur(evt);
111
+ }, this));
112
+ this.search_field.keyup(__bind(function(evt) {
113
+ return this.keyup_checker(evt);
114
+ }, this));
115
+ this.search_field.keydown(__bind(function(evt) {
116
+ return this.keydown_checker(evt);
117
+ }, this));
118
+ if (this.is_multiple) {
119
+ this.search_choices.click(__bind(function(evt) {
120
+ return this.choices_click(evt);
121
+ }, this));
122
+ return this.search_field.focus(__bind(function(evt) {
123
+ return this.input_focus(evt);
124
+ }, this));
125
+ } else {
126
+ return this.selected_item.focus(__bind(function(evt) {
127
+ return this.activate_field(evt);
128
+ }, this));
129
+ }
130
+ };
131
+ Chosen.prototype.container_click = function(evt) {
132
+ if (evt && evt.type === "click") {
133
+ evt.stopPropagation();
134
+ }
135
+ if (!this.pending_destroy_click) {
136
+ if (!this.active_field) {
137
+ if (this.is_multiple) {
138
+ this.search_field.val("");
139
+ }
140
+ $(document).click(this.click_test_action);
141
+ this.results_show();
142
+ } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
143
+ evt.preventDefault();
144
+ this.results_toggle();
145
+ }
146
+ return this.activate_field();
147
+ } else {
148
+ return this.pending_destroy_click = false;
149
+ }
150
+ };
151
+ Chosen.prototype.mouse_enter = function() {
152
+ return this.mouse_on_container = true;
153
+ };
154
+ Chosen.prototype.mouse_leave = function() {
155
+ return this.mouse_on_container = false;
156
+ };
157
+ Chosen.prototype.input_focus = function(evt) {
158
+ if (!this.active_field) {
159
+ return setTimeout((__bind(function() {
160
+ return this.container_click();
161
+ }, this)), 50);
162
+ }
163
+ };
164
+ Chosen.prototype.input_blur = function(evt) {
165
+ if (!this.mouse_on_container) {
166
+ this.active_field = false;
167
+ return setTimeout((__bind(function() {
168
+ return this.blur_test();
169
+ }, this)), 100);
170
+ }
171
+ };
172
+ Chosen.prototype.blur_test = function(evt) {
173
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
174
+ return this.close_field();
175
+ }
176
+ };
177
+ Chosen.prototype.close_field = function() {
178
+ $(document).unbind("click", this.click_test_action);
179
+ if (!this.is_multiple) {
180
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
181
+ this.search_field.attr("tabindex", -1);
182
+ }
183
+ this.active_field = false;
184
+ this.results_hide();
185
+ this.container.removeClass("chzn-container-active");
186
+ this.winnow_results_clear();
187
+ this.clear_backstroke();
188
+ this.show_search_field_default();
189
+ return this.search_field_scale();
190
+ };
191
+ Chosen.prototype.activate_field = function() {
192
+ if (!this.is_multiple && !this.active_field) {
193
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
194
+ this.selected_item.attr("tabindex", -1);
195
+ }
196
+ this.container.addClass("chzn-container-active");
197
+ this.active_field = true;
198
+ this.search_field.val(this.search_field.val());
199
+ return this.search_field.focus();
200
+ };
201
+ Chosen.prototype.test_active_click = function(evt) {
202
+ if ($(evt.target).parents('#' + this.container.id).length) {
203
+ return this.active_field = true;
204
+ } else {
205
+ return this.close_field();
206
+ }
207
+ };
208
+ Chosen.prototype.results_build = function() {
209
+ var content, data, startTime, _i, _len, _ref;
210
+ startTime = new Date();
211
+ this.parsing = true;
212
+ this.results_data = SelectParser.select_to_array(this.form_field);
213
+ if (this.is_multiple && this.choices > 0) {
214
+ this.search_choices.find("li.search-choice").remove();
215
+ this.choices = 0;
216
+ } else if (!this.is_multiple) {
217
+ this.selected_item.find("span").text(this.default_text);
218
+ }
219
+ content = '';
220
+ _ref = this.results_data;
221
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
222
+ data = _ref[_i];
223
+ if (data.group) {
224
+ content += this.result_add_group(data);
225
+ } else if (!data.empty) {
226
+ content += this.result_add_option(data);
227
+ if (data.selected && this.is_multiple) {
228
+ this.choice_build(data);
229
+ } else if (data.selected && !this.is_multiple) {
230
+ this.selected_item.find("span").text(data.text);
231
+ }
232
+ }
233
+ }
234
+ this.show_search_field_default();
235
+ this.search_field_scale();
236
+ this.search_results.html(content);
237
+ return this.parsing = false;
238
+ };
239
+ Chosen.prototype.result_add_group = function(group) {
240
+ if (!group.disabled) {
241
+ group.dom_id = this.form_field.id + "chzn_g_" + group.array_index;
242
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
243
+ } else {
244
+ return "";
245
+ }
246
+ };
247
+ Chosen.prototype.result_add_option = function(option) {
248
+ var classes;
249
+ if (!option.disabled) {
250
+ option.dom_id = this.form_field.id + "chzn_o_" + option.array_index;
251
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
252
+ if (option.selected) {
253
+ classes.push("result-selected");
254
+ }
255
+ if (option.group_array_index != null) {
256
+ classes.push("group-option");
257
+ }
258
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + $("<div />").text(option.text).html() + '</li>';
259
+ } else {
260
+ return "";
261
+ }
262
+ };
263
+ Chosen.prototype.results_update_field = function() {
264
+ this.result_clear_highlight();
265
+ this.result_single_selected = null;
266
+ return this.results_build();
267
+ };
268
+ Chosen.prototype.result_do_highlight = function(el) {
269
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
270
+ if (el.length) {
271
+ this.result_clear_highlight();
272
+ this.result_highlight = el;
273
+ this.result_highlight.addClass("highlighted");
274
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
275
+ visible_top = this.search_results.scrollTop();
276
+ visible_bottom = maxHeight + visible_top;
277
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
278
+ high_bottom = high_top + this.result_highlight.outerHeight();
279
+ if (high_bottom >= visible_bottom) {
280
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
281
+ } else if (high_top < visible_top) {
282
+ return this.search_results.scrollTop(high_top);
283
+ }
284
+ }
285
+ };
286
+ Chosen.prototype.result_clear_highlight = function() {
287
+ if (this.result_highlight) {
288
+ this.result_highlight.removeClass("highlighted");
289
+ }
290
+ return this.result_highlight = null;
291
+ };
292
+ Chosen.prototype.results_toggle = function() {
293
+ if (this.results_showing) {
294
+ return this.results_hide();
295
+ } else {
296
+ return this.results_show();
297
+ }
298
+ };
299
+ Chosen.prototype.results_show = function() {
300
+ var dd_top;
301
+ if (!this.is_multiple) {
302
+ this.selected_item.addClass("chzn-single-with-drop");
303
+ if (this.result_single_selected) {
304
+ this.result_do_highlight(this.result_single_selected);
305
+ }
306
+ }
307
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
308
+ this.dropdown.css({
309
+ "top": dd_top + "px",
310
+ "left": 0
311
+ });
312
+ this.results_showing = true;
313
+ this.search_field.focus();
314
+ this.search_field.val(this.search_field.val());
315
+ return this.winnow_results();
316
+ };
317
+ Chosen.prototype.results_hide = function() {
318
+ if (!this.is_multiple) {
319
+ this.selected_item.removeClass("chzn-single-with-drop");
320
+ }
321
+ this.result_clear_highlight();
322
+ this.dropdown.css({
323
+ "left": "-9000px"
324
+ });
325
+ return this.results_showing = false;
326
+ };
327
+ Chosen.prototype.set_tab_index = function(el) {
328
+ var ti;
329
+ if (this.form_field_jq.attr("tabindex")) {
330
+ ti = this.form_field_jq.attr("tabindex");
331
+ this.form_field_jq.attr("tabindex", -1);
332
+ if (this.is_multiple) {
333
+ return this.search_field.attr("tabindex", ti);
334
+ } else {
335
+ this.selected_item.attr("tabindex", ti);
336
+ return this.search_field.attr("tabindex", -1);
337
+ }
338
+ }
339
+ };
340
+ Chosen.prototype.show_search_field_default = function() {
341
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
342
+ this.search_field.val(this.default_text);
343
+ return this.search_field.addClass("default");
344
+ } else {
345
+ this.search_field.val("");
346
+ return this.search_field.removeClass("default");
347
+ }
348
+ };
349
+ Chosen.prototype.search_results_click = function(evt) {
350
+ var target;
351
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
352
+ if (target.length) {
353
+ this.result_highlight = target;
354
+ return this.result_select();
355
+ }
356
+ };
357
+ Chosen.prototype.search_results_mouseover = function(evt) {
358
+ var target;
359
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
360
+ if (target) {
361
+ return this.result_do_highlight(target);
362
+ }
363
+ };
364
+ Chosen.prototype.search_results_mouseout = function(evt) {
365
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
366
+ return this.result_clear_highlight();
367
+ }
368
+ };
369
+ Chosen.prototype.choices_click = function(evt) {
370
+ evt.preventDefault();
371
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
372
+ return this.results_show();
373
+ }
374
+ };
375
+ Chosen.prototype.choice_build = function(item) {
376
+ var choice_id, link;
377
+ choice_id = this.form_field.id + "_chzn_c_" + item.array_index;
378
+ this.choices += 1;
379
+ 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>');
380
+ link = $('#' + choice_id).find("a").first();
381
+ return link.click(__bind(function(evt) {
382
+ return this.choice_destroy_link_click(evt);
383
+ }, this));
384
+ };
385
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
386
+ evt.preventDefault();
387
+ this.pending_destroy_click = true;
388
+ return this.choice_destroy($(evt.target));
389
+ };
390
+ Chosen.prototype.choice_destroy = function(link) {
391
+ this.choices -= 1;
392
+ this.show_search_field_default();
393
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
394
+ this.results_hide();
395
+ }
396
+ this.result_deselect(link.attr("rel"));
397
+ return link.parents('li').first().remove();
398
+ };
399
+ Chosen.prototype.result_select = function() {
400
+ var high, high_id, item, position;
401
+ if (this.result_highlight) {
402
+ high = this.result_highlight;
403
+ high_id = high.attr("id");
404
+ this.result_clear_highlight();
405
+ high.addClass("result-selected");
406
+ if (this.is_multiple) {
407
+ this.result_deactivate(high);
408
+ } else {
409
+ this.result_single_selected = high;
410
+ }
411
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
412
+ item = this.results_data[position];
413
+ item.selected = true;
414
+ this.form_field.options[item.options_index].selected = true;
415
+ if (this.is_multiple) {
416
+ this.choice_build(item);
417
+ } else {
418
+ this.selected_item.find("span").first().text(item.text);
419
+ }
420
+ this.results_hide();
421
+ this.search_field.val("");
422
+ this.form_field_jq.trigger("change");
423
+ return this.search_field_scale();
424
+ }
425
+ };
426
+ Chosen.prototype.result_activate = function(el) {
427
+ return el.addClass("active-result").show();
428
+ };
429
+ Chosen.prototype.result_deactivate = function(el) {
430
+ return el.removeClass("active-result").hide();
431
+ };
432
+ Chosen.prototype.result_deselect = function(pos) {
433
+ var result, result_data;
434
+ result_data = this.results_data[pos];
435
+ result_data.selected = false;
436
+ this.form_field.options[result_data.options_index].selected = false;
437
+ result = $("#" + this.form_field.id + "chzn_o_" + pos);
438
+ result.removeClass("result-selected").addClass("active-result").show();
439
+ this.result_clear_highlight();
440
+ this.winnow_results();
441
+ this.form_field_jq.trigger("change");
442
+ return this.search_field_scale();
443
+ };
444
+ Chosen.prototype.results_search = function(evt) {
445
+ if (this.results_showing) {
446
+ return this.winnow_results();
447
+ } else {
448
+ return this.results_show();
449
+ }
450
+ };
451
+ Chosen.prototype.winnow_results = function() {
452
+ var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
453
+ startTime = new Date();
454
+ this.no_results_clear();
455
+ results = 0;
456
+ searchText = this.search_field.val() === this.default_text ? "" : $.trim(this.search_field.val());
457
+ regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
458
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
459
+ _ref = this.results_data;
460
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
461
+ option = _ref[_i];
462
+ if (!option.disabled && !option.empty) {
463
+ if (option.group) {
464
+ $('#' + option.dom_id).hide();
465
+ } else if (!(this.is_multiple && option.selected)) {
466
+ found = false;
467
+ result_id = option.dom_id;
468
+ if (regex.test(option.text)) {
469
+ found = true;
470
+ results += 1;
471
+ } else if (option.text.indexOf(" ") >= 0 || option.text.indexOf("[") === 0) {
472
+ parts = option.text.replace(/\[|\]/g, "").split(" ");
473
+ if (parts.length) {
474
+ for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
475
+ part = parts[_j];
476
+ if (regex.test(part)) {
477
+ found = true;
478
+ results += 1;
479
+ }
480
+ }
481
+ }
482
+ }
483
+ if (found) {
484
+ if (searchText.length) {
485
+ startpos = option.text.search(zregex);
486
+ text = option.text.substr(0, startpos + searchText.length) + '</em>' + option.text.substr(startpos + searchText.length);
487
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
488
+ } else {
489
+ text = option.text;
490
+ }
491
+ if ($("#" + result_id).html !== text) {
492
+ $("#" + result_id).html(text);
493
+ }
494
+ this.result_activate($("#" + result_id));
495
+ if (option.group_array_index != null) {
496
+ $("#" + this.results_data[option.group_array_index].dom_id).show();
497
+ }
498
+ } else {
499
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
500
+ this.result_clear_highlight();
501
+ }
502
+ this.result_deactivate($("#" + result_id));
503
+ }
504
+ }
505
+ }
506
+ }
507
+ if (results < 1 && searchText.length) {
508
+ return this.no_results(searchText);
509
+ } else {
510
+ return this.winnow_results_set_highlight();
511
+ }
512
+ };
513
+ Chosen.prototype.winnow_results_clear = function() {
514
+ var li, lis, _i, _len, _results;
515
+ this.search_field.val("");
516
+ lis = this.search_results.find("li");
517
+ _results = [];
518
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
519
+ li = lis[_i];
520
+ li = $(li);
521
+ _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
522
+ }
523
+ return _results;
524
+ };
525
+ Chosen.prototype.winnow_results_set_highlight = function() {
526
+ var do_high;
527
+ if (!this.result_highlight) {
528
+ do_high = this.search_results.find(".active-result").first();
529
+ if (do_high) {
530
+ return this.result_do_highlight(do_high);
531
+ }
532
+ }
533
+ };
534
+ Chosen.prototype.no_results = function(terms) {
535
+ var no_results_html;
536
+ no_results_html = $('<li class="no-results">No results match "<span></span>"</li>');
537
+ no_results_html.find("span").first().text(terms);
538
+ return this.search_results.append(no_results_html);
539
+ };
540
+ Chosen.prototype.no_results_clear = function() {
541
+ return this.search_results.find(".no-results").remove();
542
+ };
543
+ Chosen.prototype.keydown_arrow = function() {
544
+ var first_active, next_sib;
545
+ if (!this.result_highlight) {
546
+ first_active = this.search_results.find("li.active-result").first();
547
+ if (first_active) {
548
+ this.result_do_highlight($(first_active));
549
+ }
550
+ } else if (this.results_showing) {
551
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
552
+ if (next_sib) {
553
+ this.result_do_highlight(next_sib);
554
+ }
555
+ }
556
+ if (!this.results_showing) {
557
+ return this.results_show();
558
+ }
559
+ };
560
+ Chosen.prototype.keyup_arrow = function() {
561
+ var prev_sibs;
562
+ if (!this.results_showing && !this.is_multiple) {
563
+ return this.results_show();
564
+ } else if (this.result_highlight) {
565
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
566
+ if (prev_sibs.length) {
567
+ return this.result_do_highlight(prev_sibs.first());
568
+ } else {
569
+ if (this.choices > 0) {
570
+ this.results_hide();
571
+ }
572
+ return this.result_clear_highlight();
573
+ }
574
+ }
575
+ };
576
+ Chosen.prototype.keydown_backstroke = function() {
577
+ if (this.pending_backstroke) {
578
+ this.choice_destroy(this.pending_backstroke.find("a").first());
579
+ return this.clear_backstroke();
580
+ } else {
581
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
582
+ return this.pending_backstroke.addClass("search-choice-focus");
583
+ }
584
+ };
585
+ Chosen.prototype.clear_backstroke = function() {
586
+ if (this.pending_backstroke) {
587
+ this.pending_backstroke.removeClass("search-choice-focus");
588
+ }
589
+ return this.pending_backstroke = null;
590
+ };
591
+ Chosen.prototype.keyup_checker = function(evt) {
592
+ var stroke, _ref;
593
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
594
+ this.search_field_scale();
595
+ switch (stroke) {
596
+ case 8:
597
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
598
+ return this.keydown_backstroke();
599
+ } else if (!this.pending_backstroke) {
600
+ this.result_clear_highlight();
601
+ return this.results_search();
602
+ }
603
+ break;
604
+ case 13:
605
+ evt.preventDefault();
606
+ if (this.results_showing) {
607
+ return this.result_select();
608
+ }
609
+ break;
610
+ case 27:
611
+ if (this.results_showing) {
612
+ return this.results_hide();
613
+ }
614
+ break;
615
+ case 9:
616
+ case 38:
617
+ case 40:
618
+ case 16:
619
+ break;
620
+ default:
621
+ return this.results_search();
622
+ }
623
+ };
624
+ Chosen.prototype.keydown_checker = function(evt) {
625
+ var stroke, _ref;
626
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
627
+ this.search_field_scale();
628
+ if (stroke !== 8 && this.pending_backstroke) {
629
+ this.clear_backstroke();
630
+ }
631
+ switch (stroke) {
632
+ case 8:
633
+ this.backstroke_length = this.search_field.val().length;
634
+ break;
635
+ case 9:
636
+ this.mouse_on_container = false;
637
+ break;
638
+ case 13:
639
+ evt.preventDefault();
640
+ break;
641
+ case 38:
642
+ evt.preventDefault();
643
+ this.keyup_arrow();
644
+ break;
645
+ case 40:
646
+ this.keydown_arrow();
647
+ break;
648
+ }
649
+ };
650
+ Chosen.prototype.search_field_scale = function() {
651
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
652
+ if (this.is_multiple) {
653
+ h = 0;
654
+ w = 0;
655
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
656
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
657
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
658
+ style = styles[_i];
659
+ style_block += style + ":" + this.search_field.css(style) + ";";
660
+ }
661
+ div = $('<div />', {
662
+ 'style': style_block
663
+ });
664
+ div.text(this.search_field.val());
665
+ $('body').append(div);
666
+ w = div.width() + 25;
667
+ div.remove();
668
+ if (w > this.f_width - 10) {
669
+ w = this.f_width - 10;
670
+ }
671
+ this.search_field.css({
672
+ 'width': w + 'px'
673
+ });
674
+ dd_top = this.container.height();
675
+ return this.dropdown.css({
676
+ "top": dd_top + "px"
677
+ });
678
+ }
679
+ };
680
+ return Chosen;
681
+ })();
682
+ get_side_border_padding = function(elmt) {
683
+ var side_border_padding;
684
+ return side_border_padding = elmt.outerWidth() - elmt.width();
685
+ };
686
+ root.get_side_border_padding = get_side_border_padding;
687
+ SelectParser = (function() {
688
+ function SelectParser() {
689
+ this.options_index = 0;
690
+ this.parsed = [];
691
+ }
692
+ SelectParser.prototype.add_node = function(child) {
693
+ if (child.nodeName === "OPTGROUP") {
694
+ return this.add_group(child);
695
+ } else {
696
+ return this.add_option(child);
697
+ }
698
+ };
699
+ SelectParser.prototype.add_group = function(group) {
700
+ var group_position, option, _i, _len, _ref, _results;
701
+ group_position = this.parsed.length;
702
+ this.parsed.push({
703
+ array_index: group_position,
704
+ group: true,
705
+ label: group.label,
706
+ children: 0,
707
+ disabled: group.disabled
708
+ });
709
+ _ref = group.childNodes;
710
+ _results = [];
711
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
712
+ option = _ref[_i];
713
+ _results.push(this.add_option(option, group_position, group.disabled));
714
+ }
715
+ return _results;
716
+ };
717
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
718
+ if (option.nodeName === "OPTION") {
719
+ if (option.text !== "") {
720
+ if (group_position != null) {
721
+ this.parsed[group_position].children += 1;
722
+ }
723
+ this.parsed.push({
724
+ array_index: this.parsed.length,
725
+ options_index: this.options_index,
726
+ value: option.value,
727
+ text: option.text,
728
+ selected: option.selected,
729
+ disabled: group_disabled === true ? group_disabled : option.disabled,
730
+ group_array_index: group_position
731
+ });
732
+ } else {
733
+ this.parsed.push({
734
+ array_index: this.parsed.length,
735
+ options_index: this.options_index,
736
+ empty: true
737
+ });
738
+ }
739
+ return this.options_index += 1;
740
+ }
741
+ };
742
+ return SelectParser;
743
+ })();
744
+ SelectParser.select_to_array = function(select) {
745
+ var child, parser, _i, _len, _ref;
746
+ parser = new SelectParser();
747
+ _ref = select.childNodes;
748
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
749
+ child = _ref[_i];
750
+ parser.add_node(child);
751
+ }
752
+ return parser.parsed;
753
+ };
754
+ root.SelectParser = SelectParser;
755
+ }).call(this);