2001-09-20 04:02:59 +04:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
1999-08-19 18:28:44 +04:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2001-09-20 04:02:59 +04:00
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
1999-08-19 18:28:44 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
2001-09-20 04:02:59 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-08-19 18:28:44 +04:00
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
2001-09-20 04:02:59 +04:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
1999-08-19 18:28:44 +04:00
|
|
|
|
1999-05-06 03:29:18 +04:00
|
|
|
var anchorElement = null;
|
1999-07-03 02:52:34 +04:00
|
|
|
var imageElement = null;
|
2000-02-15 18:54:05 +03:00
|
|
|
var insertNew = false;
|
2000-08-11 07:20:47 +04:00
|
|
|
var replaceExistingLink = false;
|
2000-02-15 18:54:05 +03:00
|
|
|
var insertLinkAtCaret;
|
1999-05-06 03:29:18 +04:00
|
|
|
var needLinkText = false;
|
1999-09-04 02:05:47 +04:00
|
|
|
var href;
|
|
|
|
var newLinkText;
|
1999-09-30 01:45:50 +04:00
|
|
|
var HNodeArray;
|
2001-04-28 06:47:03 +04:00
|
|
|
var gHaveNamedAnchors = false;
|
|
|
|
var gHaveHeadings = false;
|
|
|
|
var gCanChangeHeadingSelected = true;
|
|
|
|
var gCanChangeAnchorSelected = true;
|
2001-09-17 23:31:19 +04:00
|
|
|
var gHaveDocumentUrl = false;
|
1999-05-06 03:29:18 +04:00
|
|
|
|
1999-07-03 02:52:34 +04:00
|
|
|
// NOTE: Use "href" instead of "a" to distinguish from Named Anchor
|
|
|
|
// The returned node is has an "a" tagName
|
|
|
|
var tagName = "href";
|
1999-05-06 03:29:18 +04:00
|
|
|
|
|
|
|
// dialog initialization code
|
1999-06-11 22:58:32 +04:00
|
|
|
function Startup()
|
|
|
|
{
|
1999-07-14 19:24:33 +04:00
|
|
|
if (!InitEditorShell())
|
|
|
|
return;
|
1999-08-25 18:36:13 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
doSetOKCancel(onOK, onCancel);
|
2000-02-15 18:54:05 +03:00
|
|
|
|
1999-08-02 02:37:58 +04:00
|
|
|
// Message was wrapped in a <label> or <div>, so actual text is a child text node
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextCaption = document.getElementById("linkTextCaption");
|
|
|
|
gDialog.linkTextMessage = document.getElementById("linkTextMessage");
|
|
|
|
gDialog.linkTextInput = document.getElementById("linkTextInput");
|
|
|
|
gDialog.hrefInput = document.getElementById("hrefInput");
|
|
|
|
gDialog.NamedAnchorList = document.getElementById("NamedAnchorList");
|
|
|
|
gDialog.HeadingsList = document.getElementById("HeadingsList");
|
|
|
|
gDialog.MoreSection = document.getElementById("MoreSection");
|
|
|
|
gDialog.MoreFewerButton = document.getElementById("MoreFewerButton");
|
|
|
|
gDialog.AdvancedEditSection = document.getElementById("AdvancedEdit");
|
1999-05-06 03:29:18 +04:00
|
|
|
|
1999-07-25 05:24:51 +04:00
|
|
|
var selection = editorShell.editorSelection;
|
2000-04-17 00:29:08 +04:00
|
|
|
if (selection)
|
1999-05-07 04:44:46 +04:00
|
|
|
dump("There is a selection: collapsed = "+selection.isCollapsed+"\n");
|
2000-04-17 00:29:08 +04:00
|
|
|
else
|
1999-05-06 03:29:18 +04:00
|
|
|
dump("Failed to get selection\n");
|
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
// See if we have a single selected image
|
|
|
|
imageElement = editorShell.GetSelectedElement("img");
|
2000-08-24 04:40:59 +04:00
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
if (imageElement)
|
|
|
|
{
|
|
|
|
// Get the parent link if it exists -- more efficient than GetSelectedElement()
|
|
|
|
anchorElement = editorShell.GetElementOrParentByTagName("href", imageElement);
|
|
|
|
if (anchorElement)
|
|
|
|
{
|
|
|
|
if (anchorElement.childNodes.length > 1)
|
|
|
|
{
|
|
|
|
// If there are other children, then we want to break
|
|
|
|
// this image away by inserting a new link around it,
|
|
|
|
// so make a new node and copy existing attributes
|
|
|
|
anchorElement = anchorElement.cloneNode(false);
|
2000-08-11 07:20:47 +04:00
|
|
|
//insertNew = true;
|
|
|
|
replaceExistingLink = true;
|
1999-07-03 02:52:34 +04:00
|
|
|
}
|
|
|
|
}
|
1999-05-07 04:44:46 +04:00
|
|
|
}
|
2000-02-15 18:54:05 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get an anchor element if caret or
|
|
|
|
// entire selection is within the link.
|
|
|
|
anchorElement = editorShell.GetSelectedElement(tagName);
|
|
|
|
|
|
|
|
if (anchorElement)
|
|
|
|
{
|
|
|
|
// Select the entire link
|
|
|
|
editorShell.SelectElement(anchorElement);
|
|
|
|
selection = editorShell.editorSelection;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If selection starts in a link, but extends beyond it,
|
|
|
|
// the user probably wants to extend existing link to new selection,
|
|
|
|
// so check if either end of selection is within a link
|
|
|
|
// POTENTIAL PROBLEM: This prevents user from selecting text in an existing
|
|
|
|
// link and making 2 links.
|
|
|
|
// Note that this isn't a problem with images, handled above
|
|
|
|
|
|
|
|
anchorElement = editorShell.GetElementOrParentByTagName("href", selection.anchorNode);
|
|
|
|
if (!anchorElement)
|
|
|
|
anchorElement = editorShell.GetElementOrParentByTagName("href", selection.focusNode);
|
|
|
|
|
|
|
|
if (anchorElement)
|
|
|
|
{
|
|
|
|
// But clone it for reinserting/merging around existing
|
|
|
|
// link that only partially overlaps the selection
|
|
|
|
anchorElement = anchorElement.cloneNode(false);
|
2000-08-11 07:20:47 +04:00
|
|
|
//insertNew = true;
|
|
|
|
replaceExistingLink = true;
|
2000-02-15 18:54:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!anchorElement)
|
|
|
|
{
|
|
|
|
// No existing link -- create a new one
|
|
|
|
anchorElement = editorShell.CreateElementWithDefaults(tagName);
|
|
|
|
insertNew = true;
|
2000-08-11 07:20:47 +04:00
|
|
|
// Hide message about removing existing link
|
|
|
|
document.getElementById("RemoveLinkMsg").setAttribute("hidden","true");
|
2000-02-15 18:54:05 +03:00
|
|
|
}
|
1999-05-06 03:29:18 +04:00
|
|
|
if(!anchorElement)
|
|
|
|
{
|
|
|
|
dump("Failed to get selected element or create a new one!\n");
|
1999-05-27 01:40:51 +04:00
|
|
|
window.close();
|
2001-05-05 21:17:11 +04:00
|
|
|
return;
|
2000-02-15 18:54:05 +03:00
|
|
|
}
|
1999-05-07 04:44:46 +04:00
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
// We insert at caret only when nothing is selected
|
|
|
|
insertLinkAtCaret = selection.isCollapsed;
|
|
|
|
|
2001-05-05 21:17:11 +04:00
|
|
|
var selectedText;
|
2000-02-15 18:54:05 +03:00
|
|
|
if (insertLinkAtCaret)
|
|
|
|
{
|
2001-07-06 06:01:52 +04:00
|
|
|
// Groupbox caption:
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextCaption.setAttribute("label", GetString("LinkText"));
|
2001-09-17 23:31:19 +04:00
|
|
|
|
2000-04-17 00:29:08 +04:00
|
|
|
// Message above input field:
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextMessage.setAttribute("value", GetString("EnterLinkText"));
|
1999-05-06 03:29:18 +04:00
|
|
|
}
|
2000-02-15 18:54:05 +03:00
|
|
|
else
|
1999-05-08 02:26:23 +04:00
|
|
|
{
|
2000-02-15 18:54:05 +03:00
|
|
|
if (!imageElement)
|
|
|
|
{
|
2000-08-24 04:40:59 +04:00
|
|
|
// We get here if selection is exactly around a link node
|
2000-02-15 18:54:05 +03:00
|
|
|
// Check if selection has some text - use that first
|
2001-05-05 21:17:11 +04:00
|
|
|
selectedText = GetSelectionAsText();
|
2001-08-11 02:30:59 +04:00
|
|
|
if (!selectedText)
|
2000-02-15 18:54:05 +03:00
|
|
|
{
|
|
|
|
// No text, look for first image in the selection
|
|
|
|
var children = anchorElement.childNodes;
|
|
|
|
if (children)
|
|
|
|
{
|
2000-09-02 03:04:03 +04:00
|
|
|
for(var i=0; i < children.length; i++)
|
2000-02-15 18:54:05 +03:00
|
|
|
{
|
2000-08-24 04:40:59 +04:00
|
|
|
var nodeName = children.item(i).nodeName.toLowerCase();
|
|
|
|
if (nodeName == "img")
|
2000-02-15 18:54:05 +03:00
|
|
|
{
|
|
|
|
imageElement = children.item(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Set "caption" for link source and the source text or image URL
|
|
|
|
if (imageElement)
|
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextCaption.setAttribute("label", GetString("LinkImage"));
|
2000-02-15 18:54:05 +03:00
|
|
|
// Link source string is the source URL of image
|
|
|
|
// TODO: THIS DOESN'T HANDLE MULTIPLE SELECTED IMAGES!
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextMessage.setAttribute("value", imageElement.src);
|
2000-02-15 18:54:05 +03:00
|
|
|
} else {
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextCaption.setAttribute("label", GetString("LinkText"));
|
2001-05-05 21:17:11 +04:00
|
|
|
if (selectedText)
|
|
|
|
{
|
2001-09-17 23:31:19 +04:00
|
|
|
// Use just the first 60 characters and add "..."
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextMessage.setAttribute("value", TruncateStringAtWordEnd(ReplaceWhitespace(selectedText, " "), 60, true));
|
2000-02-15 18:54:05 +03:00
|
|
|
} else {
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextMessage.setAttribute("value", GetString("MixedSelection"));
|
2000-02-15 18:54:05 +03:00
|
|
|
}
|
|
|
|
}
|
1999-05-08 02:26:23 +04:00
|
|
|
}
|
1999-09-02 05:47:18 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Make a copy to use for AdvancedEdit and onSaveDefault
|
|
|
|
globalElement = anchorElement.cloneNode(false);
|
|
|
|
|
1999-09-30 01:45:50 +04:00
|
|
|
// Get the list of existing named anchors and headings
|
1999-10-20 18:15:25 +04:00
|
|
|
FillListboxes();
|
1999-09-30 01:45:50 +04:00
|
|
|
|
2001-09-17 23:31:19 +04:00
|
|
|
// We only need to test for this once per dialog load
|
|
|
|
gHaveDocumentUrl = GetDocumentBaseUrl();
|
|
|
|
|
1999-09-02 05:47:18 +04:00
|
|
|
// Set data for the dialog controls
|
|
|
|
InitDialog();
|
2001-05-05 21:17:11 +04:00
|
|
|
|
|
|
|
// Search for a URI pattern in the selected text
|
|
|
|
// as candidate href
|
|
|
|
selectedText = TrimString(selectedText);
|
2001-10-11 00:07:06 +04:00
|
|
|
if (!gDialog.hrefInput.value && TextIsURI(selectedText))
|
|
|
|
gDialog.hrefInput.value = selectedText;
|
1999-09-02 05:47:18 +04:00
|
|
|
|
|
|
|
// Set initial focus
|
2000-02-15 18:54:05 +03:00
|
|
|
if (insertLinkAtCaret) {
|
1999-09-02 05:47:18 +04:00
|
|
|
// We will be using the HREF inputbox, so text message
|
2001-10-11 00:07:06 +04:00
|
|
|
SetTextboxFocus(gDialog.linkTextInput);
|
1999-09-02 05:47:18 +04:00
|
|
|
} else {
|
2001-10-11 00:07:06 +04:00
|
|
|
SetTextboxFocus(gDialog.hrefInput);
|
1999-09-02 05:47:18 +04:00
|
|
|
|
|
|
|
// We will not insert a new link at caret, so remove link text input field
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextInput.setAttribute("hidden", "true");
|
|
|
|
gDialog.linkTextInput = null;
|
1999-09-02 05:47:18 +04:00
|
|
|
}
|
2000-08-11 07:20:47 +04:00
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
InitMoreFewer();
|
2000-08-11 07:20:47 +04:00
|
|
|
|
|
|
|
// This sets enable state on OK button
|
2001-09-17 23:31:19 +04:00
|
|
|
doEnabling();
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
|
|
|
SetWindowLocation();
|
1999-09-02 05:47:18 +04:00
|
|
|
}
|
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Set dialog widgets with attribute data
|
|
|
|
// We get them from globalElement copy so this can be used
|
|
|
|
// by AdvancedEdit(), which is shared by all property dialogs
|
1999-09-02 05:47:18 +04:00
|
|
|
function InitDialog()
|
|
|
|
{
|
2001-01-11 07:59:19 +03:00
|
|
|
// Must use getAttribute, not "globalElement.href",
|
|
|
|
// or foreign chars aren't coverted correctly!
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.hrefInput.value = globalElement.getAttribute("href");
|
2001-09-17 23:31:19 +04:00
|
|
|
|
|
|
|
// Set "Relativize" checkbox according to current URL state
|
|
|
|
SetRelativeCheckbox();
|
1999-05-06 03:29:18 +04:00
|
|
|
}
|
1999-04-21 22:53:55 +04:00
|
|
|
|
1999-12-02 01:20:50 +03:00
|
|
|
function chooseFile()
|
1999-05-27 01:40:51 +04:00
|
|
|
{
|
|
|
|
// Get a local file, converted into URL format
|
2001-10-11 00:07:06 +04:00
|
|
|
var fileName = GetLocalFileURL("html, img");
|
2001-09-17 23:31:19 +04:00
|
|
|
if (fileName)
|
|
|
|
{
|
|
|
|
// Always try to relativize local file URLs
|
|
|
|
if (gHaveDocumentUrl)
|
|
|
|
fileName = MakeRelativeUrl(fileName);
|
|
|
|
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.hrefInput.value = fileName;
|
2001-09-17 23:31:19 +04:00
|
|
|
|
|
|
|
SetRelativeCheckbox();
|
|
|
|
doEnabling();
|
1999-05-27 01:40:51 +04:00
|
|
|
}
|
|
|
|
// Put focus into the input field
|
2001-10-11 00:07:06 +04:00
|
|
|
SetTextboxFocus(gDialog.hrefInput);
|
1999-05-27 01:40:51 +04:00
|
|
|
}
|
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
function FillListboxes()
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2000-02-15 18:54:05 +03:00
|
|
|
var NamedAnchorNodeList = editorShell.editorDocument.anchors;
|
1999-10-14 04:13:27 +04:00
|
|
|
var NamedAnchorCount = NamedAnchorNodeList.length;
|
2000-09-14 09:30:06 +04:00
|
|
|
var item;
|
2000-04-17 00:29:08 +04:00
|
|
|
if (NamedAnchorCount > 0)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < NamedAnchorCount; i++)
|
2001-10-11 00:07:06 +04:00
|
|
|
AppendStringToTreelist(gDialog.NamedAnchorList, NamedAnchorNodeList.item(i).name);
|
2000-04-17 00:29:08 +04:00
|
|
|
|
2001-04-28 06:47:03 +04:00
|
|
|
gHaveNamedAnchors = true;
|
2000-04-21 19:00:23 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-10-20 18:15:25 +04:00
|
|
|
// Message to tell user there are none
|
2001-10-11 00:07:06 +04:00
|
|
|
item = AppendStringToTreelistById(gDialog.NamedAnchorList, "NoNamedAnchors");
|
2000-04-17 00:29:08 +04:00
|
|
|
if (item) item.setAttribute("disabled", "true");
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
1999-10-14 04:13:27 +04:00
|
|
|
var firstHeading = true;
|
2000-04-17 00:29:08 +04:00
|
|
|
for (var j = 1; j <= 6; j++)
|
|
|
|
{
|
1999-10-14 04:13:27 +04:00
|
|
|
var headingList = editorShell.editorDocument.getElementsByTagName("h"+String(j));
|
2000-04-17 00:29:08 +04:00
|
|
|
if (headingList.length > 0)
|
|
|
|
{
|
1999-10-14 04:13:27 +04:00
|
|
|
var heading = headingList.item(0);
|
1999-09-30 01:45:50 +04:00
|
|
|
|
1999-10-14 04:13:27 +04:00
|
|
|
// 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;
|
2000-04-17 00:29:08 +04:00
|
|
|
if (child && child.nodeName == "A" && child.name && (child.name.length>0))
|
1999-10-14 04:13:27 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
var range = editorShell.editorDocument.createRange();
|
|
|
|
range.setStart(heading,0);
|
|
|
|
var lastChildIndex = heading.childNodes.length;
|
|
|
|
range.setEnd(heading,lastChildIndex);
|
|
|
|
var text = range.toString();
|
2000-04-17 00:29:08 +04:00
|
|
|
if (text)
|
|
|
|
{
|
1999-10-14 04:13:27 +04:00
|
|
|
// Use just first 40 characters, don't add "...",
|
|
|
|
// and replace whitespace with "_" and strip non-word characters
|
2001-03-07 00:12:28 +03:00
|
|
|
text = ConvertToCDATAString(TruncateStringAtWordEnd(text, 40, false));
|
1999-10-14 04:13:27 +04:00
|
|
|
// Append "_" to any name already in the list
|
1999-10-20 18:15:25 +04:00
|
|
|
if (GetExistingHeadingIndex(text) > -1)
|
1999-10-14 04:13:27 +04:00
|
|
|
text += "_";
|
2001-10-11 00:07:06 +04:00
|
|
|
AppendStringToTreelist(gDialog.HeadingsList, text);
|
1999-10-20 18:15:25 +04:00
|
|
|
|
1999-10-14 04:13:27 +04:00
|
|
|
// Save nodes in an array so we can create anchor node under it later
|
|
|
|
if (!HNodeArray)
|
|
|
|
HNodeArray = new Array(heading)
|
|
|
|
else
|
|
|
|
HNodeArray[HNodeArray.length] = heading;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-17 00:29:08 +04:00
|
|
|
if (HNodeArray)
|
|
|
|
{
|
2001-04-28 06:47:03 +04:00
|
|
|
gHaveHeadings = true;
|
1999-10-20 18:15:25 +04:00
|
|
|
} else {
|
|
|
|
// Message to tell user there are none
|
2001-10-11 00:07:06 +04:00
|
|
|
item = AppendStringToTreelistById(gDialog.HeadingsList, "NoHeadings");
|
2000-04-17 00:29:08 +04:00
|
|
|
if (item) item.setAttribute("disabled", "true");
|
1999-10-20 18:15:25 +04:00
|
|
|
}
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
|
|
|
|
2001-09-17 23:31:19 +04:00
|
|
|
function doEnabling()
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
{
|
2001-08-24 23:32:36 +04:00
|
|
|
// We disable Ok button when there's no href text only if inserting a new link
|
2001-10-26 22:51:37 +04:00
|
|
|
var enable = insertNew ? (TrimString(gDialog.hrefInput.value).length > 0) : true;
|
2001-09-17 23:31:19 +04:00
|
|
|
|
2001-04-28 06:47:03 +04:00
|
|
|
SetElementEnabledById( "ok", enable);
|
2001-10-31 02:46:25 +03:00
|
|
|
SetElementEnabledById( "AdvancedEditButton1", enable);
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
2001-03-07 00:12:28 +03:00
|
|
|
var gClearListSelections = true;
|
|
|
|
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
function ChangeLocation()
|
|
|
|
{
|
2001-03-07 00:12:28 +03:00
|
|
|
if (gClearListSelections)
|
|
|
|
{
|
|
|
|
// Unselect the treelists
|
|
|
|
UnselectNamedAnchor();
|
|
|
|
UnselectHeadings();
|
|
|
|
}
|
2001-09-17 23:31:19 +04:00
|
|
|
|
|
|
|
SetRelativeCheckbox();
|
|
|
|
|
2000-08-11 07:20:47 +04:00
|
|
|
// Set OK button enable state
|
2001-09-17 23:31:19 +04:00
|
|
|
doEnabling();
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
function GetExistingHeadingIndex(text)
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
var len = gDialog.HeadingsList.getAttribute("length");
|
2000-04-17 00:29:08 +04:00
|
|
|
for (var i=0; i < len; i++)
|
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
if (GetTreelistValueAt(gDialog.HeadingsList, i) == text)
|
1999-10-14 04:13:27 +04:00
|
|
|
return i;
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
1999-10-14 04:13:27 +04:00
|
|
|
return -1;
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:13:27 +04:00
|
|
|
function SelectNamedAnchor()
|
|
|
|
{
|
2001-04-28 06:47:03 +04:00
|
|
|
if (gCanChangeAnchorSelected)
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
{
|
2001-04-28 06:47:03 +04:00
|
|
|
if (gHaveNamedAnchors)
|
2001-01-11 07:59:19 +03:00
|
|
|
{
|
2001-03-07 00:12:28 +03:00
|
|
|
// Prevent ChangeLocation() from unselecting the list
|
|
|
|
gClearListSelections = false;
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.hrefInput.value = "#"+GetSelectedTreelistValue(gDialog.NamedAnchorList);
|
2001-03-07 00:12:28 +03:00
|
|
|
gClearListSelections = true;
|
2001-04-28 06:47:03 +04:00
|
|
|
|
2001-09-17 23:31:19 +04:00
|
|
|
SetRelativeCheckbox();
|
|
|
|
|
2001-04-28 06:47:03 +04:00
|
|
|
// ChangeLocation isn't always called, so be sure Ok is enabled
|
2001-09-17 23:31:19 +04:00
|
|
|
doEnabling();
|
2001-01-11 07:59:19 +03:00
|
|
|
}
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
else
|
|
|
|
UnselectNamedAnchor();
|
|
|
|
|
|
|
|
UnselectHeadings();
|
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function SelectHeading()
|
|
|
|
{
|
2001-04-28 06:47:03 +04:00
|
|
|
if (gCanChangeHeadingSelected)
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
{
|
2001-04-28 06:47:03 +04:00
|
|
|
if (gHaveHeadings)
|
2001-01-11 07:59:19 +03:00
|
|
|
{
|
2001-03-07 00:12:28 +03:00
|
|
|
gClearListSelections = false;
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.hrefInput.value = "#"+GetSelectedTreelistValue(gDialog.HeadingsList);
|
2001-03-07 00:12:28 +03:00
|
|
|
gClearListSelections = true;
|
2001-04-28 06:47:03 +04:00
|
|
|
|
2001-09-17 23:31:19 +04:00
|
|
|
SetRelativeCheckbox();
|
|
|
|
doEnabling();
|
2001-01-11 07:59:19 +03:00
|
|
|
}
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
else
|
|
|
|
UnselectHeadings();
|
|
|
|
|
|
|
|
UnselectNamedAnchor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function UnselectNamedAnchor()
|
|
|
|
{
|
|
|
|
// Prevent recursive calling of SelectNamedAnchor()
|
2001-04-28 06:47:03 +04:00
|
|
|
gCanChangeAnchorSelected = false;
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.NamedAnchorList.selectedIndex = -1;
|
2001-04-28 06:47:03 +04:00
|
|
|
gCanChangeAnchorSelected = true;
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function UnselectHeadings()
|
|
|
|
{
|
|
|
|
// Prevent recursive calling of SelectHeading()
|
2001-04-28 06:47:03 +04:00
|
|
|
gCanChangeHeadingSelected = false;
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.HeadingsList.selectedIndex = -1;
|
2001-04-28 06:47:03 +04:00
|
|
|
gCanChangeHeadingSelected = true;
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-09-30 01:45:50 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Get and validate data from widgets.
|
|
|
|
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
|
|
|
function ValidateData()
|
1999-09-02 05:47:18 +04:00
|
|
|
{
|
2001-10-26 22:51:37 +04:00
|
|
|
href = TrimString(gDialog.hrefInput.value);
|
2001-08-17 17:54:41 +04:00
|
|
|
if (href)
|
2000-04-17 00:29:08 +04:00
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
// Set the HREF directly on the editor document's anchor node
|
|
|
|
// or on the newly-created node if insertNew is true
|
|
|
|
globalElement.setAttribute("href",href);
|
2000-04-17 00:29:08 +04:00
|
|
|
}
|
|
|
|
else if (insertNew)
|
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
// We must have a URL to insert a new link
|
2000-02-15 18:54:05 +03:00
|
|
|
//NOTE: We accept an empty HREF on existing link to indicate removing the link
|
1999-09-04 02:05:47 +04:00
|
|
|
ShowInputErrorMessage(GetString("EmptyHREFError"));
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-11 00:07:06 +04:00
|
|
|
if (gDialog.linkTextInput)
|
2000-04-17 00:29:08 +04:00
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
// The text we will insert isn't really an attribute,
|
|
|
|
// but it makes sense to validate it
|
2001-10-11 00:07:06 +04:00
|
|
|
newLinkText = TrimString(gDialog.linkTextInput.value);
|
2001-08-17 17:54:41 +04:00
|
|
|
if (!newLinkText)
|
2000-04-17 00:29:08 +04:00
|
|
|
{
|
2001-08-17 17:54:41 +04:00
|
|
|
if (href)
|
|
|
|
newLinkText = href
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowInputErrorMessage(GetString("EmptyLinkTextError"));
|
2001-10-11 00:07:06 +04:00
|
|
|
SetTextboxFocus(gDialog.linkTextInput);
|
2001-08-17 17:54:41 +04:00
|
|
|
return false;
|
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
1999-09-02 05:47:18 +04:00
|
|
|
}
|
|
|
|
|
2001-06-28 17:48:52 +04:00
|
|
|
function doHelpButton()
|
|
|
|
{
|
|
|
|
openHelp("chrome://help/content/help.xul?link_properties");
|
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
|
1999-06-09 05:27:08 +04:00
|
|
|
function onOK()
|
1999-05-06 03:29:18 +04:00
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
if (ValidateData())
|
|
|
|
{
|
2000-04-17 00:29:08 +04:00
|
|
|
if (href.length > 0)
|
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
// Copy attributes to element we are changing or inserting
|
|
|
|
editorShell.CloneAttributes(anchorElement, globalElement);
|
1999-06-09 05:27:08 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Coalesce into one undo transaction
|
|
|
|
editorShell.BeginBatchChanges();
|
1999-07-16 22:04:03 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Get text to use for a new link
|
2000-04-17 00:29:08 +04:00
|
|
|
if (insertLinkAtCaret)
|
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
// Append the link text as the last child node
|
|
|
|
// of the anchor node
|
2000-09-15 10:08:51 +04:00
|
|
|
var textNode = editorShell.editorDocument.createTextNode(newLinkText);
|
2000-04-17 00:29:08 +04:00
|
|
|
if (textNode)
|
1999-09-04 02:05:47 +04:00
|
|
|
anchorElement.appendChild(textNode);
|
1999-10-14 04:13:27 +04:00
|
|
|
try {
|
|
|
|
editorShell.InsertElementAtSelection(anchorElement, false);
|
|
|
|
} catch (e) {
|
|
|
|
dump("Exception occured in InsertElementAtSelection\n");
|
|
|
|
return true;
|
|
|
|
}
|
2000-08-11 07:20:47 +04:00
|
|
|
} else if (insertNew || replaceExistingLink)
|
2000-04-17 00:29:08 +04:00
|
|
|
{
|
2000-02-15 18:54:05 +03:00
|
|
|
// Link source was supplied by the selection,
|
|
|
|
// so insert a link node as parent of this
|
|
|
|
// (may be text, image, or other inline content)
|
1999-10-14 04:13:27 +04:00
|
|
|
try {
|
|
|
|
editorShell.InsertLinkAroundSelection(anchorElement);
|
|
|
|
} catch (e) {
|
|
|
|
dump("Exception occured in InsertElementAtSelection\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
// Check if the link was to a heading
|
2000-04-17 00:29:08 +04:00
|
|
|
if (href[0] == "#")
|
|
|
|
{
|
1999-10-14 04:13:27 +04:00
|
|
|
var name = href.substr(1);
|
1999-10-20 18:15:25 +04:00
|
|
|
var index = GetExistingHeadingIndex(name);
|
|
|
|
if (index >= 0) {
|
1999-10-14 04:13:27 +04:00
|
|
|
// We need to create a named anchor
|
|
|
|
// and insert it as the first child of the heading element
|
1999-10-20 18:15:25 +04:00
|
|
|
var headNode = HNodeArray[index];
|
1999-10-14 04:13:27 +04:00
|
|
|
var anchorNode = editorShell.editorDocument.createElement("a");
|
|
|
|
if (anchorNode) {
|
|
|
|
anchorNode.name = name;
|
|
|
|
// Remember to use editorShell method so it is undoable!
|
2001-05-02 05:18:21 +04:00
|
|
|
editorShell.InsertElement(anchorNode, headNode, 0, false);
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
} else {
|
|
|
|
dump("HREF is a heading but is not in the list!\n");
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-07-16 22:04:03 +04:00
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
editorShell.EndBatchChanges();
|
2000-04-17 00:29:08 +04:00
|
|
|
}
|
|
|
|
else if (!insertNew)
|
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
// We already had a link, but empty HREF means remove it
|
|
|
|
editorShell.RemoveTextProperty("a", "");
|
1999-04-21 22:53:55 +04:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
SaveWindowLocation();
|
1999-09-04 02:05:47 +04:00
|
|
|
return true;
|
1999-05-06 03:29:18 +04:00
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
return false;
|
1999-05-06 03:29:18 +04:00
|
|
|
}
|