home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Menus / MM / Accelerators_Main.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  3.9 KB  |  185 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. function bodyCase(direction, bShift)
  4. {
  5.   var bHaveLayerSelected = false;
  6.   var bHaveMultipleLayersSelected = false;
  7.   var selarray = dw.getDocumentDOM().getSelection(true);
  8.   var theNode = dw.getDocumentDOM().offsetsToNode(selarray[0],selarray[1]);
  9.  
  10.   if (theNode.nodeType == Node.ELEMENT_NODE)
  11.   {
  12.     bHaveLayerSelected =  (theNode.tagName == "SPAN" || theNode.tagName == "DIV" ||  theNode.tagName == "LAYER" || theNode.tagName == "ILAYER");
  13.   
  14.     if (selarray.length > 2)
  15.     {
  16.       theNode = dw.getDocumentDOM().offsetsToNode(selarray[2],selarray[3]);
  17.       bHaveMultipleLayersSelected = (theNode.tagName == "SPAN" || theNode.tagName == "DIV" || theNode.tagName == "LAYER" || theNode.tagName == "ILAYER");
  18.     }
  19.   }
  20.  
  21.   if (direction == "right")
  22.   {
  23.     if (bHaveLayerSelected)
  24.     {
  25.       if (bHaveMultipleLayersSelected)
  26.       {
  27.         dw.getDocumentDOM().align("right");
  28.       }
  29.       else
  30.       {
  31.         dw.getDocumentDOM().resizeSelectionBy(0,0,bShift ? 10:1,0);
  32.       }
  33.     }
  34.     else
  35.     {
  36.       dw.getDocumentDOM().nextWord(1, bShift);
  37.     }
  38.   }
  39.   if (direction == "left")
  40.   {
  41.     if (bHaveLayerSelected)
  42.     {
  43.       if (bHaveMultipleLayersSelected)
  44.       {
  45.         dw.getDocumentDOM().align("left");
  46.       }
  47.       else
  48.       {
  49.         dw.getDocumentDOM().resizeSelectionBy(0,0,bShift ? -10:-1,0);
  50.       }
  51.     }
  52.     else
  53.     {
  54.       dw.getDocumentDOM().previousWord(1, bShift);
  55.     }
  56.   }
  57.   if (direction == "up")
  58.   {
  59.     if (bHaveLayerSelected)
  60.     {
  61.       if (bHaveMultipleLayersSelected)
  62.       {
  63.         dw.getDocumentDOM().align("top");
  64.       }
  65.       else
  66.       {
  67.         dw.getDocumentDOM().resizeSelectionBy(0,0,0,bShift ? -10:-1);
  68.       }
  69.     }
  70.     else
  71.     {
  72.       dw.getDocumentDOM().previousParagraph(1, bShift);
  73.     }
  74.   }
  75.   if (direction == "down")
  76.   {
  77.     if (bHaveLayerSelected)
  78.     {
  79.       if (bHaveMultipleLayersSelected)
  80.       {
  81.         dw.getDocumentDOM().align("bottom");
  82.       }
  83.       else
  84.       {
  85.         dw.getDocumentDOM().resizeSelectionBy(0,0,0,bShift ? 10:1);
  86.       }
  87.     }
  88.     else
  89.     {
  90.       dw.getDocumentDOM().nextParagraph(1, bShift);
  91.     }
  92.   }
  93. }
  94.   
  95. function frameCase(direction,bShift)
  96. {
  97.   var theSel = dw.getDocumentDOM().getSelectedNode();
  98.   var theMotherNode = theSel.parentNode;
  99.   var siblings = theMotherNode.childNodes;
  100.   var children = theSel.childNodes;
  101.   var numberOneSon = (children > 0) ? theSel.childNodes[0] : null;
  102.   
  103.   if (direction == "left")
  104.   {
  105.     for (var i=0; i <= siblings.length; i++)
  106.     {
  107.       if ((siblings[i] == theSel) && (i > 0))
  108.       {
  109.         dw.getDocumentDOM().setSelectedNode(siblings[i-1]);
  110.         break;
  111.       }
  112.         else if (siblings[i] == theSel && siblings.length > 1)
  113.         {
  114.         dw.getDocumentDOM().setSelectedNode(siblings[i+1]);
  115.         break;
  116.       }
  117.     }
  118.   }
  119.   
  120.   if (direction == "right")
  121.   {
  122.     for (var i=0; i <= siblings.length; i++)
  123.     {
  124.       if (siblings[i] == theSel && i < siblings.length - 1)
  125.       {
  126.         dw.getDocumentDOM().setSelectedNode(siblings[i+1]);
  127.         break;
  128.       }
  129.       else if (siblings[i] == theSel && siblings.length > 1)
  130.       {
  131.         dw.getDocumentDOM().setSelectedNode(siblings[i-1]);
  132.         break;
  133.       }
  134.     }
  135.   }
  136.   
  137.   if (direction == "up")
  138.   {
  139.     if (theMotherNode.tagName == 'FRAME' || theMotherNode.tagName == 'FRAMESET')
  140.     {
  141.       dw.getDocumentDOM().setSelectedNode(theMotherNode);
  142.     }
  143.   }
  144.   
  145.   if (direction == "down")
  146.   {
  147.     if (numberOneSon)
  148.     {
  149.       dw.getDocumentDOM().setSelectedNode(numberOneSon);
  150.     }
  151.   }
  152. }
  153.  
  154. function receiveArguments()
  155. {
  156.   if (dw.getDocumentDOM() == null)
  157.   {
  158.     return;
  159.   }
  160.  
  161.   if (dw.getFocus(true) != 'frames' && dw.getFocus() != 'document')
  162.   {
  163.     return;
  164.   }
  165.   
  166.   if (arguments.length != 2)
  167.   {
  168.     alert(MSG_WrongAcceleratorArgs);
  169.     return;
  170.   }
  171.   
  172.   var direction = arguments[0];
  173.   var bShift = arguments[1];
  174.  
  175.   if (dw.getDocumentDOM().getFocus() == 'body')
  176.   {
  177.     bodyCase(direction,bShift);
  178.   }
  179.   else if (dw.getDocumentDOM().getFocus() == 'frameset')
  180.   {
  181.     frameCase(direction,bShift);
  182.   }
  183. }
  184.  
  185.