• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

This javascript has the same error in all it's for loops.

The loops are written like this:

      // Let's determine the maximum height out of all columns specified
      var maxHeight = 0;
      for (i = 0; i < divs.length; ++i) {
         if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
      }
This says "for each value of i from 1 to divs.length+1". ++i means "increment i and then execute the code with the new value of i". This is obviously not what was intended, as Javascript array indexes run from 0 to length-1.

You should have written:

      // Let's determine the maximum height out of all columns specified
      var maxHeight = 0;
      for (i = 0; i < divs.length; i++) {
         if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
      }
Note: i++ (postincrement) and not ++i (preincrement). This now says "for each value of i from 0 to divs.length".

huh??? it's the < that cases it to go to divs.length-1, and has nothing to do with preincrement vs. postincrement. when ++i or i++ are "by themselves", there's no difference between the two (it only makes a difference when they are used in part of another expression) -- WN

This error causes IE to fall over when viewing old revs of topics.

CC


Huh? Is IE a special case?

Just doing a quick test:

   <script type="text/javascript">
   //<![CDATA[
      var i = 0;
      var divs = new Array();
      divs[0] = "leftbar";
      divs[1] = "main";
      // ----
      document.write("preincrement" + "<br />");
      for (i = 0; i < divs.length; ++i) {
         document.write(i + " " + divs[i] + "<br />");
      }
      // ----
      document.write("postincrement" + "<br />");
      for (i = 0; i < divs.length; i++) {
         document.write(i + " " + divs[i] + "<br />");
      }
      // ----
      document.write("test empty divs list" + "<br />");
      divs = new Array();
      document.write("preincrement" + "<br />");
      for (i = 0; i < divs.length; ++i) {
         document.write(i + " " + divs[i] + "<br />");
      }
      document.write("postincrement" + "<br />");
      for (i = 0; i < divs.length; i++) {
         document.write(i + " " + divs[i] + "<br />");
      }
   //]]>
   </script>

On the page: Test:

This doesn't give me any error, and Firefox Javascript console is quiet.

AC


This error causes IE to fall over when viewing old revs of topics. - is this any older revision, or one specific page? AC
The bug was that on a diff page the div #patternLeftBar does not exist, and the script did not have a check on non existing elements. I've added the check and the bug is gone.

SVN 7479.

AC

ItemTemplate
Summary JavaScript error in pattern_equalheightcols
ReportedBy CrawfordCurrie
AppliesTo Extension
Component PatternSkin
Priority Urgent
CurrentState Closed
WaitingFor

Checkins 7479
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r5 - 2005-11-16 - WillNorris
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback