1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 2<!-- 3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 4 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 5 * 6 * == BEGIN LICENSE == 7 * 8 * Licensed under the terms of any of the following licenses at your 9 * choice: 10 * 11 * - GNU General Public License Version 2 or later (the "GPL") 12 * http://www.gnu.org/licenses/gpl.html 13 * 14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 15 * http://www.gnu.org/licenses/lgpl.html 16 * 17 * - Mozilla Public License Version 1.1 or later (the "MPL") 18 * http://www.mozilla.org/MPL/MPL-1.1.html 19 * 20 * == END LICENSE == 21 * 22 * Anchor dialog window. 23--> 24<html> 25 <head> 26 <title>Anchor Properties</title> 27 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 28 <meta content="noindex, nofollow" name="robots"> 29 <script src="common/fck_dialog_common.js" type="text/javascript"></script> 30 <script type="text/javascript"> 31 32var oEditor = window.parent.InnerDialogLoaded() ; 33var FCK = oEditor.FCK ; 34var FCKBrowserInfo = oEditor.FCKBrowserInfo ; 35var FCKTools = oEditor.FCKTools ; 36var FCKRegexLib = oEditor.FCKRegexLib ; 37 38// Gets the document DOM 39var oDOM = oEditor.FCK.EditorDocument ; 40 41var oFakeImage = FCK.Selection.GetSelectedElement() ; 42var oAnchor ; 43 44if ( oFakeImage ) 45{ 46 if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckanchor') ) 47 oAnchor = FCK.GetRealElement( oFakeImage ) ; 48 else 49 oFakeImage = null ; 50} 51 52//Search for a real anchor 53if ( !oFakeImage ) 54{ 55 oAnchor = FCK.Selection.MoveToAncestorNode( 'A' ) ; 56 if ( oAnchor ) 57 FCK.Selection.SelectNode( oAnchor ) ; 58} 59 60window.onload = function() 61{ 62 // First of all, translate the dialog box texts 63 oEditor.FCKLanguageManager.TranslatePage(document) ; 64 65 if ( oAnchor ) 66 GetE('txtName').value = oAnchor.name ; 67 else 68 oAnchor = null ; 69 70 window.parent.SetOkButton( true ) ; 71} 72 73function Ok() 74{ 75 var sNewName = GetE('txtName').value ; 76 77 // Remove any illegal character in a name attribute: 78 // A name should start with a letter, but the validator passes anyway. 79 sNewName = sNewName.replace( /[^\w-_\.:]/g, '_' ) ; 80 81 if ( sNewName.length == 0 ) 82 { 83 // Remove the anchor if the user leaves the name blank 84 if ( oAnchor ) 85 { 86 // Removes the current anchor from the document using the new command 87 FCK.Commands.GetCommand( 'AnchorDelete' ).Execute() ; 88 return true ; 89 } 90 91 alert( oEditor.FCKLang.DlgAnchorErrorName ) ; 92 return false ; 93 } 94 95 oEditor.FCKUndo.SaveUndoStep() ; 96 97 if ( oAnchor ) // Modifying an existent anchor. 98 { 99 ReadjustLinksToAnchor( oAnchor.name, sNewName ); 100 101 // Buggy explorer, bad bad browser. http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/ 102 // Instead of just replacing the .name for the existing anchor (in order to preserve the content), we must remove the .name 103 // and assign .name, although it won't appear until it's specially processed in fckxhtml.js 104 105 // We remove the previous name 106 oAnchor.removeAttribute( 'name' ) ; 107 // Now we set it, but later we must process it specially 108 oAnchor.name = sNewName ; 109 110 return true ; 111 } 112 113 // Create a new anchor preserving the current selection 114 var aNewAnchors = oEditor.FCK.CreateLink( '#' ) ; 115 116 if ( aNewAnchors.length == 0 ) 117 { 118 // Nothing was selected, so now just create a normal A 119 aNewAnchors.push( oEditor.FCK.InsertElement( 'a' ) ) ; 120 } 121 else 122 { 123 // Remove the fake href 124 for ( var i = 0 ; i < aNewAnchors.length ; i++ ) 125 aNewAnchors[i].removeAttribute( 'href' ) ; 126 } 127 128 // More than one anchors may have been created, so interact through all of them (see #220). 129 for ( var i = 0 ; i < aNewAnchors.length ; i++ ) 130 { 131 oAnchor = aNewAnchors[i] ; 132 133 // Set the name 134 oAnchor.name = sNewName ; 135 136 // IE does require special processing to show the Anchor's image 137 // Opera doesn't allow to select empty anchors 138 if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera ) 139 { 140 if ( oAnchor.innerHTML != '' ) 141 { 142 if ( FCKBrowserInfo.IsIE ) 143 oAnchor.className += ' FCK__AnchorC' ; 144 } 145 else 146 { 147 // Create a fake image for both IE and Opera 148 var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ; 149 oImg.setAttribute( '_fckanchor', 'true', 0 ) ; 150 151 oAnchor.parentNode.insertBefore( oImg, oAnchor ) ; 152 oAnchor.parentNode.removeChild( oAnchor ) ; 153 } 154 155 } 156 } 157 158 return true ; 159} 160 161// Checks all the links in the current page pointing to the current name and changes them to the new name 162function ReadjustLinksToAnchor( sCurrent, sNew ) 163{ 164 var oDoc = FCK.EditorDocument ; 165 166 var aLinks = oDoc.getElementsByTagName( 'A' ) ; 167 168 var sReference = '#' + sCurrent ; 169 // The url of the document, so we check absolute and partial references. 170 var sFullReference = oDoc.location.href.replace( /(#.*$)/, '') ; 171 sFullReference += sReference ; 172 173 var oLink ; 174 var i = aLinks.length - 1 ; 175 while ( i >= 0 && ( oLink = aLinks[i--] ) ) 176 { 177 var sHRef = oLink.getAttribute( '_fcksavedurl' ) ; 178 if ( sHRef == null ) 179 sHRef = oLink.getAttribute( 'href' , 2 ) || '' ; 180 181 if ( sHRef == sReference || sHRef == sFullReference ) 182 { 183 oLink.href = '#' + sNew ; 184 SetAttribute( oLink, '_fcksavedurl', '#' + sNew ) ; 185 } 186 } 187} 188 189 </script> 190 </head> 191 <body style="OVERFLOW: hidden" scroll="no"> 192 <table height="100%" width="100%"> 193 <tr> 194 <td align="center"> 195 <table border="0" cellpadding="0" cellspacing="0" width="80%"> 196 <tr> 197 <td> 198 <span fckLang="DlgAnchorName">Anchor Name</span><BR> 199 <input id="txtName" style="WIDTH: 100%" type="text"> 200 </td> 201 </tr> 202 </table> 203 </td> 204 </tr> 205 </table> 206 </body> 207</html> 208