home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / editor / EdImageProps.js < prev    next >
Encoding:
JavaScript  |  2001-09-24  |  21.4 KB  |  675 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 Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Pete Collins
  22.  *   Brian King
  23.  *   Ben Goodger
  24.  */
  25.  
  26. var insertNew     = true;
  27. var insertNewIMap = true;
  28. var wasEnableAll  = false;
  29. var constrainOn = false;
  30. // Note used in current version, but these are set correctly
  31. //  and could be used to reset width and height used for constrain ratio
  32. var constrainWidth  = 0;
  33. var constrainHeight = 0;
  34. var imageElement;
  35. var imageMap = 0;
  36. var canRemoveImageMap = false;
  37. var imageMapDisabled = false;
  38. var dialog;
  39. var globalMap;
  40. var firstTimeOkUsed = true;
  41. var doAltTextError = false;
  42. var actualWidth = "";
  43. var gOriginalSrc = "";
  44. var actualHeight = "";
  45. var gHaveDocumentUrl = false;
  46.  
  47. // These must correspond to values in EditorDialog.css for each theme
  48. // (unfortunately, setting "style" attribute here doesn't work!)
  49. var gPreviewImageWidth = 80;
  50. var gPreviewImageHeight = 50;
  51. var StartupCalled = false;
  52.  
  53. // dialog initialization code
  54.  
  55. function Startup()
  56. {
  57.   //XXX Very weird! When calling this with an existing image,
  58.   //    we get called twice. That causes dialog layout
  59.   //    to explode to fullscreen!
  60.   if (StartupCalled)
  61.   {
  62.     dump("*** CALLING IMAGE DIALOG Startup() AGAIN! ***\n");
  63.     return;
  64.   }
  65.   StartupCalled = true;
  66.  
  67.   if (!InitEditorShell())
  68.     return;
  69.  
  70.   doSetOKCancel(onOK, onCancel);
  71.  
  72.   // Create dialog object to store controls for easy access
  73.   dialog = new Object;
  74.  
  75.   dialog.srcInput          = document.getElementById( "srcInput" );
  76.   dialog.altTextInput      = document.getElementById( "altTextInput" );
  77.   dialog.MoreFewerButton   = document.getElementById( "MoreFewerButton" );
  78.   dialog.MoreSection       = document.getElementById( "MoreSection" );
  79.   dialog.customSizeRadio   = document.getElementById( "customSizeRadio" );
  80.   dialog.actualSizeRadio = document.getElementById( "actualSizeRadio" );
  81.   dialog.constrainCheckbox = document.getElementById( "constrainCheckbox" );
  82.   dialog.widthInput        = document.getElementById( "widthInput" );
  83.   dialog.heightInput       = document.getElementById( "heightInput" );
  84.   dialog.widthUnitsMenulist   = document.getElementById( "widthUnitsMenulist" );
  85.   dialog.heightUnitsMenulist  = document.getElementById( "heightUnitsMenulist" );
  86.   dialog.imagelrInput      = document.getElementById( "imageleftrightInput" );
  87.   dialog.imagetbInput      = document.getElementById( "imagetopbottomInput" );
  88.   dialog.border            = document.getElementById( "border" );
  89.   dialog.alignTypeSelect   = document.getElementById( "alignTypeSelect" );
  90.   dialog.ImageHolder       = document.getElementById( "preview-image-holder" );
  91.   dialog.PreviewWidth      = document.getElementById( "PreviewWidth" );
  92.   dialog.PreviewHeight     = document.getElementById( "PreviewHeight" );
  93.   dialog.PreviewSize       = document.getElementById( "PreviewSize" );
  94.   dialog.PreviewImage      = null;
  95.  
  96.   // Get a single selected image element
  97.   var tagName = "img"
  98.   imageElement = editorShell.GetSelectedElement(tagName);
  99.  
  100.   if (imageElement)
  101.   {
  102.     // We found an element and don't need to insert one
  103.     insertNew = false;
  104.     actualWidth  = imageElement.naturalWidth;
  105.     actualHeight = imageElement.naturalHeight;
  106.   }
  107.   else
  108.   {
  109.     insertNew = true;
  110.  
  111.     // We don't have an element selected,
  112.     //  so create one with default attributes
  113.  
  114.     imageElement = editorShell.CreateElementWithDefaults(tagName);
  115.     if( !imageElement )
  116.     {
  117.       dump("Failed to get selected element or create a new one!\n");
  118.       window.close();
  119.       return;
  120.     }
  121.   }
  122.  
  123.   // Make a copy to use for AdvancedEdit
  124.   globalElement = imageElement.cloneNode(false);
  125.  
  126.   // We only need to test for this once per dialog load
  127.   gHaveDocumentUrl = GetDocumentBaseUrl();
  128.  
  129.   InitDialog();
  130.  
  131.   // Save initial source URL
  132.   gOriginalSrc = dialog.srcInput.value;
  133.  
  134.   // By default turn constrain on, but both width and height must be in pixels
  135.   dialog.constrainCheckbox.checked =
  136.     dialog.widthUnitsMenulist.selectedIndex == 0 &&
  137.     dialog.heightUnitsMenulist.selectedIndex == 0;
  138.  
  139.   // Set SeeMore bool to the OPPOSITE of the current state,
  140.   //   which is automatically saved by using the 'persist="more"'
  141.   //   attribute on the MoreFewerButton button
  142.   //   onMoreFewer will toggle the state and redraw the dialog
  143.   SeeMore = (dialog.MoreFewerButton.getAttribute("more") != "1");
  144.  
  145.   // Initialize widgets with image attributes in the case where the entire dialog isn't visible
  146.   onMoreFewer();  // this call will initialize all widgets if entire dialog is visible
  147.  
  148.   SetTextboxFocus(dialog.srcInput);
  149.  
  150.   SetWindowLocation();
  151. }
  152.  
  153. // Set dialog widgets with attribute data
  154. // We get them from globalElement copy so this can be used
  155. //   by AdvancedEdit(), which is shared by all property dialogs
  156. function InitDialog()
  157. {
  158.   // Set the controls to the image's attributes
  159.  
  160.   dialog.srcInput.value = globalElement.getAttribute("src");
  161.  
  162.   // Set "Relativize" checkbox according to current URL state
  163.   SetRelativeCheckbox();
  164.  
  165.   // Force loading of image from its source and show preview image
  166.   LoadPreviewImage();
  167.  
  168.   dialog.altTextInput.value = globalElement.getAttribute("alt");
  169.  
  170.   // setup the height and width widgets
  171.   var width = InitPixelOrPercentMenulist(globalElement,
  172.                     insertNew ? null : imageElement,
  173.                     "width", "widthUnitsMenulist", gPixel);
  174.   var height = InitPixelOrPercentMenulist(globalElement,
  175.                     insertNew ? null : imageElement,
  176.                     "height", "heightUnitsMenulist", gPixel);
  177.  
  178.   // Set actual radio button if both set values are the same as actual
  179.   if (actualWidth && actualHeight)
  180.     dialog.actualSizeRadio.checked = (width == actualWidth) && (height == actualHeight);
  181.   else if ( !(width || height) )
  182.     dialog.actualSizeRadio.checked = true;
  183.  
  184.   if (!dialog.actualSizeRadio.checked)
  185.     dialog.customSizeRadio.checked = true;
  186.  
  187.   dialog.widthInput.value  = constrainWidth = width ? width : (actualWidth ? actualWidth : "");
  188.   dialog.heightInput.value = constrainHeight = height ? height : (actualHeight ? actualHeight : "");
  189.  
  190.   // set spacing editfields
  191.   dialog.imagelrInput.value = globalElement.getAttribute("hspace");
  192.   dialog.imagetbInput.value = globalElement.getAttribute("vspace");
  193.   dialog.border.value       = globalElement.getAttribute("border");
  194.  
  195.   // Get alignment setting
  196.   var align = globalElement.getAttribute("align");
  197.   if (align) {
  198.     align = align.toLowerCase();
  199.   }
  200.   var imgClass;
  201.   var textID;
  202.   switch ( align )
  203.   {
  204.     case "top":
  205.     case "center":
  206.     case "right":
  207.     case "left":
  208.       dialog.alignTypeSelect.value = align;
  209.       break;
  210.     default:  // Default or "bottom"
  211.       dialog.alignTypeSelect.value = "bottom";
  212.   }
  213.  
  214.   // Get image map for image
  215.   imageMap = GetImageMap();
  216.   //XXX: We should eliminate dual imageMap variables (bug 94749)
  217.   globalMap = imageMap;
  218.  
  219.   // we want to force an update so initialize "wasEnableAll" to be the opposite of what the actual state is
  220.   wasEnableAll = !IsValidImage(dialog.srcInput.value);
  221.   doOverallEnabling();
  222.   doDimensionEnabling();
  223. }
  224.  
  225. function GetImageMap()
  226. {
  227.   var usemap = globalElement.getAttribute("usemap");
  228.   if (usemap)
  229.   {
  230.     canRemoveImageMap = true;
  231.     var mapname = usemap.substring(1, usemap.length);
  232.     var mapCollection = editorShell.editorDocument.getElementsByName(mapname);
  233.     if (mapCollection[0] != null)
  234.     {
  235.       insertNewIMap = false;
  236.       return mapCollection[0];
  237.     }
  238.   }
  239.   else
  240.   {
  241.     canRemoveImageMap = false;
  242.   }
  243.  
  244.   insertNewIMap = true;
  245.   return null;
  246. }
  247.  
  248. function chooseFile()
  249. {
  250.   // Get a local file, converted into URL format
  251.   var fileName = GetLocalFileURL("img");
  252.   if (fileName)
  253.   {
  254.     // Always try to relativize local file URLs
  255.     if (gHaveDocumentUrl)
  256.       fileName = MakeRelativeUrl(fileName);
  257.  
  258.     dialog.srcInput.value = fileName;
  259.  
  260.     SetRelativeCheckbox();
  261.     doOverallEnabling();
  262.   }
  263.   LoadPreviewImage();
  264.  
  265.   // Put focus into the input field
  266.   SetTextboxFocus(dialog.srcInput);
  267. }
  268.  
  269. function PreviewImageLoaded()
  270. {
  271.   if (dialog.PreviewImage)
  272.   {
  273.     // Image loading has completed -- we can get actual width
  274.     actualWidth  = dialog.PreviewImage.naturalWidth;
  275.     actualHeight = dialog.PreviewImage.naturalHeight;
  276.  
  277.     if (actualWidth && actualHeight)
  278.     {
  279.       // Use actual size or scale to fit preview if either dimension is too large
  280.       var width = actualWidth;
  281.       var height = actualHeight;
  282.       if (actualWidth > gPreviewImageWidth)
  283.       {
  284.           width = gPreviewImageWidth;
  285.           height = actualHeight * (gPreviewImageWidth / actualWidth);
  286.       }
  287.       if (height > gPreviewImageHeight)
  288.       {
  289.         height = gPreviewImageHeight;
  290.         width = actualWidth * (gPreviewImageHeight / actualHeight);
  291.       }
  292.       dialog.PreviewImage.width = width;
  293.       dialog.PreviewImage.height = height;
  294.  
  295.       dialog.PreviewWidth.setAttribute("value", actualWidth);
  296.       dialog.PreviewHeight.setAttribute("value", actualHeight);
  297.  
  298.       dialog.PreviewSize.setAttribute("collapsed", "false");
  299.       dialog.ImageHolder.setAttribute("collapsed", "false");
  300.  
  301.       // Use values as start for constrain proportions
  302.     }
  303.  
  304.     if (dialog.actualSizeRadio.checked)
  305.       SetActualSize();
  306.   }
  307. }
  308.  
  309. function LoadPreviewImage()
  310. {
  311.   dialog.PreviewSize.setAttribute("collapsed", "true");
  312.  
  313.   var imageSrc = TrimString(dialog.srcInput.value);
  314.   if (!imageSrc)
  315.     return;
  316.  
  317.   if (IsValidImage(dialog.srcInput.value))
  318.   {
  319.     try {
  320.       // Remove the image URL from image cache so it loads fresh
  321.       //  (if we don't do this, loads after the first will always use image cache
  322.       //   and we won't see image edit changes or be able to get actual width and height)
  323.       
  324.       var IOService = GetIOService();
  325.       if (IOService)
  326.       {
  327.         // We must have an absolute URL to preview it or remove it from the cache
  328.         imageSrc = MakeAbsoluteUrl(imageSrc);
  329.  
  330.         if (GetScheme(imageSrc))
  331.         {
  332.           var uri = IOService.newURI(imageSrc, null);
  333.           if (uri)
  334.           {
  335.             var imgCacheService = Components.classes["@mozilla.org/image/cache;1"].getService();
  336.             var imgCache = imgCacheService.QueryInterface(Components.interfaces.imgICache);
  337.  
  338.             // This returns error if image wasn't in the cache; ignore that
  339.             if (imgCache)
  340.               imgCache.removeEntry(uri);
  341.           }
  342.         }
  343.       }
  344.     } catch(e) {}
  345.  
  346.     if(dialog.PreviewImage)
  347.       removeEventListener("load", PreviewImageLoaded, true);
  348.  
  349.     if (dialog.ImageHolder.firstChild)
  350.       dialog.ImageHolder.removeChild(dialog.ImageHolder.firstChild);
  351.       
  352.     dialog.PreviewImage = document.createElementNS("http://www.w3.org/1999/xhtml", "html:img");
  353.     if(dialog.PreviewImage)
  354.     {
  355.       dialog.ImageHolder.appendChild(dialog.PreviewImage);
  356.       dialog.PreviewImage.addEventListener("load", PreviewImageLoaded, true);
  357.       dialog.PreviewImage.src = imageSrc;
  358.     }
  359.   }
  360. }
  361.  
  362. function SetActualSize()
  363. {
  364.   dialog.widthInput.value = actualWidth ? actualWidth : "";
  365.   dialog.widthUnitsMenulist.selectedIndex = 0;
  366.   dialog.heightInput.value = actualHeight ? actualHeight : "";
  367.   dialog.heightUnitsMenulist.selectedIndex = 0;
  368.   doDimensionEnabling();
  369. }
  370.  
  371. function ChangeImageSrc()
  372. {
  373.   SetRelativeCheckbox();
  374.   LoadPreviewImage();
  375.   doOverallEnabling();
  376. }
  377.  
  378. function doDimensionEnabling()
  379. {
  380.   // Enabled only if "Custom" is checked
  381.   var enable = (dialog.customSizeRadio.checked);
  382.  
  383.   // BUG 74145: After input field is disabled,
  384.   //   setting it enabled causes blinking caret to appear
  385.   //   even though focus isn't set to it.
  386.   SetElementEnabledById( "heightInput", enable );
  387.   SetElementEnabledById( "heightLabel", enable );
  388.   SetElementEnabledById( "heightUnitsMenulist", enable );
  389.  
  390.   SetElementEnabledById( "widthInput", enable );
  391.   SetElementEnabledById( "widthLabel", enable);
  392.   SetElementEnabledById( "widthUnitsMenulist", enable );
  393.  
  394.   var constrainEnable = enable
  395.          && ( dialog.widthUnitsMenulist.selectedIndex == 0 )
  396.          && ( dialog.heightUnitsMenulist.selectedIndex == 0 );
  397.  
  398.   SetElementEnabledById( "constrainCheckbox", constrainEnable );
  399. }
  400.  
  401. function doOverallEnabling()
  402. {
  403.   // An image is "valid" if it loaded correctly in the preview window
  404.   //  or has the proper file extension
  405.   var canEnableOk = IsValidImage(dialog.srcInput.value);
  406.   if ( wasEnableAll == canEnableOk )
  407.     return;
  408.  
  409.   wasEnableAll = canEnableOk;
  410.  
  411.   SetElementEnabledById("ok", canEnableOk );
  412.   SetElementEnabledById( "imagemapLabel",  canEnableOk );
  413.   //TODO: Restore when Image Map editor is finished
  414.   //SetElementEnabledById( "editImageMap",   canEnableOk );
  415.   SetElementEnabledById( "removeImageMap", canRemoveImageMap);
  416.  
  417. }
  418.  
  419. function ToggleConstrain()
  420. {
  421.   // If just turned on, save the current width and height as basis for constrain ratio
  422.   // Thus clicking on/off lets user say "Use these values as aspect ration"
  423.   if (dialog.constrainCheckbox.checked && !dialog.constrainCheckbox.disabled
  424.      && (dialog.widthUnitsMenulist.selectedIndex == 0)
  425.      && (dialog.heightUnitsMenulist.selectedIndex == 0))
  426.   {
  427.     constrainWidth = Number(dialog.widthInput.value.trimString());
  428.     constrainHeight = Number(dialog.heightInput.value.trimString());
  429.   }
  430. }
  431.  
  432. function constrainProportions( srcID, destID )
  433. {
  434.   var srcElement = document.getElementById ( srcID );
  435.   if ( !srcElement )
  436.     return;
  437.  
  438.   var destElement = document.getElementById( destID );
  439.   if ( !destElement )
  440.     return;
  441.  
  442.   // always force an integer (whether we are constraining or not)
  443.   forceInteger( srcID );
  444.  
  445.   if (!actualWidth || !actualHeight ||
  446.       !(dialog.constrainCheckbox.checked && !dialog.constrainCheckbox.disabled))
  447.     return;
  448.  
  449.   // double-check that neither width nor height is in percent mode; bail if so!
  450.   if ( (dialog.widthUnitsMenulist.selectedIndex != 0)
  451.      || (dialog.heightUnitsMenulist.selectedIndex != 0) )
  452.     return;
  453.  
  454.   // This always uses the actual width and height ratios
  455.   // which is kind of funky if you change one number without the constrain
  456.   // and then turn constrain on and change a number
  457.   // I prefer the old strategy (below) but I can see some merit to this solution
  458.   if (srcID == "widthInput")
  459.     destElement.value = Math.round( srcElement.value * actualHeight / actualWidth );
  460.   else
  461.     destElement.value = Math.round( srcElement.value * actualWidth / actualHeight );
  462.  
  463. /*
  464.   // With this strategy, the width and height ratio
  465.   //   can be reset to whatever the user entered.
  466.   if (srcID == "widthInput")
  467.     destElement.value = Math.round( srcElement.value * constrainHeight / constrainWidth );
  468.   else
  469.     destElement.value = Math.round( srcElement.value * constrainWidth / constrainHeight );
  470. */
  471. }
  472.  
  473. function editImageMap()
  474. {
  475.   // Make a copy to use for image map editor
  476.   if (insertNewIMap)
  477.   {
  478.     imageMap = editorShell.CreateElementWithDefaults("map");
  479.     globalMap = imageMap.cloneNode(true);
  480.   }
  481.   else
  482.     globalMap = imageMap;
  483.  
  484.   window.openDialog("chrome://editor/content/EdImageMap.xul", "_blank", "chrome,close,titlebar,modal", globalElement, globalMap);
  485. }
  486.  
  487. function removeImageMap()
  488. {
  489.   globalElement.removeAttribute("usemap");
  490.   if (imageMap)
  491.   {
  492.     editorShell.DeleteElement(imageMap);
  493.     insertNewIMap = true;
  494.     globalMap = null;
  495.     imageMap = null;
  496.   }
  497.   canRemoveImageMap = false;
  498.   SetElementEnabledById( "removeImageMap", false);
  499. }
  500.  
  501. // Get data from widgets, validate, and set for the global element
  502. //   accessible to AdvancedEdit() [in EdDialogCommon.js]
  503. function ValidateData()
  504. {
  505.   if ( !IsValidImage(dialog.srcInput.value))
  506.   {
  507.     AlertWithTitle(null, GetString("MissingImageError"));
  508.     window.focus();
  509.     return false;
  510.   }
  511.  
  512.   //TODO: WE NEED TO DO SOME URL VALIDATION HERE, E.G.:
  513.   // We must convert to "file:///" or "http://" format else image doesn't load!
  514.   var src = dialog.srcInput.value.trimString();
  515.   globalElement.setAttribute("src", src);
  516.  
  517.   // Note: allow typing spaces,
  518.   // Warn user if empty string just once per dialog session
  519.   //   but don't consider this a failure
  520.   var alt = dialog.altTextInput.value;
  521.   if (doAltTextError && !alt)
  522.   {
  523.     AlertWithTitle(null, GetString("NoAltText"));
  524.     SetTextboxFocus(dialog.altTextInput);
  525.     doAltTextError = false;
  526.     return false;
  527.   }
  528.   globalElement.setAttribute("alt", alt);
  529.  
  530.   var width = "";
  531.   var height = "";
  532.  
  533.   if (!dialog.actualSizeRadio.checked)
  534.   {
  535.     // Get user values for width and height
  536.     width = ValidateNumber(dialog.widthInput, dialog.widthUnitsMenulist, 1, maxPixels, 
  537.                            globalElement, "width", false, true);
  538.     if (gValidationError)
  539.       return false;
  540.  
  541.     height = ValidateNumber(dialog.heightInput, dialog.heightUnitsMenulist, 1, maxPixels, 
  542.                             globalElement, "height", false, true);
  543.     if (gValidationError)
  544.       return false;
  545.   }
  546.  
  547.   // We always set the width and height attributes, even if same as actual.
  548.   //  This speeds up layout of pages since sizes are known before image is loaded
  549.   if (!width)
  550.     width = actualWidth;
  551.   if (!height)
  552.     height = actualHeight;
  553.  
  554.   // Remove existing width and height only if source changed
  555.   //  and we couldn't obtain actual dimensions
  556.   var srcChanged = (src != gOriginalSrc);
  557.   if (width)
  558.     globalElement.setAttribute("width", width);
  559.   else if (srcChanged)
  560.     globalElement.removeAttribute("width");
  561.  
  562.   if (height)
  563.     globalElement.setAttribute("height", height);
  564.   else if (srcChanged) 
  565.     globalElement.removeAttribute("height");
  566.  
  567.   // spacing attributes
  568.  
  569.   ValidateNumber(dialog.imagelrInput, null, 0, maxPixels, 
  570.                  globalElement, "hspace", false, true, true);
  571.   if (gValidationError)
  572.     return false;
  573.  
  574.   ValidateNumber(dialog.imagetbInput, null, 0, maxPixels, 
  575.                  globalElement, "vspace", false, true);
  576.   if (gValidationError)
  577.     return false;
  578.  
  579.   // note this is deprecated and should be converted to stylesheets
  580.   ValidateNumber(dialog.border, null, 0, maxPixels, 
  581.                  globalElement, "border", false, true);
  582.   if (gValidationError)
  583.     return false;
  584.  
  585.   // Default or setting "bottom" means don't set the attribute
  586.   // Note that the attributes "left" and "right" are opposite
  587.   //  of what we use in the UI, which describes where the TEXT wraps,
  588.   //  not the image location (which is what the HTML describes)
  589.   switch ( dialog.alignTypeSelect.value )
  590.   {
  591.     case "top":
  592.     case "center":
  593.     case "right":
  594.     case "left":
  595.       globalElement.setAttribute( "align", dialog.alignTypeSelect.value );
  596.       break;
  597.     default:
  598.       globalElement.removeAttribute( "align" );
  599.   }
  600.  
  601.   return true;
  602. }
  603.  
  604. function doHelpButton()
  605. {
  606.   openHelp("chrome://help/content/help.xul?image_properties");
  607. }
  608.  
  609. function onOK()
  610. {
  611.   // Show alt text error only once
  612.   // (we don't initialize doAltTextError=true
  613.   //  so Advanced edit button dialog doesn't trigger that error message)
  614.   doAltTextError = firstTimeOkUsed;
  615.   firstTimeOkUsed = false;
  616.  
  617.   // handle insertion of new image
  618.   if (ValidateData())
  619.   {
  620.     // Assign to map if there is one
  621.     if ( globalMap )
  622.     {
  623.       var mapName = globalMap.getAttribute("name");
  624.       if (mapName != "")
  625.       {
  626.         globalElement.setAttribute("usemap", ("#"+mapName));
  627.         if (globalElement.getAttribute("border") == "")
  628.           globalElement.setAttribute("border", 0);
  629.       }
  630.  
  631.       // Copy or insert image map
  632.       imageMap = globalMap.cloneNode(true);
  633.       if (insertNewIMap)
  634.       {
  635.         try
  636.         {
  637.           editorShell.editorDocument.body.appendChild(imageMap);
  638.         //editorShell.InsertElementAtSelection(imageMap, false);
  639.         }
  640.         catch (e)
  641.         {
  642.           dump("Exception occured in InsertElementAtSelection\n");
  643.         }
  644.       }
  645.     }
  646.  
  647.     // All values are valid - copy to actual element in doc or
  648.     //   element created to insert
  649.     editorShell.CloneAttributes(imageElement, globalElement);
  650.     if (insertNew)
  651.     {
  652.       try {
  653.         // 'true' means delete the selection before inserting
  654.         editorShell.InsertElementAtSelection(imageElement, true);
  655.       } catch (e) {
  656.         dump(e);
  657.       }
  658.     }
  659.  
  660.     // un-comment to see that inserting image maps does not work!
  661.     /*test = editorShell.CreateElementWithDefaults("map");
  662.     test.setAttribute("name", "testing");
  663.     testArea = editorShell.CreateElementWithDefaults("area");
  664.     testArea.setAttribute("shape", "circle");
  665.     testArea.setAttribute("coords", "86,102,52");
  666.     testArea.setAttribute("href", "test");
  667.     test.appendChild(testArea);
  668.     editorShell.InsertElementAtSelection(test, false);*/
  669.  
  670.     SaveWindowLocation();
  671.     return true;
  672.   }
  673.   return false;
  674. }
  675.