Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
c2ee59e3
Commit
c2ee59e3
authored
14 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
showing server messages. refreshing messages on timer. removing old messages.
parent
cbe56b55
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/html/main.js
+24
-11
24 additions, 11 deletions
examples/html/main.js
with
24 additions
and
11 deletions
examples/html/main.js
+
24
−
11
View file @
c2ee59e3
// 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
=
{
// Backend URL, string.
...
...
@@ -9,25 +8,38 @@ var chat = {
errorMessageFadeOutTimeoutMs
:
2000
,
errorMessageFadeOutTimer
:
null
,
lastMessageId
:
0
,
getMessagesIntervalMs
:
1000
,
};
chat
.
normalizeText
=
function
(
text
)
{
return
text
.
replace
(
'
<
'
,
'
<
'
).
replace
(
'
>
'
,
'
>
'
);
};
chat
.
refresh
=
function
(
data
)
{
$
.
each
(
data
,
function
(
index
,
entry
)
{
var
row
=
$
(
'
<div>
'
).
addClass
(
'
message-row
'
).
appendTo
(
'
#mml
'
);
var
timestamp
=
(
new
Date
(
entry
.
timestamp
*
1000
)).
toLocaleTimeString
();
$
(
'
<span>
'
).
addClass
(
'
message-timestamp
'
).
html
(
'
[
'
+
timestamp
+
'
]
'
).
prependTo
(
row
);
$
(
'
<span>
'
).
addClass
(
'
message-user
'
).
html
(
entry
.
user
+
'
:
'
).
appendTo
(
row
);
$
(
'
<span>
'
).
addClass
(
'
message-text
'
).
html
(
entry
.
text
).
appendTo
(
row
);
$
(
'
<span>
'
)
.
addClass
(
'
message-timestamp
'
)
.
html
(
'
[
'
+
timestamp
+
'
]
'
)
.
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
;
});
// TODO(lsm): keep only chat.maxVisibleMessages, delete older ones.
/*
while ($('#mml').children().length < chat.maxVisibleMessages) {
$('#mml').children()[0].remove();
// Keep only chat.maxVisibleMessages, delete older ones.
while
(
$
(
'
#mml
'
).
children
().
length
>
chat
.
maxVisibleMessages
)
{
$
(
'
#mml div:first-child
'
).
remove
();
}
*/
};
chat
.
getMessages
=
function
()
{
...
...
@@ -39,6 +51,7 @@ chat.getMessages = function() {
error
:
function
()
{
},
});
window
.
setTimeout
(
chat
.
getMessages
,
chat
.
getMessagesIntervalMs
);
};
chat
.
handleMenuItemClick
=
function
(
ev
)
{
...
...
@@ -60,7 +73,7 @@ chat.handleMessageInput = function(ev) {
var
input
=
ev
.
target
;
if
(
ev
.
keyCode
!=
13
||
!
input
.
value
)
return
;
input
.
disabled
=
true
;
//
input.disabled = true;
$
.
ajax
({
dataType
:
'
jsonp
'
,
url
:
chat
.
backendUrl
+
'
/ajax/send_message
'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment