/pigeoncms/Plugins/fckeditor/editor/dialog/fck_anchor.html

http://pigeoncms.googlecode.com/ · HTML · 220 lines · 174 code · 24 blank · 22 comment · 0 complexity · 05d474ff57903cc391340ec0c79f4637 MD5 · raw file

  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-2009 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. var dialog = window.parent ;
  32. var oEditor = dialog.InnerDialogLoaded() ;
  33. var FCK = oEditor.FCK ;
  34. var FCKBrowserInfo = oEditor.FCKBrowserInfo ;
  35. var FCKTools = oEditor.FCKTools ;
  36. var FCKRegexLib = oEditor.FCKRegexLib ;
  37. var oDOM = FCK.EditorDocument ;
  38. var oFakeImage = dialog.Selection.GetSelectedElement() ;
  39. var oAnchor ;
  40. if ( oFakeImage )
  41. {
  42. if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckanchor') )
  43. oAnchor = FCK.GetRealElement( oFakeImage ) ;
  44. else
  45. oFakeImage = null ;
  46. }
  47. //Search for a real anchor
  48. if ( !oFakeImage )
  49. {
  50. oAnchor = FCK.Selection.MoveToAncestorNode( 'A' ) ;
  51. if ( oAnchor )
  52. FCK.Selection.SelectNode( oAnchor ) ;
  53. }
  54. window.onload = function()
  55. {
  56. // First of all, translate the dialog box texts
  57. oEditor.FCKLanguageManager.TranslatePage(document) ;
  58. if ( oAnchor )
  59. GetE('txtName').value = oAnchor.name ;
  60. else
  61. oAnchor = null ;
  62. window.parent.SetOkButton( true ) ;
  63. window.parent.SetAutoSize( true ) ;
  64. SelectField( 'txtName' ) ;
  65. }
  66. function Ok()
  67. {
  68. var sNewName = GetE('txtName').value ;
  69. // Remove any illegal character in a name attribute:
  70. // A name should start with a letter, but the validator passes anyway.
  71. sNewName = sNewName.replace( /[^\w-_\.:]/g, '_' ) ;
  72. if ( sNewName.length == 0 )
  73. {
  74. // Remove the anchor if the user leaves the name blank
  75. if ( oAnchor )
  76. {
  77. // Removes the current anchor from the document using the new command
  78. FCK.Commands.GetCommand( 'AnchorDelete' ).Execute() ;
  79. return true ;
  80. }
  81. alert( oEditor.FCKLang.DlgAnchorErrorName ) ;
  82. return false ;
  83. }
  84. oEditor.FCKUndo.SaveUndoStep() ;
  85. if ( oAnchor ) // Modifying an existent anchor.
  86. {
  87. ReadjustLinksToAnchor( oAnchor.name, sNewName );
  88. // Buggy explorer, bad bad browser. http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/
  89. // Instead of just replacing the .name for the existing anchor (in order to preserve the content), we must remove the .name
  90. // and assign .name, although it won't appear until it's specially processed in fckxhtml.js
  91. // We remove the previous name
  92. oAnchor.removeAttribute( 'name' ) ;
  93. // Now we set it, but later we must process it specially
  94. oAnchor.name = sNewName ;
  95. return true ;
  96. }
  97. // Create a new anchor preserving the current selection
  98. var aNewAnchors = oEditor.FCK.CreateLink( '#' ) ;
  99. if ( aNewAnchors.length == 0 )
  100. aNewAnchors.push( oEditor.FCK.InsertElement( 'a' ) ) ;
  101. else
  102. {
  103. // Remove the fake href
  104. for ( var i = 0 ; i < aNewAnchors.length ; i++ )
  105. aNewAnchors[i].removeAttribute( 'href' ) ;
  106. }
  107. // More than one anchors may have been created, so interact through all of them (see #220).
  108. for ( var i = 0 ; i < aNewAnchors.length ; i++ )
  109. {
  110. oAnchor = aNewAnchors[i] ;
  111. // Set the name
  112. if ( FCKBrowserInfo.IsIE )
  113. {
  114. // Setting anchor names directly in IE will trash the HTML code stored
  115. // in FCKTempBin after undos. See #2263.
  116. var replaceAnchor = oEditor.FCK.EditorDocument.createElement( '<a name="' +
  117. FCKTools.HTMLEncode( sNewName ).replace( '"', '&quot;' ) + '">' ) ;
  118. oEditor.FCKDomTools.MoveChildren( oAnchor, replaceAnchor ) ;
  119. oAnchor.parentNode.replaceChild( replaceAnchor, oAnchor ) ;
  120. oAnchor = replaceAnchor ;
  121. }
  122. else
  123. oAnchor.name = sNewName ;
  124. // IE does require special processing to show the Anchor's image
  125. // Opera doesn't allow to select empty anchors
  126. if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
  127. {
  128. if ( oAnchor.innerHTML != '' )
  129. {
  130. if ( FCKBrowserInfo.IsIE )
  131. oAnchor.className += ' FCK__AnchorC' ;
  132. }
  133. else
  134. {
  135. // Create a fake image for both IE and Opera
  136. var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ;
  137. oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
  138. oAnchor.parentNode.insertBefore( oImg, oAnchor ) ;
  139. oAnchor.parentNode.removeChild( oAnchor ) ;
  140. }
  141. }
  142. }
  143. return true ;
  144. }
  145. // Checks all the links in the current page pointing to the current name and changes them to the new name
  146. function ReadjustLinksToAnchor( sCurrent, sNew )
  147. {
  148. var oDoc = FCK.EditorDocument ;
  149. var aLinks = oDoc.getElementsByTagName( 'A' ) ;
  150. var sReference = '#' + sCurrent ;
  151. // The url of the document, so we check absolute and partial references.
  152. var sFullReference = oDoc.location.href.replace( /(#.*$)/, '') ;
  153. sFullReference += sReference ;
  154. var oLink ;
  155. var i = aLinks.length - 1 ;
  156. while ( i >= 0 && ( oLink = aLinks[i--] ) )
  157. {
  158. var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
  159. if ( sHRef == null )
  160. sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
  161. if ( sHRef == sReference || sHRef == sFullReference )
  162. {
  163. oLink.href = '#' + sNew ;
  164. SetAttribute( oLink, '_fcksavedurl', '#' + sNew ) ;
  165. }
  166. }
  167. }
  168. </script>
  169. </head>
  170. <body style="overflow: hidden">
  171. <table height="100%" width="100%">
  172. <tr>
  173. <td align="center">
  174. <table border="0" cellpadding="0" cellspacing="0" width="80%">
  175. <tr>
  176. <td>
  177. <span fckLang="DlgAnchorName">Anchor Name</span><BR>
  178. <input id="txtName" style="WIDTH: 100%" type="text">
  179. </td>
  180. </tr>
  181. </table>
  182. </td>
  183. </tr>
  184. </table>
  185. </body>
  186. </html>