📄 fckenterkey.js
字号:
// Get the current selection.
var oRange = new FCKDomRange( this.Window ) ;
oRange.MoveToSelection() ;
// Kludge for #247
if ( FCKBrowserInfo.IsIE && this._CheckIsAllContentsIncluded( oRange, this.Window.document.body ) )
{
this._FixIESelectAllBug( oRange ) ;
return true ;
}
// There is just one special case for collapsed selections at the end of a block.
if ( oRange.CheckIsCollapsed() && oRange.CheckEndOfBlock( FCKBrowserInfo.IsGeckoLike ) )
{
var oCurrentBlock = oRange.StartBlock ;
var eCurrentCell = FCKTools.GetElementAscensor( oCurrentBlock, 'td' );
var eNext = FCKDomTools.GetNextSourceElement( oCurrentBlock, true, [ oRange.StartBlockLimit.nodeName ],
['UL','OL','TR'], true ) ;
// Bug #1323 : if we're in a table cell, and the next node belongs to a different cell, then don't
// delete anything.
if ( eCurrentCell )
{
var eNextCell = FCKTools.GetElementAscensor( eNext, 'td' );
if ( eNextCell != eCurrentCell )
return true ;
}
bCustom = this._ExecuteBackspace( oRange, oCurrentBlock, eNext ) ;
}
oRange.Release() ;
return bCustom ;
}
/*
* Executes the <Tab> key behavior.
*/
FCKEnterKey.prototype.DoTab = function()
{
var oRange = new FCKDomRange( this.Window );
oRange.MoveToSelection() ;
// If the user pressed <tab> inside a table, we should give him the default behavior ( moving between cells )
// instead of giving him more non-breaking spaces. (Bug #973)
var node = oRange._Range.startContainer ;
while ( node )
{
if ( node.nodeType == 1 )
{
var tagName = node.tagName.toLowerCase() ;
if ( tagName == "tr" || tagName == "td" || tagName == "th" || tagName == "tbody" || tagName == "table" )
return false ;
else
break ;
}
node = node.parentNode ;
}
if ( this.TabText )
{
oRange.DeleteContents() ;
oRange.InsertNode( this.Window.document.createTextNode( this.TabText ) ) ;
oRange.Collapse( false ) ;
oRange.Select() ;
}
return true ;
}
FCKEnterKey.prototype._ExecuteEnterBlock = function( blockTag, range )
{
// Get the current selection.
var oRange = range || new FCKDomRange( this.Window ) ;
var oSplitInfo = oRange.SplitBlock( blockTag ) ;
if ( oSplitInfo )
{
// Get the current blocks.
var ePreviousBlock = oSplitInfo.PreviousBlock ;
var eNextBlock = oSplitInfo.NextBlock ;
var bIsStartOfBlock = oSplitInfo.WasStartOfBlock ;
var bIsEndOfBlock = oSplitInfo.WasEndOfBlock ;
// If there is one block under a list item, modify the split so that the list item gets split as well. (Bug #1647)
if ( eNextBlock )
{
if ( eNextBlock.parentNode.nodeName.IEquals( 'li' ) )
{
FCKDomTools.BreakParent( eNextBlock, eNextBlock.parentNode ) ;
FCKDomTools.MoveNode( eNextBlock, eNextBlock.nextSibling, true ) ;
}
}
else if ( ePreviousBlock && ePreviousBlock.parentNode.nodeName.IEquals( 'li' ) )
{
FCKDomTools.BreakParent( ePreviousBlock, ePreviousBlock.parentNode ) ;
oRange.MoveToElementEditStart( ePreviousBlock.nextSibling );
FCKDomTools.MoveNode( ePreviousBlock, ePreviousBlock.previousSibling ) ;
}
// If we have both the previous and next blocks, it means that the
// boundaries were on separated blocks, or none of them where on the
// block limits (start/end).
if ( !bIsStartOfBlock && !bIsEndOfBlock )
{
// If the next block is an <li> with another list tree as the first child
// We'll need to append a placeholder or the list item wouldn't be editable. (Bug #1420)
if ( eNextBlock.nodeName.IEquals( 'li' ) && eNextBlock.firstChild
&& eNextBlock.firstChild.nodeName.IEquals( ['ul', 'ol'] ) )
eNextBlock.insertBefore( FCKTools.GetElementDocument( eNextBlock ).createTextNode( '\xa0' ), eNextBlock.firstChild ) ;
// Move the selection to the end block.
if ( eNextBlock )
oRange.MoveToElementEditStart( eNextBlock ) ;
}
else
{
if ( bIsStartOfBlock && bIsEndOfBlock && ePreviousBlock.tagName.toUpperCase() == 'LI' )
{
oRange.MoveToElementStart( ePreviousBlock ) ;
this._OutdentWithSelection( ePreviousBlock, oRange ) ;
oRange.Release() ;
return true ;
}
var eNewBlock ;
if ( ePreviousBlock )
{
var sPreviousBlockTag = ePreviousBlock.tagName.toUpperCase() ;
// If is a header tag, or we are in a Shift+Enter (#77),
// create a new block element (later in the code).
if ( !this._HasShift && !(/^H[1-6]$/).test( sPreviousBlockTag ) )
{
// Otherwise, duplicate the previous block.
eNewBlock = FCKDomTools.CloneElement( ePreviousBlock ) ;
}
}
else if ( eNextBlock )
eNewBlock = FCKDomTools.CloneElement( eNextBlock ) ;
if ( !eNewBlock )
eNewBlock = this.Window.document.createElement( blockTag ) ;
// Recreate the inline elements tree, which was available
// before the hitting enter, so the same styles will be
// available in the new block.
var elementPath = oSplitInfo.ElementPath ;
if ( elementPath )
{
for ( var i = 0, len = elementPath.Elements.length ; i < len ; i++ )
{
var element = elementPath.Elements[i] ;
if ( element == elementPath.Block || element == elementPath.BlockLimit )
break ;
if ( FCKListsLib.InlineChildReqElements[ element.nodeName.toLowerCase() ] )
{
element = FCKDomTools.CloneElement( element ) ;
FCKDomTools.MoveChildren( eNewBlock, element ) ;
eNewBlock.appendChild( element ) ;
}
}
}
if ( FCKBrowserInfo.IsGeckoLike )
FCKTools.AppendBogusBr( eNewBlock ) ;
oRange.InsertNode( eNewBlock ) ;
// This is tricky, but to make the new block visible correctly
// we must select it.
if ( FCKBrowserInfo.IsIE )
{
// Move the selection to the new block.
oRange.MoveToElementEditStart( eNewBlock ) ;
oRange.Select() ;
}
// Move the selection to the new block.
oRange.MoveToElementEditStart( bIsStartOfBlock && !bIsEndOfBlock ? eNextBlock : eNewBlock ) ;
}
if ( FCKBrowserInfo.IsGeckoLike )
FCKDomTools.ScrollIntoView( eNextBlock || eNewBlock, false ) ;
oRange.Select() ;
}
// Release the resources used by the range.
oRange.Release() ;
return true ;
}
FCKEnterKey.prototype._ExecuteEnterBr = function( blockTag )
{
// Get the current selection.
var oRange = new FCKDomRange( this.Window ) ;
oRange.MoveToSelection() ;
// The selection boundaries must be in the same "block limit" element.
if ( oRange.StartBlockLimit == oRange.EndBlockLimit )
{
oRange.DeleteContents() ;
// Get the new selection (it is collapsed at this point).
oRange.MoveToSelection() ;
var bIsStartOfBlock = oRange.CheckStartOfBlock() ;
var bIsEndOfBlock = oRange.CheckEndOfBlock() ;
var sStartBlockTag = oRange.StartBlock ? oRange.StartBlock.tagName.toUpperCase() : '' ;
var bHasShift = this._HasShift ;
var bIsPre = false ;
if ( !bHasShift && sStartBlockTag == 'LI' )
return this._ExecuteEnterBlock( null, oRange ) ;
// If we are at the end of a header block.
if ( !bHasShift && bIsEndOfBlock && (/^H[1-6]$/).test( sStartBlockTag ) )
{
// Insert a BR after the current paragraph.
FCKDomTools.InsertAfterNode( oRange.StartBlock, this.Window.document.createElement( 'br' ) ) ;
// The space is required by Gecko only to make the cursor blink.
if ( FCKBrowserInfo.IsGecko )
FCKDomTools.InsertAfterNode( oRange.StartBlock, this.Window.document.createTextNode( '' ) ) ;
// IE and Gecko have different behaviors regarding the position.
oRange.SetStart( oRange.StartBlock.nextSibling, FCKBrowserInfo.IsIE ? 3 : 1 ) ;
}
else
{
var eLineBreak ;
bIsPre = sStartBlockTag.IEquals( 'pre' ) ;
if ( bIsPre )
eLineBreak = this.Window.document.createTextNode( FCKBrowserInfo.IsIE ? '\r' : '\n' ) ;
else
eLineBreak = this.Window.document.createElement( 'br' ) ;
oRange.InsertNode( eLineBreak ) ;
// The space is required by Gecko only to make the cursor blink.
if ( FCKBrowserInfo.IsGecko )
FCKDomTools.InsertAfterNode( eLineBreak, this.Window.document.createTextNode( '' ) ) ;
// If we are at the end of a block, we must be sure the bogus node is available in that block.
if ( bIsEndOfBlock && FCKBrowserInfo.IsGeckoLike )
FCKTools.AppendBogusBr( eLineBreak.parentNode ) ;
if ( FCKBrowserInfo.IsIE )
oRange.SetStart( eLineBreak, 4 ) ;
else
oRange.SetStart( eLineBreak.nextSibling, 1 ) ;
if ( ! FCKBrowserInfo.IsIE )
{
var dummy = null ;
if ( FCKBrowserInfo.IsOpera )
dummy = this.Window.document.createElement( 'span' ) ;
else
dummy = this.Window.document.createElement( 'br' ) ;
eLineBreak.parentNode.insertBefore( dummy, eLineBreak.nextSibling ) ;
FCKDomTools.ScrollIntoView( dummy, false ) ;
dummy.parentNode.removeChild( dummy ) ;
}
}
// This collapse guarantees the cursor will be blinking.
oRange.Collapse( true ) ;
oRange.Select( bIsPre ) ;
}
// Release the resources used by the range.
oRange.Release() ;
return true ;
}
// Outdents a LI, maintaining the selection defined on a range.
FCKEnterKey.prototype._OutdentWithSelection = function( li, range )
{
var oBookmark = range.CreateBookmark() ;
FCKListHandler.OutdentListItem( li ) ;
range.MoveToBookmark( oBookmark ) ;
range.Select() ;
}
// Is all the contents under a node included by a range?
FCKEnterKey.prototype._CheckIsAllContentsIncluded = function( range, node )
{
var startOk = false ;
var endOk = false ;
/*
FCKDebug.Output( 'sc='+range.StartContainer.nodeName+
',so='+range._Range.startOffset+
',ec='+range.EndContainer.nodeName+
',eo='+range._Range.endOffset ) ;
*/
if ( range.StartContainer == node || range.StartContainer == node.firstChild )
startOk = ( range._Range.startOffset == 0 ) ;
if ( range.EndContainer == node || range.EndContainer == node.lastChild )
{
var nodeLength = range.EndContainer.nodeType == 3 ? range.EndContainer.length : range.EndContainer.childNodes.length ;
endOk = ( range._Range.endOffset == nodeLength ) ;
}
return startOk && endOk ;
}
// Kludge for #247
FCKEnterKey.prototype._FixIESelectAllBug = function( range )
{
var doc = this.Window.document ;
doc.body.innerHTML = '' ;
var editBlock ;
if ( FCKConfig.EnterMode.IEquals( ['div', 'p'] ) )
{
editBlock = doc.createElement( FCKConfig.EnterMode ) ;
doc.body.appendChild( editBlock ) ;
}
else
editBlock = doc.body ;
range.MoveToNodeContents( editBlock ) ;
range.Collapse( true ) ;
range.Select() ;
range.Release() ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -