Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
c2ee59e3
Commit
c2ee59e3
authored
May 05, 2010
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
showing server messages. refreshing messages on timer. removing old messages.
parent
cbe56b55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
main.js
examples/html/main.js
+24
-11
No files found.
examples/html/main.js
View file @
c2ee59e3
// This file is part of Mongoose project, http://code.google.com/p/mongoose
// This file is part of Mongoose project, http://code.google.com/p/mongoose
// $Id: main.js 514 2010-05-03 11:06:27Z valenok $
var
chat
=
{
var
chat
=
{
// Backend URL, string.
// Backend URL, string.
...
@@ -9,25 +8,38 @@ var chat = {
...
@@ -9,25 +8,38 @@ var chat = {
errorMessageFadeOutTimeoutMs
:
2000
,
errorMessageFadeOutTimeoutMs
:
2000
,
errorMessageFadeOutTimer
:
null
,
errorMessageFadeOutTimer
:
null
,
lastMessageId
:
0
,
lastMessageId
:
0
,
getMessagesIntervalMs
:
1000
,
};
chat
.
normalizeText
=
function
(
text
)
{
return
text
.
replace
(
'<'
,
'<'
).
replace
(
'>'
,
'>'
);
};
};
chat
.
refresh
=
function
(
data
)
{
chat
.
refresh
=
function
(
data
)
{
$
.
each
(
data
,
function
(
index
,
entry
)
{
$
.
each
(
data
,
function
(
index
,
entry
)
{
var
row
=
$
(
'<div>'
).
addClass
(
'message-row'
).
appendTo
(
'#mml'
);
var
row
=
$
(
'<div>'
).
addClass
(
'message-row'
).
appendTo
(
'#mml'
);
var
timestamp
=
(
new
Date
(
entry
.
timestamp
*
1000
)).
toLocaleTimeString
();
var
timestamp
=
(
new
Date
(
entry
.
timestamp
*
1000
)).
toLocaleTimeString
();
$
(
'<span>'
).
addClass
(
'message-timestamp'
).
html
(
$
(
'<span>'
)
'['
+
timestamp
+
']'
).
prependTo
(
row
);
.
addClass
(
'message-timestamp'
)
$
(
'<span>'
).
addClass
(
'message-user'
).
html
(
entry
.
user
+
':'
).
appendTo
(
row
);
.
html
(
'['
+
timestamp
+
']'
)
$
(
'<span>'
).
addClass
(
'message-text'
).
html
(
entry
.
text
).
appendTo
(
row
);
.
prependTo
(
row
);
$
(
'<span>'
)
.
addClass
(
'message-user'
)
.
addClass
(
entry
.
user
?
''
:
'message-user-server'
)
.
html
(
chat
.
normalizeText
((
entry
.
user
||
'[server]'
)
+
':'
))
.
appendTo
(
row
);
$
(
'<span>'
)
.
addClass
(
'message-text'
)
.
addClass
(
entry
.
user
?
''
:
'message-text-server'
)
.
html
(
chat
.
normalizeText
(
entry
.
text
))
.
appendTo
(
row
);
chat
.
lastMessageId
=
Math
.
max
(
chat
.
lastMessageId
,
entry
.
id
)
+
1
;
chat
.
lastMessageId
=
Math
.
max
(
chat
.
lastMessageId
,
entry
.
id
)
+
1
;
});
});
// TODO(lsm): keep only chat.maxVisibleMessages, delete older ones.
// Keep only chat.maxVisibleMessages, delete older ones.
/*
while
(
$
(
'#mml'
).
children
().
length
>
chat
.
maxVisibleMessages
)
{
while ($('#mml').children().length < chat.maxVisibleMessages) {
$
(
'#mml div:first-child'
).
remove
();
$('#mml').children()[0].remove();
}
}
*/
};
};
chat
.
getMessages
=
function
()
{
chat
.
getMessages
=
function
()
{
...
@@ -39,6 +51,7 @@ chat.getMessages = function() {
...
@@ -39,6 +51,7 @@ chat.getMessages = function() {
error
:
function
()
{
error
:
function
()
{
},
},
});
});
window
.
setTimeout
(
chat
.
getMessages
,
chat
.
getMessagesIntervalMs
);
};
};
chat
.
handleMenuItemClick
=
function
(
ev
)
{
chat
.
handleMenuItemClick
=
function
(
ev
)
{
...
@@ -60,7 +73,7 @@ chat.handleMessageInput = function(ev) {
...
@@ -60,7 +73,7 @@ chat.handleMessageInput = function(ev) {
var
input
=
ev
.
target
;
var
input
=
ev
.
target
;
if
(
ev
.
keyCode
!=
13
||
!
input
.
value
)
if
(
ev
.
keyCode
!=
13
||
!
input
.
value
)
return
;
return
;
input
.
disabled
=
true
;
//
input.disabled = true;
$
.
ajax
({
$
.
ajax
({
dataType
:
'jsonp'
,
dataType
:
'jsonp'
,
url
:
chat
.
backendUrl
+
'/ajax/send_message'
,
url
:
chat
.
backendUrl
+
'/ajax/send_message'
,
...
...
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