social_stream 0.26.1 → 0.26.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.rdoc +10 -0
  2. data/base/lib/social_stream/base/version.rb +1 -1
  3. data/base/social_stream-base.gemspec +1 -1
  4. data/lib/social_stream/release/component.rb +5 -0
  5. data/lib/social_stream/release/global.rb +8 -7
  6. data/lib/social_stream/release/kernel.rb +24 -0
  7. data/lib/social_stream/version.rb +1 -1
  8. data/presence/app/assets/javascripts/jquery.flexselect.sstreampresence.js +2 -2
  9. data/presence/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +5 -5
  10. data/presence/app/assets/javascripts/presence.js.erb +6 -4
  11. data/presence/app/assets/javascripts/presence_XmppClient.js.erb +1146 -996
  12. data/presence/app/assets/javascripts/presence_audio.js.erb +74 -60
  13. data/presence/app/assets/javascripts/presence_game.js.erb +35 -22
  14. data/presence/app/assets/javascripts/presence_game_comunication.js.erb +22 -5
  15. data/presence/app/assets/javascripts/presence_game_factory.js.erb +1 -1
  16. data/presence/app/assets/javascripts/presence_game_interface.js.erb +33 -13
  17. data/presence/app/assets/javascripts/presence_notifications.js +206 -183
  18. data/presence/app/assets/javascripts/presence_parser.js +265 -247
  19. data/presence/app/assets/javascripts/presence_persistence.js +199 -188
  20. data/presence/app/assets/javascripts/presence_store.js +22 -11
  21. data/presence/app/assets/javascripts/presence_uiManager.js.erb +553 -530
  22. data/presence/app/assets/javascripts/presence_utilities.js +244 -219
  23. data/presence/app/assets/javascripts/presence_videochat.js.erb +436 -409
  24. data/presence/app/assets/javascripts/presence_windowManager.js +586 -532
  25. data/presence/app/views/chat/_index.html.erb +7 -13
  26. data/presence/config/locales/en.yml +2 -1
  27. data/presence/config/locales/es.yml +2 -1
  28. data/presence/ejabberd/ejabberd_files.zip +0 -0
  29. data/presence/ejabberd/ejabberd_scripts/authentication_script +9 -2
  30. data/presence/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  31. data/presence/lib/generators/social_stream/presence/templates/initializer.rb +4 -0
  32. data/presence/lib/social_stream-presence.rb +3 -0
  33. data/presence/lib/social_stream/presence/version.rb +1 -1
  34. data/presence/lib/social_stream/presence/xmpp_server_order.rb +1 -0
  35. data/release.thor +33 -13
  36. data/social_stream.gemspec +2 -2
  37. metadata +90 -29
