📄 fck.js
字号:
// Protect parts of the code that must remain untouched (and invisible)
// during editing.
data = FCKConfig.ProtectedSource.Protect( data ) ;
// Call the Data Processor to transform the data.
data = FCK.DataProcessor.ConvertToHtml( data ) ;
// Fix for invalid self-closing tags (see #152).
data = data.replace( FCKRegexLib.InvalidSelfCloseTags, '$1></$2>' ) ;
// Protect event attributes (they could get fired in the editing area).
data = FCK.ProtectEvents( data ) ;
// Protect some things from the browser itself.
data = FCK.ProtectUrls( data ) ;
data = FCK.ProtectTags( data ) ;
// Insert the base tag (FCKConfig.BaseHref), if not exists in the source.
// The base must be the first tag in the HEAD, to get relative
// links on styles, for example.
if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( data ) )
data = data.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ;
// Build the HTML for the additional things we need on <head>.
var sHeadExtra = '' ;
if ( !FCKConfig.FullPage )
sHeadExtra += _FCK_GetEditorAreaStyleTags() ;
if ( FCKBrowserInfo.IsIE )
sHeadExtra += FCK._GetBehaviorsStyle() ;
else if ( FCKConfig.ShowBorders )
sHeadExtra += FCKTools.GetStyleHtml( FCK_ShowTableBordersCSS, true ) ;
sHeadExtra += FCKTools.GetStyleHtml( FCK_InternalCSS, true ) ;
// Attention: do not change it before testing it well (sample07)!
// This is tricky... if the head ends with <meta ... content type>,
// Firefox will break. But, it works if we place our extra stuff as
// the last elements in the HEAD.
data = data.replace( FCKRegexLib.HeadCloser, sHeadExtra + '$&' ) ;
// Load the HTML in the editing area.
this.EditingArea.OnLoad = _FCK_EditingArea_OnLoad ;
this.EditingArea.Start( data ) ;
}
else
{
// Remove the references to the following elements, as the editing area
// IFRAME will be removed.
FCK.EditorWindow = null ;
FCK.EditorDocument = null ;
FCKDomTools.PaddingNode = null ;
this.EditingArea.OnLoad = null ;
this.EditingArea.Start( data ) ;
// Enables the context menu in the textarea.
this.EditingArea.Textarea._FCKShowContextMenu = true ;
// Removes the enter key handler.
FCK.EnterKeyHandler = null ;
if ( resetIsDirty )
this.ResetIsDirty() ;
// Listen for keystroke events.
FCK.KeystrokeHandler.AttachToElement( this.EditingArea.Textarea ) ;
this.EditingArea.Textarea.focus() ;
FCK.Events.FireEvent( 'OnAfterSetHTML' ) ;
}
if ( FCKBrowserInfo.IsGecko )
window.onresize() ;
},
// This collection is used by the browser specific implementations to tell
// which named commands must be handled separately.
RedirectNamedCommands : new Object(),
ExecuteNamedCommand : function( commandName, commandParameter, noRedirect, noSaveUndo )
{
if ( !noSaveUndo )
FCKUndo.SaveUndoStep() ;
if ( !noRedirect && FCK.RedirectNamedCommands[ commandName ] != null )
FCK.ExecuteRedirectedNamedCommand( commandName, commandParameter ) ;
else
{
FCK.Focus() ;
FCK.EditorDocument.execCommand( commandName, false, commandParameter ) ;
FCK.Events.FireEvent( 'OnSelectionChange' ) ;
}
if ( !noSaveUndo )
FCKUndo.SaveUndoStep() ;
},
GetNamedCommandState : function( commandName )
{
try
{
// Bug #50 : Safari never returns positive state for the Paste command, override that.
if ( FCKBrowserInfo.IsSafari && FCK.EditorWindow && commandName.IEquals( 'Paste' ) )
return FCK_TRISTATE_OFF ;
if ( !FCK.EditorDocument.queryCommandEnabled( commandName ) )
return FCK_TRISTATE_DISABLED ;
else
{
return FCK.EditorDocument.queryCommandState( commandName ) ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF ;
}
}
catch ( e )
{
return FCK_TRISTATE_OFF ;
}
},
GetNamedCommandValue : function( commandName )
{
var sValue = '' ;
var eState = FCK.GetNamedCommandState( commandName ) ;
if ( eState == FCK_TRISTATE_DISABLED )
return null ;
try
{
sValue = this.EditorDocument.queryCommandValue( commandName ) ;
}
catch(e) {}
return sValue ? sValue : '' ;
},
Paste : function( _callListenersOnly )
{
// First call 'OnPaste' listeners.
if ( FCK.Status != FCK_STATUS_COMPLETE || !FCK.Events.FireEvent( 'OnPaste' ) )
return false ;
// Then call the default implementation.
return _callListenersOnly || FCK._ExecPaste() ;
},
PasteFromWord : function()
{
FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteFromWord, 'dialog/fck_paste.html', 400, 330, 'Word' ) ;
},
Preview : function()
{
var sHTML ;
if ( FCKConfig.FullPage )
{
if ( FCK.TempBaseTag.length > 0 )
sHTML = FCK.TempBaseTag + FCK.GetXHTML() ;
else
sHTML = FCK.GetXHTML() ;
}
else
{
sHTML =
FCKConfig.DocType +
'<html dir="' + FCKConfig.ContentLangDirection + '">' +
'<head>' +
FCK.TempBaseTag +
'<title>' + FCKLang.Preview + '</title>' +
_FCK_GetEditorAreaStyleTags() +
'</head><body' + FCKConfig.GetBodyAttributes() + '>' +
FCK.GetXHTML() +
'</body></html>' ;
}
var iWidth = FCKConfig.ScreenWidth * 0.8 ;
var iHeight = FCKConfig.ScreenHeight * 0.7 ;
var iLeft = ( FCKConfig.ScreenWidth - iWidth ) / 2 ;
var sOpenUrl = '' ;
if ( FCK_IS_CUSTOM_DOMAIN && FCKBrowserInfo.IsIE)
{
window._FCKHtmlToLoad = sHTML ;
sOpenUrl = 'javascript:void( (function(){' +
'document.open() ;' +
'document.domain="' + document.domain + '" ;' +
'document.write( window.opener._FCKHtmlToLoad );' +
'document.close() ;' +
'window.opener._FCKHtmlToLoad = null ;' +
'})() )' ;
}
var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft ) ;
if ( !FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE)
{
oWindow.document.write( sHTML );
oWindow.document.close();
}
},
SwitchEditMode : function( noUndo )
{
var bIsWysiwyg = ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) ;
// Save the current IsDirty state, so we may restore it after the switch.
var bIsDirty = FCK.IsDirty() ;
var sHtml ;
// Update the HTML in the view output to show, also update
// FCKTempBin for IE to avoid #2263.
if ( bIsWysiwyg )
{
FCKCommands.GetCommand( 'ShowBlocks' ).SaveState() ;
if ( !noUndo && FCKBrowserInfo.IsIE )
FCKUndo.SaveUndoStep() ;
sHtml = FCK.GetXHTML( FCKConfig.FormatSource ) ;
if ( FCKBrowserInfo.IsIE )
FCKTempBin.ToHtml() ;
if ( sHtml == null )
return false ;
}
else
sHtml = this.EditingArea.Textarea.value ;
FCK.EditMode = bIsWysiwyg ? FCK_EDITMODE_SOURCE : FCK_EDITMODE_WYSIWYG ;
FCK.SetData( sHtml, !bIsDirty ) ;
// Set the Focus.
FCK.Focus() ;
// Update the toolbar (Running it directly causes IE to fail).
FCKTools.RunFunction( FCK.ToolbarSet.RefreshModeState, FCK.ToolbarSet ) ;
return true ;
},
InsertElement : function( element )
{
// The parameter may be a string (element name), so transform it in an element.
if ( typeof element == 'string' )
element = this.EditorDocument.createElement( element ) ;
var elementName = element.nodeName.toLowerCase() ;
FCKSelection.Restore() ;
// Create a range for the selection. V3 will have a new selection
// object that may internally supply this feature.
var range = new FCKDomRange( this.EditorWindow ) ;
// Move to the selection and delete it.
range.MoveToSelection() ;
range.DeleteContents() ;
if ( FCKListsLib.BlockElements[ elementName ] != null )
{
if ( range.StartBlock )
{
if ( range.CheckStartOfBlock() )
range.MoveToPosition( range.StartBlock, 3 ) ;
else if ( range.CheckEndOfBlock() )
range.MoveToPosition( range.StartBlock, 4 ) ;
else
range.SplitBlock() ;
}
range.InsertNode( element ) ;
var next = FCKDomTools.GetNextSourceElement( element, false, null, [ 'hr','br','param','img','area','input' ], true ) ;
// Be sure that we have something after the new element, so we can move the cursor there.
if ( !next && FCKConfig.EnterMode != 'br')
{
next = this.EditorDocument.body.appendChild( this.EditorDocument.createElement( FCKConfig.EnterMode ) ) ;
if ( FCKBrowserInfo.IsGeckoLike )
FCKTools.AppendBogusBr( next ) ;
}
if ( FCKListsLib.EmptyElements[ elementName ] == null )
range.MoveToElementEditStart( element ) ;
else if ( next )
range.MoveToElementEditStart( next ) ;
else
range.MoveToPosition( element, 4 ) ;
if ( FCKBrowserInfo.IsGeckoLike )
{
if ( next )
FCKDomTools.ScrollIntoView( next, false );
FCKDomTools.ScrollIntoView( element, false );
}
}
else
{
// Insert the node.
range.InsertNode( element ) ;
// Move the selection right after the new element.
// DISCUSSION: Should we select the element instead?
range.SetStart( element, 4 ) ;
range.SetEnd( element, 4 ) ;
}
range.Select() ;
range.Release() ;
// REMOVE IT: The focus should not really be set here. It is up to the
// calling code to reset the focus if needed.
this.Focus() ;
return element ;
},
_InsertBlockElement : function( blockElement )
{
},
_IsFunctionKey : function( keyCode )
{
// keys that are captured but do not change editor contents
if ( keyCode >= 16 && keyCode <= 20 )
// shift, ctrl, alt, pause, capslock
return true ;
if ( keyCode == 27 || ( keyCode >= 33 && keyCode <= 40 ) )
// esc, page up, page down, end, home, left, up, right, down
return true ;
if ( keyCode == 45 )
// insert, no effect on FCKeditor, yet
return true ;
return false ;
},
_KeyDownListener : function( evt )
{
if (! evt)
evt = FCK.EditorWindow.event ;
if ( FCK.EditorWindow )
{
if ( !FCK._IsFunctionKey(evt.keyCode) // do not capture function key presses, like arrow keys or shift/alt/ctrl
&& !(evt.ctrlKey || evt.metaKey) // do not capture Ctrl hotkeys, as they have their snapshot capture logic
&& !(evt.keyCode == 46) ) // do not capture Del, it has its own capture logic in fckenterkey.js
FCK._KeyDownUndo() ;
}
return true ;
},
_KeyDownUndo : function()
{
if ( !FCKUndo.Typing )
{
FCKUndo.SaveUndoStep() ;
FCKUndo.Typing = true ;
FCK.Events.FireEvent( "OnSelectionChange" ) ;
}
FCKUndo.TypesCount++ ;
FCKUndo.Changed = 1 ;
if ( FCKUndo.TypesCount > FCKUndo.MaxTypes )
{
FCKUndo.TypesCount = 0 ;
FCKUndo.SaveUndoStep() ;
}
},
_TabKeyHandler : function( evt )
{
if ( ! evt )
evt = window.event ;
var keystrokeValue = evt.keyCode ;
// Pressing <Tab> in source mode should produce a tab space in the text area, not
// changing the focus to something else.
if ( keystrokeValue == 9 && FCK.EditMode != FCK_EDITMODE_WYSIWYG )
{
if ( FCKBrowserInfo.IsIE )
{
var range = document.selection.createRange() ;
if ( range.parentElement() != FCK.EditingArea.Textarea )
return true ;
range.text = '\t' ;
range.select() ;
}
else
{
var a = [] ;
var el = FCK.EditingArea.Textarea ;
var selStart = el.selectionStart ;
var selEnd = el.selectionEnd ;
a.push( el.value.substr(0, selStart ) ) ;
a.push( '\t' ) ;
a.push( el.value.substr( selEnd ) ) ;
el.value = a.join( '' ) ;
el.setSelectionRange( selStart + 1, selStart + 1 ) ;
}
if ( evt.preventDefault )
return evt.preventDefault() ;
return evt.returnValue = false ;
}
return true ;
}
} ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -