📄 fck_link.js
字号:
var oEditor = window.parent.InnerDialogLoaded() ;
var FCK = oEditor.FCK ;
var FCKLang = oEditor.FCKLang ;
var FCKConfig = oEditor.FCKConfig ;
//#### Dialog Tabs
// Set the dialog tabs.
window.parent.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ;
window.parent.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ;
// Function called when a dialog tag is selected.
function OnDialogTabChange( tabCode )
{
ShowE('divInfo' , ( tabCode == 'Info' ) ) ;
ShowE('divTarget' , ( tabCode == 'Target' ) ) ;
}
//#### Regular Expressions library.
var oRegex = new Object() ;
oRegex.UriProtocol = new RegExp('') ;
oRegex.UriProtocol.compile( '^(((http|https|ftp|news):\/\/)|mailto:)', 'gi' ) ;
oRegex.UrlOnChangeProtocol = new RegExp('') ;
oRegex.UrlOnChangeProtocol.compile( '^(http|https|ftp|news)://(?=.)', 'gi' ) ;
oRegex.UrlOnChangeTestOther = new RegExp('') ;
//oRegex.UrlOnChangeTestOther.compile( '^(javascript:|#|/)', 'gi' ) ;
oRegex.UrlOnChangeTestOther.compile( '^((javascript:)|[#/\.])', 'gi' ) ;
oRegex.ReserveTarget = new RegExp('') ;
oRegex.ReserveTarget.compile( '^_(blank|self|top|parent)$', 'i' ) ;
oRegex.PopupUri = new RegExp('') ;
oRegex.PopupUri.compile( "^javascript:void\\(\\s*window.open\\(\\s*'([^']+)'\\s*,\\s*(?:'([^']*)'|null)\\s*,\\s*'([^']*)'\\s*\\)\\s*\\)\\s*$" ) ;
oRegex.PopupFeatures = new RegExp('') ;
oRegex.PopupFeatures.compile( '(?:^|,)([^=]+)=(\\d+|yes|no)', 'gi' ) ;
//#### Parser Functions
var oParser = new Object() ;
oParser.ParseEMailUrl = function( emailUrl )
{
// Initializes the EMailInfo object.
var oEMailInfo = new Object() ;
oEMailInfo.Address = '' ;
oEMailInfo.Subject = '' ;
oEMailInfo.Body = '' ;
var oParts = emailUrl.match( /^([^\?]+)\??(.+)?/ ) ;
if ( oParts )
{
// Set the e-mail address.
oEMailInfo.Address = oParts[1] ;
// Look for the optional e-mail parameters.
if ( oParts[2] )
{
var oMatch = oParts[2].match( /(^|&)subject=([^&]+)/i ) ;
if ( oMatch ) oEMailInfo.Subject = unescape( oMatch[2] ) ;
oMatch = oParts[2].match( /(^|&)body=([^&]+)/i ) ;
if ( oMatch ) oEMailInfo.Body = unescape( oMatch[2] ) ;
}
}
return oEMailInfo ;
}
oParser.CreateEMailUri = function( address, subject, body )
{
var sBaseUri = 'mailto:' + address ;
var sParams = '' ;
if ( subject.length > 0 )
sParams = '?subject=' + escape( subject ) ;
if ( body.length > 0 )
{
sParams += ( sParams.length == 0 ? '?' : '&' ) ;
sParams += 'body=' + escape( body ) ;
}
return sBaseUri + sParams ;
}
//#### Initialization Code
// oLink: The actual selected link in the editor.
var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
if ( oLink )
FCK.Selection.SelectNode( oLink ) ;
window.onload = function()
{
// Translate the dialog box texts.
oEditor.FCKLanguageManager.TranslatePage(document) ;
// Load the selected link information (if any).
LoadSelection() ;
// Update the dialog box.
SetLinkType( GetE('cmbLinkType').value ) ;
// Show the initial dialog content.
GetE('divInfo').style.display = '' ;
// Activate the "OK" button.
window.parent.SetOkButton( true ) ;
}
function LoadSelection()
{
if ( !oLink ) return ;
var sType = 'url' ;
// Get the actual Link href.
var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
if ( !sHRef || sHRef.length == 0 )
sHRef = oLink.getAttribute( 'href' , 2 ) + '' ;
// TODO: Wait stable version and remove the following commented lines.
// if ( sHRef.startsWith( FCK.BaseUrl ) )
// sHRef = sHRef.remove( 0, FCK.BaseUrl.length ) ;
// Look for a popup javascript link.
var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ;
if( oPopupMatch )
{
GetE('cmbTarget').value = 'popup' ;
sHRef = oPopupMatch[1] ;
FillPopupFields( oPopupMatch[2], oPopupMatch[3] ) ;
SetTarget( 'popup' ) ;
}
// Search for the protocol.
var sProtocol = oRegex.UriProtocol.exec( sHRef ) ;
if ( sProtocol )
{
sProtocol = sProtocol[0].toLowerCase() ;
GetE('cmbLinkProtocol').value = sProtocol ;
// Remove the protocol and get the remainig URL.
var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ;
if ( sProtocol == 'mailto:' ) // It is an e-mail link.
{
sType = 'email' ;
var oEMailInfo = oParser.ParseEMailUrl( sUrl ) ;
GetE('txtEMailAddress').value = oEMailInfo.Address ;
GetE('txtEMailSubject').value = oEMailInfo.Subject ;
GetE('txtEMailBody').value = oEMailInfo.Body ;
}
else // It is a normal link.
{
sType = 'url' ;
GetE('txtUrl').value = sUrl ;
}
}
else // It is another type of link.
{
sType = 'url' ;
GetE('cmbLinkProtocol').value = '' ;
GetE('txtUrl').value = sHRef ;
}
if ( !oPopupMatch )
{
// Get the target.
var sTarget = oLink.target ;
if ( sTarget && sTarget.length > 0 )
{
if ( oRegex.ReserveTarget.test( sTarget ) )
{
sTarget = sTarget.toLowerCase() ;
GetE('cmbTarget').value = sTarget ;
}
else
GetE('cmbTarget').value = 'frame' ;
GetE('txtTargetFrame').value = sTarget ;
}
}
// Update the Link type combo.
GetE('cmbLinkType').value = sType ;
}
//#### Link type selection.
function SetLinkType( linkType )
{
ShowE('divLinkTypeUrl' , (linkType == 'url') ) ;
ShowE('divLinkTypeEMail' , (linkType == 'email') ) ;
if ( !FCKConfig.LinkDlgHideTarget )
window.parent.SetTabVisibility( 'Target' , (linkType == 'url') ) ;
if ( linkType == 'email' )
window.parent.SetAutoSize( true ) ;
}
//#### Target type selection.
function SetTarget( targetType )
{
GetE('tdTargetFrame').style.display = ( targetType == 'popup' ? 'none' : '' ) ;
GetE('tdPopupName').style.display =
GetE('tablePopupFeatures').style.display = ( targetType == 'popup' ? '' : 'none' ) ;
switch ( targetType )
{
case "_blank" :
case "_self" :
case "_parent" :
case "_top" :
GetE('txtTargetFrame').value = targetType ;
break ;
case "" :
GetE('txtTargetFrame').value = '' ;
break ;
}
if ( targetType == 'popup' )
window.parent.SetAutoSize( true ) ;
}
//#### Called while the user types the URL.
function OnUrlChange()
{
var sUrl = GetE('txtUrl').value ;
var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ;
if ( sProtocol )
{
sUrl = sUrl.substr( sProtocol[0].length ) ;
GetE('txtUrl').value = sUrl ;
GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ;
}
else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) )
{
GetE('cmbLinkProtocol').value = '' ;
}
}
//#### Called while the user types the target name.
function OnTargetNameChange()
{
var sFrame = GetE('txtTargetFrame').value ;
if ( sFrame.length == 0 )
GetE('cmbTarget').value = '' ;
else if ( oRegex.ReserveTarget.test( sFrame ) )
GetE('cmbTarget').value = sFrame.toLowerCase() ;
else
GetE('cmbTarget').value = 'frame' ;
}
//#### Builds the javascript URI to open a popup to the specified URI.
function BuildPopupUri( uri )
{
var oReg = new RegExp( "'", "g" ) ;
var sWindowName = "'" + GetE('txtPopupName').value.replace(oReg, "\\'") + "'" ;
var sFeatures = '' ;
var aChkFeatures = document.getElementsByName('chkFeature') ;
for ( var i = 0 ; i < aChkFeatures.length ; i++ )
{
if ( i > 0 ) sFeatures += ',' ;
sFeatures += aChkFeatures[i].value + '=' + ( aChkFeatures[i].checked ? 'yes' : 'no' ) ;
}
if ( GetE('txtPopupWidth').value.length > 0 ) sFeatures += ',width=' + GetE('txtPopupWidth').value ;
if ( GetE('txtPopupHeight').value.length > 0 ) sFeatures += ',height=' + GetE('txtPopupHeight').value ;
if ( GetE('txtPopupLeft').value.length > 0 ) sFeatures += ',left=' + GetE('txtPopupLeft').value ;
if ( GetE('txtPopupTop').value.length > 0 ) sFeatures += ',top=' + GetE('txtPopupTop').value ;
return ( "javascript:void(window.open('" + uri + "'," + sWindowName + ",'" + sFeatures + "'))" ) ;
}
//#### Fills all Popup related fields.
function FillPopupFields( windowName, features )
{
if ( windowName )
GetE('txtPopupName').value = windowName ;
var oFeatures = new Object() ;
var oFeaturesMatch ;
while( ( oFeaturesMatch = oRegex.PopupFeatures.exec( features ) ) != null )
{
var sValue = oFeaturesMatch[2] ;
if ( sValue == ( 'yes' || '1' ) )
oFeatures[ oFeaturesMatch[1] ] = true ;
else if ( ! isNaN( sValue ) && sValue != 0 )
oFeatures[ oFeaturesMatch[1] ] = sValue ;
}
// Update all features check boxes.
var aChkFeatures = document.getElementsByName('chkFeature') ;
for ( var i = 0 ; i < aChkFeatures.length ; i++ )
{
if ( oFeatures[ aChkFeatures[i].value ] )
aChkFeatures[i].checked = true ;
}
// Update position and size text boxes.
if ( oFeatures['width'] ) GetE('txtPopupWidth').value = oFeatures['width'] ;
if ( oFeatures['height'] ) GetE('txtPopupHeight').value = oFeatures['height'] ;
if ( oFeatures['left'] ) GetE('txtPopupLeft').value = oFeatures['left'] ;
if ( oFeatures['top'] ) GetE('txtPopupTop').value = oFeatures['top'] ;
}
//#### The OK button was hit.
function Ok()
{
var sUri ;
switch ( GetE('cmbLinkType').value )
{
case 'url' :
sUri = GetE('txtUrl').value ;
if ( sUri.length == 0 )
{
alert( FCKLang.DlnLnkMsgNoUrl ) ;
return false ;
}
sUri = GetE('cmbLinkProtocol').value + sUri ;
if( GetE('cmbTarget').value == 'popup' )
sUri = BuildPopupUri( sUri ) ;
break ;
case 'email' :
sUri = GetE('txtEMailAddress').value ;
if ( sUri.length == 0 )
{
alert( FCKLang.DlnLnkMsgNoEMail ) ;
return false ;
}
sUri = oParser.CreateEMailUri(
sUri,
GetE('txtEMailSubject').value,
GetE('txtEMailBody').value ) ;
break ;
}
if ( oLink ) // Modifying an existent link.
{
oLink.href = sUri ;
}
else // Creating a new link.
{
oLink = oEditor.FCK.CreateLink( sUri ) ;
if ( ! oLink )
return true ;
}
SetAttribute( oLink, '_fcksavedurl', sUri ) ;
// Target
if( GetE('cmbTarget').value != 'popup' )
SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ;
else
SetAttribute( oLink, 'target', null ) ;
return true ;
}
function SetUrl( url )
{
document.getElementById('txtUrl').value = url ;
OnUrlChange() ;
window.parent.SetSelectedTab( 'Info' ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -