1999-08-19 18:28:44 +04:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
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;
|
1999-10-20 18:15:25 +04:00
|
|
|
var haveNamedAnchors = false;
|
|
|
|
var haveHeadings = false;
|
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
|
|
|
var canChangeHeadingSelected = true;
|
|
|
|
var canChangeAnchorSelected = true;
|
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
|
|
|
|
|
|
|
dialog = new Object;
|
|
|
|
if (!dialog)
|
|
|
|
{
|
|
|
|
dump("Failed to create dialog object!!!\n");
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
|
1999-08-02 02:37:58 +04:00
|
|
|
// Message was wrapped in a <label> or <div>, so actual text is a child text node
|
2000-02-15 18:54:05 +03:00
|
|
|
dialog.linkTextCaption = document.getElementById("linkTextCaption");
|
|
|
|
dialog.linkTextMessage = document.getElementById("linkTextMessage");
|
|
|
|
dialog.linkTextInput = document.getElementById("linkTextInput");
|
|
|
|
dialog.hrefInput = document.getElementById("hrefInput");
|
|
|
|
dialog.NamedAnchorList = document.getElementById("NamedAnchorList");
|
|
|
|
dialog.HeadingsList = document.getElementById("HeadingsList");
|
|
|
|
dialog.MoreSection = document.getElementById("MoreSection");
|
|
|
|
dialog.MoreFewerButton = document.getElementById("MoreFewerButton");
|
|
|
|
dialog.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");
|
|
|
|
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();
|
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;
|
|
|
|
|
|
|
|
if (insertLinkAtCaret)
|
|
|
|
{
|
2000-04-17 00:29:08 +04:00
|
|
|
// Titledbox caption:
|
|
|
|
dialog.linkTextCaption.setAttribute("value",GetString("LinkText"));
|
|
|
|
// Message above input field:
|
|
|
|
dialog.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)
|
|
|
|
{
|
|
|
|
// Don't think we can ever get here!
|
|
|
|
|
|
|
|
// Check if selection has some text - use that first
|
|
|
|
selectedText = GetSelectionAsText();
|
|
|
|
if (selectedText.length == 0)
|
|
|
|
{
|
|
|
|
// No text, look for first image in the selection
|
|
|
|
var children = anchorElement.childNodes;
|
|
|
|
if (children)
|
|
|
|
{
|
|
|
|
for(i=0; i < children.length; i++)
|
|
|
|
{
|
|
|
|
if (children.item(i) == "IMG")
|
|
|
|
{
|
|
|
|
imageElement = children.item(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Set "caption" for link source and the source text or image URL
|
|
|
|
if (imageElement)
|
|
|
|
{
|
|
|
|
dialog.linkTextCaption.setAttribute("value",GetString("LinkImage"));
|
|
|
|
// Link source string is the source URL of image
|
|
|
|
// TODO: THIS DOESN'T HANDLE MULTIPLE SELECTED IMAGES!
|
|
|
|
dialog.linkTextMessage.setAttribute("value",imageElement.src);
|
|
|
|
} else {
|
|
|
|
dialog.linkTextCaption.setAttribute("value",GetString("LinkText"));
|
|
|
|
if (selectedText.length > 0) {
|
2000-05-16 09:14:52 +04:00
|
|
|
// Use just the first 40 characters and add "..."
|
|
|
|
dialog.linkTextMessage.setAttribute("value",TruncateStringAtWordEnd(selectedText, 40, true));
|
2000-02-15 18:54:05 +03:00
|
|
|
} else {
|
|
|
|
dialog.linkTextMessage.setAttribute("value",GetString("MixedSelection"));
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
1999-09-02 05:47:18 +04:00
|
|
|
// Set data for the dialog controls
|
|
|
|
InitDialog();
|
|
|
|
|
|
|
|
// 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
|
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
|
|
|
SetTextfieldFocus(dialog.linkTextInput);
|
1999-09-02 05:47:18 +04:00
|
|
|
} else {
|
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
|
|
|
SetTextfieldFocus(dialog.hrefInput);
|
1999-09-02 05:47:18 +04:00
|
|
|
|
|
|
|
// We will not insert a new link at caret, so remove link text input field
|
2000-02-15 18:54:05 +03:00
|
|
|
dialog.linkTextInput.setAttribute("hidden","true");
|
|
|
|
dialog.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
|
|
|
|
ChangeText();
|
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()
|
|
|
|
{
|
2000-02-15 18:54:05 +03:00
|
|
|
dialog.hrefInput.value = globalElement.href;
|
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
|
2000-04-04 18:51:26 +04:00
|
|
|
fileName = GetLocalFileURL("html");
|
1999-09-16 08:36:16 +04:00
|
|
|
if (fileName) {
|
2000-02-15 18:54:05 +03:00
|
|
|
dialog.hrefInput.value = fileName;
|
1999-05-27 01:40:51 +04:00
|
|
|
}
|
|
|
|
// Put focus into the input field
|
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
|
|
|
SetTextfieldFocus(dialog.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-04-17 00:29:08 +04:00
|
|
|
if (NamedAnchorCount > 0)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < NamedAnchorCount; i++)
|
2000-04-21 19:00:23 +04:00
|
|
|
AppendStringToTreelist(dialog.NamedAnchorList, NamedAnchorNodeList.item(i).name);
|
2000-04-17 00:29:08 +04:00
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
haveNamedAnchors = 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
|
2000-04-17 00:29:08 +04:00
|
|
|
var item = AppendStringToTreelistById(dialog.NamedAnchorList, "NoNamedAnchors");
|
|
|
|
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
|
|
|
|
text = PrepareStringForURL(TruncateStringAtWordEnd(text, 40, false));
|
|
|
|
// 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 += "_";
|
2000-04-17 00:29:08 +04:00
|
|
|
AppendStringToTreelist(dialog.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)
|
|
|
|
{
|
1999-10-20 18:15:25 +04:00
|
|
|
haveHeadings = true;
|
|
|
|
} else {
|
|
|
|
// Message to tell user there are none
|
2000-04-17 00:29:08 +04:00
|
|
|
var item = AppendStringToTreelistById(dialog.HeadingsList, "NoHeadings");
|
|
|
|
if (item) item.setAttribute("disabled", "true");
|
1999-10-20 18:15:25 +04:00
|
|
|
}
|
1999-09-30 01:45:50 +04: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
|
|
|
function ChangeText()
|
|
|
|
{
|
2000-08-11 07:20:47 +04:00
|
|
|
// Set OK button enable state only if inserting a new link
|
|
|
|
// (allow empty location to remove existing link)
|
|
|
|
if (insertNew)
|
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
|
|
|
{
|
2000-08-11 07:20:47 +04:00
|
|
|
var enable = true;
|
|
|
|
if (insertLinkAtCaret)
|
|
|
|
enable = dialog.linkTextInput.value.trimString().length > 0;
|
|
|
|
if (enable)
|
|
|
|
enable = dialog.hrefInput.value.trimString().length > 0;
|
|
|
|
SetElementEnabledById( "ok", 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChangeLocation()
|
|
|
|
{
|
|
|
|
// Unselect the treelists
|
|
|
|
UnselectNamedAnchor();
|
|
|
|
UnselectHeadings();
|
2000-08-11 07:20:47 +04:00
|
|
|
|
|
|
|
// Set OK button enable state
|
|
|
|
ChangeText();
|
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
|
|
|
{
|
2000-04-17 00:29:08 +04:00
|
|
|
var len = dialog.HeadingsList.getAttribute("length");
|
|
|
|
for (var i=0; i < len; i++)
|
|
|
|
{
|
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
|
|
|
if (GetTreelistValueAt(dialog.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()
|
|
|
|
{
|
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
|
|
|
if (canChangeAnchorSelected)
|
|
|
|
{
|
|
|
|
if (haveNamedAnchors)
|
|
|
|
dialog.hrefInput.value = "#"+GetSelectedTreelistValue(dialog.NamedAnchorList);
|
|
|
|
else
|
|
|
|
UnselectNamedAnchor();
|
|
|
|
|
|
|
|
UnselectHeadings();
|
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function SelectHeading()
|
|
|
|
{
|
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
|
|
|
if (canChangeHeadingSelected)
|
|
|
|
{
|
|
|
|
if (haveHeadings)
|
|
|
|
dialog.hrefInput.value = "#"+GetSelectedTreelistValue(dialog.HeadingsList);
|
|
|
|
else
|
|
|
|
UnselectHeadings();
|
|
|
|
|
|
|
|
UnselectNamedAnchor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function UnselectNamedAnchor()
|
|
|
|
{
|
|
|
|
// Prevent recursive calling of SelectNamedAnchor()
|
|
|
|
canChangeAnchorSelected = false;
|
|
|
|
dialog.NamedAnchorList.selectedIndex = -1;
|
|
|
|
canChangeAnchorSelected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function UnselectHeadings()
|
|
|
|
{
|
|
|
|
// Prevent recursive calling of SelectHeading()
|
|
|
|
canChangeHeadingSelected = false;
|
|
|
|
dialog.HeadingsList.selectedIndex = -1;
|
|
|
|
canChangeHeadingSelected = 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
|
|
|
{
|
2000-02-15 18:54:05 +03:00
|
|
|
href = dialog.hrefInput.value.trimString();
|
2000-04-17 00:29:08 +04:00
|
|
|
if (href.length > 0)
|
|
|
|
{
|
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;
|
|
|
|
}
|
2000-04-17 00:29:08 +04:00
|
|
|
if (dialog.linkTextInput)
|
|
|
|
{
|
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
|
2000-02-15 18:54:05 +03:00
|
|
|
newLinkText = TrimString(dialog.linkTextInput.value);
|
2000-04-17 00:29:08 +04:00
|
|
|
if (newLinkText.length == 0)
|
|
|
|
{
|
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
|
|
|
ShowInputErrorMessage(GetString("EmptyLinkTextError"));
|
|
|
|
SetTextfieldFocus(dialog.linkTextInput);
|
1999-09-04 02:05:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
1999-09-02 05:47:18 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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!
|
1999-10-20 18:15:25 +04:00
|
|
|
editorShell.InsertElement(anchorNode, headNode, 0);
|
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
|
|
|
}
|