1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
\r
3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
4 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
\r
6 * == BEGIN LICENSE ==
\r
8 * Licensed under the terms of any of the following licenses at your
\r
11 * - GNU General Public License Version 2 or later (the "GPL")
\r
12 * http://www.gnu.org/licenses/gpl.html
\r
14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
15 * http://www.gnu.org/licenses/lgpl.html
\r
17 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
18 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
22 * Anchor dialog window.
\r
26 <title>Anchor Properties</title>
\r
27 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
\r
28 <meta content="noindex, nofollow" name="robots">
\r
29 <script src="common/fck_dialog_common.js" type="text/javascript"></script>
\r
30 <script type="text/javascript">
\r
32 var oEditor = window.parent.InnerDialogLoaded() ;
\r
33 var FCK = oEditor.FCK ;
\r
34 var FCKBrowserInfo = oEditor.FCKBrowserInfo ;
\r
35 var FCKTools = oEditor.FCKTools ;
\r
36 var FCKRegexLib = oEditor.FCKRegexLib ;
\r
38 // Gets the document DOM
\r
39 var oDOM = oEditor.FCK.EditorDocument ;
\r
41 var oFakeImage = FCK.Selection.GetSelectedElement() ;
\r
46 if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckanchor') )
\r
47 oAnchor = FCK.GetRealElement( oFakeImage ) ;
\r
52 //Search for a real anchor
\r
55 oAnchor = FCK.Selection.MoveToAncestorNode( 'A' ) ;
\r
57 FCK.Selection.SelectNode( oAnchor ) ;
\r
60 window.onload = function()
\r
62 // First of all, translate the dialog box texts
\r
63 oEditor.FCKLanguageManager.TranslatePage(document) ;
\r
66 GetE('txtName').value = oAnchor.name ;
\r
70 window.parent.SetOkButton( true ) ;
\r
75 var sNewName = GetE('txtName').value ;
\r
77 // Remove any illegal character in a name attribute:
\r
78 // A name should start with a letter, but the validator passes anyway.
\r
79 sNewName = sNewName.replace( /[^\w-_\.:]/g, '_' ) ;
\r
81 if ( sNewName.length == 0 )
\r
83 // Remove the anchor if the user leaves the name blank
\r
90 alert( oEditor.FCKLang.DlgAnchorErrorName ) ;
\r
94 oEditor.FCKUndo.SaveUndoStep() ;
\r
96 if ( oAnchor ) // Modifying an existent anchor.
\r
98 ReadjustLinksToAnchor( oAnchor.name, sNewName );
\r
100 // Buggy explorer, bad bad browser. http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/
\r
101 // Instead of just replacing the .name for the existing anchor (in order to preserve the content), we must remove the .name
\r
102 // and assign .name, although it won't appear until it's specially processed in fckxhtml.js
\r
104 // We remove the previous name
\r
105 oAnchor.removeAttribute( 'name' ) ;
\r
106 // Now we set it, but later we must process it specially
\r
107 oAnchor.name = sNewName ;
\r
112 // Create a new anchor preserving the current selection
\r
113 var aNewAnchors = oEditor.FCK.CreateLink( '#' ) ;
\r
115 if ( aNewAnchors.length == 0 )
\r
117 // Nothing was selected, so now just create a normal A
\r
118 aNewAnchors.push( oEditor.FCK.CreateElement( 'a' ) ) ;
\r
122 // Remove the fake href
\r
123 for ( var i = 0 ; i < aNewAnchors.length ; i++ )
\r
124 aNewAnchors[i].removeAttribute( 'href' ) ;
\r
127 // More than one anchors may have been created, so interact through all of them (see #220).
\r
128 for ( var i = 0 ; i < aNewAnchors.length ; i++ )
\r
130 oAnchor = aNewAnchors[i] ;
\r
133 oAnchor.name = sNewName ;
\r
135 // IE does require special processing to show the Anchor's image
\r
136 // Opera doesn't allow to select empty anchors
\r
137 if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
\r
139 if ( oAnchor.innerHTML != '' )
\r
141 if ( FCKBrowserInfo.IsIE )
\r
142 oAnchor.className += ' FCK__AnchorC' ;
\r
146 // Create a fake image for both IE and Opera
\r
147 var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ;
\r
148 oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
\r
150 oAnchor.parentNode.insertBefore( oImg, oAnchor ) ;
\r
151 oAnchor.parentNode.removeChild( oAnchor ) ;
\r
160 // Removes the current anchor from the document
\r
161 function RemoveAnchor()
\r
163 // If it's also a link, then just remove the name and exit
\r
164 if ( oAnchor.href.length != 0 )
\r
166 oAnchor.removeAttribute( 'name' ) ;
\r
167 // Remove temporary class for IE
\r
168 if ( FCKBrowserInfo.IsIE )
\r
169 oAnchor.className = oAnchor.className.replace( FCKRegexLib.FCK_Class, '' ) ;
\r
173 // We need to remove the anchor
\r
174 // If we got a fake image, then just remove it and we're done
\r
177 oFakeImage.parentNode.removeChild( oFakeImage ) ;
\r
180 // Empty anchor, so just remove it
\r
181 if ( oAnchor.innerHTML.length == 0 )
\r
183 oAnchor.parentNode.removeChild( oAnchor ) ;
\r
186 // Anchor with content, leave the content
\r
187 FCKTools.RemoveOuterTags( oAnchor ) ;
\r
190 // Checks all the links in the current page pointing to the current name and changes them to the new name
\r
191 function ReadjustLinksToAnchor( sCurrent, sNew )
\r
193 var oDoc = FCK.EditorDocument ;
\r
195 var aLinks = oDoc.getElementsByTagName( 'A' ) ;
\r
197 var sReference = '#' + sCurrent ;
\r
198 // The url of the document, so we check absolute and partial references.
\r
199 var sFullReference = oDoc.location.href.replace( /(#.*$)/, '') ;
\r
200 sFullReference += sReference ;
\r
203 var i = aLinks.length - 1 ;
\r
204 while ( i >= 0 && ( oLink = aLinks[i--] ) )
\r
206 var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
\r
207 if ( sHRef == null )
\r
208 sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
\r
210 if ( sHRef == sReference || sHRef == sFullReference )
\r
212 oLink.href = '#' + sNew ;
\r
213 SetAttribute( oLink, '_fcksavedurl', '#' + sNew ) ;
\r
220 <body style="OVERFLOW: hidden" scroll="no">
\r
221 <table height="100%" width="100%">
\r
223 <td align="center">
\r
224 <table border="0" cellpadding="0" cellspacing="0" width="80%">
\r
227 <span fckLang="DlgAnchorName">Anchor Name</span><BR>
\r
228 <input id="txtName" style="WIDTH: 100%" type="text">
\r