fck_link.js

来自「简单博客功能实现」· JavaScript 代码 · 共 763 行 · 第 1/2 页

JS
763
字号
		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 ;

		case 'anchor' :
			var sAnchor = GetE('cmbAnchorName').value ;
			if ( sAnchor.length == 0 ) sAnchor = GetE('cmbAnchorId').value ;

			if ( sAnchor.length == 0 )
			{
				alert( FCKLang.DlnLnkMsgNoAnchor ) ;
				return false ;
			}

			sUri = '#' + sAnchor ;
			break ;
	}

	if ( oLink )	// Modifying an existent link.
	{
		oEditor.FCKUndo.SaveUndoStep() ;
		oLink.href = sUri ;
	}
	else			// Creating a new link.
	{
		oLink = oEditor.FCK.CreateLink( sUri ) ;
		if ( ! oLink )
			return true ;
	}

	// Target
	if( GetE('cmbTarget').value != 'popup' )
		SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ;
	else
		SetAttribute( oLink, 'target', null ) ;

	// Advances Attributes
	SetAttribute( oLink, 'id'		, GetE('txtAttId').value ) ;
	SetAttribute( oLink, 'name'		, GetE('txtAttName').value ) ;		// No IE. Set but doesnt't update the outerHTML.
	SetAttribute( oLink, 'dir'		, GetE('cmbAttLangDir').value ) ;
	SetAttribute( oLink, 'lang'		, GetE('txtAttLangCode').value ) ;
	SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ;
	SetAttribute( oLink, 'tabindex'	, ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ;
	SetAttribute( oLink, 'title'	, GetE('txtAttTitle').value ) ;
	SetAttribute( oLink, 'class'	, GetE('txtAttClasses').value ) ;
	SetAttribute( oLink, 'type'		, GetE('txtAttContentType').value ) ;
	SetAttribute( oLink, 'charset'	, GetE('txtAttCharSet').value ) ;

	if ( oEditor.FCKBrowserInfo.IsIE )
		oLink.style.cssText = GetE('txtAttStyle').value ;
	else
		SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ;

	return true ;
}

function BrowseServer()
{
	// Set the browser window feature.
	var iWidth	= FCKConfig.LinkBrowserWindowWidth ;
	var iHeight	= FCKConfig.LinkBrowserWindowHeight ;

	var iLeft = (FCKConfig.ScreenWidth  - iWidth) / 2 ;
	var iTop  = (FCKConfig.ScreenHeight - iHeight) / 2 ;

	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
	sOptions += ",width=" + iWidth ;
	sOptions += ",height=" + iHeight ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	if ( oEditor.FCKBrowserInfo.IsIE )
	{
		// The following change has been made otherwise IE will open the file 
		// browser on a different server session (on some cases):
		// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
		// by Simone Chiaretta.
		var oWindow = oEditor.window.open( FCKConfig.LinkBrowserURL, "FCKBrowseWindow", sOptions ) ;
		oWindow.opener = window ;
    }
    else
		window.open( FCKConfig.LinkBrowserURL, "FCKBrowseWindow", sOptions ) ;
}

function SetUrl( url )
{
	document.getElementById('txtUrl').value = url ;
	OnUrlChange() ;
	window.parent.SetSelectedTab( 'Info' ) ;
}

function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
{
	switch ( errorNumber )
	{
		case 0 :	// No errors
			alert( '文件上传成功!' ) ;
			break ;
		case 1 :	// Custom error
			alert( customMsg ) ;
			return ;
		case 101 :	// Custom warning
			alert( customMsg ) ;
			break ;
		case 201 :
			alert( '文件同名,新文件被改名为:"' + fileName + '"' ) ;
			break ;
		case 202 :
			alert( '非法的文件类型。' ) ;
			return ;
		case 203 :
			alert( "您还没有登陆或登陆超时,请重新登陆。" ) ;
			return ;
			
		case 204 :
			alert( "对不起,您上传的单个文件大小不得超过1MB。" ) ;
			return ;
			
		case 205 :
			alert( "对不起,您的空间已满,请删除部分文件后再试。" ) ;
			return ;
		case 206 :
			alert( "上传失败:非法的文件类型。" ) ;
			return ;
		default :
			alert( '文件上传失败,未知错误: ' + errorNumber ) ;
			return ;
	}

	SetUrl( fileUrl ) ;
	GetE('frmUpload').reset() ;
}

