social_stream 0.11.5 → 0.11.6
Sign up to get free protection for your applications and to get access to all the features.
- data/base/app/assets/javascripts/contacts.js +0 -6
- data/base/app/assets/javascripts/relation_customs.js +28 -81
- data/base/app/assets/javascripts/settings.js +12 -33
- data/base/app/assets/stylesheets/base.css.scss +2 -1
- data/base/app/assets/stylesheets/relation_customs.css.scss +8 -2
- data/base/app/controllers/contacts_controller.rb +7 -3
- data/base/app/controllers/messages_controller.rb +1 -1
- data/base/app/controllers/search_controller.rb +22 -6
- data/base/app/controllers/settings_controller.rb +1 -1
- data/base/app/models/contact.rb +7 -1
- data/base/app/models/relation.rb +14 -1
- data/base/app/views/activities/_new.html.erb +3 -2
- data/base/app/views/contacts/_link.html.erb +1 -1
- data/base/app/views/contacts/index.html.erb +1 -1
- data/base/app/views/conversations/_conversation.html.erb +3 -3
- data/base/app/views/conversations/_conversation_full.html.erb +3 -3
- data/base/app/views/devise/registrations/_delete_account.html.erb +20 -0
- data/base/app/views/devise/registrations/_edit_user.html.erb +87 -0
- data/base/app/views/devise/registrations/edit.html.erb +16 -93
- data/base/app/views/layouts/_header_dropdown_menu.html.erb +0 -3
- data/base/app/views/messages/_form.html.erb +1 -1
- data/base/app/views/permissions/_index.html.erb +2 -2
- data/base/app/views/permissions/index.js.erb +7 -2
- data/base/app/views/relation/customs/_list.html.erb +12 -5
- data/base/app/views/relation/customs/create.js.erb +4 -2
- data/base/app/views/relation/customs/index.html.erb +0 -5
- data/base/app/views/search/_form.html.erb +1 -1
- data/base/app/views/settings/_api_key.html.erb +3 -3
- data/base/app/views/settings/_index.html.erb +6 -1
- data/base/app/views/settings/_notifications.html.erb +3 -3
- data/base/app/views/settings/index.html.erb +4 -1
- data/base/config/locales/en.yml +31 -12
- data/base/config/locales/es.yml +33 -10
- data/base/config/routes.rb +10 -11
- data/base/lib/mailboxer/notification_decoder.rb +13 -4
- data/base/lib/social_stream/base/version.rb +1 -1
- data/documents/app/assets/javascripts/social_stream-documents.js +1 -1
- data/documents/app/views/pictures/_picture.html.erb +3 -1
- data/documents/lib/social_stream/documents/version.rb +1 -1
- data/documents/social_stream-documents.gemspec +1 -1
- data/documents/vendor/assets/javascripts/jquery.lightbox-with-resize-plugin.js +533 -0
- data/events/vendor/assets/stylesheets/jquery.ad-gallery.css +1 -1
- data/lib/social_stream/version.rb +1 -1
- data/presence/app/assets/stylesheets/chat.css +9 -1
- data/presence/app/controllers/xmpp_controller.rb +19 -10
- data/presence/app/helpers/xmpp_helper.rb +10 -23
- data/presence/app/views/xmpp/_chat.html.erb +9 -7
- data/presence/app/views/xmpp/_chat_off.html.erb +1 -1
- data/presence/lib/social_stream-presence.rb +12 -0
- data/presence/lib/social_stream/presence/config.rb +0 -4
- data/presence/lib/social_stream/presence/engine.rb +27 -14
- data/presence/lib/social_stream/presence/models/buddy_manager.rb +20 -12
- data/social_stream.gemspec +2 -2
- metadata +13 -14
- data/base/app/assets/images/title_background.png +0 -0
- data/base/vendor/assets/javascripts/ui.checkbox.js +0 -309
- data/documents/vendor/assets/javascripts/jquery.lightbox.min.js +0 -42
- data/presence/app/assets/images/arrow.png +0 -0
@@ -108,14 +108,22 @@ input.chat_password{
|
|
108
108
|
margin-bottom: 5px;
|
109
109
|
}
|
110
110
|
|
111
|
+
|
111
112
|
input.connectChatButton{
|
112
113
|
text-align: center;
|
114
|
+
width: 150px;
|
115
|
+
background-color: #1F4A75;
|
116
|
+
border: 0 none;
|
117
|
+
cursor: pointer;
|
118
|
+
color: white;
|
119
|
+
font-family: Helvetica;
|
120
|
+
font-size: 11px;
|
121
|
+
padding: 2px 0 2px 0px;
|
113
122
|
}
|
114
123
|
|
115
124
|
|
116
125
|
|
117
126
|
|
118
|
-
|
119
127
|
/* Tooltip */
|
120
128
|
|
121
129
|
.tooltip {
|
@@ -134,12 +134,12 @@ class XmppController < ApplicationController
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def authorization
|
137
|
-
return params[:password] ==
|
137
|
+
return params[:password] == SocialStream::Presence.xmpp_server_password
|
138
138
|
end
|
139
139
|
|
140
140
|
|
141
141
|
def chatWindow
|
142
|
-
if (current_user.connected) and (current_user.status != 'disable') and (params[:userConnected]=="true")
|
142
|
+
if (current_user) and (current_user.connected) and (current_user.status != 'disable') and (params[:userConnected]=="true")
|
143
143
|
render :partial => 'xmpp/chat_contacts'
|
144
144
|
else
|
145
145
|
#User not connected or chat desactivated
|
@@ -159,15 +159,24 @@ class XmppController < ApplicationController
|
|
159
159
|
|
160
160
|
def test
|
161
161
|
puts "TEST"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
162
|
+
|
163
|
+
#XMPP DOMAIN
|
164
|
+
domain = SocialStream::Presence.domain
|
165
|
+
#PASSWORD
|
166
|
+
password= SocialStream::Presence.password
|
167
|
+
#SS Username
|
168
|
+
ss_name = SocialStream::Presence.social_stream_presence_username
|
169
|
+
|
170
|
+
ss_sid = ss_name + "@" + domain
|
171
|
+
client = Jabber::Client.new(Jabber::JID.new(ss_sid))
|
172
|
+
client.connect
|
173
|
+
client.auth(password)
|
166
174
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
175
|
+
#Sending a message
|
176
|
+
msg = Jabber::Message::new(ss_sid, "Message&order")
|
177
|
+
msg.type=:chat
|
178
|
+
client.send(msg)
|
179
|
+
client.close()
|
171
180
|
end
|
172
181
|
|
173
182
|
|
@@ -1,33 +1,20 @@
|
|
1
1
|
module XmppHelper
|
2
|
+
|
2
3
|
def getChatContacts
|
3
4
|
connected_users = []
|
4
|
-
|
5
|
+
|
6
|
+
#Get bidirectional contacts
|
7
|
+
contacts = current_user.contact_actors(:type=>:user)
|
8
|
+
|
9
|
+
#Apply filters
|
10
|
+
|
5
11
|
contacts.each do |contact|
|
6
|
-
if
|
7
|
-
connected_users << contact.
|
12
|
+
if contact.user.connected
|
13
|
+
connected_users << contact.user
|
8
14
|
end
|
9
15
|
end
|
10
|
-
|
16
|
+
|
11
17
|
return connected_users
|
12
18
|
end
|
13
|
-
|
14
|
-
def getBidirectionalContacts
|
15
|
-
#Code for new SS Version
|
16
|
-
# return current_user.contact_actors(:direction => :both)
|
17
|
-
|
18
|
-
contacts = []
|
19
|
-
csenders = current_user.sent_contacts
|
20
|
-
creceivers = current_user.received_contacts
|
21
|
-
|
22
|
-
csenders.each do |csender|
|
23
|
-
creceivers.each do |creceiver|
|
24
|
-
if ((csender.sender.name == creceiver.receiver.name) && (csender.receiver.name == creceiver.sender.name))
|
25
|
-
contacts << csender
|
26
|
-
break
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
return contacts
|
31
|
-
end
|
32
19
|
|
33
20
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
<% if current_subject.subject_type=="User" %>
|
2
|
+
|
3
|
+
<% content_for :headers do %>
|
2
4
|
<%= stylesheet_link_tag "chat.css", :media => "screen, projection" %>
|
3
5
|
<%= javascript_include_tag 'jquery-ui-1.8.14.custom.min'%>
|
4
6
|
<%= javascript_include_tag 'jquery.ui.chatbox'%>
|
@@ -12,8 +14,8 @@
|
|
12
14
|
<script type="text/javascript">
|
13
15
|
|
14
16
|
//Global variables
|
15
|
-
var BOSH_SERVICE = '<%=
|
16
|
-
var domain = '<%=
|
17
|
+
var BOSH_SERVICE = '<%=SocialStream::Presence.bosh_service%>';
|
18
|
+
var domain = '<%=SocialStream::Presence.domain%>';
|
17
19
|
var user_name = '<%=current_user.name%>';
|
18
20
|
var user_slug = '<%=current_user.slug%>';
|
19
21
|
var user_jid = '<%=current_user.slug%>'+"@"+domain;
|
@@ -53,7 +55,7 @@
|
|
53
55
|
</script>
|
54
56
|
|
55
57
|
<div id="chat_partial">
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
<%= render :partial => 'xmpp/chat_connecting' %>
|
59
|
+
</div>
|
60
|
+
|
61
|
+
<% end %>
|
@@ -31,5 +31,5 @@
|
|
31
31
|
<label for="user_password" class="chatPasswordTitle">Password</label>
|
32
32
|
<input id="user_password" class="chat_password" type="password"></input>
|
33
33
|
</div>
|
34
|
-
<input class="
|
34
|
+
<input class="connectChatButton storePass" value="Connect">
|
35
35
|
</div>
|
@@ -7,6 +7,18 @@ module SocialStream
|
|
7
7
|
autoload :BuddyManager, 'social_stream/presence/models/buddy_manager'
|
8
8
|
end
|
9
9
|
|
10
|
+
mattr_accessor :domain
|
11
|
+
mattr_accessor :bosh_service
|
12
|
+
mattr_accessor :password
|
13
|
+
mattr_accessor :xmpp_server_password
|
14
|
+
mattr_accessor :social_stream_presence_username
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def setup
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
end
|
11
23
|
end
|
12
24
|
|
@@ -1,9 +1,5 @@
|
|
1
1
|
module Socialstream
|
2
2
|
module Presence
|
3
|
-
DOMAIN = "trapo"
|
4
|
-
BOSH_SERVICE = "http://localhost:8080/http-bind"
|
5
|
-
PASSWORD = "DnVCB8G|R$VGmZ@2?5=CYS8z)NrL@LuQ<CUh^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"
|
6
|
-
XMPP_SERVER_PASSWORD = "G&s6GBnO)anw2Ene%K12Cb=0quj@uDmA"
|
7
3
|
VERSION = "0.0.3"
|
8
4
|
end
|
9
5
|
end
|
@@ -18,29 +18,42 @@ module SocialStream
|
|
18
18
|
|
19
19
|
initializer "social_stream-presence.synchronize" do
|
20
20
|
#Synchronize User Presence
|
21
|
-
#
|
21
|
+
#Reset connected users when XMMP Server Down
|
22
22
|
Thread.start {
|
23
23
|
begin
|
24
|
-
|
24
|
+
#XMPP DOMAIN
|
25
|
+
domain = SocialStream::Presence.domain
|
26
|
+
#PASSWORD
|
27
|
+
password= SocialStream::Presence.password
|
28
|
+
#SS Username
|
29
|
+
ss_name = SocialStream::Presence.social_stream_presence_username
|
30
|
+
|
31
|
+
ss_sid = ss_name + "@" + domain
|
32
|
+
client = Jabber::Client.new(Jabber::JID.new(ss_sid))
|
25
33
|
client.connect
|
26
|
-
password = Socialstream::Presence::PASSWORD
|
27
34
|
client.auth(password)
|
28
35
|
|
29
|
-
msg = Jabber::Message::new(
|
36
|
+
msg = Jabber::Message::new(ss_sid, "Synchronize")
|
30
37
|
msg.type=:chat
|
31
38
|
client.send(msg)
|
32
39
|
client.close()
|
33
40
|
|
34
|
-
rescue
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
rescue Exception => e
|
42
|
+
case e
|
43
|
+
when Errno::ECONNREFUSED
|
44
|
+
begin
|
45
|
+
users = User.find_all_by_connected(true)
|
46
|
+
users.each do |user|
|
47
|
+
user.connected = false
|
48
|
+
user.save!
|
49
|
+
end
|
50
|
+
puts "Connection to XMPP Server refused: Reset Connected Users"
|
51
|
+
rescue
|
52
|
+
end
|
53
|
+
else
|
54
|
+
puts "Unknown exception: #{e.to_s}"
|
55
|
+
end
|
56
|
+
end
|
44
57
|
}
|
45
58
|
end
|
46
59
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "social_stream/presence/config"
|
2
1
|
require 'xmpp4r'
|
3
2
|
require 'xmpp4r/muc'
|
4
3
|
require 'xmpp4r/roster'
|
@@ -18,16 +17,18 @@ module SocialStream
|
|
18
17
|
module InstanceMethods
|
19
18
|
|
20
19
|
def save_buddy
|
21
|
-
|
20
|
+
|
22
21
|
unless self.receiver.subject_type == "User" and self.sender.subject_type == "User"
|
23
22
|
return
|
24
23
|
end
|
25
24
|
|
26
25
|
#XMPP DOMAIN
|
27
|
-
domain =
|
26
|
+
domain = SocialStream::Presence.domain
|
28
27
|
#PASSWORD
|
29
|
-
password=
|
30
|
-
|
28
|
+
password= SocialStream::Presence.password
|
29
|
+
#SS Username
|
30
|
+
ss_name = SocialStream::Presence.social_stream_presence_username
|
31
|
+
|
31
32
|
user_sid = self.sender.slug + "@" + domain
|
32
33
|
buddy_sid = self.receiver.slug + "@" + domain
|
33
34
|
buddy_name = self.receiver.name
|
@@ -40,19 +41,26 @@ module SocialStream
|
|
40
41
|
end
|
41
42
|
|
42
43
|
begin
|
43
|
-
|
44
|
+
ss_sid = ss_name + "@" + domain
|
45
|
+
client = Jabber::Client.new(Jabber::JID.new(ss_sid))
|
44
46
|
client.connect
|
45
|
-
password = Socialstream::Presence::PASSWORD
|
46
47
|
client.auth(password)
|
47
48
|
|
48
49
|
#Sending a message
|
49
50
|
#AddItemToRoster[UserSID,BuddySID,BuddyName,Subscription_type]
|
50
|
-
msg = Jabber::Message::new(
|
51
|
+
msg = Jabber::Message::new(ss_sid, "AddItemToRoster&" + user_sid + "&" + buddy_sid + "&" + buddy_name + "&" + sType)
|
51
52
|
msg.type=:chat
|
52
|
-
client.send(msg)
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
client.send(msg)
|
54
|
+
client.close()
|
55
|
+
|
56
|
+
rescue Exception => e
|
57
|
+
case e
|
58
|
+
when Errno::ECONNREFUSED
|
59
|
+
puts "Connection to XMPP Server refused"
|
60
|
+
else
|
61
|
+
puts "Unknown exception: #{e.to_s}"
|
62
|
+
end
|
63
|
+
end
|
56
64
|
|
57
65
|
end
|
58
66
|
|
data/social_stream.gemspec
CHANGED
@@ -11,8 +11,8 @@ 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.
|
15
|
-
s.add_runtime_dependency('social_stream-documents', '~> 0.3.
|
14
|
+
s.add_runtime_dependency('social_stream-base', '~> 0.9.20')
|
15
|
+
s.add_runtime_dependency('social_stream-documents', '~> 0.3.2')
|
16
16
|
s.add_runtime_dependency('social_stream-events', '~> 0.0.12')
|
17
17
|
|
18
18
|
# Development Gem dependencies
|
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:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 11
|
9
|
-
-
|
10
|
-
version: 0.11.
|
9
|
+
- 6
|
10
|
+
version: 0.11.6
|
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-
|
19
|
+
date: 2011-10-14 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:
|
30
|
+
hash: 19
|
31
31
|
segments:
|
32
32
|
- 0
|
33
33
|
- 9
|
34
|
-
-
|
35
|
-
version: 0.9.
|
34
|
+
- 20
|
35
|
+
version: 0.9.20
|
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:
|
46
|
+
hash: 23
|
47
47
|
segments:
|
48
48
|
- 0
|
49
49
|
- 3
|
50
|
-
-
|
51
|
-
version: 0.3.
|
50
|
+
- 2
|
51
|
+
version: 0.3.2
|
52
52
|
type: :runtime
|
53
53
|
version_requirements: *id002
|
54
54
|
- !ruby/object:Gem::Dependency
|
@@ -347,7 +347,6 @@ files:
|
|
347
347
|
- base/app/assets/images/mini-loading.gif
|
348
348
|
- base/app/assets/images/right.png
|
349
349
|
- base/app/assets/images/tipsy.gif
|
350
|
-
- base/app/assets/images/title_background.png
|
351
350
|
- base/app/assets/javascripts/activities.js.erb
|
352
351
|
- base/app/assets/javascripts/contacts.js
|
353
352
|
- base/app/assets/javascripts/conversations.js
|
@@ -512,6 +511,8 @@ files:
|
|
512
511
|
- base/app/views/conversations/show.js.erb
|
513
512
|
- base/app/views/devise/passwords/edit.html.erb
|
514
513
|
- base/app/views/devise/passwords/new.html.erb
|
514
|
+
- base/app/views/devise/registrations/_delete_account.html.erb
|
515
|
+
- base/app/views/devise/registrations/_edit_user.html.erb
|
515
516
|
- base/app/views/devise/registrations/edit.html.erb
|
516
517
|
- base/app/views/devise/registrations/new.html.erb
|
517
518
|
- base/app/views/devise/sessions/new.html.erb
|
@@ -781,7 +782,6 @@ files:
|
|
781
782
|
- base/vendor/assets/javascripts/jquery.watermarkinput.js
|
782
783
|
- base/vendor/assets/javascripts/menu.js
|
783
784
|
- base/vendor/assets/javascripts/superfish.js
|
784
|
-
- base/vendor/assets/javascripts/ui.checkbox.js
|
785
785
|
- base/vendor/assets/stylesheets/carousel.css
|
786
786
|
- base/vendor/assets/stylesheets/chosen-sprite.png
|
787
787
|
- base/vendor/assets/stylesheets/chosen.css
|
@@ -978,7 +978,7 @@ files:
|
|
978
978
|
- documents/spec/support/devise.rb
|
979
979
|
- documents/spec/support/mock.rb
|
980
980
|
- documents/vendor/assets/javascripts/jquery.jplayer.js
|
981
|
-
- documents/vendor/assets/javascripts/jquery.lightbox.
|
981
|
+
- documents/vendor/assets/javascripts/jquery.lightbox-with-resize-plugin.js
|
982
982
|
- documents/vendor/assets/stylesheets/jplayer.blue.monday.css
|
983
983
|
- documents/vendor/assets/stylesheets/jplayer.blue.monday.jpg
|
984
984
|
- documents/vendor/assets/stylesheets/jplayer.blue.monday.video.play.hover.png
|
@@ -1114,7 +1114,6 @@ files:
|
|
1114
1114
|
- presence/Rakefile
|
1115
1115
|
- presence/app/assets/audio/chat/onMessageAudio.mp3
|
1116
1116
|
- presence/app/assets/audio/chat/onMessageAudio.wav
|
1117
|
-
- presence/app/assets/images/arrow.png
|
1118
1117
|
- presence/app/assets/images/black_arrow3.png
|
1119
1118
|
- presence/app/assets/images/status/available.png
|
1120
1119
|
- presence/app/assets/images/status/away.png
|
Binary file
|
@@ -1,309 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @author alexander.farkas
|
3
|
-
* @version 1.4.1
|
4
|
-
*/
|
5
|
-
$(document).ready(function() {
|
6
|
-
|
7
|
-
var baseClasses = /ui-checkbox|ui-radio/;
|
8
|
-
$.widget('ui.checkBox', {
|
9
|
-
options: {
|
10
|
-
hideInput: true,
|
11
|
-
addVisualElement: true,
|
12
|
-
addLabel: true,
|
13
|
-
_delegated: false
|
14
|
-
},
|
15
|
-
_create: function(){
|
16
|
-
var that = this,
|
17
|
-
opts = this.options
|
18
|
-
;
|
19
|
-
|
20
|
-
if(!this.element.is(':radio,:checkbox')){
|
21
|
-
if($.nodeName(this.element[0], 'input')){return false;}
|
22
|
-
this._addDelegate();
|
23
|
-
this.updateContainer();
|
24
|
-
return false;
|
25
|
-
}
|
26
|
-
this.labels = $([]);
|
27
|
-
|
28
|
-
this.checkedStatus = false;
|
29
|
-
this.disabledStatus = false;
|
30
|
-
this.hoverStatus = false;
|
31
|
-
|
32
|
-
this.radio = (this.element.is(':radio'));
|
33
|
-
|
34
|
-
this.visualElement = $([]);
|
35
|
-
if (opts.hideInput) {
|
36
|
-
this.element
|
37
|
-
.addClass('ui-helper-hidden-accessible')
|
38
|
-
;
|
39
|
-
if(opts.addVisualElement){
|
40
|
-
this.visualElement = $('<span />')
|
41
|
-
.addClass(this.radio ? 'ui-radio' : 'ui-checkbox')
|
42
|
-
;
|
43
|
-
this.element.after(this.visualElement[0]);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
if(opts.addLabel){
|
48
|
-
this.labels = $('label[for=' + this.element.attr('id') + ']')
|
49
|
-
.addClass(this.radio ? 'ui-radio' : 'ui-checkbox')
|
50
|
-
;
|
51
|
-
}
|
52
|
-
if(!opts._delegated){
|
53
|
-
this._addEvents();
|
54
|
-
}
|
55
|
-
this.initialized = true;
|
56
|
-
this.reflectUI({type: 'initialReflect'});
|
57
|
-
return undefined;
|
58
|
-
},
|
59
|
-
updateContainer: function(){
|
60
|
-
if(!this.element.is(':radio,:checkbox') && !$.nodeName(this.element[0], 'input')){
|
61
|
-
$('input', this.element[0])
|
62
|
-
.filter(function(){
|
63
|
-
return !($.data(this, 'checkBox'));
|
64
|
-
})
|
65
|
-
.checkBox($.extend({}, this.options, {_delegated: true}))
|
66
|
-
;
|
67
|
-
}
|
68
|
-
},
|
69
|
-
_addDelegate: function(){
|
70
|
-
var opts = this.options,
|
71
|
-
|
72
|
-
toggleHover = function(e, that){
|
73
|
-
if(!that){return;}
|
74
|
-
that.hover = !!(e.type == 'focus' || e.type == 'mouseenter' || e.type == 'focusin' || e.type == 'mouseover');
|
75
|
-
that._changeStateClassChain.call(that);
|
76
|
-
return undefined;
|
77
|
-
}
|
78
|
-
;
|
79
|
-
|
80
|
-
|
81
|
-
this.element
|
82
|
-
.bind('click', function(e){
|
83
|
-
if(!$.nodeName(e.target, 'input')){return;}
|
84
|
-
var inst = ($.data(e.target) || {}).checkBox;
|
85
|
-
if(!inst){return;}
|
86
|
-
inst.reflectUI.call(inst, e.target, e);
|
87
|
-
})
|
88
|
-
.bind('focusin.checkBox focusout.checkBox', function(e){
|
89
|
-
if(!$.nodeName(e.target, 'input')){return;}
|
90
|
-
var inst = ($.data(e.target) || {}).checkBox;
|
91
|
-
toggleHover(e, inst);
|
92
|
-
})
|
93
|
-
;
|
94
|
-
|
95
|
-
if (opts.hideInput){
|
96
|
-
this.element
|
97
|
-
.bind('usermode', function(e){
|
98
|
-
if(!e.enabled){return;}
|
99
|
-
$('input', this).each(function(){
|
100
|
-
var inst = ($.data(this) || {}).checkBox;
|
101
|
-
(inst && inst.destroy.call(inst, true));
|
102
|
-
});
|
103
|
-
})
|
104
|
-
;
|
105
|
-
}
|
106
|
-
|
107
|
-
if(opts.addVisualElement){
|
108
|
-
this.element
|
109
|
-
.bind('mouseover.checkBox mouseout.checkBox', function(e){
|
110
|
-
if(!$.nodeName(e.target, 'span')){return;}
|
111
|
-
var inst = ( $.data($(e.target).prev()[0]) || {} ).checkBox;
|
112
|
-
toggleHover(e, inst);
|
113
|
-
})
|
114
|
-
.bind('click.checkBox', function(e){
|
115
|
-
if(!$.nodeName(e.target, 'span') || !baseClasses.test( e.target.className || '' )){return;}
|
116
|
-
$(e.target).prev()[0].click();
|
117
|
-
return false;
|
118
|
-
})
|
119
|
-
;
|
120
|
-
}
|
121
|
-
if(opts.addLabel){
|
122
|
-
this.element
|
123
|
-
.delegate('label.ui-radio, label.ui-checkbox', 'mouseenter.checkBox mouseleave.checkBox', function(e){
|
124
|
-
var inst = ( $.data(document.getElementById( $(this).attr('for') )) || {} ).checkBox;
|
125
|
-
toggleHover( e, inst );
|
126
|
-
});
|
127
|
-
}
|
128
|
-
|
129
|
-
},
|
130
|
-
_addEvents: function(){
|
131
|
-
var that = this,
|
132
|
-
|
133
|
-
opts = this.options,
|
134
|
-
|
135
|
-
toggleHover = function(e){
|
136
|
-
if(that.disabledStatus){
|
137
|
-
return false;
|
138
|
-
}
|
139
|
-
that.hover = (e.type == 'focus' || e.type == 'mouseenter');
|
140
|
-
that._changeStateClassChain();
|
141
|
-
return undefined;
|
142
|
-
}
|
143
|
-
;
|
144
|
-
|
145
|
-
this.element
|
146
|
-
.bind('click.checkBox', $.proxy(this, 'reflectUI'))
|
147
|
-
.bind('focus.checkBox blur.checkBox', toggleHover)
|
148
|
-
;
|
149
|
-
if (opts.hideInput){
|
150
|
-
this.element
|
151
|
-
.bind('usermode', function(e){
|
152
|
-
(e.enabled &&
|
153
|
-
that.destroy.call(that, true));
|
154
|
-
})
|
155
|
-
;
|
156
|
-
}
|
157
|
-
if(opts.addVisualElement){
|
158
|
-
this.visualElement
|
159
|
-
.bind('mouseenter.checkBox mouseleave.checkBox', toggleHover)
|
160
|
-
.bind('click.checkBox', function(e){
|
161
|
-
that.element[0].click();
|
162
|
-
return false;
|
163
|
-
})
|
164
|
-
;
|
165
|
-
}
|
166
|
-
if(opts.addLabel){
|
167
|
-
this.labels.bind('mouseenter.checkBox mouseleave.checkBox', toggleHover);
|
168
|
-
}
|
169
|
-
},
|
170
|
-
_changeStateClassChain: function(){
|
171
|
-
var allElements = this.labels.add(this.visualElement),
|
172
|
-
stateClass = '',
|
173
|
-
baseClass = 'ui-'+((this.radio) ? 'radio' : 'checkbox')
|
174
|
-
;
|
175
|
-
|
176
|
-
if(this.checkedStatus){
|
177
|
-
stateClass += '-checked';
|
178
|
-
allElements.addClass(baseClass+'-checked');
|
179
|
-
} else {
|
180
|
-
allElements.removeClass(baseClass+'-checked');
|
181
|
-
}
|
182
|
-
|
183
|
-
if(this.disabledStatus){
|
184
|
-
stateClass += '-disabled';
|
185
|
-
allElements.addClass(baseClass+'-disabled');
|
186
|
-
} else {
|
187
|
-
allElements.removeClass(baseClass+'-disabled');
|
188
|
-
}
|
189
|
-
if(this.hover){
|
190
|
-
stateClass += '-hover';
|
191
|
-
allElements.addClass(baseClass+'-hover');
|
192
|
-
} else {
|
193
|
-
allElements.removeClass(baseClass+'-hover');
|
194
|
-
}
|
195
|
-
|
196
|
-
baseClass += '-state';
|
197
|
-
if(stateClass){
|
198
|
-
stateClass = baseClass + stateClass;
|
199
|
-
}
|
200
|
-
|
201
|
-
function switchStateClass(){
|
202
|
-
var classes = this.className.split(' '),
|
203
|
-
found = false;
|
204
|
-
$.each(classes, function(i, classN){
|
205
|
-
if(classN.indexOf(baseClass) === 0){
|
206
|
-
found = true;
|
207
|
-
classes[i] = stateClass;
|
208
|
-
return false;
|
209
|
-
}
|
210
|
-
return undefined;
|
211
|
-
});
|
212
|
-
if(!found){
|
213
|
-
classes.push(stateClass);
|
214
|
-
}
|
215
|
-
this.className = classes.join(' ');
|
216
|
-
}
|
217
|
-
|
218
|
-
this.labels.each(switchStateClass);
|
219
|
-
this.visualElement.each(switchStateClass);
|
220
|
-
},
|
221
|
-
destroy: function(onlyCss){
|
222
|
-
this.element.removeClass('ui-helper-hidden-accessible');
|
223
|
-
if(this.visualElement){
|
224
|
-
this.visualElement.addClass('ui-helper-hidden');
|
225
|
-
}
|
226
|
-
if (!onlyCss) {
|
227
|
-
var o = this.options;
|
228
|
-
this.element.unbind('.checkBox');
|
229
|
-
if(this.visualElement){
|
230
|
-
this.visualElement.remove();
|
231
|
-
}
|
232
|
-
if(this.labels){
|
233
|
-
this.labels.unbind('.checkBox').removeClass('ui-state-hover ui-state-checked ui-state-disabled');
|
234
|
-
}
|
235
|
-
}
|
236
|
-
},
|
237
|
-
|
238
|
-
disable: function(){
|
239
|
-
this.element[0].disabled = true;
|
240
|
-
this.reflectUI({type: 'manuallyDisabled'});
|
241
|
-
},
|
242
|
-
|
243
|
-
enable: function(){
|
244
|
-
this.element[0].disabled = false;
|
245
|
-
this.reflectUI({type: 'manuallyenabled'});
|
246
|
-
},
|
247
|
-
|
248
|
-
toggle: function(e){
|
249
|
-
this.changeCheckStatus((this.element.is(':checked')) ? false : true, e);
|
250
|
-
},
|
251
|
-
|
252
|
-
changeCheckStatus: function(status, e){
|
253
|
-
if(e && e.type == 'click' && this.element[0].disabled){
|
254
|
-
return false;
|
255
|
-
}
|
256
|
-
this.element.attr({'checked': status});
|
257
|
-
this.reflectUI(e || {
|
258
|
-
type: 'changeCheckStatus'
|
259
|
-
});
|
260
|
-
return undefined;
|
261
|
-
},
|
262
|
-
|
263
|
-
propagate: function(n, e, _noGroupReflect){
|
264
|
-
if(!e || e.type != 'initialReflect'){
|
265
|
-
if (this.radio && !_noGroupReflect) {
|
266
|
-
//dynamic
|
267
|
-
$(document.getElementsByName(this.element.attr('name')))
|
268
|
-
.checkBox('reflectUI', e, true);
|
269
|
-
}
|
270
|
-
return this._trigger(n, e, {
|
271
|
-
options: this.options,
|
272
|
-
checked: this.checkedStatus,
|
273
|
-
labels: this.labels,
|
274
|
-
disabled: this.disabledStatus
|
275
|
-
});
|
276
|
-
}
|
277
|
-
return undefined;
|
278
|
-
},
|
279
|
-
|
280
|
-
reflectUI: function(e){
|
281
|
-
|
282
|
-
var oldChecked = this.checkedStatus,
|
283
|
-
oldDisabledStatus = this.disabledStatus;
|
284
|
-
|
285
|
-
this.disabledStatus = this.element.is(':disabled');
|
286
|
-
this.checkedStatus = this.element.is(':checked');
|
287
|
-
|
288
|
-
if (this.disabledStatus != oldDisabledStatus || this.checkedStatus !== oldChecked) {
|
289
|
-
|
290
|
-
//Change status callback
|
291
|
-
|
292
|
-
if (this.checkedStatus==true){
|
293
|
-
var id = this.element[0].id;
|
294
|
-
checkBoxEnable(id);
|
295
|
-
} else if (this.checkedStatus==false){
|
296
|
-
var id = this.element[0].id;
|
297
|
-
checkBoxDisable(id);
|
298
|
-
}
|
299
|
-
|
300
|
-
this._changeStateClassChain();
|
301
|
-
|
302
|
-
(this.disabledStatus != oldDisabledStatus && this.propagate('disabledChange', e));
|
303
|
-
|
304
|
-
(this.checkedStatus !== oldChecked && this.propagate('change', e));
|
305
|
-
}
|
306
|
-
|
307
|
-
}
|
308
|
-
});
|
309
|
-
});
|