Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
7d3c9829
Commit
7d3c9829
authored
Jun 18, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remember open and minimized chat windows upon page reload.
parent
d4673b94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
55 deletions
+50
-55
collective.xmpp.chat.js
collective.xmpp.chat.js
+50
-55
No files found.
collective.xmpp.chat.js
View file @
7d3c9829
...
...
@@ -50,35 +50,36 @@ var xmppchat = (function ($, console) {
};
obj
.
handleChatEvents
=
function
(
chat_id
)
{
var
chat_area
=
$
(
"
#
"
+
xmppchat
.
hash
(
chat_id
)
+
"
.chat-textarea
"
),
var
chat_area
=
$
(
"
#
"
+
chat_id
+
"
.chat-textarea
"
),
chat_type
=
chat_id
.
split
(
'
_
'
)[
0
],
that
=
this
;
that
.
chat_focus
[
chat_id
]
=
false
;
chat_area
.
blur
(
function
()
{
chat_area
.
blur
(
function
()
{
that
.
chat_focus
[
chat_id
]
=
false
;
chat_area
.
removeClass
(
'
chat-textarea-
'
+
chat_type
+
'
-selected
'
);
}).
focus
(
function
(){
}).
focus
(
function
(){
that
.
chat_focus
[
chat_id
]
=
true
;
chat_area
.
addClass
(
'
chat-textarea-
'
+
chat_type
+
'
-selected
'
);
});
var
chatbox
=
$
(
"
#
"
+
xmppchat
.
hash
(
chat_id
)
);
chatbox
.
click
(
function
()
{
var
chatbox
=
$
(
"
#
"
+
chat_id
);
chatbox
.
click
(
function
()
{
if
(
chatbox
.
find
(
'
.chat-content
'
).
css
(
'
display
'
)
!=
'
none
'
)
{
chatbox
.
find
(
'
.chat-textarea
'
).
focus
();
}
});
};
obj
.
createChatBox
=
function
(
chat_id
,
jid
)
{
var
path
=
xmppchat
.
sanitizePath
(
'
/@@render_chat_box
'
);
obj
.
createChatBox
=
function
(
jid
)
{
var
path
=
xmppchat
.
sanitizePath
(
'
/@@render_chat_box
'
),
chat_id
=
this
.
hash
(
jid
);
$
.
ajax
({
url
:
path
,
cache
:
false
,
async
:
false
,
data
:
{
chat_id
:
chat_
id
,
box_id
:
xmppchat
.
hash
(
chat_id
)
,
chat_id
:
'
chatbox_
'
+
j
id
,
box_id
:
chat_id
,
jid
:
jid
,
tzoffset
:
-
(
new
Date
().
getTimezoneOffset
())
},
...
...
@@ -105,16 +106,20 @@ var xmppchat = (function ($, console) {
}
}
});
return
$
(
'
#
'
+
xmppchat
.
hash
(
chat_id
)
);
return
$
(
'
#
'
+
chat_id
);
};
obj
.
createChat
=
function
(
chat_id
,
minimize
,
jid
)
{
obj
.
createChat
=
function
(
jid
,
minimize
)
{
if
(
typeof
(
jid
)
===
undefined
)
{
return
;
}
var
cookie
=
$
.
cookie
(
'
chats-open-
'
+
this
.
username
),
chat_content
,
chatbox
;
this
.
addChatToCookie
(
chat_id
);
chat_content
,
chatbox
,
chat_id
=
this
.
hash
(
jid
);
this
.
addChatToCookie
(
jid
);
chatbox
=
$
(
"
#
"
+
this
.
hash
(
chat_id
)
);
chatbox
=
$
(
"
#
"
+
chat_id
);
if
(
chatbox
.
length
>
0
)
{
// The chatbox exists, merely hidden
if
(
chatbox
.
css
(
'
display
'
)
==
'
none
'
)
{
...
...
@@ -126,11 +131,7 @@ var xmppchat = (function ($, console) {
chat_content
.
scrollTop
(
chat_content
[
0
].
scrollHeight
);
return
;
}
chatbox
=
this
.
createChatBox
(
chat_id
,
jid
);
if
(
chatbox
.
length
===
0
)
{
console
.
log
(
'
Could not create chatbox with id:
'
+
chat_id
);
return
;
}
chatbox
=
this
.
createChatBox
(
jid
);
this
.
positionNewChat
(
chatbox
);
this
.
chats
.
push
(
chat_id
);
if
(
minimize
==
1
)
{
...
...
@@ -150,9 +151,10 @@ var xmppchat = (function ($, console) {
return
chatbox
;
};
obj
.
startChat
=
function
(
chat_id
,
jid
)
{
this
.
createChat
(
chat_id
,
0
,
jid
);
$
(
"
#
"
+
this
.
hash
(
chat_id
)
+
"
.chat-textarea
"
).
focus
();
obj
.
startChat
=
function
(
jid
)
{
this
.
createChat
(
jid
,
0
);
$
(
"
#
"
+
this
.
hash
(
jid
)
+
"
.chat-textarea
"
).
focus
();
};
obj
.
reorderChats
=
function
()
{
...
...
@@ -197,10 +199,9 @@ var xmppchat = (function ($, console) {
that
=
this
;
jarnxmpp
.
Presence
.
getUserInfo
(
user_id
,
function
(
data
)
{
var
chat_id
=
'
chatbox_
'
+
user_id
;
var
chat
=
$
(
'
#
'
+
that
.
hash
(
chat_id
));
var
chat
=
$
(
'
#
'
+
that
.
hash
(
jid
));
if
(
chat
.
length
<=
0
)
{
chat
=
that
.
createChat
(
chat_id
,
0
,
jid
);
chat
=
that
.
createChat
(
jid
,
0
);
}
if
(
chat
.
css
(
'
display
'
)
==
'
none
'
)
{
chat
.
css
(
'
display
'
,
'
block
'
);
...
...
@@ -233,9 +234,9 @@ var xmppchat = (function ($, console) {
});
};
obj
.
closeChat
=
function
(
chat_id
,
audience
)
{
jQuery
(
'
#
'
+
xmppchat
.
hash
(
chat_id
)
).
css
(
'
display
'
,
'
none
'
);
obj
.
closeChat
=
function
(
jid
,
audience
)
{
var
chat_id
=
this
.
hash
(
jid
);
jQuery
(
'
#
'
+
chat_id
).
css
(
'
display
'
,
'
none
'
);
xmppchat
.
reorderChats
();
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
),
open_chats
=
[],
...
...
@@ -244,7 +245,7 @@ var xmppchat = (function ($, console) {
open_chats
=
cookie
.
split
(
'
|
'
);
}
for
(
var
i
=
0
;
i
<
open_chats
.
length
;
i
++
)
{
if
(
open_chats
[
i
]
!=
chat_
id
)
{
if
(
open_chats
[
i
]
!=
j
id
)
{
new_chats
.
push
(
open_chats
[
i
]);
}
}
...
...
@@ -257,11 +258,12 @@ var xmppchat = (function ($, console) {
this
.
chats
.
pop
(
chat_id
);
};
obj
.
toggleChat
=
function
(
chat_id
)
{
var
minimized_chats
=
xmppchat
.
getMinimizedChats
();
var
hashed_id
=
xmppchat
.
hash
(
chat_id
);
var
new_cookie
;
if
(
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-content
'
).
css
(
'
display
'
)
==
'
none
'
)
{
obj
.
toggleChat
=
function
(
jid
)
{
var
chat_id
=
this
.
hash
(
jid
),
minimized_chats
=
xmppchat
.
getMinimizedChats
(),
new_cookie
;
if
(
jQuery
(
'
#
'
+
chat_id
+
'
.chat-content
'
).
css
(
'
display
'
)
==
'
none
'
)
{
// Chat will be maximized
new_cookie
=
[];
for
(
var
i
=
0
;
i
<
minimized_chats
.
length
;
i
++
)
{
...
...
@@ -270,11 +272,11 @@ var xmppchat = (function ($, console) {
}
}
jQuery
.
cookie
(
'
chats_minimized_
'
+
xmppchat
.
username
,
new_cookie
.
join
(
'
|
'
));
var
chat_content
=
jQuery
(
'
#
'
+
hashed
_id
+
'
.chat-content
'
);
var
chat_content
=
jQuery
(
'
#
'
+
chat
_id
+
'
.chat-content
'
);
chat_content
.
css
(
'
display
'
,
'
block
'
);
chat_content
.
scrollTop
(
chat_content
[
0
].
scrollHeight
);
jQuery
(
'
#
'
+
hashed
_id
+
'
.chat-head
'
).
removeClass
(
'
chat-head-minimized-with-messages
'
);
jQuery
(
'
#
'
+
hashed
_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
block
'
);
jQuery
(
'
#
'
+
chat
_id
+
'
.chat-head
'
).
removeClass
(
'
chat-head-minimized-with-messages
'
);
jQuery
(
'
#
'
+
chat
_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
block
'
);
}
else
{
// Chat will be minimized
...
...
@@ -283,12 +285,12 @@ var xmppchat = (function ($, console) {
new_cookie
+=
'
|
'
+
minimized_chats
.
join
(
'
|
'
);
jQuery
.
cookie
(
'
chats_minimized_
'
+
xmppchat
.
username
,
new_cookie
);
}
jQuery
(
'
#
'
+
hashed
_id
+
'
.chat-content
'
).
css
(
'
display
'
,
'
none
'
);
jQuery
(
'
#
'
+
hashed
_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
none
'
);
jQuery
(
'
#
'
+
chat
_id
+
'
.chat-content
'
).
css
(
'
display
'
,
'
none
'
);
jQuery
(
'
#
'
+
chat
_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
none
'
);
}
};
obj
.
keyPressed
=
function
(
event
,
textarea
,
audience
,
hashed
_id
,
chat_type
)
{
obj
.
keyPressed
=
function
(
event
,
textarea
,
audience
,
chat
_id
,
chat_type
)
{
if
(
event
.
keyCode
==
13
&&
!
event
.
shiftKey
)
{
var
textbox
=
jQuery
(
textarea
);
var
message
=
textbox
.
val
();
...
...
@@ -308,7 +310,7 @@ var xmppchat = (function ($, console) {
var
minutes
=
now
.
getMinutes
().
toString
();
if
(
minutes
.
length
==
1
)
{
minutes
=
'
0
'
+
minutes
;}
var
time
=
now
.
toLocaleTimeString
().
substring
(
0
,
5
);
var
chat_content
=
jQuery
(
'
#
'
+
hashed
_id
+
'
.chat-content
'
);
var
chat_content
=
jQuery
(
'
#
'
+
chat
_id
+
'
.chat-content
'
);
chat_content
.
append
(
'
<div class="chat-message">
'
+
'
<span class="chat-message-me">
'
+
time
+
'
me: </span>
'
+
...
...
@@ -345,36 +347,29 @@ $(document).ready(function () {
var
chatdata
=
jQuery
(
'
span#babble-client-chatdata
'
);
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
chatdata
.
attr
(
'
username
'
));
var
open_chats
=
[],
chat_id
;
xmppchat
.
username
=
chatdata
.
attr
(
'
username
'
);
xmppchat
.
base_url
=
chatdata
.
attr
(
'
base_url
'
);
$
.
hook
([
'
show
'
,
'
hide
'
]);
chat_id
=
'
online-users-container
'
;
$
(
"
div#
"
+
chat_id
)
$
(
"
div#online-users-container
"
)
.
bind
(
'
onaftershow
'
,
function
(
e
)
{
xmppchat
.
addChatToCookie
(
chat_id
);
xmppchat
.
chats
.
push
(
chat_id
);
xmppchat
.
addChatToCookie
(
'
online-users-container
'
);
xmppchat
.
chats
.
push
(
'
online-users-container
'
);
});
$
(
'
a.user-details-toggle
'
).
live
(
'
click
'
,
function
(
e
)
{
var
userid
=
$
(
this
).
parent
().
attr
(
'
data-userid
'
),
$field
=
$
(
'
[name="message"]:input
'
,
$
(
this
).
parent
()[
0
]),
recipient
=
$field
.
attr
(
'
data-recipient
'
);
xmppchat
.
startChat
(
'
chatbox_
'
+
userid
,
recipient
);
xmppchat
.
startChat
(
recipient
);
e
.
preventDefault
();
});
/*
jQuery.cookie('chats-open-'+username, null, {path: '/'});
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
null
,
{
path
:
'
/
'
});
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
for
(
var
i
=
0
;
i
<
open_chats
.
length
;
i
++
)
{
chat_id = open_chats[i];
if (chat_id) {
createChat(chat_id, 1);
}
xmppchat
.
createChat
(
open_chats
[
i
],
1
);
}
}
*/
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment