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;
|
1999-05-06 03:29:18 +04:00
|
|
|
var insertNew = true;
|
|
|
|
var needLinkText = false;
|
1999-05-08 02:26:23 +04:00
|
|
|
var insertLinkAroundSelection = false;
|
1999-07-25 00:27:53 +04:00
|
|
|
var linkTextInput;
|
|
|
|
var hrefInput;
|
|
|
|
var linkMessage;
|
1999-09-04 02:05:47 +04:00
|
|
|
var href;
|
|
|
|
var newLinkText;
|
1999-10-14 04:13:27 +04:00
|
|
|
var NamedAnchorList = 0;
|
1999-09-30 01:45:50 +04:00
|
|
|
var HNodeArray;
|
1999-10-20 18:15:25 +04:00
|
|
|
var haveNamedAnchors = false;
|
|
|
|
var haveHeadings = false;
|
1999-10-27 03:13:00 +04:00
|
|
|
var MoreSection;
|
|
|
|
var MoreFewerButton;
|
|
|
|
var SeeMore = false;
|
|
|
|
var AdvancedEditSection;
|
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
|
|
|
|
|
|
|
doSetOKCancel(onOK, null);
|
1999-05-06 03:29:18 +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
|
1999-10-20 18:15:25 +04:00
|
|
|
linkCaption = (document.getElementById("linkTextCaption")).firstChild;
|
|
|
|
linkMessage = (document.getElementById("linkTextMessage")).firstChild;
|
|
|
|
linkTextInput = document.getElementById("linkTextInput");
|
|
|
|
hrefInput = document.getElementById("hrefInput");
|
1999-10-14 04:13:27 +04:00
|
|
|
NamedAnchorList = document.getElementById("NamedAnchorList");
|
1999-10-20 18:15:25 +04:00
|
|
|
HeadingsList = document.getElementById("HeadingsList");
|
1999-10-27 03:13:00 +04:00
|
|
|
MoreSection = document.getElementById("MoreSection");
|
|
|
|
MoreFewerButton = document.getElementById("MoreFewerButton");
|
1999-11-13 19:37:58 +03:00
|
|
|
AdvancedEditSection = document.getElementById("AdvancedEdit");
|
1999-05-07 04:44:46 +04:00
|
|
|
|
1999-05-06 03:29:18 +04:00
|
|
|
// Get a single selected anchor element
|
1999-06-11 22:58:32 +04:00
|
|
|
anchorElement = editorShell.GetSelectedElement(tagName);
|
1999-05-06 03:29:18 +04:00
|
|
|
|
1999-07-25 05:24:51 +04:00
|
|
|
var selection = editorShell.editorSelection;
|
1999-05-07 04:44:46 +04:00
|
|
|
if (selection) {
|
|
|
|
dump("There is a selection: collapsed = "+selection.isCollapsed+"\n");
|
1999-05-06 03:29:18 +04:00
|
|
|
} else {
|
|
|
|
dump("Failed to get selection\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anchorElement) {
|
|
|
|
// We found an element and don't need to insert one
|
1999-07-25 05:24:51 +04:00
|
|
|
dump("found anchor element\n");
|
1999-05-06 03:29:18 +04:00
|
|
|
insertNew = false;
|
1999-07-25 05:24:51 +04:00
|
|
|
|
|
|
|
// We get the anchor if any of the selection (or just caret)
|
|
|
|
// is enclosed by the link. Select the entire link
|
|
|
|
// so we can show the selection text
|
|
|
|
editorShell.SelectElement(anchorElement);
|
|
|
|
selection = editorShell.editorSelection;
|
|
|
|
|
1999-05-06 03:29:18 +04:00
|
|
|
} else {
|
1999-07-03 02:52:34 +04:00
|
|
|
// See if we have a selected image instead of text
|
|
|
|
imageElement = editorShell.GetSelectedElement("img");
|
|
|
|
if (imageElement) {
|
|
|
|
// See if the image is a child of a link
|
|
|
|
dump("Image element found - check if its a link...\n");
|
|
|
|
dump("Image Parent="+parent);
|
|
|
|
parent = imageElement.parentNode;
|
|
|
|
dump("Parent="+parent+" nodeName="+parent.nodeName+"\n");
|
|
|
|
if (parent) {
|
|
|
|
anchorElement = parent;
|
|
|
|
insertNew = false;
|
1999-09-04 02:05:47 +04:00
|
|
|
linkCaption.data = GetString("LinkImage");
|
1999-07-03 02:52:34 +04:00
|
|
|
// Link source string is the source URL of image
|
|
|
|
// TODO: THIS STILL DOESN'T HANDLE MULTIPLE SELECTED IMAGES!
|
1999-07-25 00:27:53 +04:00
|
|
|
linkMessage.data = imageElement.getAttribute("src");;
|
1999-07-03 02:52:34 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We don't have an element selected,
|
|
|
|
// so create one with default attributes
|
|
|
|
dump("Element not selected - calling createElementWithDefaults\n");
|
|
|
|
anchorElement = editorShell.CreateElementWithDefaults(tagName);
|
|
|
|
|
|
|
|
// We will insert a new link at caret location if there's no selection
|
|
|
|
// TODO: This isn't entirely correct. If selection doesn't have any text
|
|
|
|
// or an image, then shouldn't we clear the selection and insert new text?
|
|
|
|
insertNew = selection.isCollapsed;
|
|
|
|
dump("insertNew is " + insertNew + "\n");
|
1999-09-24 04:25:01 +04:00
|
|
|
linkCaption.data = GetString("EnterLinkText");
|
1999-08-02 02:37:58 +04:00
|
|
|
linkMessage.data = "";
|
1999-07-03 02:52:34 +04:00
|
|
|
}
|
1999-05-07 04:44:46 +04: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();
|
1999-07-03 02:52:34 +04:00
|
|
|
} else if (!insertNew && !imageElement) {
|
1999-05-07 04:44:46 +04:00
|
|
|
|
|
|
|
// Replace the link message with the link source string
|
1999-07-16 22:04:03 +04:00
|
|
|
selectedText = GetSelectionAsText();
|
1999-07-03 02:52:34 +04:00
|
|
|
if (selectedText.length > 0) {
|
|
|
|
// Use just the first 50 characters and add "..."
|
|
|
|
selectedText = TruncateStringAtWordEnd(selectedText, 50, true);
|
|
|
|
} else {
|
|
|
|
dump("Selected text for link source not found. Non-text elements selected?\n");
|
|
|
|
}
|
1999-07-25 00:27:53 +04:00
|
|
|
linkMessage.data = selectedText;
|
1999-08-02 02:37:58 +04:00
|
|
|
// The label above the selected text:
|
1999-09-24 04:25:01 +04:00
|
|
|
linkCaption.data = GetString("LinkText");
|
1999-05-06 03:29:18 +04:00
|
|
|
}
|
1999-05-08 02:26:23 +04:00
|
|
|
|
|
|
|
if (!selection.isCollapsed)
|
|
|
|
{
|
|
|
|
// HREF is a weird case: If selection extends beyond
|
|
|
|
// the link, user probably wants to extend link to
|
|
|
|
// entire selection.
|
|
|
|
// TODO: If there was already a link,
|
|
|
|
// we need to know if selection extends beyond existing
|
|
|
|
// link text before we should do this
|
|
|
|
insertLinkAroundSelection = true;
|
|
|
|
dump("insertLinkAroundSelection is TRUE\n");
|
|
|
|
}
|
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
|
|
|
|
if (insertNew) {
|
|
|
|
dump("Setting focus to linkTextInput\n");
|
|
|
|
// We will be using the HREF inputbox, so text message
|
|
|
|
linkTextInput.focus();
|
|
|
|
} else {
|
|
|
|
dump("Setting focus to linkTextInput\n");
|
|
|
|
hrefInput.focus();
|
|
|
|
|
|
|
|
// We will not insert a new link at caret, so remove link text input field
|
|
|
|
parentNode = linkTextInput.parentNode;
|
|
|
|
if (parentNode) {
|
|
|
|
dump("Removing link text input field.\n");
|
|
|
|
parentNode.removeChild(linkTextInput);
|
|
|
|
linkTextInput = null;
|
|
|
|
}
|
|
|
|
}
|
1999-10-30 02:33:34 +04:00
|
|
|
// Set SeeMore bool to the OPPOSITE of the current state,
|
|
|
|
// which is automatically saved by using the 'persist="more"'
|
|
|
|
// attribute on the MoreFewerButton button
|
|
|
|
// onMoreFewer will toggle it and redraw the dialog
|
|
|
|
SeeMore = (MoreFewerButton.getAttribute("more") != "1");
|
1999-10-27 03:13:00 +04:00
|
|
|
onMoreFewer();
|
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()
|
|
|
|
{
|
1999-09-04 02:05:47 +04:00
|
|
|
hrefInput.value = globalElement.getAttribute("href");
|
1999-09-02 05:47:18 +04:00
|
|
|
dump("Current HREF: "+hrefInput.value+"\n");
|
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
|
1999-06-11 22:58:32 +04:00
|
|
|
fileName = editorShell.GetLocalFileURL(window, "html");
|
1999-09-16 08:36:16 +04:00
|
|
|
if (fileName) {
|
1999-07-25 00:27:53 +04:00
|
|
|
hrefInput.value = fileName;
|
1999-05-27 01:40:51 +04:00
|
|
|
}
|
|
|
|
// Put focus into the input field
|
1999-07-25 00:27:53 +04:00
|
|
|
hrefInput.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function RemoveLink()
|
|
|
|
{
|
|
|
|
// Simple clear the input field!
|
|
|
|
hrefInput.value = "";
|
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
|
|
|
{
|
|
|
|
NamedAnchorNodeList = editorShell.editorDocument.anchors;
|
1999-10-14 04:13:27 +04:00
|
|
|
var NamedAnchorCount = NamedAnchorNodeList.length;
|
|
|
|
if (NamedAnchorCount > 0) {
|
|
|
|
for (var i = 0; i < NamedAnchorCount; i++) {
|
1999-10-20 18:15:25 +04:00
|
|
|
AppendStringToList(NamedAnchorList,NamedAnchorNodeList.item(i).name);
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
haveNamedAnchors = true;
|
|
|
|
} else {
|
|
|
|
// Message to tell user there are none
|
|
|
|
AppendStringToList(NamedAnchorList,GetString("NoNamedAnchors"));
|
1999-11-03 03:48:26 +03:00
|
|
|
NamedAnchorList.setAttribute("disabled", "true");
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
1999-10-14 04:13:27 +04:00
|
|
|
var firstHeading = true;
|
|
|
|
for (var j = 1; j <= 6; j++) {
|
|
|
|
var headingList = editorShell.editorDocument.getElementsByTagName("h"+String(j));
|
|
|
|
dump(headingList+" Count= "+headingList.length+"\n");
|
|
|
|
if (headingList.length > 0) {
|
|
|
|
dump("HELLO\n");
|
|
|
|
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;
|
1999-11-13 19:37:58 +03:00
|
|
|
if( child && child.name )
|
|
|
|
dump(child.name+" = Child.name. Length="+child.name.length+"\n");
|
1999-10-27 03:13:00 +04:00
|
|
|
if (child && child.nodeName == "A" && child.name && (child.name.length>0)) {
|
1999-10-14 04:13:27 +04:00
|
|
|
continue;
|
1999-10-27 03:13:00 +04:00
|
|
|
}
|
1999-10-14 04:13:27 +04:00
|
|
|
|
|
|
|
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 = 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 += "_";
|
1999-10-20 18:15:25 +04:00
|
|
|
AppendStringToList(HeadingsList, text);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
if (HNodeArray) {
|
|
|
|
haveHeadings = true;
|
|
|
|
} else {
|
|
|
|
// Message to tell user there are none
|
|
|
|
AppendStringToList(HeadingsList,GetString("NoHeadings"));
|
1999-11-03 03:48:26 +03:00
|
|
|
HeadingsList.setAttribute("disabled", "true");
|
1999-10-20 18:15:25 +04:00
|
|
|
}
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
function GetExistingHeadingIndex(text)
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
1999-10-27 03:13:00 +04:00
|
|
|
dump("Heading text: "+text+"\n");
|
1999-10-20 18:15:25 +04:00
|
|
|
for (i=0; i < HeadingsList.length; i++) {
|
1999-10-27 03:13:00 +04:00
|
|
|
dump("HeadingListItem"+i+": "+HeadingsList.options[i].value+"\n");
|
|
|
|
if (HeadingsList.options[i].value == 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()
|
|
|
|
{
|
1999-10-20 18:15:25 +04:00
|
|
|
if (haveNamedAnchors) {
|
|
|
|
hrefInput.value = "#"+NamedAnchorList.options[NamedAnchorList.selectedIndex].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectHeading()
|
|
|
|
{
|
|
|
|
if (haveHeadings) {
|
|
|
|
hrefInput.value = "#"+HeadingsList.options[HeadingsList.selectedIndex].value;
|
|
|
|
}
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-09-30 01:45:50 +04:00
|
|
|
|
1999-10-27 03:13:00 +04:00
|
|
|
function onMoreFewer()
|
|
|
|
{
|
|
|
|
if (SeeMore)
|
|
|
|
{
|
|
|
|
MoreSection.setAttribute("style","display: none");
|
1999-11-03 03:48:26 +03:00
|
|
|
window.sizeToContent();
|
1999-10-29 06:33:51 +04:00
|
|
|
MoreFewerButton.setAttribute("more","0");
|
1999-11-03 03:48:26 +03:00
|
|
|
MoreFewerButton.setAttribute("value",GetString("MoreProperties"));
|
|
|
|
SeeMore = false;
|
1999-10-27 03:13:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MoreSection.setAttribute("style","display: inherit");
|
1999-11-03 03:48:26 +03:00
|
|
|
window.sizeToContent();
|
1999-10-27 03:13:00 +04:00
|
|
|
MoreFewerButton.setAttribute("more","1");
|
1999-11-03 03:48:26 +03:00
|
|
|
MoreFewerButton.setAttribute("value",GetString("FewerProperties"));
|
|
|
|
SeeMore = true;
|
1999-10-27 03:13:00 +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
|
|
|
{
|
1999-09-16 08:36:16 +04:00
|
|
|
href = hrefInput.value.trimString();
|
1999-09-04 02:05:47 +04:00
|
|
|
if (href.length > 0) {
|
|
|
|
// 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);
|
1999-09-16 08:36:16 +04:00
|
|
|
dump("HREF:"+href+"|\n");
|
1999-09-04 02:05:47 +04:00
|
|
|
} else if (insertNew) {
|
|
|
|
// We must have a URL to insert a new link
|
|
|
|
//NOTE: WE ACCEPT AN EMPTY HREF TO ALLOW REMOVING AN EXISTING LINK,
|
1999-10-27 03:13:00 +04:00
|
|
|
dump("Empty HREF error\n");
|
1999-09-04 02:05:47 +04:00
|
|
|
ShowInputErrorMessage(GetString("EmptyHREFError"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (linkTextInput) {
|
|
|
|
// The text we will insert isn't really an attribute,
|
|
|
|
// but it makes sense to validate it
|
|
|
|
newLinkText = TrimString(linkTextInput.value);
|
|
|
|
if (newLinkText.length == 0) {
|
|
|
|
ShowInputErrorMessage(GetString("GetInputError"));
|
|
|
|
linkTextInput.focus();
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
if (href.length > 0) {
|
|
|
|
// 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
|
|
|
|
if (insertNew) {
|
|
|
|
// Append the link text as the last child node
|
|
|
|
// of the anchor node
|
|
|
|
textNode = editorShell.editorDocument.createTextNode(newLinkText);
|
|
|
|
if (textNode) {
|
|
|
|
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;
|
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
} else if (insertLinkAroundSelection) {
|
|
|
|
// Text was supplied by the selection,
|
|
|
|
// so insert a link node as parent of this text
|
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
|
|
|
|
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);
|
|
|
|
dump("Heading name="+name+" Index="+index+"\n");
|
|
|
|
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
|
|
|
dump("Anchor node created and inserted under heading\n");
|
|
|
|
}
|
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();
|
|
|
|
} else if (!insertNew) {
|
|
|
|
// We already had a link, but empty HREF means remove it
|
|
|
|
editorShell.RemoveTextProperty("a", "");
|
1999-04-21 22:53:55 +04:00
|
|
|
}
|
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
|
|
|
}
|