var oUploadAllowedExtRegex	= new RegExp( FCKConfig.LinkUploadAllowedExtensions, 'i' ) ;
var oUploadDeniedExtRegex	= new RegExp( FCKConfig.LinkUploadDeniedExtensions, 'i' ) ;

function CheckUpload()
{
	var sFile = GetE('txtUploadFile').value ;
	
	if ( sFile.length == 0 )
	{
		alert( 'Please select a file to upload' ) ;
		return false ;
	}
	
	if ( ( FCKConfig.LinkUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
		( FCKConfig.LinkUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
	{
		OnUploadCompleted( 202 ) ;
		return false ;
	}
	
	return true ;
}



//=================================================
//=================================================
//=================================================
//=================================================
//==============================================
//==============================================
var tipBox;
var slt;
//获取已经上传的文件列表
function LoadX2FileBrowser()
{
	var div=$("x2FileBrowser");
	div.style.padding="5px";
	div.style.marginTop="20px";
	div.style.lineHeight="150%";

	
	var div2=$se("div");
	div2.innerHTML="您已经上传的文件:";
	div2.style.marginBottom="10px";
	div.appendChild(div2);
	
	tipBox=$se("div");
	tipBox.innerHTML="正在从服务器下载文件列表,请稍候……";
	tipBox.style.marginTop="10px";

	


	slt=$se("select");
	var opt=new Option();
	opt.text="";
	opt.value="";
	slt.options[0]=opt;
	div.appendChild(slt);
	
	var btnSelect=$se("input");
	btnSelect.type="button";
	var btnDelete=$se("input");
	btnDelete.type="button";
	
	btnSelect.value="选择";
	btnDelete.value="删除";
	
	btnSelect.style.marginLeft=btnDelete.style.marginLeft="10px";
	
	div.appendChild(btnSelect);
	div.appendChild(btnDelete);
	
	div.appendChild(tipBox);
	
	btnSelect.onclick=function(){
		if(slt.length>0){
			SetUrl( slt.options[slt.selectedIndex].value) ;
		}else{
			return;
		}
	}
	btnDelete.onclick=deleteFile;
	
	var xmlhttp = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				if(xmlhttp.responseText=="notLogin"){
					tipBox.innerHTML="您还没有登陆或登陆超时,无法获取数据。";
					return;
				}
				tipBox.innerHTML="文件列表获取成功。";
				updateSelect(slt,xmlhttp.responseText);
			}
			else
			{
				tipBox.innerHTML="对不起,数据获取失败,请重试。";
			}
		}
	}
	var url = "../../ajax.aspx?s="+Math.random()+"&oper=getUserFiles";
	xmlhttp.open("get", url, true);
	xmlhttp.send(null);
	

}

function deleteFile(){
	if(slt.length==0)return;
	if(!confirm("确定删除此文件吗?"))return;
	tipBox.innerHTML="正在删除文件,请稍候……";
	var xmlhttp = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				if(xmlhttp.responseText=="notLogin"){
					tipBox.innerHTML="您还没有登陆或登陆超时,无法删除数据。";
					return;
				}
				tipBox.innerHTML="文件删除成功。"+checkSpace(xmlhttp.responseText);
				slt.options[slt.selectedIndex]=null;
				slt.selectedIndex=0;
				
			}
			else
			{
				tipBox.innerHTML="对不起,文件删除失败,请重试。";
			}
		}
	}
	var url = "../../ajax.aspx?s="+Math.random()+"&oper=deleteUserFile&fileName="+escape(slt.options[slt.selectedIndex].text);
	xmlhttp.open("get", url, true);
	xmlhttp.send(null);
}

function checkSpace(size){
	return "";
}

function updateSelect(slt,fileList){
	var arr=fileList.split("|");
	var size=arr[1];
	var s=checkSpace(size);
	tipBox.innerHTML+=s;
	slt.length=0;
	for(var i=2;i<arr.length;i++){
		var np=arr[i].split("*");
		var opt=new Option();
		opt.text=np[0];
		opt.value=np[1];
		slt.options[i-2]=opt;
	}
}
function $se(name){
	return document.createElement(name);
}

function $(name){
	return document.getElementById(name);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?