Got a JS problem with Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • STIAdmin
    New Member
    • Dec 2007
    • 2

    Got a JS problem with Arrays

    Happy Holidays to all of you!

    This is my first time posting. I'm working on a web project and trying to get this done before Christmas. The limitation is that I'm using an out of the box program and I don't have the skills to change it quickly, and it only outputs in a structured way... so I am not able to go dig into the code of the out-of-box program and solve it.

    This it the first time I've really dug into JS. My JS knowledge is very limited and I could write very simple JS, that is about it. I have a form that I'm building that outputs data in between < script > .... </ script >. The data output begins at number 1 of the array. It is shown below

    [CODE=javascript]
    <!-- BEGIN OUTPUT FROM MY SITE ***
    <script type="text/javascript">
    var fadeimages=new Array()
    fadeimages[1]=["../Portals/3/PropertiesImage s/thm_host_200712 09_035346.jpg", "http://www.google.com" , ""]
    fadeimages[2]=["../Portals/3/PropertiesImage s/thm_host_200712 09_091810.jpg", "http://www.google.com" , ""]
    fadeimages[3]=["../Portals/3/PropertiesImage s/thm_host_200712 09_094217.jpg", "http://www.google.com" , ""]
    fadeimages[4]=["../Portals/3/PropertiesImage s/thm_host_200712 09_094947.jpg", "http://www.google.com" , ""]
    fadeimages[5]=["../Portals/3/PropertiesImage s/thm_host_200712 09_095901.jpg", "http://www.google.com" , ""]
    fadeimages[6]=["../Portals/3/PropertiesImage s/thm_host_200712 09_100204.jpg", "http://www.google.com" , ""]
    fadeimages[7]=["../Portals/3/PropertiesImage s/thm_host_200712 09_111622.jpg", "http://www.google.com" , ""]
    var fadebgcolor="wh ite"
    </script>

    <script type="text/javascript">
    //new fadeshow(IMAGES _ARRAY_NAME, slideshow_width , slideshow_heigh t, borderwidth, delay, pause (0=no, 1=yes), optionalRandomO rder)
    new fadeshow(fadeim ages, 140, 225, 0, 3000, 1, "R")
    </script>
    *** END OUTPUT FROM MY SITE-->
    [/CODE]

    I copied the JS from this site: http://www.dynamicdrive.com/dynamici...nslideshow.htm

    I tried changing this piece of the code:
    [CODE=javascript]
    for (p=1;p<theimage s.length;p++){
    this.postimages[p]=new Image()
    this.postimages[p].src=theimages[p][0]
    }
    [/CODE]

    Where p=0, but did not work when I changed to p=1.

    Here is the full original source (sorry its long...)

    [CODE=javascript]
    ////NO need to edit beyond here/////////////

    var fadearray=new Array() //array to cache fadeshow instances
    var fadeclear=new Array() //array to cache corresponding clearinterval pointers

    var dom=(document.g etElementById) //modern dom browsers
    var iebrowser=docum ent.all

    function fadeshow(theima ges, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
    this.pausecheck =pause
    this.mouseoverc heck=0
    this.delay=dela y
    this.degree=10 //initial opacity degree (10%)
    this.curimagein dex=0
    this.nextimagei ndex=1
    fadearray[fadearray.lengt h]=this
    this.slideshowi d=fadearray.len gth-1
    this.canvasbase ="canvas"+this. slideshowid
    this.curcanvas= this.canvasbase +"_0"
    if (typeof displayorder!=" undefined")
    theimages.sort( function() {return 0.5 - Math.random();} ) //thanks to Mike (aka Mwinter) :)
    this.theimages= theimages
    this.imageborde r=parseInt(bord erwidth)
    this.postimages =new Array() //preload images
    for (p=0;p<theimage s.length;p++){
    this.postimages[p]=new Image()
    this.postimages[p].src=theimages[p][0]
    }

    var fadewidth=fadew idth+this.image border*2
    var fadeheight=fade height+this.ima geborder*2

    if (iebrowser&&dom ||dom) //if IE5+ or modern browsers (ie: Firefox)
    document.write( '<div id="master'+thi s.slideshowid+' " style="position :relative;width :'+fadewidth+'p x;height:'+fade height+'px;over flow:hidden;"> <div id="'+this.canv asbase+'_0" style="position :absolute;width :'+fadewidth+'p x;height:'+fade height+'px;top: 0;left:0; filter:progid:D XImageTransform .Microsoft.alph a(opacity=10);o pacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1; background-color:'+fadebgc olor+'"></div> <div id="'+this.canv asbase+'_1" style="position :absolute;width :'+fadewidth+'p x;height:'+fade height+'px;top: 0;left:0; filter:progid:D XImageTransform .Microsoft.alph a(opacity=10);o pacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1; background-color:'+fadebgc olor+'"></div></div>')
    else
    document.write( '<div><img name="defaultsl ide'+this.slide showid+'" src="'+this.pos timages[0].src+'"></div>')

    if (iebrowser&&dom ||dom) //if IE5+ or modern browsers such as Firefox
    this.startit()
    else{
    this.curimagein dex++
    setInterval("fa dearray["+this.slidesho wid+"].rotateimage()" , this.delay)
    }
    }

    function fadepic(obj){
    if (obj.degree<100 ){
    obj.degree+=10
    if (obj.tempobj.fi lters&&obj.temp obj.filters[0]){
    if (typeof obj.tempobj.fil ters[0].opacity=="numb er") //if IE6+
    obj.tempobj.fil ters[0].opacity=obj.de gree
    else //else if IE5.5-
    obj.tempobj.sty le.filter="alph a(opacity="+obj .degree+")"
    }
    else if (obj.tempobj.st yle.MozOpacity)
    obj.tempobj.sty le.MozOpacity=o bj.degree/101
    else if (obj.tempobj.st yle.KhtmlOpacit y)
    obj.tempobj.sty le.KhtmlOpacity =obj.degree/100
    else if (obj.tempobj.st yle.opacity&&!o bj.tempobj.filt ers)
    obj.tempobj.sty le.opacity=obj. degree/101
    }
    else{
    clearInterval(f adeclear[obj.slideshowid])
    obj.nextcanvas= (obj.curcanvas= =obj.canvasbase +"_0")? obj.canvasbase+ "_0" : obj.canvasbase+ "_1"
    obj.tempobj=ieb rowser? iebrowser[obj.nextcanvas] : document.getEle mentById(obj.ne xtcanvas)
    obj.populatesli de(obj.tempobj, obj.nextimagein dex)
    obj.nextimagein dex=(obj.nextim ageindex<obj.po stimages.length-1)? obj.nextimagein dex+1 : 0
    setTimeout("fad earray["+obj.slideshow id+"].rotateimage()" , obj.delay)
    }
    }

    fadeshow.protot ype.populatesli de=function(pic obj, picindex){
    var slideHTML=""
    if (this.theimages[picindex][1]!="") //if associated link exists for image
    slideHTML='<a href="'+this.th eimages[picindex][1]+'" target="'+this. theimages[picindex][2]+'">'
    slideHTML+='<im g src="'+this.pos timages[picindex].src+'" border="'+this. imageborder+'px ">'
    if (this.theimages[picindex][1]!="") //if associated link exists for image
    slideHTML+='</a>'
    picobj.innerHTM L=slideHTML
    }


    fadeshow.protot ype.rotateimage =function(){
    if (this.pausechec k==1) //if pause onMouseover enabled, cache object
    var cacheobj=this
    if (this.mouseover check==1)
    setTimeout(func tion(){cacheobj .rotateimage()} , 100)
    else if (iebrowser&&dom ||dom){
    this.resetit()
    var crossobj=this.t empobj=iebrowse r? iebrowser[this.curcanvas] : document.getEle mentById(this.c urcanvas)
    crossobj.style. zIndex++
    fadeclear[this.slideshowi d]=setInterval("f adepic(fadearra y["+this.slidesho wid+"])",50)
    this.curcanvas= (this.curcanvas ==this.canvasba se+"_0")? this.canvasbase +"_1" : this.canvasbase +"_0"
    }
    else{
    var ns4imgobj=docum ent.images['defaultslide'+ this.slideshowi d]
    ns4imgobj.src=t his.postimages[this.curimagein dex].src
    }
    this.curimagein dex=(this.curim ageindex<this.p ostimages.lengt h-1)? this.curimagein dex+1 : 0
    }

    fadeshow.protot ype.resetit=fun ction(){
    this.degree=10
    var crossobj=iebrow ser? iebrowser[this.curcanvas] : document.getEle mentById(this.c urcanvas)
    if (crossobj.filte rs&&crossobj.fi lters[0]){
    if (typeof crossobj.filter s[0].opacity=="numb er") //if IE6+
    crossobj.filter s(0).opacity=th is.degree
    else //else if IE5.5-
    crossobj.style. filter="alpha(o pacity="+this.d egree+")"
    }
    else if (crossobj.style .MozOpacity)
    crossobj.style. MozOpacity=this .degree/101
    else if (crossobj.style .KhtmlOpacity)
    crossobj.style. KhtmlOpacity=th is.degree/100
    else if (crossobj.style .opacity&&!cros sobj.filters)
    crossobj.style. opacity=this.de gree/101
    }


    fadeshow.protot ype.startit=fun ction(){
    var crossobj=iebrow ser? iebrowser[this.curcanvas] : document.getEle mentById(this.c urcanvas)
    this.populatesl ide(crossobj, this.curimagein dex)
    if (this.pausechec k==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
    var cacheobj=this
    var crossobjcontain er=iebrowser? iebrowser["master"+this.s lideshowid] : document.getEle mentById("maste r"+this.slidesh owid)
    crossobjcontain er.onmouseover= function(){cach eobj.mouseoverc heck=1}
    crossobjcontain er.onmouseout=f unction(){cache obj.mouseoverch eck=0}
    }
    this.rotateimag e()
    }

    </script>
    [/CODE]

    I hope I'm making sense here.

    -Eric
    Last edited by acoder; Dec 22 '07, 11:58 AM. Reason: fixed code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Why not start the fadeimages array from 0?

    Comment

    • STIAdmin
      New Member
      • Dec 2007
      • 2

      #3
      I would start the array at [0], but I have a slight problem: I have an out of the box program that outputs the data starting at 1. =(

      Its either I wait several weeks to months for the developers of the "out of the box" program by submitting an addition request or... I get this JS code figured out. The latter method is probably the best bet in terms of time.

      If you think you can solve it, I'm willing to pay you for your time. Send me your rate and a time estimate as to when you'll be able to get this nailed out. A little pocket change for Christmas! Email me at **** - email removed

      -E
      Last edited by acoder; Dec 23 '07, 09:48 PM. Reason: removed email

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        If you copied the script from dynamic drive, or anywhere else, you should credit the author. Have you offered him any Christmas cash?

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by STIAdmin
          If you think you can solve it, I'm willing to pay you for your time. Send me your rate and a time estimate as to when you'll be able to get this nailed out. A little pocket change for Christmas! Email me at **** - email removed
          That's not the way this site works. Either you get free help or no help - take your pick!

          If you've made use of a few free scripts, it may not be a bad idea to follow mrhoo's advice and donate some of the amount (that you were prepared to pay to get this fixed) to the authors, but that is entirely up to you.

          If you have a "proper" job, you can post in the Jobs forum.

          I've removed your email as it's against the site rules.

          Comment

          Working...