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
d4673b94
Commit
d4673b94
authored
Jun 18, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the remaining functions into the module. Renamed the module to xmppchat.
parent
790b9451
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
148 additions
and
157 deletions
+148
-157
collective.xmpp.chat.js
collective.xmpp.chat.js
+148
-157
No files found.
collective.xmpp.chat.js
View file @
d4673b94
var
babblexmpp
=
(
function
(
$
,
console
)
{
var
xmppchat
=
(
function
(
$
,
console
)
{
var
obj
=
{};
obj
.
chats
=
[];
obj
.
chat_focus
=
[];
obj
.
chats
=
[];
obj
.
chat_focus
=
[];
obj
.
sanitizePath
=
function
(
call
)
{
return
babblexmpp
.
base_url
+
call
;
return
xmppchat
.
base_url
+
call
;
};
obj
.
hash
=
function
(
str
)
{
...
...
@@ -26,7 +26,7 @@ var babblexmpp = (function ($, console) {
};
obj
.
getMinimizedChats
=
function
()
{
var
cookie
=
$
.
cookie
(
'
chats_minimized_
'
+
babblexmpp
.
username
);
var
cookie
=
$
.
cookie
(
'
chats_minimized_
'
+
xmppchat
.
username
);
if
(
cookie
)
{
return
cookie
.
split
(
/
\|
/
);
}
...
...
@@ -35,8 +35,8 @@ var babblexmpp = (function ($, console) {
obj
.
positionNewChat
=
function
(
chatbox
)
{
var
open_chats
=
0
;
for
(
var
i
=
0
;
i
<
babblexmpp
.
chats
.
length
;
i
++
)
{
if
(
$
(
"
#
"
+
babblexmpp
.
hash
(
babblexmpp
.
chats
[
i
])).
css
(
'
display
'
)
!=
'
none
'
)
{
for
(
var
i
=
0
;
i
<
xmppchat
.
chats
.
length
;
i
++
)
{
if
(
$
(
"
#
"
+
xmppchat
.
hash
(
xmppchat
.
chats
[
i
])).
css
(
'
display
'
)
!=
'
none
'
)
{
open_chats
++
;
}
}
...
...
@@ -50,7 +50,7 @@ var babblexmpp = (function ($, console) {
};
obj
.
handleChatEvents
=
function
(
chat_id
)
{
var
chat_area
=
$
(
"
#
"
+
babblexmpp
.
hash
(
chat_id
)
+
"
.chat-textarea
"
),
var
chat_area
=
$
(
"
#
"
+
xmppchat
.
hash
(
chat_id
)
+
"
.chat-textarea
"
),
chat_type
=
chat_id
.
split
(
'
_
'
)[
0
],
that
=
this
;
...
...
@@ -62,7 +62,7 @@ var babblexmpp = (function ($, console) {
that
.
chat_focus
[
chat_id
]
=
true
;
chat_area
.
addClass
(
'
chat-textarea-
'
+
chat_type
+
'
-selected
'
);
});
var
chatbox
=
$
(
"
#
"
+
babblexmpp
.
hash
(
chat_id
));
var
chatbox
=
$
(
"
#
"
+
xmppchat
.
hash
(
chat_id
));
chatbox
.
click
(
function
()
{
if
(
chatbox
.
find
(
'
.chat-content
'
).
css
(
'
display
'
)
!=
'
none
'
)
{
chatbox
.
find
(
'
.chat-textarea
'
).
focus
();
...
...
@@ -71,14 +71,14 @@ var babblexmpp = (function ($, console) {
};
obj
.
createChatBox
=
function
(
chat_id
,
jid
)
{
var
path
=
babblexmpp
.
sanitizePath
(
'
/@@render_chat_box
'
);
var
path
=
xmppchat
.
sanitizePath
(
'
/@@render_chat_box
'
);
$
.
ajax
({
url
:
path
,
cache
:
false
,
async
:
false
,
data
:
{
chat_id
:
chat_id
,
box_id
:
babblexmpp
.
hash
(
chat_id
),
box_id
:
xmppchat
.
hash
(
chat_id
),
jid
:
jid
,
tzoffset
:
-
(
new
Date
().
getTimezoneOffset
())
},
...
...
@@ -105,27 +105,16 @@ var babblexmpp = (function ($, console) {
}
}
});
return
$
(
'
#
'
+
babblexmpp
.
hash
(
chat_id
));
return
$
(
'
#
'
+
xmppchat
.
hash
(
chat_id
));
};
obj
.
createChat
=
function
(
chat_id
,
minimize
,
jid
)
{
var
cookie
=
$
.
cookie
(
'
chats-open-
'
+
this
.
username
),
open_chats
=
[],
new_cookie
,
chat_content
;
console
.
log
(
'
createChat: chat_id is
'
+
chat_id
);
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
if
(
!
(
chat_id
in
this
.
oc
(
open_chats
)))
{
// Update the cookie if this new chat is not yet in it.
open_chats
.
push
(
chat_id
);
new_cookie
=
open_chats
.
join
(
'
|
'
);
$
.
cookie
(
'
chats-open-
'
+
this
.
username
,
new_cookie
,
{
path
:
'
/
'
});
console
.
log
(
'
createChat: updated cookie =
'
+
new_cookie
+
'
\n
'
);
}
chat_content
,
chatbox
;
var
chatbox
=
$
(
"
#
"
+
this
.
hash
(
chat_id
));
this
.
addChatToCookie
(
chat_id
);
chatbox
=
$
(
"
#
"
+
this
.
hash
(
chat_id
));
if
(
chatbox
.
length
>
0
)
{
// The chatbox exists, merely hidden
if
(
chatbox
.
css
(
'
display
'
)
==
'
none
'
)
{
...
...
@@ -158,9 +147,6 @@ var babblexmpp = (function ($, console) {
if
(
chat_content
.
length
)
{
chat_content
.
scrollTop
(
chat_content
[
0
].
scrollHeight
);
}
else
{
console
.
log
(
'
createChat: could not get .chat-content
'
);
}
return
chatbox
;
};
...
...
@@ -186,6 +172,24 @@ var babblexmpp = (function ($, console) {
}
};
obj
.
addChatToCookie
=
function
(
chat_id
)
{
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
),
new_cookie
,
open_chats
=
[];
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
if
(
!
(
chat_id
in
this
.
oc
(
open_chats
)))
{
// Update the cookie if this new chat is not yet in it.
open_chats
.
push
(
chat_id
);
new_cookie
=
open_chats
.
join
(
'
|
'
);
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
new_cookie
,
{
path
:
'
/
'
});
console
.
log
(
'
updated cookie =
'
+
new_cookie
+
'
\n
'
);
}
this
.
chats
.
push
(
chat_id
);
};
obj
.
receiveMessage
=
function
(
event
)
{
var
user_id
=
Strophe
.
getNodeFromJid
(
event
.
from
),
jid
=
Strophe
.
getBareJidFromJid
(
event
.
from
),
...
...
@@ -228,162 +232,149 @@ var babblexmpp = (function ($, console) {
jarnxmpp
.
UI
.
updateMsgCounter
();
});
};
return
obj
;
})(
jQuery
,
console
||
{
log
:
function
(){}}
);
obj
.
closeChat
=
function
(
chat_id
,
audience
)
{
jQuery
(
'
#
'
+
xmppchat
.
hash
(
chat_id
)).
css
(
'
display
'
,
'
none
'
);
xmppchat
.
reorderChats
();
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
),
open_chats
=
[],
new_chats
=
[];
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
for
(
var
i
=
0
;
i
<
open_chats
.
length
;
i
++
)
{
if
(
open_chats
[
i
]
!=
chat_id
)
{
new_chats
.
push
(
open_chats
[
i
]);
}
}
if
(
new_chats
.
length
)
{
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
new_chats
.
join
(
'
|
'
),
{
path
:
'
/
'
});
}
else
{
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
null
,
{
path
:
'
/
'
});
}
this
.
chats
.
pop
(
chat_id
);
};
function
keypressed
(
event
,
textarea
,
audience
,
hashed_id
,
chat_type
)
{
if
(
event
.
keyCode
==
13
&&
!
event
.
shiftKey
)
{
var
textbox
=
jQuery
(
textarea
);
var
message
=
textbox
.
val
();
var
form
=
textbox
.
parent
();
form
.
submit
();
message
=
message
.
replace
(
/^
\s
+|
\s
+jQuery/g
,
""
);
textbox
.
val
(
''
).
focus
().
css
(
'
height
'
,
'
44px
'
);
if
(
message
!==
''
)
{
message
=
message
.
replace
(
/</g
,
"
<
"
).
replace
(
/>/g
,
"
>
"
).
replace
(
/
\"
/g
,
"
"
"
);
list
=
message
.
match
(
/
\b(
http:
\/\/
www
\.\S
+
\.\w
+|www
\.\S
+
\.\w
+|http:
\/\/(?=[^
w
]){3}\S
+
[\.
:
]\S
+
)[^
]
+
\b
/g
);
if
(
list
)
{
for
(
i
=
0
;
i
<
list
.
length
;
i
++
)
{
message
=
message
.
replace
(
list
[
i
],
"
<a target='_blank' href='
"
+
escape
(
list
[
i
]
)
+
"
'>
"
+
list
[
i
]
+
"
</a>
"
);
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
'
)
{
// Chat will be maximized
new_cookie
=
[];
for
(
var
i
=
0
;
i
<
minimized_chats
.
length
;
i
++
)
{
if
(
minimized_chats
[
i
]
!=
chat_id
)
{
new_cookie
.
push
(
minimized_chats
[
i
]);
}
}
var
now
=
new
Date
();
var
minutes
=
now
.
getMinutes
().
toString
();
if
(
minutes
.
length
==
1
)
{
minutes
=
'
0
'
+
minutes
;}
var
time
=
now
.
toLocaleTimeString
().
substring
(
0
,
5
);
jQuery
.
cookie
(
'
chats_minimized_
'
+
xmppchat
.
username
,
new_cookie
.
join
(
'
|
'
));
var
chat_content
=
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-content
'
);
chat_content
.
append
(
'
<div class="chat-message">
'
+
'
<span class="chat-message-me">
'
+
time
+
'
me: </span>
'
+
'
<span class="chat-message-content">
'
+
message
+
'
</span>
'
+
'
</div>
'
);
chat_content
.
css
(
'
display
'
,
'
block
'
);
chat_content
.
scrollTop
(
chat_content
[
0
].
scrollHeight
);
}
}
var
adjustedHeight
=
textarea
.
clientHeight
;
var
maxHeight
=
94
;
if
(
maxHeight
>
adjustedHeight
)
{
adjustedHeight
=
Math
.
max
(
textarea
.
scrollHeight
,
adjustedHeight
);
if
(
maxHeight
)
{
adjustedHeight
=
Math
.
min
(
maxHeight
,
adjustedHeight
);
}
if
(
adjustedHeight
>
textarea
.
clientHeight
)
{
jQuery
(
textarea
).
css
(
'
height
'
,
adjustedHeight
+
8
+
'
px
'
);
}
}
else
{
jQuery
(
textarea
).
css
(
'
overflow
'
,
'
auto
'
);
}
}
function
closeChat
(
chat_id
,
audience
)
{
jQuery
(
'
#
'
+
babblexmpp
.
hash
(
chat_id
)).
css
(
'
display
'
,
'
none
'
);
babblexmpp
.
reorderChats
();
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
);
var
open_chats
=
[];
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
new_chats
=
[];
for
(
var
i
=
0
;
i
<
open_chats
.
length
;
i
++
)
{
if
(
open_chats
[
i
]
!=
chat_id
)
{
new_chats
.
push
(
open_chats
[
i
]);
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-head
'
).
removeClass
(
'
chat-head-minimized-with-messages
'
);
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
block
'
);
}
else
{
// Chat will be minimized
if
(
!
(
chat_id
in
xmppchat
.
oc
(
minimized_chats
)))
{
new_cookie
=
chat_id
;
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
'
);
}
}
if
(
new_chats
.
length
)
{
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
,
new_chats
.
join
(
'
|
'
),
{
path
:
'
/
'
});
}
else
{
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
,
null
,
{
path
:
'
/
'
});
}
}
};
function
toggleChat
(
chat_id
)
{
var
minimized_chats
=
babblexmpp
.
getMinimizedChats
();
var
hashed_id
=
babblexmpp
.
hash
(
chat_id
);
var
new_cookie
;
if
(
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-content
'
).
css
(
'
display
'
)
==
'
none
'
)
{
// Chat will be maximized
new_cookie
=
[];
for
(
var
i
=
0
;
i
<
minimized_chats
.
length
;
i
++
)
{
if
(
minimized_chats
[
i
]
!=
chat_id
)
{
new_cookie
.
push
(
minimized_chats
[
i
]);
obj
.
keyPressed
=
function
(
event
,
textarea
,
audience
,
hashed_id
,
chat_type
)
{
if
(
event
.
keyCode
==
13
&&
!
event
.
shiftKey
)
{
var
textbox
=
jQuery
(
textarea
);
var
message
=
textbox
.
val
();
var
form
=
textbox
.
parent
();
form
.
submit
();
message
=
message
.
replace
(
/^
\s
+|
\s
+jQuery/g
,
""
);
textbox
.
val
(
''
).
focus
().
css
(
'
height
'
,
'
44px
'
);
if
(
message
!==
''
)
{
message
=
message
.
replace
(
/</g
,
"
<
"
).
replace
(
/>/g
,
"
>
"
).
replace
(
/
\"
/g
,
"
"
"
);
list
=
message
.
match
(
/
\b(
http:
\/\/
www
\.\S
+
\.\w
+|www
\.\S
+
\.\w
+|http:
\/\/(?=[^
w
]){3}\S
+
[\.
:
]\S
+
)[^
]
+
\b
/g
);
if
(
list
)
{
for
(
i
=
0
;
i
<
list
.
length
;
i
++
)
{
message
=
message
.
replace
(
list
[
i
],
"
<a target='_blank' href='
"
+
escape
(
list
[
i
]
)
+
"
'>
"
+
list
[
i
]
+
"
</a>
"
);
}
}
var
now
=
new
Date
();
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
'
);
chat_content
.
append
(
'
<div class="chat-message">
'
+
'
<span class="chat-message-me">
'
+
time
+
'
me: </span>
'
+
'
<span class="chat-message-content">
'
+
message
+
'
</span>
'
+
'
</div>
'
);
chat_content
.
scrollTop
(
chat_content
[
0
].
scrollHeight
);
}
}
jQuery
.
cookie
(
'
chats_minimized_
'
+
babblexmpp
.
username
,
new_cookie
.
join
(
'
|
'
))
;
var
chat_content
=
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-content
'
)
;
chat_content
.
css
(
'
display
'
,
'
block
'
);
chat_content
.
scrollTop
(
chat_content
[
0
].
scroll
Height
);
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-head
'
).
removeClass
(
'
chat-head-minimized-with-messages
'
);
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
block
'
);
}
else
{
// Chat will be minimized
if
(
!
(
chat_id
in
babblexmpp
.
oc
(
minimized_chats
)))
{
new_cookie
=
chat_id
;
new_cookie
+=
'
|
'
+
minimized_chats
.
join
(
'
|
'
);
jQuery
.
cookie
(
'
chats_minimized_
'
+
babblexmpp
.
username
,
new_cookie
);
var
adjustedHeight
=
textarea
.
clientHeight
;
var
maxHeight
=
94
;
if
(
maxHeight
>
adjustedHeight
)
{
adjustedHeight
=
Math
.
max
(
textarea
.
scrollHeight
,
adjusted
Height
);
if
(
maxHeight
)
{
adjustedHeight
=
Math
.
min
(
maxHeight
,
adjustedHeight
);
}
if
(
adjustedHeight
>
textarea
.
clientHeight
)
{
jQuery
(
textarea
).
css
(
'
height
'
,
adjustedHeight
+
8
+
'
px
'
);
}
}
else
{
jQuery
(
textarea
).
css
(
'
overflow
'
,
'
auto
'
);
}
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-content
'
).
css
(
'
display
'
,
'
none
'
)
;
jQuery
(
'
#
'
+
hashed_id
+
'
.chat-input
'
).
css
(
'
display
'
,
'
none
'
);
}
}
}
;
return
obj
;
}
)(
jQuery
,
console
||
{
log
:
function
(){}}
);
$
(
document
).
unbind
(
'
jarnxmpp.message
'
);
$
(
document
).
bind
(
'
jarnxmpp.message
'
,
function
(
event
)
{
babblexmpp
.
receiveMessage
(
event
);
xmppchat
.
receiveMessage
(
event
);
});
$
(
document
).
ready
(
function
()
{
var
chatdata
=
jQuery
(
'
span#babble-client-chatdata
'
);
babblexmpp
.
username
=
chatdata
.
attr
(
'
username
'
);
babblexmpp
.
base_url
=
chatdata
.
attr
(
'
base_url
'
);
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
)
.
bind
(
'
onbeforeshow
'
,
function
(
e
)
{
})
.
bind
(
'
onshow
'
,
function
(
e
)
{
})
.
bind
(
'
onaftershow
'
,
function
(
e
)
{
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
);
var
open_chats
=
[];
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
if
(
!
(
chat_id
in
babblexmpp
.
oc
(
open_chats
)))
{
// Update the cookie if this new chat is not yet in it.
open_chats
.
push
(
chat_id
);
var
new_cookie
=
open_chats
.
join
(
'
|
'
);
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
,
new_cookie
,
{
path
:
'
/
'
});
console
.
log
(
'
updated cookie =
'
+
new_cookie
+
'
\n
'
);
}
babblexmpp
.
chats
.
push
(
chat_id
);
})
.
bind
(
'
onafterhide
'
,
function
(
e
)
{
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
);
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
new_chats
=
[];
for
(
var
i
=
0
;
i
<
open_chats
.
length
;
i
++
)
{
if
(
open_chats
[
i
]
!=
chat_id
)
{
new_chats
.
push
(
open_chats
[
i
]);
}
}
if
(
new_chats
.
length
)
{
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
,
new_chats
.
join
(
'
|
'
),
{
path
:
'
/
'
});
}
else
{
jQuery
.
cookie
(
'
chats-open-
'
+
babblexmpp
.
username
,
null
,
{
path
:
'
/
'
});
}
xmppchat
.
addChatToCookie
(
chat_id
);
xmppchat
.
chats
.
push
(
chat_id
);
});
$
(
'
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
'
);
babblexmpp
.
startChat
(
'
chatbox_
'
+
userid
,
recipient
);
xmppchat
.
startChat
(
'
chatbox_
'
+
userid
,
recipient
);
e
.
preventDefault
();
});
/*
jQuery.cookie('chats-open-'+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);
}
}
}
*/
});
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