home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / editor / EdImageOverlay.js < prev    next >
Text File  |  2003-06-08  |  20KB  |  619 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Editor Image Properties Overlay.
  13.  *
  14.  * The Initial Developer of the Original Code is Netscape
  15.  * Communications Corporation. Portions created by Netscape are
  16.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  17.  * Rights Reserved.
  18.  *
  19.  * Contributor(s):
  20.  *   Pete Collins
  21.  *   Brian King
  22.  *   Ben Goodger
  23.  *   Neil Rashbrook <neil@parkwaycc.co.uk> (Separated from EdImageProps.js)
  24.  */
  25.  
  26. /*
  27.  Note: We encourage non-empty alt text for images inserted into a page. 
  28.  When there's no alt text, we always write 'alt=""' as the attribute, since "alt" is a required attribute.
  29.  We allow users to not have alt text by checking a "Don't use alterate text" radio button,
  30.  and we don't accept spaces as valid alt text. A space used to be required to avoid the error message
  31.  if user didn't enter alt text, but is uneccessary now that we no longer annoy the user 
  32.  with the error dialog if alt="" is present on an img element.
  33.  We trim all spaces at the beginning and end of user's alt text
  34. */
  35.  
  36. var gInsertNewImage = true;
  37. var gInsertNewIMap = true;
  38. var gDoAltTextError = false;
  39. var gConstrainOn = false;
  40. // Note used in current version, but these are set correctly
  41. //  and could be used to reset width and height used for constrain ratio
  42. var gConstrainWidth  = 0;
  43. var gConstrainHeight = 0;
  44. var imageElement;
  45. var gImageMap = 0;
  46. var gCanRemoveImageMap = false;
  47. var gRemoveImageMap = false;
  48. var gImageMapDisabled = false;
  49. var gActualWidth = "";
  50. var gActualHeight = "";
  51. var gOriginalSrc = "";
  52. var gHaveDocumentUrl = false;
  53. var gTimerID;
  54. var gValidateTab;
  55.  
  56. // These must correspond to values in EditorDialog.css for each theme
  57. // (unfortunately, setting "style" attribute here doesn't work!)
  58. var gPreviewImageWidth = 80;
  59. var gPreviewImageHeight = 50;
  60.  
  61. // dialog initialization code
  62.  
  63. function ImageStartup()
  64. {
  65.   gDialog.tabBox            = document.getElementById( "TabBox" );
  66.   gDialog.tabLocation       = document.getElementById( "imageLocationTab" );
  67.   gDialog.tabDimensions     = document.getElementById( "imageDimensionsTab" );
  68.   gDialog.tabBorder         = document.getElementById( "imageBorderTab" );
  69.   gDialog.srcInput          = document.getElementById( "srcInput" );
  70.   gDialog.titleInput        = document.getElementById( "titleInput" );
  71.   gDialog.altTextInput      = document.getElementById( "altTextInput" );
  72.   gDialog.altTextRadioGroup = document.getElementById( "altTextRadioGroup" );
  73.   gDialog.altTextRadio      = document.getElementById( "altTextRadio" );
  74.   gDialog.noAltTextRadio    = document.getElementById( "noAltTextRadio" );
  75.   gDialog.customSizeRadio   = document.getElementById( "customSizeRadio" );
  76.   gDialog.actualSizeRadio   = document.getElementById( "actualSizeRadio" );
  77.   gDialog.constrainCheckbox = document.getElementById( "constrainCheckbox" );
  78.   gDialog.widthInput        = document.getElementById( "widthInput" );
  79.   gDialog.heightInput       = document.getElementById( "heightInput" );
  80.   gDialog.widthUnitsMenulist   = document.getElementById( "widthUnitsMenulist" );
  81.   gDialog.heightUnitsMenulist  = document.getElementById( "heightUnitsMenulist" );
  82.   gDialog.imagelrInput      = document.getElementById( "imageleftrightInput" );
  83.   gDialog.imagetbInput      = document.getElementById( "imagetopbottomInput" );
  84.   gDialog.border            = document.getElementById( "border" );
  85.   gDialog.alignTypeSelect   = document.getElementById( "alignTypeSelect" );
  86.   gDialog.ImageHolder       = document.getElementById( "preview-image-holder" );
  87.   gDialog.PreviewWidth      = document.getElementById( "PreviewWidth" );
  88.   gDialog.PreviewHeight     = document.getElementById( "PreviewHeight" );
  89.   gDialog.PreviewSize       = document.getElementById( "PreviewSize" );
  90.   gDialog.PreviewImage      = null;
  91.   gDialog.OkButton          = document.documentElement.getButton("accept");
  92. }
  93.  
  94. // Set dialog widgets with attribute data
  95. // We get them from globalElement copy so this can be used
  96. //   by AdvancedEdit(), which is shared by all property dialogs
  97. function InitImage()
  98. {
  99.   // Set the controls to the image's attributes
  100.   gDialog.srcInput.value = globalElement.getAttribute("src");
  101.  
  102.   // Set "Relativize" checkbox according to current URL state
  103.   SetRelativeCheckbox();
  104.  
  105.   // Force loading of image from its source and show preview image
  106.   LoadPreviewImage();
  107.  
  108.   if (globalElement.hasAttribute("title"))
  109.     gDialog.titleInput.value = globalElement.getAttribute("title");
  110.  
  111.   var hasAltText = globalElement.hasAttribute("alt");
  112.   var altText;
  113.   if (hasAltText)
  114.   {
  115.     altText = globalElement.getAttribute("alt");
  116.     gDialog.altTextInput.value = altText;
  117.   }
  118.  
  119.   // Initialize altText widgets during dialog startup 
  120.   //   or if user enterred altText in Advanced Edit dialog
  121.   //  (this preserves "Don't use alt text" radio button state)
  122.   if (!gDialog.altTextRadioGroup.selectedItem || altText)
  123.   {
  124.     if (gInsertNewImage || !hasAltText || (hasAltText && gDialog.altTextInput.value))
  125.     {
  126.       SetAltTextDisabled(false);
  127.       gDialog.altTextRadioGroup.selectedItem = gDialog.altTextRadio;
  128.     }
  129.     else
  130.     {
  131.       SetAltTextDisabled(true);
  132.       gDialog.altTextRadioGroup.selectedItem = gDialog.noAltTextRadio;
  133.     }
  134.   }
  135.  
  136.   // setup the height and width widgets
  137.   var width = InitPixelOrPercentMenulist(globalElement,
  138.                     gInsertNewImage ? null : imageElement,
  139.                     "width", "widthUnitsMenulist", gPixel);
  140.   var height = InitPixelOrPercentMenulist(globalElement,
  141.                     gInsertNewImage ? null : imageElement,
  142.                     "height", "heightUnitsMenulist", gPixel);
  143.  
  144.   // Set actual radio button if both set values are the same as actual
  145.   SetSizeWidgets(width, height);
  146.  
  147.   gDialog.widthInput.value  = gConstrainWidth = width ? width : (gActualWidth ? gActualWidth : "");
  148.   gDialog.heightInput.value = gConstrainHeight = height ? height : (gActualHeight ? gActualHeight : "");
  149.  
  150.   // set spacing editfields
  151.   gDialog.imagelrInput.value = globalElement.getAttribute("hspace");
  152.   gDialog.imagetbInput.value = globalElement.getAttribute("vspace");
  153.  
  154.   // dialog.border.value       = globalElement.getAttribute("border");
  155.   var bv = GetHTMLOrCSSStyleValue(globalElement, "border", "border-top-width");
  156.   if (/px/.test(bv))
  157.   {
  158.     // Strip out the px
  159.     bv = RegExp.leftContext;
  160.   }
  161.   else if (bv == "thin")
  162.   {
  163.     bv = "1";
  164.   }
  165.   else if (bv == "medium")
  166.   {
  167.     bv = "3";
  168.   }
  169.   else if (bv == "thick")
  170.   {
  171.     bv = "5";
  172.   }
  173.   gDialog.border.value = bv;
  174.  
  175.   // Get alignment setting
  176.   var align = globalElement.getAttribute("align");
  177.   if (align)
  178.     align = align.toLowerCase();
  179.  
  180.   var imgClass;
  181.   var textID;
  182.  
  183.   switch ( align )
  184.   {
  185.     case "top":
  186.     case "middle":
  187.     case "right":
  188.     case "left":
  189.       gDialog.alignTypeSelect.value = align;
  190.       break;
  191.     default:  // Default or "bottom"
  192.       gDialog.alignTypeSelect.value = "bottom";
  193.   }
  194.  
  195.   // Get image map for image
  196.   gImageMap = GetImageMap();
  197.  
  198.   doOverallEnabling();
  199.   doDimensionEnabling();
  200. }
  201.  
  202. function  SetSizeWidgets(width, height)
  203. {
  204.   if (!(width || height) || (gActualWidth && gActualHeight && width == gActualWidth && height == gActualHeight))
  205.     gDialog.actualSizeRadio.radioGroup.selectedItem = gDialog.actualSizeRadio;
  206.  
  207.   if (!gDialog.actualSizeRadio.selected)
  208.   {
  209.     gDialog.actualSizeRadio.radioGroup.selectedItem = gDialog.customSizeRadio;
  210.  
  211.     // Decide if user's sizes are in the same ratio as actual sizes
  212.     if (gActualWidth && gActualHeight)
  213.     {
  214.       if (gActualWidth > gActualHeight)
  215.         gDialog.constrainCheckbox.checked = (Math.round(gActualHeight * width / gActualWidth) == height);
  216.       else
  217.         gDialog.constrainCheckbox.checked = (Math.round(gActualWidth * height / gActualHeight) == width);
  218.     }
  219.   }
  220. }
  221.  
  222. // Disable alt text input when "Don't use alt" radio is checked
  223. function SetAltTextDisabled(disable)
  224. {
  225.   gDialog.altTextInput.disabled = disable;
  226. }
  227.  
  228. function GetImageMap()
  229. {
  230.   var usemap = globalElement.getAttribute("usemap");
  231.   if (usemap)
  232.   {
  233.     gCanRemoveImageMap = true;
  234.     var mapname = usemap.substring(1, usemap.length);
  235.     var mapCollection;
  236.     try {
  237.       mapCollection = GetCurrentEditor().document.getElementsByName(mapname);
  238.     } catch (e) {}
  239.     if (mapCollection && mapCollection[0] != null)
  240.     {
  241.       gInsertNewIMap = false;
  242.       return mapCollection[0];
  243.     }
  244.   }
  245.   else
  246.   {
  247.     gCanRemoveImageMap = false;
  248.   }
  249.  
  250.   gInsertNewIMap = true;
  251.   return null;
  252. }
  253.  
  254. function chooseFile()
  255. {
  256.   if (gTimerID)
  257.     clearTimeout(gTimerID);
  258.   // Get a local file, converted into URL format
  259.   var fileName = GetLocalFileURL("img");
  260.   if (fileName)
  261.   {
  262.     // Always try to relativize local file URLs
  263.     if (gHaveDocumentUrl)
  264.       fileName = MakeRelativeUrl(fileName);
  265.  
  266.     gDialog.srcInput.value = fileName;
  267.  
  268.     SetRelativeCheckbox();
  269.     doOverallEnabling();
  270.   }
  271.   LoadPreviewImage();
  272.  
  273.   // Put focus into the input field
  274.   SetTextboxFocus(gDialog.srcInput);
  275. }
  276.  
  277. function PreviewImageLoaded()
  278. {
  279.   if (gDialog.PreviewImage)
  280.   {
  281.     // Image loading has completed -- we can get actual width
  282.     gActualWidth  = gDialog.PreviewImage.naturalWidth;
  283.     gActualHeight = gDialog.PreviewImage.naturalHeight;
  284.  
  285.     if (gActualWidth && gActualHeight)
  286.     {
  287.       // Use actual size or scale to fit preview if either dimension is too large
  288.       var width = gActualWidth;
  289.       var height = gActualHeight;
  290.       if (gActualWidth > gPreviewImageWidth)
  291.       {
  292.           width = gPreviewImageWidth;
  293.           height = gActualHeight * (gPreviewImageWidth / gActualWidth);
  294.       }
  295.       if (height > gPreviewImageHeight)
  296.       {
  297.         height = gPreviewImageHeight;
  298.         width = gActualWidth * (gPreviewImageHeight / gActualHeight);
  299.       }
  300.       gDialog.PreviewImage.width = width;
  301.       gDialog.PreviewImage.height = height;
  302.  
  303.       gDialog.PreviewWidth.setAttribute("value", gActualWidth);
  304.       gDialog.PreviewHeight.setAttribute("value", gActualHeight);
  305.  
  306.       gDialog.PreviewSize.collapsed = false;
  307.       gDialog.ImageHolder.collapsed = false;
  308.  
  309.       SetSizeWidgets(gDialog.widthInput.value, gDialog.heightInput.value);
  310.     }
  311.  
  312.     if (gDialog.actualSizeRadio.selected)
  313.       SetActualSize();
  314.   }
  315. }
  316.  
  317. function LoadPreviewImage()
  318. {
  319.   gDialog.PreviewSize.collapsed = true;
  320.  
  321.   var imageSrc = TrimString(gDialog.srcInput.value);
  322.   if (!imageSrc)
  323.     return;
  324.  
  325.   try {
  326.     // Remove the image URL from image cache so it loads fresh
  327.     //  (if we don't do this, loads after the first will always use image cache
  328.     //   and we won't see image edit changes or be able to get actual width and height)
  329.     
  330.     var IOService = GetIOService();
  331.     if (IOService)
  332.     {
  333.       // We must have an absolute URL to preview it or remove it from the cache
  334.       imageSrc = MakeAbsoluteUrl(imageSrc);
  335.  
  336.       if (GetScheme(imageSrc))
  337.       {
  338.         var uri = IOService.newURI(imageSrc, null, null);
  339.         if (uri)
  340.         {
  341.           var imgCacheService = Components.classes["@mozilla.org/image/cache;1"].getService();
  342.           var imgCache = imgCacheService.QueryInterface(Components.interfaces.imgICache);
  343.  
  344.           // This returns error if image wasn't in the cache; ignore that
  345.           imgCache.removeEntry(uri);
  346.         }
  347.       }
  348.     }
  349.   } catch(e) {}
  350.  
  351.   if (gDialog.PreviewImage)
  352.     removeEventListener("load", PreviewImageLoaded, true);
  353.  
  354.   if (gDialog.ImageHolder.firstChild)
  355.     gDialog.ImageHolder.removeChild(gDialog.ImageHolder.firstChild);
  356.     
  357.   gDialog.PreviewImage = document.createElementNS("http://www.w3.org/1999/xhtml", "html:img");
  358.   if (gDialog.PreviewImage)
  359.   {
  360.     gDialog.ImageHolder.appendChild(gDialog.PreviewImage);
  361.     gDialog.PreviewImage.addEventListener("load", PreviewImageLoaded, true);
  362.     gDialog.PreviewImage.src = imageSrc;
  363.   }
  364. }
  365.  
  366. function SetActualSize()
  367. {
  368.   gDialog.widthInput.value = gActualWidth ? gActualWidth : "";
  369.   gDialog.widthUnitsMenulist.selectedIndex = 0;
  370.   gDialog.heightInput.value = gActualHeight ? gActualHeight : "";
  371.   gDialog.heightUnitsMenulist.selectedIndex = 0;
  372.   doDimensionEnabling();
  373. }
  374.  
  375. function ChangeImageSrc()
  376. {
  377.   if (gTimerID)
  378.     clearTimeout(gTimerID);
  379.  
  380.   gTimerID = setTimeout("LoadPreviewImage()", 800);
  381.  
  382.   SetRelativeCheckbox();
  383.   doOverallEnabling();
  384. }
  385.  
  386. function doDimensionEnabling()
  387. {
  388.   // Enabled only if "Custom" is selected
  389.   var enable = (gDialog.customSizeRadio.selected);
  390.  
  391.   // BUG 74145: After input field is disabled,
  392.   //   setting it enabled causes blinking caret to appear
  393.   //   even though focus isn't set to it.
  394.   SetElementEnabledById( "heightInput", enable );
  395.   SetElementEnabledById( "heightLabel", enable );
  396.   SetElementEnabledById( "heightUnitsMenulist", enable );
  397.  
  398.   SetElementEnabledById( "widthInput", enable );
  399.   SetElementEnabledById( "widthLabel", enable);
  400.   SetElementEnabledById( "widthUnitsMenulist", enable );
  401.  
  402.   var constrainEnable = enable
  403.          && ( gDialog.widthUnitsMenulist.selectedIndex == 0 )
  404.          && ( gDialog.heightUnitsMenulist.selectedIndex == 0 );
  405.  
  406.   SetElementEnabledById( "constrainCheckbox", constrainEnable );
  407. }
  408.  
  409. function doOverallEnabling()
  410. {
  411.   var enabled = TrimString(gDialog.srcInput.value) != "";
  412.  
  413.   SetElementEnabled(gDialog.OkButton, enabled);
  414.   SetElementEnabledById("AdvancedEditButton1", enabled);
  415.   SetElementEnabledById("imagemapLabel", enabled);
  416.  
  417.   //TODO: Restore when Image Map editor is finished
  418.   //SetElementEnabledById("editImageMap", enabled);
  419.   SetElementEnabledById("removeImageMap", gCanRemoveImageMap);
  420. }
  421.  
  422. function ToggleConstrain()
  423. {
  424.   // If just turned on, save the current width and height as basis for constrain ratio
  425.   // Thus clicking on/off lets user say "Use these values as aspect ration"
  426.   if (gDialog.constrainCheckbox.checked && !gDialog.constrainCheckbox.disabled
  427.      && (gDialog.widthUnitsMenulist.selectedIndex == 0)
  428.      && (gDialog.heightUnitsMenulist.selectedIndex == 0))
  429.   {
  430.     gConstrainWidth = Number(TrimString(gDialog.widthInput.value));
  431.     gConstrainHeight = Number(TrimString(gDialog.heightInput.value));
  432.   }
  433. }
  434.  
  435. function constrainProportions( srcID, destID )
  436. {
  437.   var srcElement = document.getElementById(srcID);
  438.   if (!srcElement)
  439.     return;
  440.  
  441.   var destElement = document.getElementById(destID);
  442.   if (!destElement)
  443.     return;
  444.  
  445.   // always force an integer (whether we are constraining or not)
  446.   forceInteger(srcID);
  447.  
  448.   if (!gActualWidth || !gActualHeight ||
  449.       !(gDialog.constrainCheckbox.checked && !gDialog.constrainCheckbox.disabled))
  450.     return;
  451.  
  452.   // double-check that neither width nor height is in percent mode; bail if so!
  453.   if ( (gDialog.widthUnitsMenulist.selectedIndex != 0)
  454.      || (gDialog.heightUnitsMenulist.selectedIndex != 0) )
  455.     return;
  456.  
  457.   // This always uses the actual width and height ratios
  458.   // which is kind of funky if you change one number without the constrain
  459.   // and then turn constrain on and change a number
  460.   // I prefer the old strategy (below) but I can see some merit to this solution
  461.   if (srcID == "widthInput")
  462.     destElement.value = Math.round( srcElement.value * gActualHeight / gActualWidth );
  463.   else
  464.     destElement.value = Math.round( srcElement.value * gActualWidth / gActualHeight );
  465.  
  466. /*
  467.   // With this strategy, the width and height ratio
  468.   //   can be reset to whatever the user entered.
  469.   if (srcID == "widthInput")
  470.     destElement.value = Math.round( srcElement.value * gConstrainHeight / gConstrainWidth );
  471.   else
  472.     destElement.value = Math.round( srcElement.value * gConstrainWidth / gConstrainHeight );
  473. */
  474. }
  475.  
  476. function editImageMap()
  477. {
  478.   // Create an imagemap for image map editor
  479.   if (gInsertNewIMap)
  480.   {
  481.     try {
  482.       gImageMap = GetCurrentEditor().createElementWithDefaults("map");
  483.     } catch (e) {}
  484.   }
  485.  
  486.   // Note: We no longer pass in a copy of the global ImageMap. ImageMap editor should create a copy and manage onOk and onCancel behavior
  487.   window.openDialog("chrome://editor/content/EdImageMap.xul", "_blank", "chrome,close,titlebar,modal", globalElement, gImageMap);
  488. }
  489.  
  490. function removeImageMap()
  491. {
  492.   gRemoveImageMap = true;
  493.   gCanRemoveImageMap = false;
  494.   SetElementEnabledById("removeImageMap", false);
  495. }
  496.  
  497. function SwitchToValidatePanel()
  498. {
  499.   if (gDialog.tabBox && gValidateTab && gDialog.tabBox.selectedTab != gValidateTab)
  500.     gDialog.tabBox.selectedTab = gValidateTab;
  501. }
  502.  
  503. // Get data from widgets, validate, and set for the global element
  504. //   accessible to AdvancedEdit() [in EdDialogCommon.js]
  505. function ValidateImage()
  506. {
  507.   var editor = GetCurrentEditor();
  508.   if (!editor)
  509.     return false;
  510.  
  511.   gValidateTab = gDialog.tabLocation;
  512.   if (!gDialog.srcInput.value)
  513.   {
  514.     AlertWithTitle(null, GetString("MissingImageError"));
  515.     SwitchToValidatePanel();
  516.     gDialog.srcInput.focus();
  517.     return false;
  518.   }
  519.  
  520.   //TODO: WE NEED TO DO SOME URL VALIDATION HERE, E.G.:
  521.   // We must convert to "file:///" or "http://" format else image doesn't load!
  522.   var src = TrimString(gDialog.srcInput.value);
  523.   globalElement.setAttribute("src", src);
  524.  
  525.   globalElement.setAttribute("title", TrimString(gDialog.titleInput.value));
  526.  
  527.   // Force user to enter Alt text only if "Alternate text" radio is checked
  528.   // Don't allow just spaces in alt text
  529.   var alt = "";
  530.   var useAlt = gDialog.altTextRadioGroup.selectedItem == gDialog.altTextRadio;
  531.   if (useAlt)
  532.     alt = TrimString(gDialog.altTextInput.value);
  533.  
  534.   if (gDoAltTextError && useAlt && !alt)
  535.   {
  536.     AlertWithTitle(null, GetString("NoAltText"));
  537.     SwitchToValidatePanel();
  538.     gDialog.altTextInput.focus();
  539.     return false;
  540.   }
  541.   globalElement.setAttribute("alt", alt);
  542.  
  543.   var width = "";
  544.   var height = "";
  545.  
  546.   gValidateTab = gDialog.tabDimensions;
  547.   if (!gDialog.actualSizeRadio.selected)
  548.   {
  549.     // Get user values for width and height
  550.     width = ValidateNumber(gDialog.widthInput, gDialog.widthUnitsMenulist, 1, gMaxPixels, 
  551.                            globalElement, "width", false, true);
  552.     if (gValidationError)
  553.       return false;
  554.  
  555.     height = ValidateNumber(gDialog.heightInput, gDialog.heightUnitsMenulist, 1, gMaxPixels, 
  556.                             globalElement, "height", false, true);
  557.     if (gValidationError)
  558.       return false;
  559.   }
  560.  
  561.   // We always set the width and height attributes, even if same as actual.
  562.   //  This speeds up layout of pages since sizes are known before image is loaded
  563.   if (!width)
  564.     width = gActualWidth;
  565.   if (!height)
  566.     height = gActualHeight;
  567.  
  568.   // Remove existing width and height only if source changed
  569.   //  and we couldn't obtain actual dimensions
  570.   var srcChanged = (src != gOriginalSrc);
  571.   if (width)
  572.     globalElement.setAttribute("width", width);
  573.   else if (srcChanged)
  574.     editor.removeAttributeOrEquivalent(globalElement, "width", true);
  575.  
  576.   if (height)
  577.     globalElement.setAttribute("height", height);
  578.   else if (srcChanged) 
  579.     editor.removeAttributeOrEquivalent(globalElement, "height", true);
  580.  
  581.   // spacing attributes
  582.   gValidateTab = gDialog.tabBorder;
  583.   ValidateNumber(gDialog.imagelrInput, null, 0, gMaxPixels, 
  584.                  globalElement, "hspace", false, true, true);
  585.   if (gValidationError)
  586.     return false;
  587.  
  588.   ValidateNumber(gDialog.imagetbInput, null, 0, gMaxPixels, 
  589.                  globalElement, "vspace", false, true);
  590.   if (gValidationError)
  591.     return false;
  592.  
  593.   // note this is deprecated and should be converted to stylesheets
  594.   ValidateNumber(gDialog.border, null, 0, gMaxPixels, 
  595.                  globalElement, "border", false, true);
  596.   if (gValidationError)
  597.     return false;
  598.  
  599.   // Default or setting "bottom" means don't set the attribute
  600.   // Note that the attributes "left" and "right" are opposite
  601.   //  of what we use in the UI, which describes where the TEXT wraps,
  602.   //  not the image location (which is what the HTML describes)
  603.   switch ( gDialog.alignTypeSelect.value )
  604.   {
  605.     case "top":
  606.     case "middle":
  607.     case "right":
  608.     case "left":
  609.       globalElement.setAttribute( "align", gDialog.alignTypeSelect.value );
  610.       break;
  611.     default:
  612.       try {
  613.         editor.removeAttributeOrEquivalent(globalElement, "align", true);
  614.       } catch (e) {}
  615.   }
  616.  
  617.   return true;
  618. }
  619.