Jump to content

Help adjusting code.


ameriblog

Recommended Posts

I have the following code and I'm trying to figure out the best way to include Latest News: in the code so that is displays like:

 

Latest News: The story with link

 

loadingMessage = "Loading news ...";
pauseWhenMouseOver = false;
fetchErrorMessage = "Error loading data ...";

function getAJAX() {
  var httprequest=false
  if (window.XMLHttpRequest) { 
    httprequest = new XMLHttpRequest();
    if (httprequest.overrideMimeType) {
      httprequest.overrideMimeType('text/xml')
    }
  } else if (window.ActiveXObject) { 
    try {
      httprequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        httprequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
      }
    }
  }
  return httprequest;
}

function showTicker (xmlfile, divId, divClass, delay, fadeornot) {
  this.xmlfile = xmlfile ;
  this.tickerid = divId;
  this.delay = delay;
  this.isMouseOver = 0;
  this.pointer = 0;
  this.opacitystring = (typeof fadeornot != "undefined") ? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : "";
  if (this.opacitystring != "") {
    this.delay += 500;
  }
  this.opacitysetting = 0.2;
  this.news = [];
  this.ajaxobj = getAJAX()
  document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'">Latest News: ' + loadingMessage + '</div></div>')
  this.getXMLfile()
}

showTicker.prototype.getXMLfile = function() {
  if (this.ajaxobj) {
    var instanceOfTicker = this;
    var url = this.xmlfile + "?time=" + new Date().getTime();
    this.ajaxobj.onreadystatechange =function() {
      instanceOfTicker.initialize();
    }
    this.ajaxobj.open('GET', url, true);
    this.ajaxobj.send(null);
  }
}

showTicker.prototype.initialize=function() {
  if (this.ajaxobj.readyState == 4) {
    if (this.ajaxobj.status==200 
      || window.location.href.indexOf("http") == -1) {
      this.contentdiv = document.getElementById(this.tickerid).firstChild;
      var xmldata=this.ajaxobj.responseText;
      this.contentdiv.style.display = "none";
      this.contentdiv.innerHTML = xmldata;
      if (this.contentdiv.getElementsByTagName("div").length==0) {
        this.contentdiv.innerHTML = fetchErrorMessage;
        return;
      }
      var instanceOfTicker = this;
      document.getElementById(this.tickerid).onmouseover = function(){
        instanceOfTicker.isMouseOver=1;
      }
      document.getElementById(this.tickerid).onmouseout = function() {
        instanceOfTicker.isMouseOver=0;
      }
      if (window.attachEvent) {
        window.attachEvent("onunload", function() { 
          instanceOfTicker.contentdiv = instanceOfTicker.ajaxobj=null;
        });
      }
      for (var i=0; i < this.contentdiv.getElementsByTagName("div").length; i++) {
        if (this.contentdiv.getElementsByTagName("div")[i].className == "message") {
          this.news[this.news.length] = this.contentdiv.getElementsByTagName("div")[i].innerHTML;
        }
      }
      this.contentdiv.innerHTML = "";
      this.contentdiv.style.display = "block";
      this.rotatemsg();
      //setTimeout("this.getXMLfile()", 10000);
    }
  }
}

showTicker.prototype.rotatemsg = function() {
  var instanceOfTicker = this;
  if (this.isMouseOver == 1 && pauseWhenMouseOver) {
    setTimeout(function() { 
      instanceOfTicker.rotatemsg()
    }, 100);
  } else {
    this.fadetransition("reset");
    this.contentdiv.innerHTML = this.news[this.pointer];
    this.fadetimer1 = setInterval(function() { 
      instanceOfTicker.fadetransition('up', 'fadetimer1')
    }, 100);
    this.pointer=(this.pointer<this.news.length-1)? this.pointer+1 : 0
    setTimeout(function() {
      instanceOfTicker.rotatemsg();
    }, this.delay);
  }
}

showTicker.prototype.fadetransition = function(fadetype, timerid) {
  var contentdiv=this.contentdiv;
  if (fadetype=="reset") {
    this.opacitysetting = 0.2;
  }
  if (contentdiv.filters && contentdiv.filters[0]) {
    if (typeof contentdiv.filters[0].opacity == "number") {
      contentdiv.filters[0].opacity = this.opacitysetting*100;
    } else {
      contentdiv.style.filter="alpha(opacity="+this.opacitysetting*100+")";
    }
  } else if (typeof contentdiv.style.MozOpacity != "undefined" && this.opacitystring != "") {
    contentdiv.style.MozOpacity = this.opacitysetting;
  } else {
    this.opacitysetting = 1;
  }
  if (fadetype=="up") {
    this.opacitysetting += 0.1;
  }
  if (fadetype=="up" && this.opacitysetting>=1) {
    clearInterval(this[timerid]);
  }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.