From 6ff254ec3a2c3d4e6e690535f65f89a007c66b98 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Fri, 8 Feb 2002 22:40:59 +0000 Subject: [PATCH] Add checkbox to remove link border and simplify anchor/heading selection when choosing link (b=96477, fix by neil@parkwaycc.co.uk, r=cmanske, sr=kin); improved 'Constrain' checkbox logic in image dialogs (b=58133, r=neil@parkwaycc.co.uk, sr=kin) --- editor/ui/dialogs/content/EdDialogCommon.js | 92 +++++++- editor/ui/dialogs/content/EdDialogOverlay.xul | 33 ++- editor/ui/dialogs/content/EdImageOverlay.js | 156 ++++---------- editor/ui/dialogs/content/EdImageOverlay.xul | 6 +- editor/ui/dialogs/content/EdImageProps.js | 167 +++++++++++++-- editor/ui/dialogs/content/EdImageProps.xul | 8 +- editor/ui/dialogs/content/EdInputImage.js | 5 +- editor/ui/dialogs/content/EdLinkProps.js | 199 ++---------------- editor/ui/dialogs/content/EdLinkProps.xul | 34 +-- .../dialogs/locale/en-US/EdDialogOverlay.dtd | 3 + .../locale/en-US/EditorImageProperties.dtd | 4 +- .../locale/en-US/EditorLinkProperties.dtd | 6 - 12 files changed, 340 insertions(+), 373 deletions(-) diff --git a/editor/ui/dialogs/content/EdDialogCommon.js b/editor/ui/dialogs/content/EdDialogCommon.js index cea3f2dea20..d8331b06199 100644 --- a/editor/ui/dialogs/content/EdDialogCommon.js +++ b/editor/ui/dialogs/content/EdDialogCommon.js @@ -220,6 +220,7 @@ function SetTextboxFocus(textbox) { // Select entire contents if (textbox.value.length > 0) + // This doesn't work for editable menulists yet textbox.select(); else textbox.focus(); @@ -888,11 +889,13 @@ function onCancel() return true; } -function SetRelativeCheckbox() +function SetRelativeCheckbox(checkbox) { - var checkbox = document.getElementById("MakeRelativeCheckbox"); - if (!checkbox) - return; + if (!checkbox) { + checkbox = document.getElementById("MakeRelativeCheckbox"); + if (!checkbox) + return; + } // Mail never allows relative URLs, so hide the checkbox if (editorShell.editorType == "htmlmail") @@ -947,16 +950,12 @@ function SetRelativeCheckbox() } } - SetElementEnabledById("MakeRelativeCheckbox", enable); + SetElementEnabled(checkbox, enable); } // oncommand handler for the Relativize checkbox in EditorOverlay.xul -function MakeInputValueRelativeOrAbsolute() +function MakeInputValueRelativeOrAbsolute(checkbox) { - var checkbox = document.getElementById("MakeRelativeCheckbox"); - if (!checkbox) - return; - var input = document.getElementById(checkbox.getAttribute("for")); if (!input) return; @@ -979,7 +978,7 @@ function MakeInputValueRelativeOrAbsolute() input.value = MakeAbsoluteUrl(input.value); // Reset checkbox to reflect url state - SetRelativeCheckbox(checkbox, input.value); + SetRelativeCheckbox(checkbox); } } @@ -1203,3 +1202,74 @@ function RemoveElementKeepingChildren(element) editorShell.EndBatchChanges(); } +function FillLinkMenulist(linkMenulist, headingsArray) +{ + var NamedAnchorNodeList = editorShell.editorDocument.anchors; + var NamedAnchorCount = NamedAnchorNodeList.length; + if (NamedAnchorCount > 0) + { + for (var i = 0; i < NamedAnchorCount; i++) + linkMenulist.appendItem("#" + NamedAnchorNodeList.item(i).name); + } + for (var j = 1; j <= 6; j++) + { + var headingList = editorShell.editorDocument.getElementsByTagName("h" + j); + for (var k = 0; k < headingList.length; k++) + { + var heading = headingList.item(k); + + // Skip headings that already have a named anchor as their first child + // (this may miss nearby anchors, but at least we don't insert another + // under the same heading) + var child = heading.firstChild; + if (child && child.nodeName == "A" && child.name && (child.name.length>0)) + continue; + + var range = editorShell.editorDocument.createRange(); + range.setStart(heading,0); + var lastChildIndex = heading.childNodes.length; + range.setEnd(heading,lastChildIndex); + var text = range.toString(); + if (text) + { + // Use just first 40 characters, don't add "...", + // and replace whitespace with "_" and strip non-word characters + text = "#" + ConvertToCDATAString(TruncateStringAtWordEnd(text, 40, false)); + // Append "_" to any name already in the list + while (linkMenulist.getElementsByAttribute("label", text).length) + text += "_"; + linkMenulist.appendItem(text); + + // Save nodes in an array so we can create anchor node under it later + headingsArray[NamedAnchorCount++] = heading; + } + } + } + if (!linkMenulist.firstChild.hasChildNodes()) + { + var item = linkMenulist.appendItem(GetString("NoNamedAnchorsOrHeadings")); + item.setAttribute("disabled", "true"); + } +} + +// Shared by Image and Link dialogs for the "Choose" button for links +function chooseLinkFile() +{ + // Get a local file, converted into URL format + var fileName = GetLocalFileURL("html, img"); + if (fileName) + { + // Always try to relativize local file URLs + if (gHaveDocumentUrl) + fileName = MakeRelativeUrl(fileName); + + gDialog.hrefInput.value = fileName; + + // Do stuff specific to a particular dialog + // (This is defined separately in Image and Link dialogs) + ChangeLinkLocation(); + } + // Put focus into the input field + SetTextboxFocus(gDialog.hrefInput); +} + diff --git a/editor/ui/dialogs/content/EdDialogOverlay.xul b/editor/ui/dialogs/content/EdDialogOverlay.xul index 4515866c0a5..ad499b061ae 100644 --- a/editor/ui/dialogs/content/EdDialogOverlay.xul +++ b/editor/ui/dialogs/content/EdDialogOverlay.xul @@ -58,11 +58,38 @@ oncommand = "chooseFile()" label = "&chooseButton.label;"/> +