Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 01:12 PM   PM User | #1
Carga Sok
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Carga Sok is an unknown quantity at this point
Lightbulb 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>
Carga Sok is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:02 PM.


Advertisement
Log in to turn off these ads.