@@ -1,191 +1,214 @@
1
- ////////////////////
2
- //Chat Boxes Notifications
3
- ////////////////////
1
+ PRESENCE.NOTIFICATIONS = (function(P,$,undefined){
4
2
 
5
- function fadeInChatNotification(notification){
6
- if(notification!=null){
7
- notification.css("display","block");
8
- notification.css("visibility","visible");
9
- notification.fadeIn();
10
- }
11
- }
12
-
13
- function showChatNotification(notification,type,msg){
14
- notification.html("<p notification_type=\"" + type + "\" class=\"ui-chatbox-notify-text\">" + msg + "</p>");
15
- fadeInChatNotification(notification);
16
- }
17
-
18
- function showChatNotificationForSlug(slug,type,msg){
19
- var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
20
- if(notification.length==1){
21
- showChatNotification(notification,type,msg);
22
- }
23
- }
24
-
25
- function showOfflineChatNotificationForSlug(slug){
26
- var msg = I18n.t("chat.notify.guestOffline", {name: getNameFromSlug(slug)});
27
- showChatNotificationForSlug(slug,"guestOffline",msg);
28
- }
3
+ var init = function(){ }
29
4
 
30
- function showVideoChatNotificationForSlug(slug,msg){
31
- showChatNotificationForSlug(slug,"videochat",msg);
32
- }
33
5
 
34
- function showVideoChatNotificationForSlugClientIssue(slug){
35
- var msg = I18n.t("chat.notify.videochat.clientIssue", {name: getNameFromSlug(slug)});
36
- showVideoChatNotificationForSlug(slug,msg);
37
- }
38
-
39
- function showVideoChatNotificationForSlugClientOffline(slug){
40
- var msg = I18n.t("chat.notify.videochat.offline", {name: getNameFromSlug(slug)});
41
- showVideoChatNotificationForSlug(slug,msg);
42
- }
43
-
44
- function fadeOutChatNotification(notification){
45
- if(notification!=null){
46
- notification.fadeOut();
47
- notification.css("display","none");
48
- notification.css("visibility","hidden");
6
+ ////////////////////
7
+ //Chat Boxes Notifications
8
+ ////////////////////
9
+
10
+ var fadeInChatNotification = function(notification){
11
+ if(notification!=null){
12
+ notification.css("display","block");
13
+ notification.css("visibility","visible");
14
+ notification.fadeIn();
15
+ }
49
16
  }
50
- }
51
-
52
- function hideChatNotificationForSlug(slug){
53
- var notification = getChatNotificationForSlug(slug);
54
- fadeOutChatNotification(notification);
55
- }
56
-
57
- function updateNotificationsAfterUserDisconnect(){
58
- var notification = $("div.ui-chatbox-notify");
59
- var msg = I18n.t('chat.notify.offline');
60
- showChatNotification(notification,"userOffline",msg);
61
- }
62
-
63
- function hideAllNotifications(){
64
- var notification = $("div.ui-chatbox-notify");
65
- fadeOutChatNotification(notification);
66
- }
67
-
68
- function updateAllNotifications(){
69
- hideAllNotifications();
70
- if(disconnectionFlag){
71
- updateNotificationsAfterUserDisconnect();
72
- } else {
73
- //Notification for offline contacts
74
- $.each(getAllDisconnectedSlugsWithChatBoxes(), function(index, value) {
75
- if(!isSlugGroup(value)){
76
- showOfflineChatNotificationForSlug(value)
77
- }
78
- });
79
- }
80
- }
81
-
82
- function getChatNotificationForSlug(slug){
83
- var chatBox = getChatBoxForSlug(slug)
84
- if(chatBox!=null){
85
- var notification = chatBox.parent().find("div.ui-chatbox-notify");
86
- if (notification.length == 1) {
87
- return notification;
88
- }
89
- }
90
- return null;
91
- }
92
-
93
- function getNotificationType(notification){
94
- return $(notification).find("p").attr("notification_type");
95
- }
96
-
97
- function addTextToNotification(notification,txt,type,name){
98
- var new_p = document.createElement('p')
99
- $(new_p).attr("class","ui-chatbox-notify-text")
100
- $(new_p).attr("notification_type",type)
101
- $(new_p).html(txt)
102
- if(name!=null){
103
- $(new_p).attr("name",name)
104
- }
105
- $(notification).append(new_p)
106
- fadeInChatNotification(notification)
107
- }
108
-
109
- function removeTextFromNotification(notification,name){
110
- var p = $(notification).find("p.ui-chatbox-notify-text[name=" + name + "]")
111
- if (p!=null){
112
- p.remove()
113
- var empty = ($(notification).find("p").length==0)
114
- if (empty){
115
- fadeOutChatNotification(notification)
116
- }
117
- }
118
- }
119
-
120
- function removeAllTextsFromNotification(notification){
121
- var p = $(notification).find("p.ui-chatbox-notify-text")
122
- if (p!=null){
123
- p.remove()
124
- var empty = ($(notification).find("p").length==0)
125
- if (empty){
126
- fadeOutChatNotification(notification)
127
- }
128
- }
129
- }
130
-
131
- function addTextToNotificationForSlug(slug,txt,type,name){
132
- var notification = getChatNotificationForSlug(slug);
133
- if(notification!=null){
134
- addTextToNotification(notification,txt,type,name)
135
- }
136
- }
137
-
138
- function removeTextFromNotificationForSlug(slug,name){
139
- var notification = getChatNotificationForSlug(slug);
140
- if(notification!=null){
141
- removeTextFromNotification(notification,name)
142
- }
143
- }
144
-
145
- function removeAllTextsFromNotificationForSlug(slug){
146
- var notification = getChatNotificationForSlug(slug);
147
- if(notification!=null){
148
- removeAllTextsFromNotification(notification)
149
- }
150
- }
151
-
152
-
153
- ////////////////////////
154
- // Group notifications
155
- ///////////////////////
156
-
157
- function addNickToNotificationInGroup(roomName,nick){
158
- if(isSlugGroup(roomName)){
159
- addTextToNotificationForSlug(roomName,nick,"roomNotification",nick)
160
- }
161
- }
162
-
163
- function removeNickFromNotificationInGroup(roomName,nick){
164
- if(isSlugGroup(roomName)){
165
- removeTextFromNotificationForSlug(roomName,nick)
166
- }
167
- }
168
-
169
- function initialNotificationInGroup(roomName,msg){
170
- removeAllTextsFromNotificationForSlug(roomName);
171
- addTextToNotificationForSlug(roomName,msg,"roomNotification","Initial_Notification")
172
- }
173
-
174
- function changeInitialNotificationInGroup(roomName,msg){
175
- var notification = getChatNotificationForSlug(roomName);
176
- if(notification!=null){
177
- $(notification).find("p.ui-chatbox-notify-text[name=" + "Initial_Notification" + "]").html(msg)
17
+
18
+ var showChatNotification = function(notification,type,msg){
19
+ notification.html("<p notification_type=\"" + type + "\" class=\"ui-chatbox-notify-text\">" + msg + "</p>");
20
+ fadeInChatNotification(notification);
21
+ }
22
+
23
+ var showChatNotificationForSlug = function(slug,type,msg){
24
+ var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
25
+ if(notification.length==1){
26
+ showChatNotification(notification,type,msg);
27
+ }
178
28
  }
179
- }
29
+
30
+ var showOfflineChatNotificationForSlug = function(slug){
31
+ var msg = I18n.t("chat.notify.guestOffline", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)});
32
+ showChatNotificationForSlug(slug,"guestOffline",msg);
33
+ }
34
+
35
+ var showVideoChatNotificationForSlug = function(slug,msg){
36
+ showChatNotificationForSlug(slug,"videochat",msg);
37
+ }
38
+
39
+ var showVideoChatNotificationForSlugClientIssue = function(slug){
40
+ var msg = I18n.t("chat.notify.videochat.clientIssue", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)});
41
+ showVideoChatNotificationForSlug(slug,msg);
42
+ }
43
+
44
+ var showVideoChatNotificationForSlugClientOffline = function(slug){
45
+ var msg = I18n.t("chat.notify.videochat.offline", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)});
46
+ showVideoChatNotificationForSlug(slug,msg);
47
+ }
48
+
49
+ var fadeOutChatNotification = function(notification){
50
+ if(notification!=null){
51
+ notification.fadeOut();
52
+ notification.css("display","none");
53
+ notification.css("visibility","hidden");
54
+ }
55
+ }
56
+
57
+ var hideChatNotificationForSlug = function(slug){
58
+ var notification = getChatNotificationForSlug(slug);
59
+ fadeOutChatNotification(notification);
60
+ }
61
+
62
+ var updateNotificationsAfterUserDisconnect = function(){
63
+ var notification = $("div.ui-chatbox-notify");
64
+ var msg = I18n.t('chat.notify.offline');
65
+ showChatNotification(notification,"userOffline",msg);
66
+ }
67
+
68
+ var hideAllNotifications = function(){
69
+ var notification = $("div.ui-chatbox-notify");
70
+ fadeOutChatNotification(notification);
71
+ }
72
+
73
+ var updateAllNotifications = function(){
74
+ hideAllNotifications();
75
+ if(PRESENCE.XMPPClient.getDisconnectionFlag()){
76
+ updateNotificationsAfterUserDisconnect();
77
+ } else {
78
+ //Notification for offline contacts
79
+ $.each(PRESENCE.WINDOW.getAllDisconnectedSlugsWithChatBoxes(), function(index, value) {
80
+ if(!PRESENCE.WINDOW.isSlugGroup(value)){
81
+ showOfflineChatNotificationForSlug(value)
82
+ }
83
+ });
84
+ }
85
+ }
86
+
87
+ var getChatNotificationForSlug = function(slug){
88
+ var chatBox = PRESENCE.WINDOW.getChatBoxForSlug(slug)
89
+ if(chatBox!=null){
90
+ var notification = chatBox.parent().find("div.ui-chatbox-notify");
91
+ if (notification.length == 1) {
92
+ return notification;
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+
98
+ var getNotificationType = function(notification){
99
+ return $(notification).find("p").attr("notification_type");
100
+ }
101
+
102
+ var addTextToNotification = function(notification,txt,type,name){
103
+ var new_p = document.createElement('p')
104
+ $(new_p).attr("class","ui-chatbox-notify-text")
105
+ $(new_p).attr("notification_type",type)
106
+ $(new_p).html(txt)
107
+ if(name!=null){
108
+ $(new_p).attr("name",name)
109
+ }
110
+ $(notification).append(new_p)
111
+ fadeInChatNotification(notification)
112
+ }
113
+
114
+ var removeTextFromNotification = function(notification,name){
115
+ var p = $(notification).find("p.ui-chatbox-notify-text[name=" + name + "]")
116
+ if (p!=null){
117
+ p.remove()
118
+ var empty = ($(notification).find("p").length==0)
119
+ if (empty){
120
+ fadeOutChatNotification(notification)
121
+ }
122
+ }
123
+ }
124
+
125
+ var removeAllTextsFromNotification = function(notification){
126
+ var p = $(notification).find("p.ui-chatbox-notify-text")
127
+ if (p!=null){
128
+ p.remove()
129
+ var empty = ($(notification).find("p").length==0)
130
+ if (empty){
131
+ fadeOutChatNotification(notification)
132
+ }
133
+ }
134
+ }
135
+
136
+ var addTextToNotificationForSlug = function(slug,txt,type,name){
137
+ var notification = getChatNotificationForSlug(slug);
138
+ if(notification!=null){
139
+ addTextToNotification(notification,txt,type,name)
140
+ }
141
+ }
142
+
143
+ var removeTextFromNotificationForSlug = function(slug,name){
144
+ var notification = getChatNotificationForSlug(slug);
145
+ if(notification!=null){
146
+ removeTextFromNotification(notification,name)
147
+ }
148
+ }
149
+
150
+ var removeAllTextsFromNotificationForSlug = function(slug){
151
+ var notification = getChatNotificationForSlug(slug);
152
+ if(notification!=null){
153
+ removeAllTextsFromNotification(notification)
154
+ }
155
+ }
156
+
157
+
158
+ ////////////////////////
159
+ // Group notifications
160
+ ///////////////////////
161
+
162
+ var addNickToNotificationInGroup = function(roomName,nick){
163
+ if(PRESENCE.WINDOW.isSlugGroup(roomName)){
164
+ addTextToNotificationForSlug(roomName,nick,"roomNotification",nick)
165
+ }
166
+ }
167
+
168
+ var removeNickFromNotificationInGroup = function(roomName,nick){
169
+ if(PRESENCE.WINDOW.isSlugGroup(roomName)){
170
+ removeTextFromNotificationForSlug(roomName,nick)
171
+ }
172
+ }
173
+
174
+ var initialNotificationInGroup = function(roomName,msg){
175
+ removeAllTextsFromNotificationForSlug(roomName);
176
+ addTextToNotificationForSlug(roomName,msg,"roomNotification","Initial_Notification")
177
+ }
178
+
179
+ var changeInitialNotificationInGroup = function(roomName,msg){
180
+ var notification = getChatNotificationForSlug(roomName);
181
+ if(notification!=null){
182
+ $(notification).find("p.ui-chatbox-notify-text[name=" + "Initial_Notification" + "]").html(msg)
183
+ }
184
+ }
185
+
186
+
187
+ ////////////////////
188
+ //Events
189
+ ////////////////////
190
+
191
+ var onClickChatNotification = function(notification){
192
+ if (getNotificationType(notification)=="roomNotification"){
193
+ return;
194
+ }
195
+ fadeOutChatNotification(notification)
196
+ }
197
+
180
198
 
181
199
 
182
- ////////////////////
183
- //Events
184
- ////////////////////
200
+ return {
201
+ init: init,
202
+ showOfflineChatNotificationForSlug : showOfflineChatNotificationForSlug,
203
+ hideChatNotificationForSlug : hideChatNotificationForSlug,
204
+ updateNotificationsAfterUserDisconnect : updateNotificationsAfterUserDisconnect,
205
+ updateAllNotifications : updateAllNotifications,
206
+ addNickToNotificationInGroup : addNickToNotificationInGroup,
207
+ removeNickFromNotificationInGroup : removeNickFromNotificationInGroup,
208
+ initialNotificationInGroup : initialNotificationInGroup,
209
+ changeInitialNotificationInGroup : changeInitialNotificationInGroup,
210
+ onClickChatNotification : onClickChatNotification
211
+ };
212
+
213
+ }) (PRESENCE, jQuery);
185
214
 
186
- function onClickChatNotification(notification){
187
- if (getNotificationType(notification)=="roomNotification"){
188
- return;
189
- }
190
- fadeOutChatNotification(notification)
191
- }
@@ -1,257 +1,275 @@
1
1
  ////////////////////
2
- //Hash table
2
+ //Social Stream Presence: Parser module
3
3
  ////////////////////
4
- var chatIcons = new Array();
5
- chatIcons[':)'] = "face-smile.png";
6
- chatIcons[':('] = "face-sad.png";
7
- chatIcons['(B)'] = "beer.png";
8
- chatIcons['(C)'] = "clock.png";
9
- chatIcons['(P)'] = "present.png";
10
- chatIcons[':P']= "face-raspberry.png";
11
- chatIcons[':Z']= "face-tired.png";
12
- chatIcons['(R)']= "rain.png";
13
- chatIcons['(S)']= "sun.png";
14
- chatIcons[';)']= "face-wink.png";
15
4
 
16
- ///////////////////////////////////////////////////////
17
- // Parser functions
18
- // Allow new features in chat msg like links, images, emoticons, ...
19
- ///////////////////////////////////////////////////////
5
+ PRESENCE.PARSER = (function(P,$,undefined){
20
6
 
21
- //Patterns
22
- var html_tag_pattern=/.*\<[^>]+>.*/g
23
- var simple_word_pattern=/^[aA-zZ0-9]+$/g
24
- var http_urls_pattern=/(http(s)?:\/\/)([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
25
- var www_urls_pattern = /(www[.])([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
26
- var icons_a_pattern=/\([A-Z]\)/g
27
- var icons_b_pattern=/((:|;)([()A-Z]))/g
28
- var youtube_video_pattern=/(http(s)?:\/\/)?(((youtu.be\/)([aA-zZ0-9]+))|((www.youtube.com\/watch\?v=)([aA-z0-9Z&=.])+))/g
7
+ ////////////////////
8
+ //Hash table
9
+ ////////////////////
10
+ var chatIcons = new Array();
11
+ chatIcons[':)'] = "face-smile.png";
12
+ chatIcons[':('] = "face-sad.png";
13
+ chatIcons['(B)'] = "beer.png";
14
+ chatIcons['(C)'] = "clock.png";
15
+ chatIcons['(P)'] = "present.png";
16
+ chatIcons[':P']= "face-raspberry.png";
17
+ chatIcons[':Z']= "face-tired.png";
18
+ chatIcons['(R)']= "rain.png";
19
+ chatIcons['(S)']= "sun.png";
20
+ chatIcons[';)']= "face-wink.png";
29
21
 
22
+ var init = function(){ }
30
23
 
31
- function getParsedContent(content,fromUser){
32
- if (fromUser){
33
- var chatTextclass = "ownChatText"
34
- } else {
35
- var chatTextclass = "guestChatText"
36
- }
37
- return ("<span class=\"" + chatTextclass + "\">" + parseContent(content) + "</span>");
38
- }
39
-
40
-
41
- function parseContent(content){
42
-
43
- if (content.match(html_tag_pattern)!=null){
44
- content = content.replace(/>/g, "&gt;");
45
- content = content.replace(/</g, "&lt;");
46
- return "<pre>" + content + "</pre>"
47
- }
48
-
49
- var words = content.split(" ");
50
- for(i=0; i<words.length; i++){
51
- words[i] = parseWord(words[i]);
52
- }
53
-
54
- return words.join(" ");
55
- }
56
-
57
- function parseWord(word){
58
-
59
- //Look for empty or simple words
60
- if ((word.trim()=="")||(word.match(simple_word_pattern)!=null)){
61
- return word
62
- }
63
-
64
- //Look for http urls
65
- var http_urls = word.match(http_urls_pattern)
66
- if (http_urls!=null){
67
- var url = http_urls[0]
68
- var type = getUrlType(url);
69
-
70
- switch(type){
71
- case "link":
72
- var link = buildUrlLink(url,url)
73
- var subwords = splitFirst(word,url)
74
- return parseWord(subwords[0]) + link + parseWord(subwords[1])
75
- case "image":
76
- var imageLink = buildImageLink(url);
77
- var subwords = splitFirst(word,url)
78
- return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
79
- case "video-youtube":
80
- var youtubeLink = buildYoutubeVideoLink(url);
81
- var subwords = splitFirst(word,url)
82
- return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
83
- default:
84
- return word
85
- }
86
- }
87
-
88
-
89
- //Look for www urls
90
- var www_urls = word.match(www_urls_pattern)
91
- if (www_urls!=null){
92
- var url = www_urls[0]
93
- var type = getUrlType(url);
94
-
95
- switch(type){
96
- case "link":
97
- var link = buildUrlLink("http://" + url,url)
98
- var subwords = splitFirst(word,url)
99
- return parseWord(subwords[0]) + link + parseWord(subwords[1])
100
- case "image":
101
- var imageLink = buildImageLink("http://" + url);
102
- var subwords = splitFirst(word,url)
103
- return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
104
- case "video-youtube":
105
- var youtubeLink = buildYoutubeVideoLink("http://" + url);
106
- var subwords = splitFirst(word,url)
107
- return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
108
- default:
109
- return word
110
- }
111
- }
112
-
113
- //Look for icons: Regex
114
- var icons_a = word.match(icons_a_pattern)
115
- if(icons_a!=null){
116
- for(g=0; g<icons_a.length; g++){
117
- word = word.replace(buildRegex(icons_a[g]), buildIconImage(icons_a[g]))
118
- }
119
- }
120
-
121
- var icons_b = word.match(icons_b_pattern)
122
- if(icons_b!=null){
123
- for(h=0; h<icons_b.length; h++){
124
- word = word.replace(buildRegex(icons_b[h]), buildIconImage(icons_b[h]))
125
- }
126
- }
127
-
128
-
129
- //No special content detected (maybe emoticons but not special pattern like urls)
130
- return word
131
- }
132
-
133
- function splitFirst(word,key){
134
- var split=[]
135
- var cut = word.split(key);
136
- split[0]=cut[0]
137
- cut.shift()
138
- var paste = cut.join(key)
139
- split[1]=paste
140
- return split
141
- }
142
-
143
- function buildIconImage(icon){
144
- if (icon in chatIcons){
145
- var image_file = chatIcons[icon]
146
- return "<img class=\"chatEmoticon\" src=\"/assets/emoticons/" + image_file + "\"/>";
147
- }
148
- return icon
149
- }
150
-
151
- function buildUrlLink(url,name){
152
- return "<a target=\"_blank\" class=\"chatLink\" href=\"" + url + "\">" + name + "</a>";
153
- }
154
-
155
- function buildImageLink(url){
156
- return "<a target=\"_blank\" class=\"chatImageLink\" href=\"" + url + "\">" + "<img class=\"chatImage\" src=\"" + url + "\"/>" + "</a>";
157
- }
158
-
159
- function buildYoutubeVideoLink(url){
160
- //Get youtube video id
161
- var youtube_video_id=url.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
162
- var youtube_api_url = "http://gdata.youtube.com/feeds/api/videos/" + youtube_video_id
163
-
164
- //Get info from the video
165
- $.ajax({
166
- type: "GET",
167
- url: youtube_api_url,
168
- cache: false,
169
- dataType:'jsonp',
170
- success: function(data){
171
- var url_name = url;
172
- var youtube_video_thumbnail = "";
173
-
174
- //Video title
175
- var video_title = $(data).find("media\\:title")
176
- if (video_title.length > 0) {
177
- //url_name = url + " (" + $(video_title).text() + ")";
178
- url_name = $(video_title).text()
179
- }
180
-
181
- //Thumbnails
182
- var thumbnails = $(data).find("media\\:thumbnail")
183
- if (thumbnails.length>0){
184
- var thumbnail_url = $(thumbnails[0]).attr("url")
185
- if (thumbnail_url!=null){
186
- youtube_video_thumbnail = "<p><img class=\"chatVideoImage\" src=\"" + thumbnail_url + "\"/></p>";
187
- }
188
- }
189
-
190
- //Replace video link
191
- $("a[youtube_id=" + youtube_video_id + "]").html(buildUrlLink(url,url_name)+youtube_video_thumbnail);
192
- },
193
- error: function(xOptions, textStatus){
194
- //Handle errors
195
- }
196
- });
197
-
198
- return "<a target=\"_blank\" youtube_id=\"" + youtube_video_id + "\" class=\"chatLink\" href=\"" + url + "\">" + url + "</a>";
199
- }
200
-
201
- function buildRegex(word){
202
- word = word.replace(")","\\)")
203
- word = word.replace("(","\\(")
204
- var pattern = "(" + word + ")";
205
- pattern = buildPattern(pattern)
206
- return (new RegExp(pattern,'g'));
207
- }
208
24
 
209
- function buildPattern(pattern){
210
- //Escape pattern special characters
211
- pattern = pattern.replace("+","\\+")
212
- pattern = pattern.replace("?","\\?")
213
- return pattern
214
- }
215
-
216
-
217
- function getUrlType(url){
218
-
219
- if (url.match(youtube_video_pattern)!=null){
220
- return "video-youtube"
221
- }
222
-
223
- var urlArray = url.split(".");
224
- if (urlArray!=null && urlArray.length>0){
225
- var extension= urlArray[urlArray.length-1]
226
- } else {
227
- var extension = null;
228
- }
229
-
230
- switch(extension){
231
- case "jpg":
232
- return "image"
233
- break;
234
- case "png":
235
- return "image"
236
- break;
237
- case "gif":
238
- return "image"
239
- break;
240
- default:
241
- return "link"
242
- }
243
- }
25
+ ///////////////////////////////////////////////////////
26
+ // Parser functions
27
+ // Allow new features in chat msg like links, images, emoticons, ...
28
+ ///////////////////////////////////////////////////////
29
+
30
+ //Patterns
31
+ var html_tag_pattern=/.*\<[^>]+>.*/g
32
+ var simple_word_pattern=/^[aA-zZ0-9]+$/g
33
+ var http_urls_pattern=/(http(s)?:\/\/)([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
34
+ var www_urls_pattern = /(www[.])([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
35
+ var icons_a_pattern=/\([A-Z]\)/g
36
+ var icons_b_pattern=/((:|;)([()A-Z]))/g
37
+ var youtube_video_pattern=/(http(s)?:\/\/)?(((youtu.be\/)([aA-zZ0-9]+))|((www.youtube.com\/watch\?v=)([aA-z0-9Z&=.])+))/g
38
+
39
+
40
+ function getParsedContent(content,fromUser){
41
+ if (fromUser){
42
+ var chatTextclass = "ownChatText"
43
+ } else {
44
+ var chatTextclass = "guestChatText"
45
+ }
46
+ return ("<span class=\"" + chatTextclass + "\">" + parseContent(content) + "</span>");
47
+ }
48
+
49
+
50
+ function parseContent(content){
51
+
52
+ if (content.match(html_tag_pattern)!=null){
53
+ content = content.replace(/>/g, "&gt;");
54
+ content = content.replace(/</g, "&lt;");
55
+ return "<pre>" + content + "</pre>"
56
+ }
57
+
58
+ var words = content.split(" ");
59
+ for(i=0; i<words.length; i++){
60
+ words[i] = parseWord(words[i]);
61
+ }
62
+
63
+ return words.join(" ");
64
+ }
65
+
66
+ function parseWord(word){
67
+
68
+ //Look for empty or simple words
69
+ if ((word.trim()=="")||(word.match(simple_word_pattern)!=null)){
70
+ return word
71
+ }
72
+
73
+ //Look for http urls
74
+ var http_urls = word.match(http_urls_pattern)
75
+ if (http_urls!=null){
76
+ var url = http_urls[0]
77
+ var type = getUrlType(url);
78
+
79
+ switch(type){
80
+ case "link":
81
+ var link = buildUrlLink(url,url)
82
+ var subwords = splitFirst(word,url)
83
+ return parseWord(subwords[0]) + link + parseWord(subwords[1])
84
+ case "image":
85
+ var imageLink = buildImageLink(url);
86
+ var subwords = splitFirst(word,url)
87
+ return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
88
+ case "video-youtube":
89
+ var youtubeLink = buildYoutubeVideoLink(url);
90
+ var subwords = splitFirst(word,url)
91
+ return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
92
+ default:
93
+ return word
94
+ }
95
+ }
96
+
97
+
98
+ //Look for www urls
99
+ var www_urls = word.match(www_urls_pattern)
100
+ if (www_urls!=null){
101
+ var url = www_urls[0]
102
+ var type = getUrlType(url);
103
+
104
+ switch(type){
105
+ case "link":
106
+ var link = buildUrlLink("http://" + url,url)
107
+ var subwords = splitFirst(word,url)
108
+ return parseWord(subwords[0]) + link + parseWord(subwords[1])
109
+ case "image":
110
+ var imageLink = buildImageLink("http://" + url);
111
+ var subwords = splitFirst(word,url)
112
+ return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
113
+ case "video-youtube":
114
+ var youtubeLink = buildYoutubeVideoLink("http://" + url);
115
+ var subwords = splitFirst(word,url)
116
+ return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
117
+ default:
118
+ return word
119
+ }
120
+ }
121
+
122
+ //Look for icons: Regex
123
+ var icons_a = word.match(icons_a_pattern)
124
+ if(icons_a!=null){
125
+ for(g=0; g<icons_a.length; g++){
126
+ word = word.replace(buildRegex(icons_a[g]), buildIconImage(icons_a[g]))
127
+ }
128
+ }
129
+
130
+ var icons_b = word.match(icons_b_pattern)
131
+ if(icons_b!=null){
132
+ for(h=0; h<icons_b.length; h++){
133
+ word = word.replace(buildRegex(icons_b[h]), buildIconImage(icons_b[h]))
134
+ }
135
+ }
136
+
137
+
138
+ //No special content detected (maybe emoticons but not special pattern like urls)
139
+ return word
140
+ }
141
+
142
+ function splitFirst(word,key){
143
+ var split=[]
144
+ var cut = word.split(key);
145
+ split[0]=cut[0]
146
+ cut.shift()
147
+ var paste = cut.join(key)
148
+ split[1]=paste
149
+ return split
150
+ }
151
+
152
+ function buildIconImage(icon){
153
+ if (icon in chatIcons){
154
+ var image_file = chatIcons[icon]
155
+ return "<img class=\"chatEmoticon\" src=\"/assets/emoticons/" + image_file + "\"/>";
156
+ }
157
+ return icon
158
+ }
159
+
160
+ function buildUrlLink(url,name){
161
+ return "<a target=\"_blank\" class=\"chatLink\" href=\"" + url + "\">" + name + "</a>";
162
+ }
163
+
164
+ function buildImageLink(url){
165
+ return "<a target=\"_blank\" class=\"chatImageLink\" href=\"" + url + "\">" + "<img class=\"chatImage\" src=\"" + url + "\"/>" + "</a>";
166
+ }
167
+
168
+ function buildYoutubeVideoLink(url){
169
+ //Get youtube video id
170
+ var youtube_video_id=url.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
171
+ var youtube_api_url = "http://gdata.youtube.com/feeds/api/videos/" + youtube_video_id
172
+
173
+ //Get info from the video
174
+ $.ajax({
175
+ type: "GET",
176
+ url: youtube_api_url,
177
+ cache: false,
178
+ dataType:'jsonp',
179
+ success: function(data){
180
+ var url_name = url;
181
+ var youtube_video_thumbnail = "";
182
+
183
+ //Video title
184
+ var video_title = $(data).find("media\\:title")
185
+ if (video_title.length > 0) {
186
+ //url_name = url + " (" + $(video_title).text() + ")";
187
+ url_name = $(video_title).text()
188
+ }
189
+
190
+ //Thumbnails
191
+ var thumbnails = $(data).find("media\\:thumbnail")
192
+ if (thumbnails.length>0){
193
+ var thumbnail_url = $(thumbnails[0]).attr("url")
194
+ if (thumbnail_url!=null){
195
+ youtube_video_thumbnail = "<p><img class=\"chatVideoImage\" src=\"" + thumbnail_url + "\"/></p>";
196
+ }
197
+ }
198
+
199
+ //Replace video link
200
+ $("a[youtube_id=" + youtube_video_id + "]").html(buildUrlLink(url,url_name)+youtube_video_thumbnail);
201
+ },
202
+ error: function(xOptions, textStatus){
203
+ //Handle errors
204
+ }
205
+ });
206
+
207
+ return "<a target=\"_blank\" youtube_id=\"" + youtube_video_id + "\" class=\"chatLink\" href=\"" + url + "\">" + url + "</a>";
208
+ }
209
+
210
+ function buildRegex(word){
211
+ word = word.replace(")","\\)")
212
+ word = word.replace("(","\\(")
213
+ var pattern = "(" + word + ")";
214
+ pattern = buildPattern(pattern)
215
+ return (new RegExp(pattern,'g'));
216
+ }
217
+
218
+ function buildPattern(pattern){
219
+ //Escape pattern special characters
220
+ pattern = pattern.replace("+","\\+")
221
+ pattern = pattern.replace("?","\\?")
222
+ return pattern
223
+ }
224
+
225
+
226
+ function getUrlType(url){
227
+
228
+ if (url.match(youtube_video_pattern)!=null){
229
+ return "video-youtube"
230
+ }
231
+
232
+ var urlArray = url.split(".");
233
+ if (urlArray!=null && urlArray.length>0){
234
+ var extension= urlArray[urlArray.length-1]
235
+ } else {
236
+ var extension = null;
237
+ }
238
+
239
+ switch(extension){
240
+ case "jpg":
241
+ return "image"
242
+ break;
243
+ case "png":
244
+ return "image"
245
+ break;
246
+ case "gif":
247
+ return "image"
248
+ break;
249
+ default:
250
+ return "link"
251
+ }
252
+ }
253
+
254
+
255
+ ///////////////////////////////////////////////////////
256
+ // Parsing user titles
257
+ ///////////////////////////////////////////////////////
258
+
259
+ function getParsedName(name, fromUser){
260
+ if (fromUser){
261
+ var chatTextclass = "ownName"
262
+ } else {
263
+ var chatTextclass = "guestName"
264
+ }
265
+ return ("<span class=\"" + chatTextclass + "\">" + name + "</span>");
266
+ }
244
267
 
245
268
 
246
- ///////////////////////////////////////////////////////
247
- // Parsing user titles
248
- ///////////////////////////////////////////////////////
269
+ return {
270
+ init: init,
271
+ getParsedContent : getParsedContent,
272
+ getParsedName : getParsedName
273
+ };
249
274
 
250
- function getParsedName(name, fromUser){
251
- if (fromUser){
252
- var chatTextclass = "ownName"
253
- } else {
254
- var chatTextclass = "guestName"
255
- }
256
- return ("<span class=\"" + chatTextclass + "\">" + name + "</span>");
257
- }
275
+ }) (PRESENCE, jQuery);