Class: Index
Instance Attribute Summary
Attributes inherited from WebPage
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(h) ⇒ Index
constructor
A new instance of Index.
- #js ⇒ Object
- #to_css ⇒ Object
- #to_html ⇒ Object
Methods inherited from WebPage
Constructor Details
#initialize(h) ⇒ Index
Returns a new instance of Index.
220 221 222 |
# File 'lib/h2g_ajaxchat.rb', line 220 def initialize(h) @h = h end |
Instance Method Details
#html ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/h2g_ajaxchat.rb', line 224 def html() @html ||= <<EOF <body onload="refresh()"> <div id="wrapper"> <div id="menu"> <p class="welcome">Welcome, <b> <%= @h[:username] %> </b></p> <p class="logout"><a id="exit" href="logout">Exit Chat</a></p> <div style="clear:both"></div> </div> <div id="chatbox"></div> <input name="usermsg" type="text" id="usermsg" size="33" onkeyup='ajaxCall1(event.keyCode, this)' autofocus='true'/> </div> EOF end |
#js ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/h2g_ajaxchat.rb', line 255 def js() @js ||= <<EOF function updateScroll(){ var element = document.getElementById("chatbox"); element.scrollTop = element.scrollHeight; } // ajaxCall1(); function ajaxRequest(url, cFunction) { var xhttp; xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { cFunction(this); } }; xhttp.open("GET", url, true); xhttp.send(); } function ajaxCall1(keyCode, e) { if (keyCode==13){ ajaxRequest('chatter?msg=' + e.value, ajaxResponse1) e.value = ''; } } function ajaxResponse1(xhttp) { e = document.getElementById('chatbox') s = xhttp.responseText; e.innerHTML = e.innerHTML + s; if (s.length > 1) updateScroll(); } function refresh() { setInterval(ajaxCall2,2000); } function ajaxCall2() { ajaxRequest('chatter', ajaxResponse1) } EOF end |
#to_css ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/h2g_ajaxchat.rb', line 242 def to_css() @css ||= ' body {font-family: Arial;} #chatbox {overflow: scroll; height: 40%} div p span {colour: #dde} ' end |
#to_html ⇒ Object
250 251 252 253 |
# File 'lib/h2g_ajaxchat.rb', line 250 def to_html() super() end |