CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   XML (http://www.codingforums.com/forumdisplay.php?f=3)
-   -   Help on this code (http://www.codingforums.com/showthread.php?t=284897)

Carga Sok 12-27-2012 01:12 PM

Help on this code
 
I have a code that needs to be edited to look better that its ouput. I wish someone can edit this code

Code:

<html>
  <head>
      <title>SMS And Twitter Messages Ticker</title>
      <script language="javascript" type="text/javascript">
       
        // configuration
        var MessageExtractionUrl      =
http://127.0.0.1:9999/get.messages?$clientid=0y=2168";
        var MessageExtractionInterval = 1;
        var MessageAnimationSpeed    = 15;
        var MessageAnimationSteps    = 20;
        var MessageFontSize          = "12px";
        var MessageLeftPadding        = "5px";
        var MessageBackground        = "white";
        var SwitchMessageBackground  = "white";
        var MessageDisplayCount      = 12;
       
        // global variables
        var animateWhiteDiv = true;
        var animateMessage  = false;
        var animateStep    = 0
        var pollingXmlData  = false;
        var textMessages    = [];
        var timerTick      = "";
        var serverSerialNo  = -1;
       
        function OnReadyStateChange() {
            if (xmlhttp.readyState == 4) {
              if (xmlhttp.status == 200) {
                  if (xmlhttp.responseXML.firstChild.attributes["serial"] != null) {
                    var serial = parseInt(xmlhttp.responseXML.firstChild.attributes["serial"].nodeValue);
                    if (serial > serverSerialNo) {
                        serverSerialNo = serial;
                        var elementChild = xmlhttp.responseXML.firstChild.firstElementChild;
                        while (elementChild) {
                          //alert("nuevos mensaje '" + elementChild.textContent + "'");
                          textMessages.push(elementChild.textContent);
                          elementChild = elementChild.nextElementSibling;
                        }
                    }
                  }
              } else {
                  alert("There was a problem retrieving the XML data");
              }
              pollingXmlData = false;
            }
        }
       
        function AnimateIntervalTick() {
            if (animateMessage) {
              var divTextMessages = document.getElementById("divTextMessages");
              var textMessagesDivs = divTextMessages.getElementsByTagName("div");
              if (animateStep < MessageAnimationSteps) {
                  textMessagesDivs[0].style.height = animateStep + "px";
                  animateStep++;
              } else {
                  var textElement = document.createElement("p");
                  textElement.style.fontSize  = MessageFontSize;
                  textElement.style.lineHeight = textMessagesDivs[0].style.height;
                  textElement.style.paddingLeft = MessageLeftPadding;
                  textElement.innerHTML = textMessages.pop();
                  textMessagesDivs[0].appendChild(textElement);
                  // remove oldest message
                  var textMessageCount = textMessagesDivs.length;
                  if (textMessageCount >= MessageDisplayCount) {
                    divTextMessages.removeChild(textMessagesDivs[textMessageCount - 1]);
                  }
                  animateMessage = false;
              }
            }
        }
       
        function PollIntervalTick() {
            if (!animateMessage && textMessages.length > 0) {
              // add a new text message
              var divTextMessages = document.getElementById("divTextMessages");
              var divTopMessage = divTextMessages.getElementsByTagName("div")[0];
              var divMessage = document.createElement("div");
              // set message animation
              divMessage.style.fontSize  = "0px";
              if (animateWhiteDiv) {
                  divMessage.style.background = MessageBackground;
                  animateWhiteDiv = false;
              } else {
                  divMessage.style.background = SwitchMessageBackground;
                  animateWhiteDiv = true;
              }
              divTextMessages.insertBefore(divMessage, divTopMessage);
              animateStep    = 0;
              animateMessage = true;
            } else if (!pollingXmlData && textMessages.length <= 5) {
              pollingXmlData = true;
              if (window.XMLHttpRequest) {        // AJAX code for Mozilla, Safari, Opera etc.
                  xmlhttp = new XMLHttpRequest();
                  xmlhttp.onreadystatechange = OnReadyStateChange;
                  xmlhttp.open("GET", MessageExtractionUrl, true);
                  xmlhttp.send(null);
              } else if (window.ActiveXObject) {  // AJAX code for IE
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  if (xmlhttp) {
                    xmlhttp.onreadystatechange = OnReadyStateChange;
                    xmlhttp.open("GET", MessageExtractionUrl, true);
                    xmlhttp.send();
                  }
              }
            }
        }
       
        function Initialize() {
            // message animation timer
            animateTick = setInterval("AnimateIntervalTick()", MessageAnimationSpeed);
            // message extraction timer
            PollIntervalTick();
            timerTick = setInterval("PollIntervalTick()", MessageExtractionInterval);
        }
       
      </script>
  </head>
  <body onload = "Initialize()">
      <div id = "divTextMessages" fontface ="verdana" style = "position:absolute;top:50px;width:600px;height:300px;background-color:white;overflow:wrap">
        <div id = "divMessage0" />
      </div>
  </body>
</html>



All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.