social_stream-presence 0.0.21 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/chat_audio.js +73 -0
- data/app/assets/javascripts/chat_interface_manager.js.erb +197 -0
- data/app/assets/javascripts/chat_parser.js +243 -0
- data/app/assets/javascripts/chat_utilities.js +71 -0
- data/app/assets/javascripts/chat_window_manager.js +138 -0
- data/app/assets/javascripts/social_stream-presence.js +3 -0
- data/app/assets/javascripts/store.js +0 -7
- data/app/assets/javascripts/xmpp_client_management.js.erb +304 -0
- data/app/assets/stylesheets/chat.css +49 -3
- data/app/assets/stylesheets/social_stream-presence.css +1 -0
- data/app/controllers/xmpp_controller.rb +43 -9
- data/app/views/{xmpp/_chat_connecting.html.erb → chat/_connecting.html.erb} +0 -0
- data/app/views/{xmpp/_chat_contacts.html.erb → chat/_contacts.html.erb} +0 -0
- data/app/views/{xmpp/_chat.html.erb → chat/_index.html.erb} +3 -13
- data/app/views/{xmpp/_chat_off.html.erb → chat/_off.html.erb} +0 -0
- data/app/views/chat/_settings.html.erb +38 -0
- data/config/routes.rb +1 -1
- data/db/migrate/20111116194112_add_chat_enabled_column_to_user.rb +9 -0
- data/lib/social_stream/presence/version.rb +1 -1
- data/{app → vendor}/assets/javascripts/jquery.tools.tooltip.js +0 -0
- data/{app → vendor}/assets/javascripts/jquery.ui.chatbox.js +14 -12
- data/{app → vendor}/assets/javascripts/strophe.js +0 -0
- data/{app → vendor}/assets/stylesheets/jquery.ui.chatbox.css +0 -0
- metadata +19 -14
- data/app/assets/javascripts/jquery-ui-1.8.14.custom.min.js +0 -789
- data/app/assets/javascripts/jquery.tools.min.js +0 -17
- data/app/assets/javascripts/xmpp_client.js.erb +0 -925
@@ -1,17 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* jQuery Tools v1.2.5 - The missing UI library for the Web
|
3
|
-
*
|
4
|
-
* overlay/overlay.js
|
5
|
-
* scrollable/scrollable.js
|
6
|
-
* tabs/tabs.js
|
7
|
-
* tooltip/tooltip.js
|
8
|
-
*
|
9
|
-
* NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
|
10
|
-
*
|
11
|
-
* http://flowplayer.org/tools/
|
12
|
-
*
|
13
|
-
*/
|
14
|
-
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.overlay={addEffect:function(a,b,d){c[a]=[b,d]},conf:{close:null,closeOnClick:!0,closeOnEsc:!0,closeSpeed:"fast",effect:"default",fixed:!a.browser.msie||a.browser.version>6,left:"center",load:!1,mask:null,oneInstance:!0,speed:"normal",target:null,top:"10%"}};var b=[],c={};a.tools.overlay.addEffect("default",function(b,c){var d=this.getConf(),e=a(window);d.fixed||(b.top+=e.scrollTop(),b.left+=e.scrollLeft()),b.position=d.fixed?"fixed":"absolute",this.getOverlay().css(b).fadeIn(d.speed,c)},function(a){this.getOverlay().fadeOut(this.getConf().closeSpeed,a)});function d(d,e){var f=this,g=d.add(f),h=a(window),i,j,k,l=a.tools.expose&&(e.mask||e.expose),m=Math.random().toString().slice(10);l&&(typeof l=="string"&&(l={color:l}),l.closeOnClick=l.closeOnEsc=!1);var n=e.target||d.attr("rel");j=n?a(n):null||d;if(!j.length)throw"Could not find Overlay: "+n;d&&d.index(j)==-1&&d.click(function(a){f.load(a);return a.preventDefault()}),a.extend(f,{load:function(d){if(f.isOpened())return f;var i=c[e.effect];if(!i)throw"Overlay: cannot find effect : \""+e.effect+"\"";e.oneInstance&&a.each(b,function(){this.close(d)}),d=d||a.Event(),d.type="onBeforeLoad",g.trigger(d);if(d.isDefaultPrevented())return f;k=!0,l&&a(j).expose(l);var n=e.top,o=e.left,p=j.outerWidth({margin:!0}),q=j.outerHeight({margin:!0});typeof n=="string"&&(n=n=="center"?Math.max((h.height()-q)/2,0):parseInt(n,10)/100*h.height()),o=="center"&&(o=Math.max((h.width()-p)/2,0)),i[0].call(f,{top:n,left:o},function(){k&&(d.type="onLoad",g.trigger(d))}),l&&e.closeOnClick&&a.mask.getMask().one("click",f.close),e.closeOnClick&&a(document).bind("click."+m,function(b){a(b.target).parents(j).length||f.close(b)}),e.closeOnEsc&&a(document).bind("keydown."+m,function(a){a.keyCode==27&&f.close(a)});return f},close:function(b){if(!f.isOpened())return f;b=b||a.Event(),b.type="onBeforeClose",g.trigger(b);if(!b.isDefaultPrevented()){k=!1,c[e.effect][1].call(f,function(){b.type="onClose",g.trigger(b)}),a(document).unbind("click."+m).unbind("keydown."+m),l&&a.mask.close();return f}},getOverlay:function(){return j},getTrigger:function(){return d},getClosers:function(){return i},isOpened:function(){return k},getConf:function(){return e}}),a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),i=j.find(e.close||".close"),!i.length&&!e.close&&(i=a("<a class=\"close\"></a>"),j.prepend(i)),i.click(function(a){f.close(a)}),e.load&&f.load()}a.fn.overlay=function(c){var e=this.data("overlay");if(e)return e;a.isFunction(c)&&(c={onBeforeLoad:c}),c=a.extend(!0,{},a.tools.overlay.conf,c),this.each(function(){e=new d(a(this),c),b.push(e),a(this).data("overlay",e)});return c.api?e:this}})(jQuery);
|
15
|
-
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.scrollable={conf:{activeClass:"active",circular:!1,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:null,items:".items",keyboard:!0,mousewheel:!1,next:".next",prev:".prev",speed:400,vertical:!1,touch:!0,wheelSpeed:0}};function b(a,b){var c=parseInt(a.css(b),10);if(c)return c;var d=a[0].currentStyle;return d&&d.width&&parseInt(d.width,10)}function c(b,c){var d=a(c);return d.length<2?d:b.parent().find(c)}var d;function e(b,e){var f=this,g=b.add(f),h=b.children(),i=0,j=e.vertical;d||(d=f),h.length>1&&(h=a(e.items,b)),a.extend(f,{getConf:function(){return e},getIndex:function(){return i},getSize:function(){return f.getItems().size()},getNaviButtons:function(){return m.add(n)},getRoot:function(){return b},getItemWrap:function(){return h},getItems:function(){return h.children(e.item).not("."+e.clonedClass)},move:function(a,b){return f.seekTo(i+a,b)},next:function(a){return f.move(1,a)},prev:function(a){return f.move(-1,a)},begin:function(a){return f.seekTo(0,a)},end:function(a){return f.seekTo(f.getSize()-1,a)},focus:function(){d=f;return f},addItem:function(b){b=a(b),e.circular?(h.children("."+e.clonedClass+":last").before(b),h.children("."+e.clonedClass+":first").replaceWith(b.clone().addClass(e.clonedClass))):h.append(b),g.trigger("onAddItem",[b]);return f},seekTo:function(b,c,k){b.jquery||(b*=1);if(e.circular&&b===0&&i==-1&&c!==0)return f;if(!e.circular&&b<0||b>f.getSize()||b<-1)return f;var l=b;b.jquery?b=f.getItems().index(b):l=f.getItems().eq(b);var m=a.Event("onBeforeSeek");if(!k){g.trigger(m,[b,c]);if(m.isDefaultPrevented()||!l.length)return f}var n=j?{top:-l.position().top}:{left:-l.position().left};i=b,d=f,c===undefined&&(c=e.speed),h.animate(n,c,e.easing,k||function(){g.trigger("onSeek",[b])});return f}}),a.each(["onBeforeSeek","onSeek","onAddItem"],function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}});if(e.circular){var k=f.getItems().slice(-1).clone().prependTo(h),l=f.getItems().eq(1).clone().appendTo(h);k.add(l).addClass(e.clonedClass),f.onBeforeSeek(function(a,b,c){if(!a.isDefaultPrevented()){if(b==-1){f.seekTo(k,c,function(){f.end(0)});return a.preventDefault()}b==f.getSize()&&f.seekTo(l,c,function(){f.begin(0)})}}),f.seekTo(0,0,function(){})}var m=c(b,e.prev).click(function(){f.prev()}),n=c(b,e.next).click(function(){f.next()});!e.circular&&f.getSize()>1&&(f.onBeforeSeek(function(a,b){setTimeout(function(){a.isDefaultPrevented()||(m.toggleClass(e.disabledClass,b<=0),n.toggleClass(e.disabledClass,b>=f.getSize()-1))},1)}),e.initialIndex||m.addClass(e.disabledClass)),e.mousewheel&&a.fn.mousewheel&&b.mousewheel(function(a,b){if(e.mousewheel){f.move(b<0?1:-1,e.wheelSpeed||50);return!1}});if(e.touch){var o={};h[0].ontouchstart=function(a){var b=a.touches[0];o.x=b.clientX,o.y=b.clientY},h[0].ontouchmove=function(a){if(a.touches.length==1&&!h.is(":animated")){var b=a.touches[0],c=o.x-b.clientX,d=o.y-b.clientY;f[j&&d>0||!j&&c>0?"next":"prev"](),a.preventDefault()}}}e.keyboard&&a(document).bind("keydown.scrollable",function(b){if(e.keyboard&&!b.altKey&&!b.ctrlKey&&!a(b.target).is(":input")){if(e.keyboard!="static"&&d!=f)return;var c=b.keyCode;if(j&&(c==38||c==40)){f.move(c==38?-1:1);return b.preventDefault()}if(!j&&(c==37||c==39)){f.move(c==37?-1:1);return b.preventDefault()}}}),e.initialIndex&&f.seekTo(e.initialIndex,0,function(){})}a.fn.scrollable=function(b){var c=this.data("scrollable");if(c)return c;b=a.extend({},a.tools.scrollable.conf,b),this.each(function(){c=new e(a(this),b),a(this).data("scrollable",c)});return b.api?c:this}})(jQuery);
|
16
|
-
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:!1,history:!1},addEffect:function(a,c){b[a]=c}};var b={"default":function(a,b){this.getPanes().hide().eq(a).show(),b.call()},fade:function(a,b){var c=this.getConf(),d=c.fadeOutSpeed,e=this.getPanes();d?e.fadeOut(d):e.hide(),e.eq(a).fadeIn(c.fadeInSpeed,b)},slide:function(a,b){this.getPanes().slideUp(200),this.getPanes().eq(a).slideDown(400,b)},ajax:function(a,b){this.getPanes().eq(0).load(this.getTabs().eq(a).attr("href"),b)}},c;a.tools.tabs.addEffect("horizontal",function(b,d){c||(c=this.getPanes().eq(0).width()),this.getCurrentPane().animate({width:0},function(){a(this).hide()}),this.getPanes().eq(b).animate({width:c},function(){a(this).show(),d.call()})});function d(c,d,e){var f=this,g=c.add(this),h=c.find(e.tabs),i=d.jquery?d:c.children(d),j;h.length||(h=c.children()),i.length||(i=c.parent().find(d)),i.length||(i=a(d)),a.extend(this,{click:function(c,d){var i=h.eq(c);typeof c=="string"&&c.replace("#","")&&(i=h.filter("[href*="+c.replace("#","")+"]"),c=Math.max(h.index(i),0));if(e.rotate){var k=h.length-1;if(c<0)return f.click(k,d);if(c>k)return f.click(0,d)}if(!i.length){if(j>=0)return f;c=e.initialIndex,i=h.eq(c)}if(c===j)return f;d=d||a.Event(),d.type="onBeforeClick",g.trigger(d,[c]);if(!d.isDefaultPrevented()){b[e.effect].call(f,c,function(){d.type="onClick",g.trigger(d,[c])}),j=c,h.removeClass(e.current),i.addClass(e.current);return f}},getConf:function(){return e},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return f.click(j+1)},prev:function(){return f.click(j-1)},destroy:function(){h.unbind(e.event).removeClass(e.current),i.find("a[href^=#]").unbind("click.T");return f}}),a.each("onBeforeClick,onClick".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.history&&a.fn.history&&(a.tools.history.init(h),e.event="history"),h.each(function(b){a(this).bind(e.event,function(a){f.click(b,a);return a.preventDefault()})}),i.find("a[href^=#]").bind("click.T",function(b){f.click(a(this).attr("href"),b)}),location.hash&&e.tabs=="a"&&c.find("[href="+location.hash+"]").length?f.click(location.hash):(e.initialIndex===0||e.initialIndex>0)&&f.click(e.initialIndex)}a.fn.tabs=function(b,c){var e=this.data("tabs");e&&(e.destroy(),this.removeData("tabs")),a.isFunction(c)&&(c={onBeforeClick:c}),c=a.extend({},a.tools.tabs.conf,c),this.each(function(){e=new d(a(this),b,c),a(this).data("tabs",e)});return c.api?e:this}})(jQuery);
|
17
|
-
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:!1,cancelDefault:!0,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,c,d){b[a]=[c,d]}};var b={toggle:[function(a){var b=this.getConf(),c=this.getTip(),d=b.opacity;d<1&&c.css({opacity:d}),c.show(),a.call()},function(a){this.getTip().hide(),a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};function c(b,c,d){var e=d.relative?b.position().top:b.offset().top,f=d.relative?b.position().left:b.offset().left,g=d.position[0];e-=c.outerHeight()-d.offset[0],f+=b.outerWidth()+d.offset[1],/iPad/i.test(navigator.userAgent)&&(e-=a(window).scrollTop());var h=c.outerHeight()+b.outerHeight();g=="center"&&(e+=h/2),g=="bottom"&&(e+=h),g=d.position[1];var i=c.outerWidth()+b.outerWidth();g=="center"&&(f-=i/2),g=="left"&&(f-=i);return{top:e,left:f}}function d(d,e){var f=this,g=d.add(f),h,i=0,j=0,k=d.attr("title"),l=d.attr("data-tooltip"),m=b[e.effect],n,o=d.is(":input"),p=o&&d.is(":checkbox, :radio, select, :button, :submit"),q=d.attr("type"),r=e.events[q]||e.events[o?p?"widget":"input":"def"];if(!m)throw"Nonexistent effect \""+e.effect+"\"";r=r.split(/,\s*/);if(r.length!=2)throw"Tooltip: bad events configuration for "+q;d.bind(r[0],function(a){clearTimeout(i),e.predelay?j=setTimeout(function(){f.show(a)},e.predelay):f.show(a)}).bind(r[1],function(a){clearTimeout(j),e.delay?i=setTimeout(function(){f.hide(a)},e.delay):f.hide(a)}),k&&e.cancelDefault&&(d.removeAttr("title"),d.data("title",k)),a.extend(f,{show:function(b){if(!h){l?h=a(l):e.tip?h=a(e.tip).eq(0):k?h=a(e.layout).addClass(e.tipClass).appendTo(document.body).hide().append(k):(h=d.next(),h.length||(h=d.parent().next()));if(!h.length)throw"Cannot find tooltip for "+d}if(f.isShown())return f;h.stop(!0,!0);var o=c(d,h,e);e.tip&&h.html(d.data("title")),b=b||a.Event(),b.type="onBeforeShow",g.trigger(b,[o]);if(b.isDefaultPrevented())return f;o=c(d,h,e),h.css({position:"absolute",top:o.top,left:o.left}),n=!0,m[0].call(f,function(){b.type="onShow",n="full",g.trigger(b)});var p=e.events.tooltip.split(/,\s*/);h.data("__set")||(h.bind(p[0],function(){clearTimeout(i),clearTimeout(j)}),p[1]&&!d.is("input:not(:checkbox, :radio), textarea")&&h.bind(p[1],function(a){a.relatedTarget!=d[0]&&d.trigger(r[1].split(" ")[0])}),h.data("__set",!0));return f},hide:function(c){if(!h||!f.isShown())return f;c=c||a.Event(),c.type="onBeforeHide",g.trigger(c);if(!c.isDefaultPrevented()){n=!1,b[e.effect][1].call(f,function(){c.type="onHide",g.trigger(c)});return f}},isShown:function(a){return a?n=="full":n},getConf:function(){return e},getTip:function(){return h},getTrigger:function(){return d}}),a.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}})}a.fn.tooltip=function(b){var c=this.data("tooltip");if(c)return c;b=a.extend(!0,{},a.tools.tooltip.conf,b),typeof b.position=="string"&&(b.position=b.position.split(/,?\s/)),this.each(function(){c=new d(a(this),b),a(this).data("tooltip",c)});return b.api?c:this}})(jQuery);
|
@@ -1,925 +0,0 @@
|
|
1
|
-
////////////////////
|
2
|
-
//Test functions
|
3
|
-
////////////////////
|
4
|
-
|
5
|
-
function log(msg) {
|
6
|
-
//console.log(msg)
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
////////////////////
|
11
|
-
//Hash table
|
12
|
-
////////////////////
|
13
|
-
var statusMessage = new Array();
|
14
|
-
statusMessage[''] = "";
|
15
|
-
statusMessage['chat'] = "";
|
16
|
-
statusMessage['away'] = "Away";
|
17
|
-
statusMessage['xa'] = "Away";
|
18
|
-
statusMessage['dnd'] = "Busy";
|
19
|
-
|
20
|
-
var statusIcons = new Array();
|
21
|
-
statusIcons[''] = "available";
|
22
|
-
statusIcons['chat'] = "available";
|
23
|
-
statusIcons['away'] = "away";
|
24
|
-
statusIcons['xa'] = "away";
|
25
|
-
statusIcons['dnd'] = "dnd";
|
26
|
-
|
27
|
-
////////////////////
|
28
|
-
//Connect functions
|
29
|
-
////////////////////
|
30
|
-
|
31
|
-
function connectToServerWithCookie(){
|
32
|
-
try {
|
33
|
-
connection = new Strophe.Connection(BOSH_SERVICE);
|
34
|
-
connection.connect(user_jid, cookie, onConnect);
|
35
|
-
} catch (err) {
|
36
|
-
//"Handle errors"
|
37
|
-
return false;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
//Password: Get from chatPassword param if exists, instead try to get from sessionStorage.
|
42
|
-
function connectToServerWithPassword(chatPassword){
|
43
|
-
|
44
|
-
//Get Password
|
45
|
-
if ((chatPassword!=null)&&(chatPassword!="")){
|
46
|
-
var password = chatPassword;
|
47
|
-
} else if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)) {
|
48
|
-
var password = sessionStorage.getItem("ss_user_pass");
|
49
|
-
} else {
|
50
|
-
return false;
|
51
|
-
}
|
52
|
-
|
53
|
-
try {
|
54
|
-
//Connect actual user to the chat
|
55
|
-
connection = new Strophe.Connection(BOSH_SERVICE);
|
56
|
-
connection.connect(user_jid, password, onConnect);
|
57
|
-
} catch (err) {
|
58
|
-
//"Handle errors"
|
59
|
-
return false;
|
60
|
-
}
|
61
|
-
|
62
|
-
return true;
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
////////////////////
|
67
|
-
//Reconnect button functions
|
68
|
-
////////////////////
|
69
|
-
|
70
|
-
var connectButtonTimer;
|
71
|
-
var periodBetweenAttempts=15; //(seg)
|
72
|
-
var connectButtonTimerCounter=periodBetweenAttempts;
|
73
|
-
|
74
|
-
function connectButtonTimerFunction(){
|
75
|
-
if(connectButtonTimerCounter < periodBetweenAttempts){
|
76
|
-
connectButtonTimerCounter++;
|
77
|
-
} else if (connectButtonTimerCounter == periodBetweenAttempts) {
|
78
|
-
$("#chat_header_title").html('<%=I18n.t('chat.disconnected')%>')
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
function requestConnectToChat(){
|
83
|
-
if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
|
84
|
-
connectButtonTimerCounter=0;
|
85
|
-
$("#chat_header_title").html('<%=I18n.t('chat.connecting')%>')
|
86
|
-
return true
|
87
|
-
} else {
|
88
|
-
return false
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
////////////////////
|
93
|
-
//Strophe functions
|
94
|
-
////////////////////
|
95
|
-
|
96
|
-
//Global variables
|
97
|
-
var userStatus = "chat";
|
98
|
-
var awayTimerPeriod = 16000;
|
99
|
-
var timerPeriod = 5000;
|
100
|
-
var refreshMinTime = 3*timerPeriod;
|
101
|
-
var awayTime = 300000;
|
102
|
-
var awayCounter = 0;
|
103
|
-
var timerCounter = 0;
|
104
|
-
var connection = null;
|
105
|
-
var userConnected = false;
|
106
|
-
var reconnectAttempts = 3;
|
107
|
-
var awayTimer;
|
108
|
-
var timer;
|
109
|
-
var requestContacts=false;
|
110
|
-
var cyclesToRefresh = (refreshMinTime/timerPeriod);
|
111
|
-
|
112
|
-
function onConnect(status) {
|
113
|
-
|
114
|
-
//Status.ERROR An error has occurred
|
115
|
-
//Status.CONNECTING The connection is currently being made
|
116
|
-
//Status.CONNFAIL The connection attempt failed
|
117
|
-
//Status.AUTHENTICATING The connection is authenticating
|
118
|
-
//Status.AUTHFAIL The authentication attempt failed
|
119
|
-
//Status.CONNECTED The connection has succeeded
|
120
|
-
//Status.DISCONNECTED The connection has been terminated
|
121
|
-
//Status.DISCONNECTING The connection is currently being terminated
|
122
|
-
//Status.ATTACHED The connection has been attached
|
123
|
-
|
124
|
-
log('Strophe onConnect callback call with status ' + status);
|
125
|
-
|
126
|
-
if (status == Strophe.Status.ATTACHED){
|
127
|
-
log('Strophe connection attached');
|
128
|
-
return;
|
129
|
-
}
|
130
|
-
|
131
|
-
if (status == Strophe.Status.AUTHENTICATING ){
|
132
|
-
log('Strophe connection AUTHENTICATING');
|
133
|
-
return;
|
134
|
-
}
|
135
|
-
|
136
|
-
if (status == Strophe.Status.CONNECTING) {
|
137
|
-
log('Strophe is connecting.');
|
138
|
-
return;
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
clearTimeout(initialTimer);
|
143
|
-
|
144
|
-
if (status == Strophe.Status.CONNFAIL) {
|
145
|
-
log('Strophe failed to connect.');
|
146
|
-
userConnected = false;
|
147
|
-
setTimeout ("onReconnect()", 3000);
|
148
|
-
} else if (status == Strophe.Status.AUTHFAIL) {
|
149
|
-
log('Strophe authentication fail.');
|
150
|
-
if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
|
151
|
-
sessionStorage.setItem("ss_user_pass",null);
|
152
|
-
}
|
153
|
-
userConnected = false;
|
154
|
-
} else if (status == Strophe.Status.ERROR) {
|
155
|
-
log('Strophe error.');
|
156
|
-
userConnected = false;
|
157
|
-
} else if (status == Strophe.Status.DISCONNECTED) {
|
158
|
-
log('Strophe is disconnected.');
|
159
|
-
userConnected = false;
|
160
|
-
clearTimeout(awayTimer);
|
161
|
-
setTimeout ("onReconnect()", 3000);
|
162
|
-
} else if (status == Strophe.Status.CONNECTED) {
|
163
|
-
log('Strophe is connected.');
|
164
|
-
log('Presenze stanza send for:' + connection.jid);
|
165
|
-
connection.addHandler(onMessage, null, 'message', null, null, null);
|
166
|
-
connection.addHandler(onPresence, null, 'presence', null, null, null);
|
167
|
-
//addHandler:(callback, namespace to match, stanza name, stanza type, stanza id , stanza from, options)
|
168
|
-
sendStatus(userStatus);
|
169
|
-
userConnected = true;
|
170
|
-
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
171
|
-
timer = setInterval("timerFunction()", timerPeriod);
|
172
|
-
}
|
173
|
-
|
174
|
-
updateChatWindow();
|
175
|
-
}
|
176
|
-
|
177
|
-
function onReconnect(){
|
178
|
-
if ((connection != null)&&(!userConnected)) {
|
179
|
-
if (reconnectAttempts>0) {
|
180
|
-
reconnectAttempts--;
|
181
|
-
connectToServer(null);
|
182
|
-
setTimeout ("onReconnect()", 9000);
|
183
|
-
} else {
|
184
|
-
//Notify issue to Rails App Server?
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
188
|
-
|
189
|
-
function onMessage(msg) {
|
190
|
-
var to = msg.getAttribute('to');
|
191
|
-
var from = msg.getAttribute('from');
|
192
|
-
var type = msg.getAttribute('type');
|
193
|
-
var elems = msg.getElementsByTagName('body');
|
194
|
-
|
195
|
-
if (type == "chat" && elems.length > 0) {
|
196
|
-
|
197
|
-
var body = elems[0];
|
198
|
-
var from_slug = from.split("@")[0];
|
199
|
-
var from_name = $("#" + from_slug).attr("name");
|
200
|
-
var from_jid = from_slug + "@" + domain;
|
201
|
-
|
202
|
-
|
203
|
-
if (typeof ($('div.user_presence[slug=' + from_slug + ']').attr('name')) == 'undefined') {
|
204
|
-
//No connectionBox for this user!
|
205
|
-
var from_name = from_slug;
|
206
|
-
refreshChatWindow();
|
207
|
-
} else {
|
208
|
-
showConnectionBoxFromSlug(from_slug);
|
209
|
-
var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
|
210
|
-
}
|
211
|
-
|
212
|
-
if (createChatBox(from_slug,from_name,from_jid,user_name,user_jid)) {
|
213
|
-
} else {
|
214
|
-
window[getChatVariableFromSlug(from_slug)].chatbox("option", "boxManager").toggleBox(true);
|
215
|
-
}
|
216
|
-
|
217
|
-
content = parseContent(Strophe.getText(body));
|
218
|
-
//Send message to chatBox and post-message functions.
|
219
|
-
$("#" + from_slug).chatbox("option", "boxManager").addMsg(from_name, content);
|
220
|
-
rotatePriority(from_slug);
|
221
|
-
blinkTitleOnMessage(from_name);
|
222
|
-
if (mustPlaySoundForChatWindow(window[getChatVariableFromSlug(from_slug)])){
|
223
|
-
playSound("onMessageAudio");
|
224
|
-
}
|
225
|
-
|
226
|
-
}
|
227
|
-
|
228
|
-
// we must return true to keep the handler alive.
|
229
|
-
// returning false would remove it after it finishes.
|
230
|
-
return true;
|
231
|
-
}
|
232
|
-
|
233
|
-
///////////////////////////////////////////////////////
|
234
|
-
//Allow new features in chat msg like links, images, icons, ...
|
235
|
-
///////////////////////////////////////////////////////
|
236
|
-
|
237
|
-
var chatIcons = new Array();
|
238
|
-
chatIcons[':)'] = "face-smile.png";
|
239
|
-
chatIcons[':('] = "face-sad.png";
|
240
|
-
chatIcons['(B)'] = "beer.png";
|
241
|
-
chatIcons['(C)'] = "clock.png";
|
242
|
-
chatIcons['(P)'] = "present.png";
|
243
|
-
chatIcons[':P']= "face-raspberry.png";
|
244
|
-
chatIcons[':Z']= "face-tired.png";
|
245
|
-
chatIcons['(R)']= "rain.png";
|
246
|
-
chatIcons['(S)']= "sun.png";
|
247
|
-
chatIcons[';)']= "face-wink.png";
|
248
|
-
|
249
|
-
|
250
|
-
function parseContent(content){
|
251
|
-
|
252
|
-
var html_tag_pattern=/.*\<[^>]+>.*/g
|
253
|
-
if (html_tag_pattern.test(content)){
|
254
|
-
content = content.replace(/>/g, ">");
|
255
|
-
content = content.replace(/</g, "<");
|
256
|
-
return "<pre>" + content + "</pre>"
|
257
|
-
}
|
258
|
-
|
259
|
-
words = content.split(" ");
|
260
|
-
for(i=0; i<words.length; i++){
|
261
|
-
words[i] = parseWord(words[i]);
|
262
|
-
}
|
263
|
-
|
264
|
-
return words.join(" ");
|
265
|
-
}
|
266
|
-
|
267
|
-
function parseWord(word){
|
268
|
-
|
269
|
-
//Look for empty words
|
270
|
-
if (word.trim()==""){
|
271
|
-
return word
|
272
|
-
}
|
273
|
-
|
274
|
-
//Look for simple words
|
275
|
-
var simple_word_pattern=/^[aA-zZ0-9]+$/g
|
276
|
-
if (simple_word_pattern.test(word)){
|
277
|
-
return word
|
278
|
-
}
|
279
|
-
|
280
|
-
//Look for http urls
|
281
|
-
var http_urls_pattern=/(http(s)?:\/\/)([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
|
282
|
-
http_urls = word.match(http_urls_pattern)
|
283
|
-
if (http_urls!=null){
|
284
|
-
url = http_urls[0]
|
285
|
-
type = getUrlType(url);
|
286
|
-
|
287
|
-
switch(type){
|
288
|
-
case "link":
|
289
|
-
link = buildUrlLink(url,url)
|
290
|
-
subwords = word.split(url)
|
291
|
-
word = parseWord(subwords[0]) + link + parseWord(subwords[1])
|
292
|
-
break;
|
293
|
-
case "image":
|
294
|
-
imageLink = buildImageLink(url);
|
295
|
-
subwords = word.split(url)
|
296
|
-
word = parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
|
297
|
-
break;
|
298
|
-
default:
|
299
|
-
}
|
300
|
-
return word
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
//Look for www urls
|
305
|
-
var www_urls_pattern = /(www[.])([aA-zZ0-9%=_&+?])+([.][aA-zZ0-9%=_&+?]+)*[/]?/g
|
306
|
-
www_urls = word.match(www_urls_pattern)
|
307
|
-
if (www_urls!=null){
|
308
|
-
url = www_urls[0]
|
309
|
-
type = getUrlType(url);
|
310
|
-
|
311
|
-
switch(type){
|
312
|
-
case "link":
|
313
|
-
link = buildUrlLink("http://" + url,url)
|
314
|
-
subwords = word.split(url)
|
315
|
-
word = parseWord(subwords[0]) + link + parseWord(subwords[1])
|
316
|
-
break;
|
317
|
-
case "image":
|
318
|
-
imageLink = buildImageLink("http://" + url);
|
319
|
-
subwords = word.split(url)
|
320
|
-
word = parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
|
321
|
-
break;
|
322
|
-
default:
|
323
|
-
}
|
324
|
-
return word
|
325
|
-
}
|
326
|
-
|
327
|
-
//Look for icons: Directly replace
|
328
|
-
var icons_a_pattern=/\(([A-Z])+\)/g
|
329
|
-
var icons_b_pattern=/(:|;)([()A-Z])(.)*/g
|
330
|
-
if (((icons_a_pattern.test(word))) || (icons_b_pattern.test(word))) {
|
331
|
-
for (var i in chatIcons) {
|
332
|
-
word = word.replace(buildRegex(i), buildIconImage(i))
|
333
|
-
}
|
334
|
-
}
|
335
|
-
|
336
|
-
//Look for icons with Regex
|
337
|
-
// var icons_a_pattern=/\(([A-Z])+\)/g
|
338
|
-
// if (icons_a_pattern.test(word)){
|
339
|
-
// icon = word.replace(/[^(]*(\([A-Z]+\))(\([A-Z]+\))?(.)*/g, "$1")
|
340
|
-
// subwords = splitFirst(word,icon)
|
341
|
-
// image = buildIconImage(icon);
|
342
|
-
// return subwords[0] + image + subwords[1];
|
343
|
-
// }
|
344
|
-
|
345
|
-
// var icons_b_pattern=/:([()A-Z])(.)*/g
|
346
|
-
// if (icons_b_pattern.test(word)){
|
347
|
-
// icon = word.replace(/[aA-zZ]*(:[()A-Z])(.)*/g, "$1")
|
348
|
-
// subwords = splitFirst(word,icon)
|
349
|
-
// image = buildIconImage(icon);
|
350
|
-
// return subwords[0] + image + subwords[1];
|
351
|
-
//return parseWord(subwords[0]) + image + parseWord(subwords[1]);
|
352
|
-
// }
|
353
|
-
|
354
|
-
|
355
|
-
//No special content detected
|
356
|
-
return word
|
357
|
-
}
|
358
|
-
|
359
|
-
function splitFirst(word,key){
|
360
|
-
split=[]
|
361
|
-
cut = word.split(key);
|
362
|
-
split[0]=cut[0]
|
363
|
-
cut.shift()
|
364
|
-
paste = cut.join(key)
|
365
|
-
split[1]=paste
|
366
|
-
return split
|
367
|
-
}
|
368
|
-
|
369
|
-
function buildIconImage(icon){
|
370
|
-
if (icon in chatIcons){
|
371
|
-
image_file = chatIcons[icon]
|
372
|
-
image = "<img class=\"chatIcon\" src=\"assets/emoticons/" + image_file + "\"/>";
|
373
|
-
return image
|
374
|
-
}
|
375
|
-
return icon
|
376
|
-
}
|
377
|
-
|
378
|
-
function buildUrlLink(url,name){
|
379
|
-
link = "<a target=\"_blank\" class=\"chatLink\" href=\"" + url + "\">" + name + "</a>";
|
380
|
-
return link
|
381
|
-
}
|
382
|
-
|
383
|
-
function buildImageLink(url){
|
384
|
-
link = "<a target=\"_blank\" class=\"chatImageLink\" href=\"" + url + "\">" + "<img class=\"chatImage\" src=\"" + url + "\"/>" + "</a>";
|
385
|
-
return link
|
386
|
-
}
|
387
|
-
|
388
|
-
|
389
|
-
function buildRegex(word){
|
390
|
-
word = word.replace(")","\\)")
|
391
|
-
word = word.replace("(","\\(")
|
392
|
-
pattern = "(" + word + ")";
|
393
|
-
pattern = buildPattern(pattern)
|
394
|
-
return (new RegExp(pattern,'g'));
|
395
|
-
}
|
396
|
-
|
397
|
-
function buildPattern(pattern){
|
398
|
-
//Escape pattern special characters
|
399
|
-
pattern = pattern.replace("+","\\+")
|
400
|
-
pattern = pattern.replace("?","\\?")
|
401
|
-
return pattern
|
402
|
-
}
|
403
|
-
|
404
|
-
function getUrlType(url){
|
405
|
-
urlArray = url.split(".");
|
406
|
-
if (urlArray!=null && urlArray.length>0){
|
407
|
-
extension= urlArray[urlArray.length-1]
|
408
|
-
} else {
|
409
|
-
extension = null;
|
410
|
-
}
|
411
|
-
|
412
|
-
switch(extension){
|
413
|
-
case "jpg":
|
414
|
-
return "image"
|
415
|
-
break;
|
416
|
-
case "png":
|
417
|
-
return "image"
|
418
|
-
break;
|
419
|
-
case "gif":
|
420
|
-
return "image"
|
421
|
-
break;
|
422
|
-
default:
|
423
|
-
return "link"
|
424
|
-
}
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
function onPresence(presence) {
|
430
|
-
|
431
|
-
//Check presence stanza type
|
432
|
-
ptype = $(presence).attr('type');
|
433
|
-
|
434
|
-
switch (ptype){
|
435
|
-
case undefined:
|
436
|
-
processAvailablePresenceStanza(presence)
|
437
|
-
break;
|
438
|
-
case "available":
|
439
|
-
processAvailablePresenceStanza(presence)
|
440
|
-
break;
|
441
|
-
case "unavailable":
|
442
|
-
processUnavailablePresenceStanza(presence)
|
443
|
-
break;
|
444
|
-
default :
|
445
|
-
//Stanza type not recognize
|
446
|
-
processAvailablePresenceStanza(presence)
|
447
|
-
}
|
448
|
-
|
449
|
-
return true;
|
450
|
-
}
|
451
|
-
|
452
|
-
function processAvailablePresenceStanza(presence){
|
453
|
-
from = $(presence).attr('from');
|
454
|
-
slug = from.split("@")[0];
|
455
|
-
|
456
|
-
if (slug != user_slug) {
|
457
|
-
if (getConnectionBoxFromSlug(slug)!=null){
|
458
|
-
status = $(presence).find('show').text();
|
459
|
-
setUserIconStatus(slug, status);
|
460
|
-
if (cacheConnectedUsers.indexOf(slug) != -1) {
|
461
|
-
showConnectionBoxFromSlug(slug);
|
462
|
-
}
|
463
|
-
} else {
|
464
|
-
setTimeout("refreshChatWindow()", 3000);
|
465
|
-
}
|
466
|
-
}
|
467
|
-
}
|
468
|
-
|
469
|
-
function processUnavailablePresenceStanza(presence){
|
470
|
-
from = $(presence).attr('from');
|
471
|
-
slug = from.split("@")[0];
|
472
|
-
|
473
|
-
if (slug != user_slug) {
|
474
|
-
if (getConnectionBoxFromSlug(slug)!=null){
|
475
|
-
hideConnectionBoxFromSlug(slug)
|
476
|
-
}
|
477
|
-
}
|
478
|
-
}
|
479
|
-
|
480
|
-
function sendChatMessage(from,to,text){
|
481
|
-
var type = "chat";
|
482
|
-
var body= $build("body");
|
483
|
-
body.t(text);
|
484
|
-
var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
|
485
|
-
connection.send(message.tree());
|
486
|
-
resumeAwayTimerIfAway();
|
487
|
-
return true;
|
488
|
-
}
|
489
|
-
|
490
|
-
function authByCookie(){
|
491
|
-
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
492
|
-
return authMethod=="cookie";
|
493
|
-
}
|
494
|
-
|
495
|
-
function authByPassword(){
|
496
|
-
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
497
|
-
return authMethod=="password";
|
498
|
-
}
|
499
|
-
|
500
|
-
function ifCookie(){
|
501
|
-
return (!(typeof cookie == 'undefined'))
|
502
|
-
}
|
503
|
-
|
504
|
-
////////////////////
|
505
|
-
//Audio functions
|
506
|
-
////////////////////
|
507
|
-
|
508
|
-
//Global audio variables
|
509
|
-
var onMessageAudio;
|
510
|
-
|
511
|
-
var html5_audiotypes=[
|
512
|
-
["mp3","audio/mpeg"],
|
513
|
-
//["mp4","audio/mp4"],
|
514
|
-
//["ogg","audio/ogg"],
|
515
|
-
["wav","audio/wav"]
|
516
|
-
]
|
517
|
-
|
518
|
-
function initAudio(){
|
519
|
-
//Init all audio files
|
520
|
-
initSound("onMessageAudio");
|
521
|
-
}
|
522
|
-
|
523
|
-
function initSound(sound){
|
524
|
-
|
525
|
-
//Check support for HTML5 audio
|
526
|
-
var html5audio=document.createElement('audio')
|
527
|
-
|
528
|
-
if (html5audio.canPlayType){
|
529
|
-
path = 'assets/chat/' + sound;
|
530
|
-
window[sound] = new Audio();
|
531
|
-
|
532
|
-
for(i=0; i<html5_audiotypes.length; i++){
|
533
|
-
if (window[sound].canPlayType(html5_audiotypes[i][1])) {
|
534
|
-
var source= document.createElement('source');
|
535
|
-
source.type= html5_audiotypes[i][1];
|
536
|
-
source.src= path + '.' + html5_audiotypes[i][0];
|
537
|
-
window[sound].addEventListener('ended', endSoundListener);
|
538
|
-
window[sound].appendChild(source);
|
539
|
-
}
|
540
|
-
}
|
541
|
-
} else {
|
542
|
-
//Browser doesn't support HTML5 audio
|
543
|
-
}
|
544
|
-
}
|
545
|
-
|
546
|
-
function endSoundListener(){ }
|
547
|
-
|
548
|
-
function playSound(sound){
|
549
|
-
if (window[sound]!=null){
|
550
|
-
window[sound].play();
|
551
|
-
} else {
|
552
|
-
//Fallback option: When browser doesn't support HTML5 audio
|
553
|
-
$('body').append('<embed src="/' + sound + '.mp3" autostart="true" hidden="true" loop="false">');
|
554
|
-
}
|
555
|
-
}
|
556
|
-
|
557
|
-
function initAndPlaySound(sound){
|
558
|
-
initSound(sound);
|
559
|
-
playSound(sound);
|
560
|
-
}
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
////////////////////
|
565
|
-
//Chat view jquery
|
566
|
-
////////////////////
|
567
|
-
|
568
|
-
function setUserFunctions(){
|
569
|
-
|
570
|
-
$("div.user_presence").click(function(event, ui){
|
571
|
-
var guest_name = $(this).attr("name");
|
572
|
-
var guest_slug = $(this).attr("slug");
|
573
|
-
var guest_jid = guest_slug + "@" + domain;
|
574
|
-
|
575
|
-
if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
|
576
|
-
} else {
|
577
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
|
578
|
-
};
|
579
|
-
});
|
580
|
-
|
581
|
-
//JQuery DropdwanStatus
|
582
|
-
|
583
|
-
$(".dropdown dt a").click(function(event) {
|
584
|
-
event.preventDefault();
|
585
|
-
$(".dropdown dd ul").toggle();
|
586
|
-
});
|
587
|
-
|
588
|
-
$(".dropdown dd ul li a.option").click(function(event) {
|
589
|
-
event.preventDefault();
|
590
|
-
var text = $(this).html();
|
591
|
-
$(".dropdown dt a span").html(text);
|
592
|
-
userStatus = getSelectedValue("status");
|
593
|
-
sendStatus(userStatus);
|
594
|
-
$(".dropdown dd ul").hide();
|
595
|
-
});
|
596
|
-
|
597
|
-
|
598
|
-
function getSelectedValue(id) {
|
599
|
-
return $("#" + id).find("dt a span.value").html();
|
600
|
-
}
|
601
|
-
|
602
|
-
$(document).bind('click', function(e) {
|
603
|
-
var $clicked = $(e.target);
|
604
|
-
if (! $clicked.parents().hasClass("dropdown")){
|
605
|
-
//Click outside the select...
|
606
|
-
$(".dropdown dd ul").hide();
|
607
|
-
}
|
608
|
-
});
|
609
|
-
}
|
610
|
-
|
611
|
-
|
612
|
-
function awayTimerFunction(){
|
613
|
-
awayCounter++;
|
614
|
-
if (awayCounter > (awayTime/awayTimerPeriod)){
|
615
|
-
userStatus = "away";
|
616
|
-
sendStatus(userStatus);
|
617
|
-
clearTimeout(awayTimer);
|
618
|
-
} else {
|
619
|
-
userStatus = "chat";
|
620
|
-
}
|
621
|
-
}
|
622
|
-
|
623
|
-
function resumeAwayTimerIfAway(){
|
624
|
-
if (userStatus == "away"){
|
625
|
-
awayCounter = 0;
|
626
|
-
userStatus = "chat";
|
627
|
-
sendStatus(userStatus);
|
628
|
-
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
629
|
-
}
|
630
|
-
}
|
631
|
-
|
632
|
-
function timerFunction(){
|
633
|
-
timerCounter++;
|
634
|
-
|
635
|
-
if((timerCounter > cyclesToRefresh)&&(requestContacts)) {
|
636
|
-
requestContacts = false;
|
637
|
-
updateChatWindow();
|
638
|
-
}
|
639
|
-
}
|
640
|
-
|
641
|
-
function refreshChatWindow(){
|
642
|
-
if(timerCounter > cyclesToRefresh){
|
643
|
-
updateChatWindow();
|
644
|
-
} else {
|
645
|
-
requestContacts = true;
|
646
|
-
}
|
647
|
-
}
|
648
|
-
|
649
|
-
function updateChatWindow(){
|
650
|
-
timerCounter=0;
|
651
|
-
log("updateChatWindow()");
|
652
|
-
$.post("/chatWindow", { userConnected: userConnected }, function(data){
|
653
|
-
$(".tooltip").hide() //Prevent tooltips
|
654
|
-
$("#chat_partial").html(data);
|
655
|
-
if (userConnected) {
|
656
|
-
$(".user_presence a[title]").tooltip();
|
657
|
-
setUserFunctions();
|
658
|
-
}
|
659
|
-
});
|
660
|
-
}
|
661
|
-
|
662
|
-
function sendStatus(status){
|
663
|
-
if (status in statusMessage){
|
664
|
-
//Send status to the XMPP Server
|
665
|
-
var pres = $pres()
|
666
|
-
.c('status')
|
667
|
-
.t(statusMessage[status]).up() //Status message
|
668
|
-
.c('show')
|
669
|
-
.t(status);
|
670
|
-
connection.send(pres.tree());
|
671
|
-
}
|
672
|
-
}
|
673
|
-
|
674
|
-
|
675
|
-
function mustPlaySoundForChatWindow(chatBox){
|
676
|
-
//Deny conditions
|
677
|
-
if(userStatus == "dnd"){
|
678
|
-
return false;
|
679
|
-
}
|
680
|
-
|
681
|
-
//Accept conditions
|
682
|
-
if (!chatFocus){
|
683
|
-
return true;
|
684
|
-
}
|
685
|
-
|
686
|
-
//Default action
|
687
|
-
return false
|
688
|
-
}
|
689
|
-
|
690
|
-
|
691
|
-
var chatFocus;
|
692
|
-
|
693
|
-
function onChatBlur() {
|
694
|
-
chatFocus = false;
|
695
|
-
};
|
696
|
-
|
697
|
-
function onChatFocus(){
|
698
|
-
stopBlink();
|
699
|
-
titles = []; //Remove titles after StopBlink!
|
700
|
-
chatFocus = true;
|
701
|
-
};
|
702
|
-
|
703
|
-
function initFocusListeners(){
|
704
|
-
if (/*@cc_on!@*/false) { // check for Internet Explorer
|
705
|
-
document.onfocusin = onFocus;
|
706
|
-
document.onfocusout = onBlur;
|
707
|
-
} else {
|
708
|
-
window.onfocus = onChatFocus;
|
709
|
-
window.onblur = onChatBlur;
|
710
|
-
}
|
711
|
-
}
|
712
|
-
|
713
|
-
|
714
|
-
var blinkTimer;
|
715
|
-
var titles=[];
|
716
|
-
|
717
|
-
function blinkTitle(titles,index){
|
718
|
-
$(document).attr("title", titles[index]);
|
719
|
-
index = (index+1)%titles.length
|
720
|
-
blinkTimer=setTimeout(function(){blinkTitle(titles,index)}, 2000);
|
721
|
-
}
|
722
|
-
|
723
|
-
function stopBlink(){
|
724
|
-
clearTimeout(blinkTimer);
|
725
|
-
if (titles.length > 0) {
|
726
|
-
$(document).attr("title", titles[0]);
|
727
|
-
}
|
728
|
-
}
|
729
|
-
|
730
|
-
function blinkTitleOnMessage(username){
|
731
|
-
if (!chatFocus){
|
732
|
-
if (titles.length==0){
|
733
|
-
titles.push($(document).attr("title"))
|
734
|
-
}
|
735
|
-
if (titles.indexOf(username) == -1){
|
736
|
-
titles.push(username + " says...")
|
737
|
-
}
|
738
|
-
stopBlink();
|
739
|
-
blinkTitle(titles,titles.length-1);
|
740
|
-
}
|
741
|
-
}
|
742
|
-
|
743
|
-
function getConnectionBoxFromSlug(slug){
|
744
|
-
if ($('div.user_presence[slug=' + slug + ']').length > 0){
|
745
|
-
return ($('div.user_presence[slug=' + slug + ']'))[0];
|
746
|
-
} else {
|
747
|
-
return null;
|
748
|
-
}
|
749
|
-
}
|
750
|
-
|
751
|
-
|
752
|
-
var cacheConnectedUsers = [];
|
753
|
-
function hideConnectionBoxFromSlug(slug){
|
754
|
-
if ($('div.user_presence[slug=' + slug + ']').length > 0){
|
755
|
-
$('div.user_presence[slug=' + slug + ']').hide();
|
756
|
-
if(cacheConnectedUsers.indexOf(slug)==-1){
|
757
|
-
cacheConnectedUsers.push(slug);
|
758
|
-
}
|
759
|
-
}
|
760
|
-
}
|
761
|
-
|
762
|
-
function showConnectionBoxFromSlug(slug){
|
763
|
-
if ($('div.user_presence[slug=' + slug + ']').length > 0){
|
764
|
-
if (!($('div.user_presence[slug=' + slug + ']').is(":visible"))){
|
765
|
-
$('div.user_presence[slug=' + slug + ']').show();
|
766
|
-
}
|
767
|
-
}
|
768
|
-
}
|
769
|
-
|
770
|
-
function setUserIconStatus(slug, status){
|
771
|
-
if (status in statusIcons) {
|
772
|
-
iconName = statusIcons[status];
|
773
|
-
var $img_status = $('img.presence_status');
|
774
|
-
connectionBox = getConnectionBoxFromSlug(slug);
|
775
|
-
$(connectionBox).find($img_status).attr("src", "/assets/status/" + iconName + ".png")
|
776
|
-
}
|
777
|
-
}
|
778
|
-
|
779
|
-
function getAllConnectedSlugs(){
|
780
|
-
connectedSlugs=[];
|
781
|
-
connectionBoxes = $('div.user_presence[slug]');
|
782
|
-
$.each(connectionBoxes, function(index, value) {
|
783
|
-
if($(value).is(":visible")){
|
784
|
-
connectedSlugs.push($(value).attr("slug"))
|
785
|
-
}
|
786
|
-
});
|
787
|
-
return connectedSlugs
|
788
|
-
}
|
789
|
-
|
790
|
-
|
791
|
-
////////////////////
|
792
|
-
//Chat functions
|
793
|
-
////////////////////
|
794
|
-
|
795
|
-
var nBox = 0;
|
796
|
-
var maxBox = 5;
|
797
|
-
var chatBoxWidth = 230;
|
798
|
-
var visibleChatBoxes = new Array();
|
799
|
-
var chatBoxSeparation = chatBoxWidth+12;
|
800
|
-
|
801
|
-
|
802
|
-
function createChatBox(guest_slug,guest_name,guest_jid,user_name,user_jid){
|
803
|
-
|
804
|
-
//Create chatbox for new conversations
|
805
|
-
//Open chatbox for old conversations
|
806
|
-
|
807
|
-
//Box Variable name = getChatVariableFromSlug(guest_slug)
|
808
|
-
if (typeof window[getChatVariableFromSlug(guest_slug)] == 'undefined') {
|
809
|
-
|
810
|
-
//Add div with id = guest_slug
|
811
|
-
$("#chat_divs").append("<div id=" + guest_slug + " name=" + guest_name + "></div>")
|
812
|
-
|
813
|
-
//Add CSS [...]
|
814
|
-
|
815
|
-
|
816
|
-
//Offset Management for new box
|
817
|
-
boxParams = getBoxParams();
|
818
|
-
var offset = boxParams[0];
|
819
|
-
var position = boxParams[1];
|
820
|
-
|
821
|
-
|
822
|
-
window[getChatVariableFromSlug(guest_slug)] = $("#" + guest_slug).chatbox({id: user_name,
|
823
|
-
user:{key : "value"},
|
824
|
-
hidden: false,
|
825
|
-
offset: offset, // relative to right edge of the browser window
|
826
|
-
width: chatBoxWidth, // width of the chatbox
|
827
|
-
title : guest_name,
|
828
|
-
position: position,
|
829
|
-
priority: visibleChatBoxes.length+1,
|
830
|
-
boxClosed: function(id) {
|
831
|
-
|
832
|
-
position = $("#" + guest_slug).chatbox("option", "position");
|
833
|
-
|
834
|
-
for (i=position+1;i<visibleChatBoxes.length+1;i++){
|
835
|
-
visibleChatBoxes[i-1].chatbox("option", "offset", visibleChatBoxes[i-1].chatbox("option", "offset") - chatBoxSeparation);
|
836
|
-
visibleChatBoxes[i-1].chatbox("option", "position", visibleChatBoxes[i-1].chatbox("option", "position") - 1 );
|
837
|
-
}
|
838
|
-
|
839
|
-
visibleChatBoxes.splice(position-1,1);
|
840
|
-
$("#" + guest_slug).chatbox("option", "hidden", true);
|
841
|
-
nBox--;
|
842
|
-
},
|
843
|
-
|
844
|
-
messageSent : function(id, user, msg) {
|
845
|
-
rotatePriority(guest_slug);
|
846
|
-
$("#" + guest_slug).chatbox("option", "boxManager").addMsg(id, parseContent(msg));
|
847
|
-
sendChatMessage(user_jid,guest_jid,msg);
|
848
|
-
}});
|
849
|
-
|
850
|
-
visibleChatBoxes[position-1] = window[getChatVariableFromSlug(guest_slug)];
|
851
|
-
|
852
|
-
return true;
|
853
|
-
|
854
|
-
} else {
|
855
|
-
|
856
|
-
if (visibleChatBoxes.indexOf(window[getChatVariableFromSlug(guest_slug)]) == -1) {
|
857
|
-
|
858
|
-
//Offset Management for old box
|
859
|
-
boxParams = getBoxParams();
|
860
|
-
var offset = boxParams[0];
|
861
|
-
var position = boxParams[1];
|
862
|
-
|
863
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "offset", offset);
|
864
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "position", position);
|
865
|
-
visibleChatBoxes[position-1] = window[getChatVariableFromSlug(guest_slug)];
|
866
|
-
}
|
867
|
-
|
868
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "hidden", false);
|
869
|
-
return false;
|
870
|
-
}
|
871
|
-
|
872
|
-
}
|
873
|
-
|
874
|
-
function getBoxParams(){
|
875
|
-
|
876
|
-
var boxParams = new Array(2);
|
877
|
-
|
878
|
-
if (nBox==maxBox){
|
879
|
-
//Select box to replaced
|
880
|
-
replaced = visibleChatBoxes[getBoxIndexToReplace()];
|
881
|
-
replaced.chatbox("option", "hidden", true)
|
882
|
-
index = visibleChatBoxes.indexOf(replaced);
|
883
|
-
boxParams[0] = replaced.chatbox("option", "offset")
|
884
|
-
boxParams[1] = replaced.chatbox("option", "position")
|
885
|
-
} else {
|
886
|
-
nBox++;
|
887
|
-
boxParams[0] = (nBox-1)*(chatBoxSeparation);
|
888
|
-
boxParams[1] = nBox;
|
889
|
-
}
|
890
|
-
|
891
|
-
return boxParams
|
892
|
-
}
|
893
|
-
|
894
|
-
|
895
|
-
function getBoxIndexToReplace(){
|
896
|
-
|
897
|
-
tmp = visibleChatBoxes[0];
|
898
|
-
for (i=0;i<visibleChatBoxes.length;i++){
|
899
|
-
if (visibleChatBoxes[i].chatbox("option", "priority") > tmp.chatbox("option", "priority")) {
|
900
|
-
tmp = visibleChatBoxes[i];
|
901
|
-
}
|
902
|
-
}
|
903
|
-
|
904
|
-
return visibleChatBoxes.indexOf(tmp);
|
905
|
-
}
|
906
|
-
|
907
|
-
function rotatePriority(guest_slug){
|
908
|
-
priority = $("#" + guest_slug).chatbox("option", "priority")
|
909
|
-
if(priority>1){
|
910
|
-
for (i=0;i<visibleChatBoxes.length;i++){
|
911
|
-
if(visibleChatBoxes[i].chatbox("option", "priority")<priority){
|
912
|
-
visibleChatBoxes[i].chatbox("option", "priority",visibleChatBoxes[i].chatbox("option", "priority")+1);
|
913
|
-
}
|
914
|
-
}
|
915
|
-
$("#" + guest_slug).chatbox("option", "priority", 1);
|
916
|
-
}
|
917
|
-
}
|
918
|
-
|
919
|
-
function getChatVariableFromSlug(slug){
|
920
|
-
return "slug_" + slug;
|
921
|
-
}
|
922
|
-
|
923
|
-
function getSlugFromChatVariable(variable){
|
924
|
-
return variable.split("_")[1];
|
925
|
-
}
|