home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Shared / MM / Scripts / CMN / menuItem.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  1.8 KB  |  65 lines

  1. //
  2. // Copyright 1999 Macromedia, Inc. All rights reserved.
  3. //
  4. //menuItem.js
  5. //
  6. //Adds stars or values to a listed menu item.
  7. //
  8. //--------------------------------------------------------------
  9. //
  10. //
  11. //addStarToMenuItem(theSelect,menuIndex) {
  12. //addValueToMenuItem(theSelect,menuIndex,value) {
  13. //stripStar(theStr) {
  14. //stripValue(theStr) {
  15.  
  16.  
  17. //Given theSelect obj and an index, it appends a star
  18. //and inserts the new string into the menu at position index.
  19. //If the menu item was "layer[2]" it becomes "layer[2]  *".
  20. //Existing "  *" values get stripped off first.
  21.  
  22. function addStarToMenuItem(theSelect,menuIndex) {
  23.   var newMenuText;
  24.  
  25.   newMenuText = stripStar(theSelect.options[menuIndex].text); //remove if old star
  26.   newMenuText += "  *";  //append "  *"
  27.   theSelect.options[menuIndex]=new Option(newMenuText); //add new line to menu
  28. }
  29.  
  30.  
  31.  
  32. //Given theSelect obj and an index and a value, it appends the value in parens
  33. //and inserts the new string into the menu at position index.
  34. //If the menu item was "layer[2]" and value is "show", it becomes "layer[2] (show)".
  35. //Existing " (value)" values get stripped off first. If value is empty, strips all.
  36.  
  37. function addValueToMenuItem(theSelect,menuIndex,value) {
  38.   var newMenuText = stripValue(theSelect.options[menuIndex].text); //remove old val
  39.   if (value.length > 0) { //if valid value
  40.     newMenuText += " (" + value + ")";  //append " (value)"
  41.   }
  42.   theSelect.options[menuIndex]=new Option(newMenuText); //add new line to menu
  43. }
  44.  
  45. //Given a string "myObject  *" returns "myObject  *".
  46.  
  47. function stripStar(theStr) {
  48.   var endPos;
  49.  
  50.   endPos = theStr.indexOf('  *');
  51.   return ((endPos > 0)? theStr.substring(0,endPos) : theStr);
  52. }
  53.  
  54.  
  55.  
  56. //Given a string "some property (value)" returns "some property".
  57.  
  58. function stripValue(theStr) {
  59.   var endPos = theStr.indexOf(' (');
  60.   return ((endPos > 0)? theStr.substring(0,endPos) : theStr);
  61. }
  62.  
  63.  
  64.  
  65.