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
@@ -113,40 +113,43 @@ parseXmlCdata(Msg) ->
113
113
 
114
114
  execute(Message) ->
115
115
  %?INFO_MSG("Message vale: ~p", [Message]),
116
+ %?INFO_MSG("Order vale: ~p", [Order]),
116
117
  [Order|Params] = string:tokens(Message, "&"),
117
-
118
118
  case Order of
119
119
  "AddItemToRoster" ->
120
120
  case length(Params) of
121
121
  4 -> [UserSID,BuddySID,BuddyName,Subscription_type] = Params,
122
122
  ?INFO_MSG("Execute: ~p with params ~p", [Order,Params]),
123
-
124
- %Command Name: add_rosteritem
125
- % Needs mod_admin_extra (http://www.ejabberd.im/ejabberd-modules)
126
- % ejabberdctl add_rosteritem localuser localserver user server nick group subs
127
- %subs= none, from, to or both",
128
-
129
- %frank-williamson@trapo adds demo@trapo to its roster
130
- %ejabberdctl add_rosteritem frank-williamson trapo demo trapo NickName SocialStream from
131
-
132
- %frank-williamson@trapo adds demo@trapo and demo@trapo adds frank-williamson@trapo to its roster
133
- %ejabberdctl add_rosteritem frank-williamson trapo demo trapo NickName SocialStream both
134
-
135
123
  [ContactName|_R] = string:tokens(BuddyName, " "),
136
124
  [UserSlug,UserDomain] = string:tokens(UserSID, "@"),
137
125
  [BuddySlug,BuddyDomain] = string:tokens(BuddySID, "@"),
126
+ addItemToRoster(UserSlug,UserDomain,BuddySlug,BuddyDomain,ContactName,"SocialStream",Subscription_type),
127
+ ok;
128
+ _ -> ?INFO_MSG("Incorrect parameters in order ~p", [Order]),
129
+ ok
130
+ end,
131
+ ok;
138
132
 
139
- Command = lists:concat(["ejabberdctl add_rosteritem ", UserSlug , " ", UserDomain, " ", BuddySlug, " ", BuddyDomain , " ", ContactName , " ", "SocialStream" , " ", Subscription_type]),
140
- os:cmd(Command),
141
- ?INFO_MSG("Execute command: ~p", [Command]),
133
+ "SetRosterForBidirectionalTie" ->
134
+ case length(Params) of
135
+ 4 -> [UserASID,UserBSID,UserAName,UserBName] = Params,
136
+ ?INFO_MSG("Executing: ~p with params ~p", [Order,Params]),
137
+ [UserASlug,UserADomain] = string:tokens(UserASID, "@"),
138
+ [UserBSlug,UserBDomain] = string:tokens(UserBSID, "@"),
139
+ addItemToRoster(UserASlug,UserADomain,UserBSlug,UserBDomain,UserBName,"SocialStream","both"),
140
+ addItemToRoster(UserBSlug,UserBDomain,UserASlug,UserADomain,UserAName,"SocialStream","both"),
142
141
  ok;
143
- _ -> ?INFO_MSG("Incorrect parameters", []),
142
+ _ -> ?INFO_MSG("Incorrect parameters in order ~p", [Order]),
144
143
  ok
145
144
  end,
146
145
  ok;
147
146
 
148
147
  "Synchronize" ->
149
- synchronize(),
148
+ synchronizePresence(),
149
+ ok;
150
+
151
+ "SynchronizeRosters" ->
152
+ synchronizeRosters(),
150
153
  ok;
151
154
 
152
155
  _ -> ?INFO_MSG("Command not found", []),
@@ -154,6 +157,23 @@ execute(Message) ->
154
157
  end.
155
158
 
156
159
 
160
+
161
+ %%Call ejabberdctl command add_rosteritem
162
+ %Command Name: add_rosteritem
163
+ %Needs mod_admin_extra (http://www.ejabberd.im/ejabberd-modules)
164
+ %ejabberdctl add_rosteritem localuser localserver buddy buddyserver nick group subs
165
+ %subs= none, from, to or both,
166
+
167
+ %Example
168
+ %ejabberdctl add_rosteritem frank-williamson trapo demo trapo NickName SocialStream from
169
+ %frank-williamson@trapo adds demo@trapo to its roster with subscription from, in the group SocialStream with the name Nickname
170
+ %%
171
+ addItemToRoster(UserSlug,UserDomain,BuddySlug,BuddyDomain,ContactName,Group,Subscription_type) ->
172
+ Command = lists:concat(["ejabberdctl add_rosteritem ", UserSlug , " ", UserDomain, " ", BuddySlug, " ", BuddyDomain , " \\'", ContactName , "\\' ", Group , " ", Subscription_type]),
173
+ os:cmd(Command),
174
+ ?INFO_MSG("Execute command: ~p", [Command]),
175
+ ok.
176
+
157
177
  %%GETTERS CONFIG VALUES
158
178
  %%CONFIG FILE: /etc/ejabberd/ssconfig.cfg
159
179
 
@@ -214,12 +234,19 @@ end.
214
234
 
215
235
 
216
236
  %%Send all connected users to Social Stream Rails Application
217
- synchronize() ->
237
+ synchronizePresence() ->
218
238
  Synchronize_path = string:concat(getOptionValue("scripts_path="), "/synchronize_presence_script "),
219
239
  os:cmd(Synchronize_path),
220
240
  ok.
221
241
 
222
242
 
243
+ %%Reset all rosters and wait to received data from Social Stream Rails Application
244
+ synchronizeRosters() ->
245
+ SynchronizeRosters_path = string:concat(getOptionValue("scripts_path="), "/emanagement removeAllRosters"),
246
+ os:cmd(SynchronizeRosters_path),
247
+ ok.
248
+
249
+
223
250
  %Reset all connections
224
251
  %reset_connections() ->
225
252
  % Reset_path = string:concat(getOptionValue("scripts_path="), "/reset_connection_script "),
@@ -0,0 +1,28 @@
1
+ class SocialStream::Presence::InstallGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def create_initializer_file
7
+ copy_file 'initializer.rb', 'config/initializers/social_stream-presence.rb'
8
+ end
9
+
10
+ def create_migration_file
11
+ require 'rake'
12
+ Rails.application.load_tasks
13
+ Rake::Task['railties:install:migrations'].reenable
14
+ Rake::Task['social_stream_presence_engine:install:migrations'].invoke
15
+ end
16
+
17
+ def require_javascripts
18
+ inject_into_file 'app/assets/javascripts/application.js',
19
+ "//= require social_stream-presence\n",
20
+ :before => '//= require_tree .'
21
+ end
22
+
23
+ def require_stylesheets
24
+ inject_into_file 'app/assets/stylesheets/application.css',
25
+ " *= require social_stream-presence\n",
26
+ :before => ' *= require_tree .'
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ SocialStream::Presence.setup do |config|
2
+ #Configures XMPP Server Domain
3
+ config.domain = "localhost"
4
+ #Configures Bosh Service Path
5
+ config.bosh_service = "http://localhost:8080/http-bind"
6
+ #Configures Social Stream Rails App Password
7
+ config.password = "DnVCB8G|R$VGmZ@2?5=CYS8z)NrL@LuQ&LTCUh^9B(DF4gC&sQpfbCMbaNKEdNrGYkT4L5zxM0wNWs5q3?ww(b&0d5fK87z^BmgJMMF2SKXT9pEk^UEcch!GX!Avf5GT9)j@FpHe)4RH)BK7J98u!sUmJHUN(Je6aBmn!FtZ4Ab5h8$|nsvUt3Jkq?21HOH$r0sDyJZZvGOCgFS2EKw@0wXsJRHYVRPBe&Eb!1X55e55bQ^h2AW&^R70TK0m)Fu8"
8
+ #Configures XMPP Server Password
9
+ config.xmpp_server_password = "G&s6GBnO)anw2Ene%K12Cb=0quj@uDmA"
10
+ #Username of the the Social Stream Admin sid
11
+ config.social_stream_presence_username = "social_stream-presence"
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Socialstream
2
2
  module Presence
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -4,7 +4,6 @@ namespace :presence do
4
4
 
5
5
  namespace :synchronize do
6
6
 
7
-
8
7
  desc "Synchronize user presence."
9
8
  task :connections => :environment do
10
9
  puts "Starting presence:synchronize:connections"
@@ -26,6 +25,7 @@ namespace :presence do
26
25
  puts "Connecting to Xmpp Server"
27
26
  client = Jabber::Client.new(Jabber::JID.new(ss_sid))
28
27
  client.connect
28
+ puts "Authentication..."
29
29
  client.auth(password)
30
30
  puts "Connected to Xmpp Server"
31
31
 
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "social_stream/presence/config"
3
+ require "social_stream/presence/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "social_stream-presence"
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files`.split("\n")
12
12
 
13
13
  # Gem dependencies
14
- s.add_runtime_dependency('social_stream-base', '~> 0.9.21')
15
- s.add_runtime_dependency('social_stream-documents', '~> 0.3.2')
16
- s.add_runtime_dependency('social_stream-events', '~> 0.0.13')
14
+ s.add_runtime_dependency('social_stream-base', '~> 0.9.22')
15
+ s.add_runtime_dependency('social_stream-documents', '~> 0.3.3')
16
+ s.add_runtime_dependency('social_stream-events', '~> 0.0.15')
17
17
 
18
18
  # Development Gem dependencies
19
19
  #
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 11
9
- - 7
10
- version: 0.11.7
9
+ - 8
10
+ version: 0.11.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - GING - DIT - UPM
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-17 00:00:00 +02:00
19
+ date: 2011-10-19 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -27,12 +27,12 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: 17
30
+ hash: 23
31
31
  segments:
32
32
  - 0
33
33
  - 9
34
- - 21
35
- version: 0.9.21
34
+ - 22
35
+ version: 0.9.22
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
@@ -43,12 +43,12 @@ dependencies:
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- hash: 23
46
+ hash: 21
47
47
  segments:
48
48
  - 0
49
49
  - 3
50
- - 2
51
- version: 0.3.2
50
+ - 3
51
+ version: 0.3.3
52
52
  type: :runtime
53
53
  version_requirements: *id002
54
54
  - !ruby/object:Gem::Dependency
@@ -59,12 +59,12 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- hash: 5
62
+ hash: 1
63
63
  segments:
64
64
  - 0
65
65
  - 0
66
- - 13
67
- version: 0.0.13
66
+ - 15
67
+ version: 0.0.15
68
68
  type: :runtime
69
69
  version_requirements: *id003
70
70
  - !ruby/object:Gem::Dependency
@@ -329,6 +329,11 @@ files:
329
329
  - base/app/assets/images/icon_checkbox.png
330
330
  - base/app/assets/images/icons/favicon.ico
331
331
  - base/app/assets/images/left.png
332
+ - base/app/assets/images/lightbox-blank.gif
333
+ - base/app/assets/images/lightbox-btn-close.gif
334
+ - base/app/assets/images/lightbox-btn-next.gif
335
+ - base/app/assets/images/lightbox-btn-prev.gif
336
+ - base/app/assets/images/lightbox-ico-loading.gif
332
337
  - base/app/assets/images/loader.gif
333
338
  - base/app/assets/images/loading.gif
334
339
  - base/app/assets/images/logo.png
@@ -348,6 +353,7 @@ files:
348
353
  - base/app/assets/images/right.png
349
354
  - base/app/assets/images/tipsy.gif
350
355
  - base/app/assets/javascripts/activities.js.erb
356
+ - base/app/assets/javascripts/activities_security_chosen-modified.jquery.js
351
357
  - base/app/assets/javascripts/contacts.js
352
358
  - base/app/assets/javascripts/conversations.js
353
359
  - base/app/assets/javascripts/groups.js
@@ -622,7 +628,7 @@ files:
622
628
  - base/app/views/search/index.html.erb
623
629
  - base/app/views/search/index.js.erb
624
630
  - base/app/views/settings/_api_key.html.erb
625
- - base/app/views/settings/_contacts.html.erb
631
+ - base/app/views/settings/_destroy.html.erb
626
632
  - base/app/views/settings/_index.html.erb
627
633
  - base/app/views/settings/_notifications.html.erb
628
634
  - base/app/views/settings/index.html.erb
@@ -765,15 +771,16 @@ files:
765
771
  - base/spec/support/devise.rb
766
772
  - base/spec/support/mock.rb
767
773
  - base/vendor/assets/javascripts/ajax.paginate.js
768
- - base/vendor/assets/javascripts/chosen.jquery.js
769
774
  - base/vendor/assets/javascripts/d3.geom.js
770
775
  - base/vendor/assets/javascripts/d3.js
771
776
  - base/vendor/assets/javascripts/d3.layout.js
772
777
  - base/vendor/assets/javascripts/hoverIntent.js
773
778
  - base/vendor/assets/javascripts/jqcloud-0.1.3.js
779
+ - base/vendor/assets/javascripts/jquery.ae.image.resize.js
774
780
  - base/vendor/assets/javascripts/jquery.ba-url.js
775
781
  - base/vendor/assets/javascripts/jquery.cleditor.min.js
776
782
  - base/vendor/assets/javascripts/jquery.fcbkcomplete.js
783
+ - base/vendor/assets/javascripts/jquery.lightbox-with-resize-plugin.js
777
784
  - base/vendor/assets/javascripts/jquery.livequery.js
778
785
  - base/vendor/assets/javascripts/jquery.scrollTo.min.js
779
786
  - base/vendor/assets/javascripts/jquery.tipsy.js
@@ -847,11 +854,6 @@ files:
847
854
  - documents/app/assets/images/btn/btn_video.png
848
855
  - documents/app/assets/images/btn/btn_word.png
849
856
  - documents/app/assets/images/btn/document.png
850
- - documents/app/assets/images/lightbox-blank.gif
851
- - documents/app/assets/images/lightbox-btn-close.gif
852
- - documents/app/assets/images/lightbox-btn-next.gif
853
- - documents/app/assets/images/lightbox-btn-prev.gif
854
- - documents/app/assets/images/lightbox-ico-loading.gif
855
857
  - documents/app/assets/javascripts/documents.js.erb
856
858
  - documents/app/assets/javascripts/social_stream-documents.js
857
859
  - documents/app/assets/stylesheets/documents.css
@@ -978,7 +980,6 @@ files:
978
980
  - documents/spec/support/devise.rb
979
981
  - documents/spec/support/mock.rb
980
982
  - documents/vendor/assets/javascripts/jquery.jplayer.js
981
- - documents/vendor/assets/javascripts/jquery.lightbox-with-resize-plugin.js
982
983
  - documents/vendor/assets/stylesheets/jplayer.blue.monday.css
983
984
  - documents/vendor/assets/stylesheets/jplayer.blue.monday.jpg
984
985
  - documents/vendor/assets/stylesheets/jplayer.blue.monday.video.play.hover.png
@@ -1145,11 +1146,11 @@ files:
1145
1146
  - presence/ejabberd/conf/ejabberd.cfg
1146
1147
  - presence/ejabberd/conf/ejabberdctl.cfg
1147
1148
  - presence/ejabberd/conf/inetrc
1148
- - presence/ejabberd/conf/server.pem
1149
1149
  - presence/ejabberd/conf/ssconfig.cfg
1150
1150
  - presence/ejabberd/ejabberd_scripts/authentication_script
1151
1151
  - presence/ejabberd/ejabberd_scripts/authentication_script_org
1152
1152
  - presence/ejabberd/ejabberd_scripts/compile_module
1153
+ - presence/ejabberd/ejabberd_scripts/emanagement
1153
1154
  - presence/ejabberd/ejabberd_scripts/generate_random_password
1154
1155
  - presence/ejabberd/ejabberd_scripts/kill_authentication_script.sh
1155
1156
  - presence/ejabberd/ejabberd_scripts/reset_connection_script
@@ -1163,12 +1164,15 @@ files:
1163
1164
  - presence/ejabberd/ejabberd_scripts/unset_connection_script
1164
1165
  - presence/ejabberd/mod_admin_extra/mod_admin_extra.beam
1165
1166
  - presence/ejabberd/mod_admin_extra/mod_admin_extra.erl
1167
+ - presence/ejabberd/mod_sspresence/mod_sspresence.beam
1166
1168
  - presence/ejabberd/mod_sspresence/mod_sspresence.erl
1169
+ - presence/lib/generators/social_stream/presence/install_generator.rb
1170
+ - presence/lib/generators/social_stream/presence/templates/initializer.rb
1167
1171
  - presence/lib/social_stream-presence.rb
1168
1172
  - presence/lib/social_stream/migrations/presence.rb
1169
- - presence/lib/social_stream/presence/config.rb
1170
1173
  - presence/lib/social_stream/presence/engine.rb
1171
1174
  - presence/lib/social_stream/presence/models/buddy_manager.rb
1175
+ - presence/lib/social_stream/presence/version.rb
1172
1176
  - presence/lib/tasks/presence/synchronize.rake
1173
1177
  - presence/social_stream-presence.gemspec
1174
1178
  - presence/spec/demo/.gitignore
@@ -1,16 +0,0 @@
1
- <div class="block" id="manage_settings">
2
- <div class="header">
3
- <div class="header_text">
4
- <%= t('settings.manage.name')%>
5
- </div>
6
- <div class="header_icon_right">
7
- <%= link_to image_tag('btn/edit.png'), contacts_path %>
8
- </div>
9
- </div>
10
- <div class="content" id="contact_settings_briefing">
11
- <div class="form_row">
12
- <%= t('settings.manage.briefing')%>
13
- </div>
14
- </div>
15
- </div>
16
-
@@ -1,755 +0,0 @@
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);