class Index

Public Class Methods

new(h) click to toggle source
# File lib/h2g_ajaxchat.rb, line 220
def initialize(h)
  @h = h
end

Public Instance Methods

html() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
Calls superclass method WebPage#to_html
# File lib/h2g_ajaxchat.rb, line 250
def to_html()
  
  super()
end