[ Index ] |
|
Code source de FCKeditor 2.4 |
1 /* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * File Name: fck_gecko.js 22 * Creation and initialization of the "FCK" object. This is the main 23 * object that represents an editor instance. 24 * (Gecko specific implementations) 25 * 26 * File Authors: 27 * Frederico Caldeira Knabben (www.fckeditor.net) 28 */ 29 30 FCK.Description = "FCKeditor for Gecko Browsers" ; 31 32 FCK.InitializeBehaviors = function() 33 { 34 // When calling "SetHTML", the editing area IFRAME gets a fixed height. So we must recaulculate it. 35 if ( FCKBrowserInfo.IsGecko ) // Not for Safari/Opera. 36 Window_OnResize() ; 37 38 FCKFocusManager.AddWindow( this.EditorWindow ) ; 39 40 this.ExecOnSelectionChange = function() 41 { 42 FCK.Events.FireEvent( "OnSelectionChange" ) ; 43 } 44 45 this.ExecOnSelectionChangeTimer = function() 46 { 47 if ( FCK.LastOnChangeTimer ) 48 window.clearTimeout( FCK.LastOnChangeTimer ) ; 49 50 FCK.LastOnChangeTimer = window.setTimeout( FCK.ExecOnSelectionChange, 100 ) ; 51 } 52 53 this.EditorDocument.addEventListener( 'mouseup', this.ExecOnSelectionChange, false ) ; 54 55 // On Gecko, firing the "OnSelectionChange" event on every key press started to be too much 56 // slow. So, a timer has been implemented to solve performance issues when tipying to quickly. 57 this.EditorDocument.addEventListener( 'keyup', this.ExecOnSelectionChangeTimer, false ) ; 58 59 this._DblClickListener = function( e ) 60 { 61 FCK.OnDoubleClick( e.target ) ; 62 e.stopPropagation() ; 63 } 64 this.EditorDocument.addEventListener( 'dblclick', this._DblClickListener, true ) ; 65 66 // Reset the context menu. 67 FCK.ContextMenu._InnerContextMenu.SetMouseClickWindow( FCK.EditorWindow ) ; 68 FCK.ContextMenu._InnerContextMenu.AttachToElement( FCK.EditorDocument ) ; 69 } 70 71 FCK.MakeEditable = function() 72 { 73 this.EditingArea.MakeEditable() ; 74 } 75 76 // Disable the context menu in the editor (outside the editing area). 77 function Document_OnContextMenu( e ) 78 { 79 if ( !e.target._FCKShowContextMenu ) 80 e.preventDefault() ; 81 } 82 document.oncontextmenu = Document_OnContextMenu ; 83 84 // GetNamedCommandState overload for Gecko. 85 FCK._BaseGetNamedCommandState = FCK.GetNamedCommandState ; 86 FCK.GetNamedCommandState = function( commandName ) 87 { 88 switch ( commandName ) 89 { 90 case 'Unlink' : 91 return FCKSelection.HasAncestorNode('A') ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ; 92 default : 93 return FCK._BaseGetNamedCommandState( commandName ) ; 94 } 95 } 96 97 // Named commands to be handled by this browsers specific implementation. 98 FCK.RedirectNamedCommands = 99 { 100 Print : true, 101 Paste : true, 102 Cut : true, 103 Copy : true 104 } ; 105 106 // ExecuteNamedCommand overload for Gecko. 107 FCK.ExecuteRedirectedNamedCommand = function( commandName, commandParameter ) 108 { 109 switch ( commandName ) 110 { 111 case 'Print' : 112 FCK.EditorWindow.print() ; 113 break ; 114 case 'Paste' : 115 try { if ( FCK.Paste() ) FCK.ExecuteNamedCommand( 'Paste', null, true ) ; } 116 catch (e) { alert(FCKLang.PasteErrorPaste) ; } 117 break ; 118 case 'Cut' : 119 try { FCK.ExecuteNamedCommand( 'Cut', null, true ) ; } 120 catch (e) { alert(FCKLang.PasteErrorCut) ; } 121 break ; 122 case 'Copy' : 123 try { FCK.ExecuteNamedCommand( 'Copy', null, true ) ; } 124 catch (e) { alert(FCKLang.PasteErrorCopy) ; } 125 break ; 126 default : 127 FCK.ExecuteNamedCommand( commandName, commandParameter ) ; 128 } 129 } 130 131 FCK.AttachToOnSelectionChange = function( functionPointer ) 132 { 133 this.Events.AttachEvent( 'OnSelectionChange', functionPointer ) ; 134 } 135 136 FCK.Paste = function() 137 { 138 if ( FCKConfig.ForcePasteAsPlainText ) 139 { 140 FCK.PasteAsPlainText() ; 141 return false ; 142 } 143 144 /* For now, the AutoDetectPasteFromWord feature is IE only. */ 145 146 return true ; 147 } 148 149 //** 150 // FCK.InsertHtml: Inserts HTML at the current cursor location. Deletes the 151 // selected content if any. 152 FCK.InsertHtml = function( html ) 153 { 154 html = FCKConfig.ProtectedSource.Protect( html ) ; 155 html = FCK.ProtectUrls( html ) ; 156 157 // Delete the actual selection. 158 var oSel = FCKSelection.Delete() ; 159 160 // Get the first available range. 161 var oRange = oSel.getRangeAt(0) ; 162 163 // Create a fragment with the input HTML. 164 var oFragment = oRange.createContextualFragment( html ) ; 165 166 // Get the last available node. 167 var oLastNode = oFragment.lastChild ; 168 169 // Insert the fragment in the range. 170 oRange.insertNode(oFragment) ; 171 172 // Set the cursor after the inserted fragment. 173 FCKSelection.SelectNode( oLastNode ) ; 174 FCKSelection.Collapse( false ) ; 175 176 this.Focus() ; 177 } 178 179 FCK.InsertElement = function( element ) 180 { 181 // Deletes the actual selection. 182 var oSel = FCKSelection.Delete() ; 183 184 // Gets the first available range. 185 var oRange = oSel.getRangeAt(0) ; 186 187 // Inserts the element in the range. 188 oRange.insertNode( element ) ; 189 190 // Set the cursor after the inserted fragment. 191 FCKSelection.SelectNode( element ) ; 192 FCKSelection.Collapse( false ) ; 193 194 this.Focus() ; 195 } 196 197 FCK.PasteAsPlainText = function() 198 { 199 // TODO: Implement the "Paste as Plain Text" code. 200 201 FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteAsText, 'dialog/fck_paste.html', 400, 330, 'PlainText' ) ; 202 203 /* 204 var sText = FCKTools.HTMLEncode( clipboardData.getData("Text") ) ; 205 sText = sText.replace( /\n/g, '<BR>' ) ; 206 this.InsertHtml( sText ) ; 207 */ 208 } 209 /* 210 FCK.PasteFromWord = function() 211 { 212 // TODO: Implement the "Paste as Plain Text" code. 213 214 FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteFromWord, 'dialog/fck_paste.html', 400, 330, 'Word' ) ; 215 216 // FCK.CleanAndPaste( FCK.GetClipboardHTML() ) ; 217 } 218 */ 219 FCK.GetClipboardHTML = function() 220 { 221 return '' ; 222 } 223 224 FCK.CreateLink = function( url ) 225 { 226 FCK.ExecuteNamedCommand( 'Unlink' ) ; 227 228 if ( url.length > 0 ) 229 { 230 // Generate a temporary name for the link. 231 var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ; 232 233 // Use the internal "CreateLink" command to create the link. 234 FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ; 235 236 // Retrieve the just created link using XPath. 237 var oLink = this.EditorDocument.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ; 238 239 if ( oLink ) 240 { 241 oLink.href = url ; 242 return oLink ; 243 } 244 } 245 246 return null ; 247 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |