Class: Index

Inherits:
WebPage show all
Defined in:
lib/h2g_ajaxchat.rb

Instance Attribute Summary

Attributes inherited from WebPage

#css, #s

Instance Method Summary collapse

Methods inherited from WebPage

#to_js, #to_s

Constructor Details

#initialize(h) ⇒ Index

Returns a new instance of Index.



217
218
219
# File 'lib/h2g_ajaxchat.rb', line 217

def initialize(h)
  @h = h
end

Instance Method Details

#htmlObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/h2g_ajaxchat.rb', line 221

def html()
  
@html ||= "<body onload=\"refresh()\">\n<div id=\"wrapper\">\n <div id=\"menu\">\n  <p class=\"welcome\">Welcome, <b> <%= @h[:username] %> </b></p>\n  <p class=\"logout\"><a id=\"exit\" href=\"logout\">Exit Chat</a></p>\n  <div style=\"clear:both\"></div>\n </div> \n <div id=\"chatbox\"></div>\n  <input name=\"usermsg\" type=\"text\" id=\"usermsg\" size=\"33\" onkeyup='ajaxCall1(event.keyCode, this)' autofocus='true'/>\n\n</div>      \n"

end

#jsObject



252
253
254
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
# File 'lib/h2g_ajaxchat.rb', line 252

def js()
  
@js ||= "\nfunction updateScroll(){\n  var element = document.getElementById(\"chatbox\");\n  element.scrollTop = element.scrollHeight;\n}  \n// ajaxCall1();\n\nfunction ajaxRequest(url, cFunction) {\nvar xhttp;\nxhttp = new XMLHttpRequest();\nxhttp.onreadystatechange = function() {\n  if (this.readyState == 4 && this.status == 200) {\n    cFunction(this);\n  }\n};\nxhttp.open(\"GET\", url, true);\nxhttp.send();\n}\n\n\nfunction ajaxCall1(keyCode, e) {\nif (keyCode==13){\n  ajaxRequest('chatter?msg=' + e.value, ajaxResponse1)\n  e.value = '';\n}  \n}\n\nfunction ajaxResponse1(xhttp) {\ne = document.getElementById('chatbox')\ns = xhttp.responseText;\ne.innerHTML = e.innerHTML + s;\n\nif (s.length > 1)\n  updateScroll();\n}\n\nfunction refresh() {\nsetInterval(ajaxCall2,2000);\n}\n\nfunction ajaxCall2() {\najaxRequest('chatter', ajaxResponse1)\n}\n\n"

end

#to_cssObject



239
240
241
242
243
244
245
# File 'lib/h2g_ajaxchat.rb', line 239

def to_css()
@css ||= '
body {font-family: Arial;}
#chatbox {overflow: scroll; height: 40%}
div p span {colour: #dde}
'
end

#to_htmlObject



247
248
249
250
# File 'lib/h2g_ajaxchat.rb', line 247

def to_html()
  
  super()
end