7 replies
I found a testimonial system on a website that i'm trying to copy. I don't understand javascript and am trying to get this working on my site.
THE JAVASCRIPT
Code:
function rotateTestimonials(cur, tot)
{
	if(!($('testimonial'+cur))) return;
	Element.addClassName('testimonial'+cur, 'hide');
	do { cur++; if(cur >= tot) cur = 0; } while(!$('testimonial'+cur));
	Element.removeClassName('testimonial'+cur, 'hide');
	setTimeout('rotateTestimonials('+cur+','+tot+')', 10000);
}
I used right click view source to get the HTML
Code:
<h3>Testimonials</h3>
<div id="testimonial0" class="testimonial_large">Some text</div>
<div id="testimonial1" class="testimonial_large hide">Some text</div>
<div id="testimonial2" class="testimonial_large hide">Some text</div>
<div id="testimonial3" class="testimonial_large hide">Some text</div>

<script type="text/javascript" src="/js/setup.js"></script>
<script type="text/javascript">
setupPage();
<!-- TemplateBeginIf cond="TestimonialsLarge!=''" -->
setTimeout('rotateTestimonials(0,4)', 10000);
<!-- TemplateEndIf -->
</script>
What code do I need to put into my html document to get this working?
Can anyone make sense of this script? If so how do I get it to function?
#javascript
  • Profile picture of the author donnan
    I don't like your chances to get this going.

    Firstly it is calling a javascript file name setup.js. Without this file on your system, you havn't got a chance to get it going.

    Secondly, it's calling a function you don't have named
    setupPage();
    {{ DiscussionBoard.errors[3201080].message }}
    • Profile picture of the author brandon2664
      Does that help?

      function setupPage()
      {
      var nscaffid = /\bnscaffid=([0-9A-Z]+)/.exec(window.location.search);
      if(nscaffid != null) Cookie.set('nscaffid', escape(nscaffid[1]));

      if($('friend_email'))
      {
      Element.addClassName('friend_email', 'default_text');
      $('friend_email').value='Enter email address';
      Event.observe('friend_email', 'focus', function(e){if(Element.hasClassName('friend_email' , 'default_text')){Element.removeClassName('friend_e mail','default_text');$('friend_email').value='';} });
      }

      if($('search_query'))
      {
      Element.addClassName('search_query', 'default_text');
      $('search_query').value='Search for a course';
      Event.observe('search_query', 'focus', function(e){if(Element.hasClassName('search_query' , 'default_text')){Element.removeClassName('search_q uery','default_text');$('search_query').value='';} });
      }

      if($('choose_state_link') && $('choose_state_form'))
      {
      Event.observe('choose_state_link', 'click', function(e){Element.show('choose_state_form');Elem ent.hide('choose_state_link');return false;});
      if($('choose_state_list')) Event.observe('choose_state_list', 'change', function(e){$('choose_state_form').submit();});
      }

      if($('jump_form') && $('jump_directory') && $('jump_state'))
      {
      Event.observe('jump_state', 'change', function(e){self.location.href='/'+$F('jump_directory')+'/'+($F('jump_state') != '' ? $F('jump_state')+'.html' : '');});
      }

      $A(document.getElementsByClassName('search_link')) .each(function(el){Event.observe(el,'click',functi on(ev){new Ajax.Request('/code/search-record.php',{method: 'get',parameters: 'id='+escape($F('search_id'))+'&t='+escape($(el).i nnerHTML)+'&u='+escape($(el).href),onSuccess:funct ion(t){self.location.href=$(el).href; } });Event.sto p(ev);});});

      // add popups
      if($('popup'))
      {
      Element.hide('popup');
      Event.observe('popup_close_link', 'click', function(e){hidePopup(); return false;}, true);
      $A(document.getElementsByClassName('popup_small')) .each(function(el){Event.observe(el,'click',functi on(ev){showPopup(el.href, Event.pointerX(ev), Event.pointerY(ev), 250, 250);Event.stop(ev);return false;},true);});
      $A(document.getElementsByClassName('popup_medium') ).each(function(el){Event.observe(el,'click',funct ion(ev){showPopup(el.href, Event.pointerX(ev), Event.pointerY(ev), 350, 350);Event.stop(ev);return false;},true);});
      $A(document.getElementsByClassName('popup_large')) .each(function(el){Event.observe(el,'click',functi on(ev){showPopup(el.href, Event.pointerX(ev), Event.pointerY(ev), 450, 450);Event.stop(ev);return false;},true);});
      }
      }

      function showPopup(url, x, y, w, h)
      {
      if($('popup'))
      {
      Element.hide('popup');
      $('popup_content').innerHTML = "";
      Element.setStyle('popup', $H({top:y+'px',left:Math.max(0,x-w)+'px'}));
      Element.setStyle('popup_content', $H({width:w+'px',height:h+'px'}));
      new Ajax.Updater('popup_content', url);
      Element.show('popup');
      }
      }

      function hidePopup()
      {
      if($('popup')) Element.hide('popup');
      }

      function rotateTestimonials(cur, tot)
      {
      if(!($('testimonial'+cur))) return;
      Element.addClassName('testimonial'+cur, 'hide');
      do { cur++; if(cur >= tot) cur = 0; } while(!$('testimonial'+cur));
      Element.removeClassName('testimonial'+cur, 'hide');
      setTimeout('rotateTestimonials('+cur+','+tot+')', 10000);
      }

      function nscTrack(id)
      {
      var c = Cookie.get('nscTrack');
      if(c != null)
      {
      if(!c.match('(?:^|#)'+escape(id)+'(?:#|$)')) Cookie.set('nscTrack', c+'#'+escape(id));
      } else Cookie.set('nscTrack', escape(id));
      return true;
      }
      {{ DiscussionBoard.errors[3201219].message }}
  • Profile picture of the author donnan
    you still need the setup.js file
    {{ DiscussionBoard.errors[3201501].message }}
  • Profile picture of the author brandon2664
    I think thats it unless i am completely lost.
    {{ DiscussionBoard.errors[3206836].message }}
    • Profile picture of the author expertname
      Originally Posted by brandon2664 View Post

      I think thats it unless i am completely lost.
      That looks it could be the contents of setup.js. Can you PM me a link to the place you found this working?
      {{ DiscussionBoard.errors[3207218].message }}
  • Profile picture of the author tuldok
    i suggest you create your logic and seek help on designing or building the program for you
    instead of modifying that code..
    {{ DiscussionBoard.errors[3208180].message }}
  • Profile picture of the author expertname
    The javascript code is manipulating the CSS for the divs that rotate. You need to also include the CSS files along with the javascript files in your HTML file.

    Also, for your testing example, change the text in each testimonial div or you will never know if it is working.
    {{ DiscussionBoard.errors[3211171].message }}

Trending Topics