We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22525
    • 6 Posts
    Hello everyone,

    I am new to MODx... I have this wonderful jQuery horizontal accordion that I use in my website... When i tried to make the move to MODx it stopped working... I am sure its a path issue or something... Here is the code

    /**************************
           ACCORDION CODE
    **************************/
     
    // default width of accordion for this template is set to 960 pixels,
    // this value is hardcoded and must be equal to accordion width coded in
    // accordionContainer CSS style (file: indexCSS.css)
    var ACCORDION_WIDTH = 960;
    // this variable determine the width of div then it is draw aside
    var ACCORDION_DRAW_ASIDE_WIDTH = 50;
    // slide function, the default is "liner" which is implemented in jQuery,
    // it's not looking good, so we use special easing pluging and method "jQuery EasIng v1.1.2"
    var ACCORDION_EASING_METHOD = "easeOutCirc";
    // slide time
    var ACCORDION_SLIDE_TIME = 650;
    // collection of objects which describe divs included in accordion image slider,
    // every described div have included one main image, and some addiotonal images and
    // elements whith other informations needed for main image, we pack objects into an array
    var g_slidedDivs = null;
    var g_hoveredSlideIndex = null;
    function setupAccordionImageSlider()
    {
        // turn off displaying border-left for first div holding image in accordion
        $j("#accordionContainer").find(".accordionImgDiv:first").css("border-left", "0px");
        
        // get list of all slided divs in slider
        var slidedDivsList = $j("#accordionContainer .accordionImgDiv");
        // collect information on every div in to an global array
        g_slidedDivs = new Array;
        var firstDiv = $j("#accordionContainer .accordionImgDiv:first");
        for(var i = 0; i < slidedDivsList.length; i++)
        {
            var obj = new Object(); 
            obj.name = "#" + $j(firstDiv).attr('id'); 
            obj.dest = 0;
            obj.out = 0;
            g_slidedDivs.push(obj); 
    
            firstDiv = $j(firstDiv).next(".accordionImgDiv");
        }
                     
        // calculating rib width based on accordion containter width divided by slides number in accordion
        var ribOutWidth = 0;
        // calculate width of the rib
        ribOutWidth = ACCORDION_WIDTH / g_slidedDivs.length;
        
        // then the page is load we must set the left margin of every div in accordion
        // distance between divs a equal to rib width so the divs are placed equally
        for(var i = 0; i < g_slidedDivs.length; i++)
        {
            // set left margin
            $j(g_slidedDivs[i].name).css("margin-left", (i*ribOutWidth)+"px");
            // addiotinaly we set the dest member to the same value
            g_slidedDivs[i].dest = i*ribOutWidth;
        }
    
        // we set the acction for hover the accordion container,
        // when the mouse is moved on, there is no action taken,
        // when mouse is moved from we distribyte all slided divs in accordion
        // equally on accordion space
        $j("#accordionContainer").hover(
            function()
            {   
                // stop the auto play accordion image slider
                if(true == g_sliderAutoPlay)
                {
                    clearTimeout(g_sliderTimerAutoPlay);
                }
                // if slider is not fully loaded
                if(g_loadedStripCount < g_slidedDivs.length)
                {
                    return;
                }            
                // hide slide strip desc
                $j("#accordionContainer .accordionImgDiv").find(".slideDesc").stop().animate({opacity: 0.0}, 150);
            },
            function()
            {   
                // if slider is not fully loaded 
                if(g_loadedStripCount < g_slidedDivs.length)
                {
                    return;
                }
                
                mouseOutAccorOnAll(null);        
                for(var i = 0; i < g_slidedDivs.length; i++)
                {
                    // if div is currently moved we stop the animation
                    // and set new animation for left margin
                    $j(g_slidedDivs[i].name).stop()
                        .animate({marginLeft: (i*ribOutWidth)+"px"}, {duration: 900, easing: ACCORDION_EASING_METHOD});
                    // we set the destination member to the same value
                    g_slidedDivs[i].dest = i*ribOutWidth;
                    // show strip desc
                    $j(g_slidedDivs[i].name).find(".slideDesc").stop().animate({opacity: 1.0}, 1200);
                }
                // fire up auto play for slider
                if(true == g_sliderAutoPlay)
                {
                    clearTimeout(g_sliderTimerAutoPlay);
                    mouseOutAccorOnAll(null);
                    g_sliderTimerAutoPlay = setTimeout(accordionPlay, g_sliderTimerInterval);
                }
            }
        );                                                    
    
        // setting hover action for every div of class accordionImgDiv in accordion,
        // when user move mause on div, we must to draw aside all dive except the hovered
        $j(".accordionImgDiv").hover(
            function()
            {   
                // stop the auto play accordion image slider
                if(true == g_sliderAutoPlay)
                {
                    clearTimeout(g_sliderTimerAutoPlay);
                }        
                // if slider is not fully loaded we return
                if(g_loadedStripCount < g_slidedDivs.length)
                {
                    return;
                }        
            
                // save in variable id of hovered element
                var divID = ("#" + $j(this).attr('id'));
                // fade out all divs with excluding hovered div
                mouseOutAccorOnAll(divID);
    
                g_hoveredSlideIndex = $j("#accordionContainer .accordionImgDiv").index(this);    
                
                var context = $j(this)[0];
                // stop and set new animation of main image opacity
                $j(".accordionSlideImage", context).find("img").stop().animate({opacity: 1.0}, 400); 
                // stop and set new animation of image description background div
                $j(".accordionDescBack", context).stop().animate({bottom: 0, opacity: 0.8}, 1000);
                // stop and set new animation of image description div
                $j(".accordionDesc", context).stop().animate({bottom: 0, opacity: 1.0}, 1000);
                $j(".slideStrip", context).stop().animate({opacity: 0.0}, 200, ACCORDION_EASING_METHOD); 
                
                g_slidedDivs[g_hoveredSlideIndex].out = 0;
                // draw aside all divs
                setMoveForAccordionDivs(g_hoveredSlideIndex);
            }, 
            function()
            {
                if(g_loadedStripCount < g_slidedDivs.length)
                {
                    return;
                }        
            
                g_hoveredSlideIndex = null;
                
                // save in variable id of hovered element
                var divID = ("#" + $j(this).attr('id'));
                // now we need to find the index of hovered div,
                // so we searching it name in array g_slidedDivs, when
                // the named match we save index and break loop  
                var index = 0;
                for(var i = 0; i < g_slidedDivs.length; i++)
                {
                    if(divID == g_slidedDivs[i].name)
                    {        
                        index = i;
                        break;
                    }
                }
                
                if(g_slidedDivs[index].out != 1)
                {
                    g_slidedDivs[index].out = 1;            
                    mouseOutAccor(this);
                }
            }
        );
    } // end of function setupAccordionImageSlider 
    
    // Function set value of left margin for every slided div in accordion
    // @param[in] index - index of ohovered div with class accordionImgDiv 
    function setMoveForAccordionDivs(index)
    {
        // for every slided div we make the same
        for(var i = 0; i < g_slidedDivs.length; i++)
        {
            var context = $j(g_slidedDivs[i].name)[0];
            var object = $j(g_slidedDivs[i].name);
            $j(".slideDesc", context).stop().animate({opacity: 0.0}, 150);
            // if div lie on left we move it on left
            if(i < index)
            {
                // calculate new margin, this equal to calculate new position of div
                var newMargin = (i*ACCORDION_DRAW_ASIDE_WIDTH);
                // if new margin is diffrent from div destination margin the animation is set    
                if(g_slidedDivs[i].dest != newMargin)
                {
                    // first we stop the old animation
                    object.stop();
                    // animation time
                    var animTime = ACCORDION_SLIDE_TIME;
                    // save new margin 
                    g_slidedDivs[i].dest = newMargin;
                    // set new animation
                    object.animate(
                        {marginLeft: newMargin+"px"}, 
                        {duration: animTime, easing: ACCORDION_EASING_METHOD});
                }
                // go to next iteraction of loop
                continue;
            }
            // if div is hovered, we move it max to the left, the code is identical,
            // but is separated for future to add maybe some special actions
            if(index == i)
            {
                // calculate new margin
                var newMargin = (i*ACCORDION_DRAW_ASIDE_WIDTH);
                // if new margin is diffrent from div destination margin the animation is set 
                if(g_slidedDivs[i].dest != newMargin) 
                {   
                    // first we stop old animation
                    object.stop();
                    // animation time
                    var animTime = ACCORDION_SLIDE_TIME;
                    // save new margin           
                    g_slidedDivs[i].dest = newMargin;
                    // set new animation
                    object.animate(
                        {marginLeft: newMargin+"px"}, 
                        {duration: animTime, easing: ACCORDION_EASING_METHOD});
                }
                // go to next iteraction of loop   
                continue;
            }
            // if div lie on right we move it on right, we must calculate
            // margin from right border of accordion container   
            if(i > index)
            {
                // calculate new margin 
                var newMargin = (ACCORDION_WIDTH - ((g_slidedDivs.length - i) * ACCORDION_DRAW_ASIDE_WIDTH));
                // if new margin is diffrent from div destination margin the animation is set 
                if(g_slidedDivs[i].dest != newMargin) 
                {   
                    // first we stop old animation   
                    object.stop();
                    // animation time    
                    var animTime = ACCORDION_SLIDE_TIME;
                    // save new margin            
                    g_slidedDivs[i].dest = newMargin;
                    // set new animation   
                    object.animate({"marginLeft": newMargin+"px"}, {duration: animTime,
                        easing: ACCORDION_EASING_METHOD});
                }
                // go to next iteraction of loop 
                continue;
            }
        }
    } // end of function setMoveForAccordionDivs  
    
    
    var g_actualSlideImage = 0;
    // auto play timer handle for accordion image slider
    var g_sliderTimerAutoPlay = null;
    // slider timer interval
    var g_sliderTimerInterval = 4500;
    // is accordion auto play on/off
    var g_sliderAutoPlay = true;
    // if have true, the new loop of slider is starting
    var g_sliderNewLoop = false;
    // true if new slider loop gona be start
    var g_setBackwardBtnOnLast = false;
    
    function accordionPlay()
    {
        if(g_loadedStripCount < g_slidedDivs.length)
        {
            // fire up slider
            if(true == g_sliderAutoPlay)
            {
                g_sliderTimerAutoPlay = setTimeout(accordionPlay, g_sliderTimerInterval);
            }      
            return;
        }      
    
        var timeOut = g_sliderTimerInterval;
     
        if(BACKWARD == g_lastSlideMoveDirection)
        {
            g_actualSlideImage++;
            if(g_actualSlideImage >= g_slidedDivs.length)
            {
                g_actualSlideImage = 0;
                g_sliderNewLoop = true;
            } 
        }
        g_lastSlideMoveDirection = FORWARD;
        
        g_setBackwardBtnOnLast = false;
        if(true == g_sliderNewLoop)
        {
            ribOutWidth = ACCORDION_WIDTH / g_slidedDivs.length;
            mouseOutAccorOnAll(null);
           
            for(var i = 0; i < g_slidedDivs.length; i++)
            {
                // if div is currently moved we stop the animation
                // and set new animation for left margin
                $j(g_slidedDivs[i].name).stop()
                    .animate({marginLeft: (i*ribOutWidth)+"px"}, {duration: 900, easing: ACCORDION_EASING_METHOD});
                // we set the destination member to the same value
                g_slidedDivs[i].dest = i*ribOutWidth;
                $j(g_slidedDivs[i].name).find(".slideDesc").stop().animate({opacity: 1.0}, 2000); 
            }
            timeOut = g_sliderTimerInterval * 2;
            g_sliderNewLoop = false;
            // for backward button, we set the index to last element
            g_setBackwardBtnOnLast = true;
            // fire up slider
            g_sliderTimerAutoPlay = setTimeout(accordionPlay, timeOut); 
            return;
        }
        
        mouseOutAccorOnAll(null); 
        mouseOnAccor(g_slidedDivs[g_actualSlideImage].name);
        
        g_actualSlideImage++;
        if(g_actualSlideImage >= g_slidedDivs.length)
        {
            g_actualSlideImage = 0;
            g_sliderNewLoop = true;   
        }
        
        // fire up slider
        if(true == g_sliderAutoPlay)
        {
            g_sliderTimerAutoPlay = setTimeout(accordionPlay, g_sliderTimerInterval);
        }      
        
    } // end of function accordionPlay
    
    function setupAccordionAutoPlay()
    {
        // fire up auto play for accordion image slider
        if(true == g_sliderAutoPlay)
        {
            g_sliderTimerAutoPlay = setTimeout(accordionPlay, g_sliderTimerInterval);
        }
    } // end of function setupAccordionAutoPlay
    
    function mouseOnAccor(_this)
    {
        // now we need to find the index of hovered div,
        // so we searching it name in array g_slidedDivs, when
        // the named match we save index and break loop  
        var index = 0;
        for(var i = 0; i < g_slidedDivs.length; i++)
        {
            if(("#" + $j(_this).attr('id')) == g_slidedDivs[i].name)
            {        
                index = i;
                break;
            }
        }
        g_slidedDivs[index].out = 0;
    
        // stop and set new animation of main image opacity
        $j(_this).find(".accordionSlideImage").find("img").stop().animate({opacity: 1.0}, 400); 
        // stop and set new animation of image description background div
        $j(_this).find(".accordionDescBack").stop().animate({bottom: 0, opacity: 0.8}, 1000);
        // stop and set new animation of image description div
        $j(_this).find(".accordionDesc").stop().animate({bottom: 0, opacity: 1.0}, 1000);
        $j(_this).find(".slideStrip").stop().animate({opacity: 0.0}, 300);
      
        // draw aside all divs
        setMoveForAccordionDivs(index);
    } // end of function mouseOnAccor
    
    function mouseOutAccor(_this)
    {
        var context = $j('#accordionContainer')[0];
        // stop and set new animation of main image opacity
        $j(_this, context).find(".accordionSlideImage").find("img").stop().animate({opacity: 0.0}, 800
        ,function(){$j(_this, context).find(".slideStrip").stop().animate({opacity: 1.0}, 600);}
        );
        // stop and set new animation of image description background div   
        $j(_this, context).find(".accordionDescBack").stop().animate({bottom: -70, opacity: 0}, 300);
        // stop and set new animation of image description div   
        $j(_this, context).find(".accordionDesc").stop().animate({bottom: -70, opacity: 0}, 300);
        
    } // end of function mouseOutAccor
    
    function mouseOutAccorOnAll(excludedID)
    {
        for(var j = 0; j < g_slidedDivs.length; j++)
        {
           if(excludedID != null)
           {
             if(excludedID == g_slidedDivs[j].name)
             {
                continue;
             }
           }
           if(g_slidedDivs[j].out != 1)
           {
                g_slidedDivs[j].out = 1;
                mouseOutAccor(g_slidedDivs[j].name);
           }
        } 
    } // end of function mouseOutAccorOnAll
    
    


      • 22525
      • 6 Posts
      css styles
      /******************************** 
      ACCORDION
      *********************************/

      #accordionContainer {
      width:960px;
      height:300px;
      overflow:hidden;
      background-color:#eee;
      position:relative;
      border:0px solid #000;
      margin-left:40px;
      margin-top:15px;
      }

      .asyncImgLoadAccordion { clear: none; }

      .accordionImgDiv
      {
      width: 760px;
      height: 300px;
      position: absolute;
      border-left:0px solid #222;
      margin-left: 0px;
      background-color:#eee;
      cursor:pointer;
      overflow: hidden;
      }

      .accordionImgDiv .slideStrip
      {
      position: absolute;
      width: 160px;
      height: 300px;
      left:0px;
      top:0px;
      overflow: hidden;
      background-image: url('../img/common/ajax/loading6.gif');
      background-repeat: no-repeat;
      background-position: 100% 50%;
      background-color: transparent;
      }

      .accordionImgDiv .slideDesc
      {
      position: absolute;
      left: 15px;
      bottom: 15px;
      font: normal 12px/12px "Trebuchet MS", Arial, Helvetica, sans-serif;
      text-transform: uppercase;
      color: #eee;
      }

      .accordionSlideImage
      {
      border-left: 0px solid #AAA;
      width:760px;
      height:300px;

      background-image: url('../img/common/ajax/loading10.gif');
      background-repeat: no-repeat;
      background-position: 50% 50%;
      }

      .accordionDescBack
      {
      bottom:-70px;
      margin-left:0px;
      margin-top:0px;
      position:absolute;
      left:0px;
      width:760px;
      height:76px;
      opacity:0.0;
      filter:alpha(opacity=0); /* IE */
      background-color:#000;
      border-top:1px solid #111;
      }

      .accordionDesc
      {
      font-weight:normal;
      font-family: verdana;
      font-size:10px;
      padding-top:0px;
      padding-left:10px;
      text-align:center;
      color:#DDD;
      bottom:-70px;
      margin-left:0px;
      margin-top:0px;
      position:absolute;
      left:0px;
      width:760px;
      height:70px;
      opacity:0.0;
      filter:alpha(opacity=0); /* IE */
      background:none;
      border:0px solid red;
      }

      .accordionDescHeader
      {
      margin-top:5px;
      position:static;
      color:#FFF;
      font: bold 20px "Trebuchet MS", Arial, Helvetica, sans-serif;
      padding-bottom:30px;
      margin-bottom:0px;
      text-align:center;
      }
      <br /><br />HTML<br />
        <!-- ACCORDION IMAGE ROTATOR -->
      <div id="accordionContainer">
      <!-- slide 1 -->
      <div id="slide1" class="accordionImgDiv">
      <div id="slideimg1" class="accordionSlideImage asyncImgLoadAccordion" title="img/slider/accordion/img/cs760x30.png"></div>
      <div class="accordionDescBack"></div>
      <div class="accordionDesc">
      <h3 class="accordionDescHeader">Featured Special</h3>
      </div>
      <div class="slideStrip" title="img/slider/accordion/img/featuredbars_01.png"></div>
      <p class="slideDesc">Featured

      Special</p>
      </div>
      <!-- slide 2 -->
      <div id="slide2" class="accordionImgDiv">
      <div id="slideimg2" class="accordionSlideImage asyncImgLoadAccordion" title="img/slider/accordion/img/cs760x30.png"></div>
      <div class="accordionDescBack"></div>
      <div class="accordionDesc">
      <h3 class="accordionDescHeader">Featured Special</h3>
      </div>
      <div class="slideStrip" title="img/slider/accordion/img/featuredbars_02.png"></div>
      <p class="slideDesc">Featured

      Special</p>
      </div>
      <!-- slide 3 -->
      <div id="slide4" class="accordionImgDiv">
      <div id="slideimg4" class="accordionSlideImage asyncImgLoadAccordion" title="img/slider/accordion/img/cs760x30.png"></div>
      <div class="accordionDescBack"></div>
      <div class="accordionDesc">
      <h3 class="accordionDescHeader">Featured Special</h3>
      </div>
      <div class="slideStrip" title="img/slider/accordion/img/featuredbars_03.png"></div>
      <p class="slideDesc">Featured

      Special</p>
      </div>
      <!-- slide 4 -->
      <div id="slide3" class="accordionImgDiv">
      <div id="slideimg3" class="accordionSlideImage asyncImgLoadAccordion" title="img/slider/accordion/img/cs760x30.png"></div>
      <div class="accordionDescBack"></div>
      <div class="accordionDesc">
      <h3 class="accordionDescHeader">Featured Special</h3>
      </div>
      <div class="slideStrip" title="img/slider/accordion/img/featuredbars_04.png"></div>
      <p class="slideDesc">Featured

      Special</p>
      </div>
      <!-- slide 5 -->
      <div id="slide5" class="accordionImgDiv">
      <div id="slideimg5" class="accordionSlideImage asyncImgLoadAccordion" title="img/slider/accordion/img/cs760x30.png"></div>
      <div class="accordionDescBack"></div>
      <div class="accordionDesc">
      <h3 class="accordionDescHeader">Featured Special</h3>
      </div>
      <div class="slideStrip" title="img/slider/accordion/img/featuredbars_05.png"></div>
      <p class="slideDesc">Featured

      Special</p>
      </div>
      <!-- slide 6 -->
      <div id="slide6" class="accordionImgDiv">
      <div id="slideimg6" class="accordionSlideImage asyncImgLoadAccordion" title="img/slider/accordion/img/cs760x30.png"></div>
      <div class="accordionDescBack"></div>
      <div class="accordionDesc">
      <h3 class="accordionDescHeader">Featured Special</h3>
      </div>
      <div class="slideStrip" title="img/slider/accordion/img/featuredbars_06.png"></div>
      <p class="slideDesc">Featured

      Special</p>
      </div>
      </div>
      <!-- accordionContainer -->
      <br />LOL Finally the header HTML<br />
      <head>
      <!-- HEAD -->
      <meta name="Prolific Communications" content="Ineternet Service Provider" />
      <meta name="description" content="Prolific Communications provides internet services, VOIP Services, PC Repair and many more. With two
      locations: Ithaca and Clare Michigan. You can be sure that Prolific Communications is your one stop shop for all your internet service needs." />
      <meta name="keywords" content="Coming Soon.........." />
      <meta name="language" content="english" />
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Pro Com - Internet Services for Ithaca and Clare Michigan</title>
      <!-- ICON -->
      <link rel="icon" href="img/common/icons/favicon.ico" type="image/x-icon" />
      <link href="style.css" rel="stylesheet" type="text/css" />
      <!-- JavaScript Files -->
      <script type="text/javascript" src="lib/jquery-1.3.2.min.js"></script>
      <script type="text/javascript" src="lib/jquery.easing.1.2.js"></script>
      <script type="text/javascript" src="lib/jquery.prettyPhoto.js"></script>
      <script type="text/javascript" src="lib/cufon-yui.js"></script>
      <script type="text/javascript" src="fonts/Sansation_700.font.js"></script>
      <script type="text/javascript" src="fonts/Sansation_400.font.js"></script>
      <script type="text/javascript" src="fonts/Sansation_300.font.js"></script>
      <script type="text/javascript" src="js/common.js"></script>
      <script type="text/javascript" src="js/index.js"></script>
      <!--[if IE 6]>
      <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
      <script>
      DD_belatedPNG.fix('.ie6PNGfix, .commonLink');

      /* string argument can be any CSS selector */
      /* .ie6PNGfix example is unnecessary */
      /* change it to what suits you! */
      </script>
      <![endif]-->
      </head>
      <br /><br />all my paths should point to assets/templates/procom/<br /><br />when i set the paths NOTHING works!!<br />any ideas?<br />
        • 26931
        • 2,314 Posts
        Hi p0p0,
        <link href="style.css" rel="stylesheet" type="text/css" />
        <!-- JavaScript Files -->
        <script type="text/javascript" src="lib/jquery-1.3.2.min.js"></script>

        is style.css in your root folder and lib/jquery-1.3.2.min.js within folder "lib"?
        ... shouldn’t all those paths not be like:
        assets/templates/procom/style.css & assets/templates/procom/lib/jquery-1.3.2.min.js ... and so on?
        + add this to your head section:
        <base href="[(site_url)]"></base>

          • 22525
          • 6 Posts
          The stylesheet works with no problems.. I will add the base url tag and let you know the results
            • 22525
            • 6 Posts
            Okay styles are working, jQuery is loading... however, the slider is still not working sad prolificcommunications.com is the website... you can see that all that shows up is loading graphics... i am so confused lol.. I changed all of the paths to the right ones... I made a index.html file and placed in the root directory for testing.. I linked everything to my assets/templates/procom/ .. i.e. jQuery and images... Everything worked just fine. I created a new template in MODx and added the index.html code to it... I assigned my resource to the template and when i clicked preview... I get everthing loaded except the images for my slider... So it was working before I put it into a MODx template... what am i doing wrong???


              • 26931
              • 2,314 Posts
              prolificcommunications.com is the website... you can see that all that shows up is loading graphics
              your site is currently set offline for public
                • 22525
                • 6 Posts
                Whoops... LOL I changed the setting... Please try again
                  • 22525
                  • 6 Posts
                  I figured it out smiley... the syntax $j in jQuery was screwing things up... replaced all the $j with $ and problem solved smiley