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-2010 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 dialog = window.parent ;
\r
33 var oEditor = dialog.InnerDialogLoaded() ;
\r
35 var FCK = oEditor.FCK ;
\r
36 var FCKBrowserInfo = oEditor.FCKBrowserInfo ;
\r
37 var FCKTools = oEditor.FCKTools ;
\r
38 var FCKRegexLib = oEditor.FCKRegexLib ;
\r
40 var oDOM = FCK.EditorDocument ;
\r
42 var oFakeImage = dialog.Selection.GetSelectedElement() ;
\r
48 if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckanchor') )
\r
49 oAnchor = FCK.GetRealElement( oFakeImage ) ;
\r
54 //Search for a real anchor
\r
57 oAnchor = FCK.Selection.MoveToAncestorNode( 'A' ) ;
\r
59 FCK.Selection.SelectNode( oAnchor ) ;
\r
62 window.onload = function()
\r
64 // First of all, translate the dialog box texts
\r
65 oEditor.FCKLanguageManager.TranslatePage(document) ;
\r
68 GetE('txtName').value = oAnchor.name ;
\r
72 window.parent.SetOkButton( true ) ;
\r
73 window.parent.SetAutoSize( true ) ;
\r
75 SelectField( 'txtName' ) ;
\r
80 var sNewName = GetE('txtName').value ;
\r
82 // Remove any illegal character in a name attribute:
\r
83 // A name should start with a letter, but the validator passes anyway.
\r
84 sNewName = sNewName.replace( /[^\w-_\.:]/g, '_' ) ;
\r
86 if ( sNewName.length == 0 )
\r
88 // Remove the anchor if the user leaves the name blank
\r
91 // Removes the current anchor from the document using the new command
\r
92 FCK.Commands.GetCommand( 'AnchorDelete' ).Execute() ;
\r
96 alert( oEditor.FCKLang.DlgAnchorErrorName ) ;
\r
100 oEditor.FCKUndo.SaveUndoStep() ;
\r
102 if ( oAnchor ) // Modifying an existent anchor.
\r
104 ReadjustLinksToAnchor( oAnchor.name, sNewName );
\r
106 // Buggy explorer, bad bad browser. http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/
\r
107 // Instead of just replacing the .name for the existing anchor (in order to preserve the content), we must remove the .name
\r
108 // and assign .name, although it won't appear until it's specially processed in fckxhtml.js
\r
110 // We remove the previous name
\r
111 oAnchor.removeAttribute( 'name' ) ;
\r
112 // Now we set it, but later we must process it specially
\r
113 oAnchor.name = sNewName ;
\r
118 // Create a new anchor preserving the current selection
\r
119 var aNewAnchors = oEditor.FCK.CreateLink( '#' ) ;
\r
121 if ( aNewAnchors.length == 0 )
\r
122 aNewAnchors.push( oEditor.FCK.InsertElement( 'a' ) ) ;
\r
125 // Remove the fake href
\r
126 for ( var i = 0 ; i < aNewAnchors.length ; i++ )
\r
127 aNewAnchors[i].removeAttribute( 'href' ) ;
\r
130 // More than one anchors may have been created, so interact through all of them (see #220).
\r
131 for ( var i = 0 ; i < aNewAnchors.length ; i++ )
\r
133 oAnchor = aNewAnchors[i] ;
\r
136 if ( FCKBrowserInfo.IsIE )
\r
138 // Setting anchor names directly in IE will trash the HTML code stored
\r
139 // in FCKTempBin after undos. See #2263.
\r
140 var replaceAnchor = oEditor.FCK.EditorDocument.createElement( '<a name="' +
\r
141 FCKTools.HTMLEncode( sNewName ).replace( '"', '"' ) + '">' ) ;
\r
142 oEditor.FCKDomTools.MoveChildren( oAnchor, replaceAnchor ) ;
\r
143 oAnchor.parentNode.replaceChild( replaceAnchor, oAnchor ) ;
\r
144 oAnchor = replaceAnchor ;
\r
147 oAnchor.name = sNewName ;
\r
149 // IE does require special processing to show the Anchor's image
\r
150 // Opera doesn't allow to select empty anchors
\r
151 if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
\r
153 if ( oAnchor.innerHTML != '' )
\r
155 if ( FCKBrowserInfo.IsIE )
\r
156 oAnchor.className += ' FCK__AnchorC' ;
\r
160 // Create a fake image for both IE and Opera
\r
161 var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ;
\r
162 oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
\r
164 oAnchor.parentNode.insertBefore( oImg, oAnchor ) ;
\r
165 oAnchor.parentNode.removeChild( oAnchor ) ;
\r
174 // Checks all the links in the current page pointing to the current name and changes them to the new name
\r
175 function ReadjustLinksToAnchor( sCurrent, sNew )
\r
177 var oDoc = FCK.EditorDocument ;
\r
179 var aLinks = oDoc.getElementsByTagName( 'A' ) ;
\r
181 var sReference = '#' + sCurrent ;
\r
182 // The url of the document, so we check absolute and partial references.
\r
183 var sFullReference = oDoc.location.href.replace( /(#.*$)/, '') ;
\r
184 sFullReference += sReference ;
\r
187 var i = aLinks.length - 1 ;
\r
188 while ( i >= 0 && ( oLink = aLinks[i--] ) )
\r
190 var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
\r
191 if ( sHRef == null )
\r
192 sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
\r
194 if ( sHRef == sReference || sHRef == sFullReference )
\r
196 oLink.href = '#' + sNew ;
\r
197 SetAttribute( oLink, '_fcksavedurl', '#' + sNew ) ;
\r
204 <body style="overflow: hidden">
\r
205 <table height="100%" width="100%">
\r
207 <td align="center">
\r
208 <table border="0" cellpadding="0" cellspacing="0" width="80%">
\r
211 <span fckLang="DlgAnchorName">Anchor Name</span><BR>
\r
212 <input id="txtName" style="WIDTH: 100%" type="text">
\r