API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Change View Twisty Icons
When using a $$ViewBody field (to display a categorized view) on your $$ Templates (either $$ViewTemplate or $$NavigatorTemplate) you are "stuck" with the default icons when a individual row is collapsed () or expanded (). Or, are you really "stuck"? Here is some code that you can use to change those icons to be whatever you want. You can change them to be other icons included with Notes or you can change them to be attachments to a document if you want.

Include the following code after your $$ViewBody field. The code should be written using pass-through HTML. Here's the code:

<script language="JavaScript"><!--
function replaceImage(original, substitute) {
   if (document.images) { // make sure the browser supports on-line image changing
      for (var i=0; i < document.images.length; i++) {
         var imageString = document.images[i].src.toString();
         if (imageString.indexOf(original) != -1) {
            document.images[i].src = substitute
         }
      } // Move on to the next image
   } // Ends the check to make sure image swapping is supported
} // Ends the "replaceImage" function

replaceImage("/icons/collapse.gif", "[ImageToShowWhenExpanded]");
replaceImage("/icons/expand.gif", "[ImageToShowWhenCollapsed]");
// -->
</script>

[ImageToShowWhenCollapsed] is either a notes field or a hard-coded path to the new image to be displayed when the line is expanded. Similarly, [ImageToShowWhenExpanded] is the path to the new image to be displayed when the line is collapsed. Make sure that if you use Notes fields that the fields are text and computed for display.

Note that this only works on browsers that support on-line image changing (version 3 or 4 of Netscape, or version 4 of IE). But the code will not fail on older browsers -- it will just simply leave the default expand and collapse icons alone.

Alternate Method

If you don't like the above way of changing the icons, then in your $$HTMLHead field, or in the JSHeader section, include the following script:

<SCRIPT language=JavaScript>
function changeTwisties() {
   var i, nullcount, expand, collapse;
   expand = new Image(); // creates new image object instance and assigns reference
   expand.src = "/icons/grayexp.gif"; // place URL to your image for expand
   collapse = new Image();
   collapse.src = "/icons/graycol.gif"; // place URL to your image for collapse
   nullcount = 1; // initialize nullcount to non-zero so it enters the while loop.
   while (nullcount) { // while loop tests if all the images are loaded by the browser
      nullcount = 0; // Reset nullcount which counts number of images remaining to download.
      // document.images is collection of all images (<IMG> tags) on the document
      // it has length attribute representing the image count.
      for (i = 0; i < document.images.length; i++) {
         if (document.images[i].src == null) { // src is property that stores the image url
            nullcount++;
         } else { // If the image has been loaded into the browser
            if (document.images[i].src.indexOf('expand.gif')>0) { // checks expand
               document.images[i].src = expand.src; // Change the image's source to be the image you want
            } else if (document.images[i].src.indexOf('collapse.gif')>0) { //checks collapse
               document.images[i].src = collapse.src; // Change the image's source to be the image you want
            } // Ends the check to see if it's one of the images we want to change
         } // Ends the check to see if the image's source is null
      } // Move on to the next image
   } // Ends the "while" loop
} // Ends the "replaceTwisties" function
</SCRIPT>

This code will loop through the images on the page and replace the image source on the page. This function needs to be called after the page is loaded by putting the following into the view template's HTML Body Attributes field:
"onLoad=\"replaceTwisties()\""

Each code works equally well and only works on browsers that support image changing on the fly (but won't error on other browsers).