2004-04-18 18:21:17 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
2004-04-18 18:21:17 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Charles Manske (cmanske@netscape.com)
|
|
|
|
* Neil Rashbrook (neil@parkwaycc.co.uk)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-19 18:28:44 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
var gActiveEditor;
|
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;
|
2002-09-19 07:32:23 +04:00
|
|
|
var gHNodeArray = {};
|
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()
|
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor = GetCurrentEditor();
|
|
|
|
if (!gActiveEditor)
|
|
|
|
{
|
|
|
|
dump("Failed to get active editor!\n");
|
|
|
|
window.close();
|
1999-07-14 19:24:33 +04:00
|
|
|
return;
|
2002-09-19 07:32:23 +04: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");
|
2002-02-09 01:40:59 +03:00
|
|
|
gDialog.makeRelativeLink = document.getElementById("MakeRelativeLink");
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AdvancedEditSection = document.getElementById("AdvancedEdit");
|
1999-05-06 03:29:18 +04:00
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
// See if we have a single selected image
|
2002-09-19 07:32:23 +04:00
|
|
|
imageElement = gActiveEditor.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()
|
2002-09-19 07:32:23 +04:00
|
|
|
anchorElement = gActiveEditor.getElementOrParentByTagName("href", imageElement);
|
2000-02-15 18:54:05 +03:00
|
|
|
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.
|
2002-09-19 07:32:23 +04:00
|
|
|
anchorElement = gActiveEditor.getSelectedElement(tagName);
|
2000-02-15 18:54:05 +03:00
|
|
|
|
|
|
|
if (anchorElement)
|
|
|
|
{
|
|
|
|
// Select the entire link
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.selectElement(anchorElement);
|
2000-02-15 18:54:05 +03:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
anchorElement = gActiveEditor.getElementOrParentByTagName("href", gActiveEditor.selection.anchorNode);
|
2000-02-15 18:54:05 +03:00
|
|
|
if (!anchorElement)
|
2002-09-19 07:32:23 +04:00
|
|
|
anchorElement = gActiveEditor.getElementOrParentByTagName("href", gActiveEditor.selection.focusNode);
|
2000-02-15 18:54:05 +03:00
|
|
|
|
|
|
|
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
|
2002-09-19 07:32:23 +04:00
|
|
|
anchorElement = gActiveEditor.createElementWithDefaults(tagName);
|
2000-02-15 18:54:05 +03:00
|
|
|
insertNew = true;
|
2000-08-11 07:20:47 +04:00
|
|
|
// Hide message about removing existing link
|
2002-11-19 18:51:56 +03:00
|
|
|
//document.getElementById("RemoveLinkMsg").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
|
2002-09-19 07:32:23 +04:00
|
|
|
insertLinkAtCaret = gActiveEditor.selection.isCollapsed;
|
2000-02-15 18:54:05 +03:00
|
|
|
|
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"));
|
2002-04-20 20:07:09 +04:00
|
|
|
gDialog.linkTextMessage.setAttribute("accesskey", GetString("EnterLinkTextAccessKey"));
|
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
|
2002-02-09 01:40:59 +03:00
|
|
|
FillLinkMenulist(gDialog.hrefInput, gHNodeArray);
|
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
|
2002-11-19 18:51:56 +03:00
|
|
|
gDialog.linkTextInput.hidden = true;
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.linkTextInput = null;
|
1999-09-02 05:47:18 +04:00
|
|
|
}
|
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
|
2002-02-09 01:40:59 +03:00
|
|
|
SetRelativeCheckbox(gDialog.makeRelativeLink);
|
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-11-03 21:46:07 +03:00
|
|
|
|
|
|
|
// anon. content, so can't use SetElementEnabledById here
|
|
|
|
var dialogNode = document.getElementById("linkDlg");
|
|
|
|
dialogNode.getButton("accept").disabled = !enable;
|
2001-09-17 23:31:19 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-02-09 01:40:59 +03:00
|
|
|
function ChangeLinkLocation()
|
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-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-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()
|
|
|
|
{
|
2002-02-26 04:13:17 +03:00
|
|
|
openHelp("link_properties");
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2001-11-03 07:06:54 +03:00
|
|
|
return true;
|
2001-06-28 17:48:52 +04:00
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2001-11-03 07:06:54 +03:00
|
|
|
function onAccept()
|
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
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.cloneAttributes(anchorElement, globalElement);
|
1999-06-09 05:27:08 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Coalesce into one undo transaction
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.beginTransaction();
|
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
|
2002-09-19 07:32:23 +04:00
|
|
|
var textNode = gActiveEditor.document.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 {
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.insertElementAtSelection(anchorElement, false);
|
1999-10-14 04:13:27 +04:00
|
|
|
} 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 {
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.insertLinkAroundSelection(anchorElement);
|
1999-10-14 04:13:27 +04:00
|
|
|
} 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
|
2002-09-19 07:32:23 +04:00
|
|
|
if (href in gHNodeArray)
|
2000-04-17 00:29:08 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
var anchorNode = gActiveEditor.createElementWithDefaults("a");
|
|
|
|
if (anchorNode)
|
2002-02-09 01:40:59 +03:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
anchorNode.name = href.substr(1);
|
|
|
|
|
|
|
|
// Insert the anchor into the document,
|
|
|
|
// but don't let the transaction change the selection
|
|
|
|
gActiveEditor.setShouldTxnSetSelection(false);
|
|
|
|
gActiveEditor.insertNode(anchorNode, gHNodeArray[href], 0);
|
|
|
|
gActiveEditor.setShouldTxnSetSelection(true);
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-07-16 22:04:03 +04:00
|
|
|
}
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.endTransaction();
|
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
|
2002-09-19 07:32:23 +04:00
|
|
|
EditorRemoveTextProperty("href", "");
|
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
|
|
|
}
|