Browse files

simplify the chat example

  • Loading branch information...
1 parent ac67f1c commit 5d5aaf4b92153b7fc4abdeefc6ae15622d777a16 @nicferrier committed Aug 29, 2012
Showing with 30 additions and 28 deletions.
  1. +21 −19 examples/chat.el
  2. +2 −2 examples/chat.html
  3. +7 −7 examples/chat.js
View
40 examples/chat.el
@@ -1,6 +1,6 @@
;;; chat example - very simple webchat -*- lexical-binding: t -*-
-
-(require 'cl) (require 'esxml)
+(require 'esxml)
+(require 'cl)
(defvar chat-list '())
@@ -20,8 +20,7 @@
(defun chat-comet-handler (httpcon)
"Defer until there is new chat."
- (let ((callback (elnode-http-param httpcon "callback"))
- (entered (current-time)))
+ (let ((entered (current-time)))
(elnode-defer-until (chat-list-since entered)
(elnode-send-json
httpcon elnode-defer-guard-it :jsonp t))))
@@ -35,31 +34,34 @@
;; Main page setup stuff
-(require 'creole)
-
(defconst chat-dir (file-name-directory
(or (buffer-file-name)
load-file-name
default-directory)))
+(defun chat-list-to-html ()
+ "Return the `chat-list' as rows for initial chat display."
+ (loop for entry in chat-list
+ if (equal 3 (length entry))
+ concat
+ (esxml-to-xml
+ `(tr
+ ()
+ (td
+ ((class . ,(concat "username," (elt entry 1)))) ,(elt entry 1))
+ (td ((class . "message")) ,(elt entry 2))))))
+
(defun chat-main-templater ()
"Return the `chat-list' as rows for initial chat display."
(list
(cons
"messages"
- (loop for entry in
- (subseq chat-list 0
- (if (> (length chat-list) 10)
- 12
- (length chat-list)))
- if (equal 3 (length entry))
- concat
- (esxml-to-xml
- `(tr
- ()
- (td
- ((class . ,(concat "username," (elt entry 1)))) ,(elt entry 1))
- (td ((class . "message")) ,(elt entry 2))))))))
+ (let ((chat-list
+ (subseq chat-list
+ 0 (if (> (length chat-list) 10)
+ 12
+ (length chat-list)))))
+ (chat-list-to-html)))))
(defun chat-main-handler (httpcon)
"The main handler."
View
4 examples/chat.html
@@ -20,13 +20,13 @@
</table>
</div>
</body>
-<script src="/chat.js" language="Javascript">
-</script>
<iframe
style="float:right;"
width="1"
height="1"
name="_sendtarget"
src="">
</iframe>
+<script src="/chat.js" language="Javascript">
+</script>
</html>
View
14 examples/chat.js
@@ -53,12 +53,15 @@ function $(selector) {
return bonzo(qwery(selector));
}
-/* user setup
- *
+
+/*
+ * Chat stuff
*/
+
+// User setup
bean.add(
- $("form")[0],
- "submit",
+ $("[name=_sendtarget]")[0],
+ "load",
function (e) {
$("[name=msg]")[0].value="";
}
@@ -87,9 +90,6 @@ else {
});
}
-/*
- * Chat stuff
- */
function chatPoll() {
snack.JSONP(
{ url: '/chat/poll/', key: 'callback', now: true },

0 comments on commit 5d5aaf4

Please sign in to comment.