feckeditor的删除问题

CKEditor无删除文件及文件夹功能,很不方便。本人修改其中代码以便支持其功能

关于FCKEditor版本

你可以在网上搜下这个压缩文件 fckeditor-java-demo-2.4.zip

我们只需修改几处个地方即可,请耐心看完此文,其实没几句话,蓝色字全是要替换的代码!

一、找到: fckeditor/editor/filemanager/browser/default/frmfolders.html FileManager左边的目录

将其中代码替换成以下代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This page shows the list of folders available in the parent folder
 * of the current folder.
-->
<html>
 <head>
  <title>Folders</title>
  <link href="browser.css" type="text/css" rel="stylesheet">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="js/common.js"></script>
  <script type="text/javascript" src="js/syncSubmit.js"></script>
  <script type="text/javascript">

var sActiveFolder ;

var bIsLoaded = false ;
var iIntervalId ;

var oListManager = new Object() ;

oListManager.Init = function()
{
 this.Table = document.getElementById('tableFiles') ;
 this.UpRow = document.getElementById('trUp') ;

 this.TableRows = new Object() ;
}

oListManager.Clear = function()
{
 // Remove all other rows available.
 while ( this.Table.rows.length > 1 )
  this.Table.deleteRow(1) ;

 // Reset the TableRows collection.
 this.TableRows = new Object() ;
}

oListManager.AddItem = function( folderName, folderPath )
{
 // Create the new row.
 var oRow = this.Table.insertRow(-1) ;
 oRow.className = 'FolderListFolder' ;

 // Build the link to view the folder.
 var sLink = '<a href="#" οnclick="OpenFolder(/'' + folderPath + '/');return false;" οncοntextmenu=/'gDeleteFloderPath="'+folderPath+'";return popMenu.show(event,"popMenu")/'>' ;

 // Add the folder icon cell.
 var oCell = oRow.insertCell(-1) ;
 oCell.width = 16 ;
 oCell.innerHTML = sLink + '<img alt="" src="images/spacer.gif" width="16" height="16" border="0"><//a>' ;

 // Add the folder name cell.
 oCell = oRow.insertCell(-1) ;
 oCell.noWrap = true ;
 oCell.innerHTML = '&nbsp;' + sLink + folderName + '<//a>' ;

 this.TableRows[ folderPath ] = oRow ;
}

oListManager.ShowUpFolder = function( upFolderPath )
{
 this.UpRow.style.display = ( upFolderPath != null ? '' : 'none' ) ;

 if ( upFolderPath != null )
 {
  document.getElementById('linkUpIcon').onclick = document.getElementById('linkUp').onclick = function()
  {
   LoadFolders( upFolderPath ) ;
   return false ;
  }
 }
}

function CheckLoaded()
{
 if ( window.top.IsLoadedActualFolder
  && window.top.IsLoadedCreateFolder
  && window.top.IsLoadedUpload
  && window.top.IsLoadedResourcesList )
 {
  window.clearInterval( iIntervalId ) ;
  bIsLoaded = true ;
  OpenFolder( sActiveFolder ) ;
 }
}

function OpenFolder( folderPath )
{
 sActiveFolder = folderPath ;

 if ( ! bIsLoaded )
 {
  if ( ! iIntervalId )
   iIntervalId = window.setInterval( CheckLoaded, 100 ) ;
  return ;
 }

 // Change the style for the select row (to show the opened folder).
 for ( var sFolderPath in oListManager.TableRows )
 {
  oListManager.TableRows[ sFolderPath ].className =
   ( sFolderPath == folderPath ? 'FolderListCurrentFolder' : 'FolderListFolder' ) ;
 }

 // Set the current folder in all frames.
 window.parent.frames['frmActualFolder'].SetCurrentFolder( oConnector.ResourceType, folderPath ) ;
 window.parent.frames['frmCreateFolder'].SetCurrentFolder( oConnector.ResourceType, folderPath ) ;
 window.parent.frames['frmUpload'].SetCurrentFolder( oConnector.ResourceType, folderPath ) ;

 // Load the resources list for this folder.
 window.parent.frames['frmResourcesList'].LoadResources( oConnector.ResourceType, folderPath ) ;
}

function LoadFolders( folderPath )
{
 // Clear the folders list.
 oListManager.Clear() ;

 // Get the parent folder path.
 var sParentFolderPath ;
 if ( folderPath != '/' )
  sParentFolderPath = folderPath.substring( 0, folderPath.lastIndexOf( '/', folderPath.length - 2 ) + 1 ) ;

 // Show/Hide the Up Folder.
 oListManager.ShowUpFolder( sParentFolderPath ) ;

 if ( folderPath != '/' )
 {
  sActiveFolder = folderPath ;
  oConnector.CurrentFolder = sParentFolderPath ;
  oConnector.SendCommand( 'GetFolders', null, GetFoldersCallBack ) ;
 }
 else
  OpenFolder( '/' ) ;
}

function GetFoldersCallBack( fckXml )
{
 if ( oConnector.CheckError( fckXml ) != 0 )
  return ;

 // Get the current folder path.
 var oNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
 var sCurrentFolderPath = oNode.attributes.getNamedItem('path').value ;

 var oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;

 for ( var i = 0 ; i < oNodes.length ; i++ )
 {
  var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
  oListManager.AddItem( sFolderName, sCurrentFolderPath + sFolderName + '/' ) ;
 }

 OpenFolder( sActiveFolder ) ;
}

function SetResourceType( type )
{
 oConnector.ResourceType = type ;
 LoadFolders( '/' ) ;
}

window.onload = function()
{
 /*delete添加*/
 document.onclick =function(){
 popMenu.hidden("popMenu")};
 
 oListManager.Init() ;
 LoadFolders( '/' ) ;
 
}
/**
 *@author zh_CN
 
 */
 var popMenu = {
 
 show : function(evt, popMenuTargetId) {
  var event = window.event || evt;
  var x = document.body.clientWidth - event.clientX;
  var y = document.body.clientHeight - event.clientY;
  var popMenuTarget = document.getElementById(popMenuTargetId);
  if (x < popMenuTarget.offsetWidth) {
   popMenuTarget.style.left = document.body.scrollLeft + event.clientX
     - popMenuTarget.offsetWidth;

  } else
   popMenuTarget.style.left = document.body.scrollLeft + event.clientX;
  if (y < popMenuTarget.offsetHeight) {
   popMenuTarget.style.top = document.body.scrollTop + event.clientY
     - popMenuTarget.offsetHeight;
  } else
   popMenuTarget.style.top = document.body.scrollTop + event.clientY;
  popMenuTarget.style.visibility = "visible";
  return false;
 },
 hidden : function(popMenuTargetId) {
  /* 隐藏菜单 */
  var popMenuTarget = document.getElementById(popMenuTargetId);
  popMenuTarget.style.visibility = "hidden";
 },
 highLightEvent : function(evt) {
  /* 菜单高亮效果 */
  var event = window.event || evt;
  var element = event.srcElement || event.target;
  if (element.className == "popMenuItem") {
   element.style.backgroundColor = "#84C1FF";
   element.style.color = "white";
  }
 },
 lowLightEvent : function(evt) {
  /* 菜单高亮还原效果 */
  var event = window.event || evt;
  var element = event.srcElement || event.target;
  if (element.className == "popMenuItem") {
   element.style.backgroundColor = "";
   element.style.color = "black";
  }
 }
}
  
    var gDeleteFloderPath=null;
    function GetUrlParam( paramName )
  {
   var oRegex = new RegExp( '[/?&]' + paramName + '=([^&]+)', 'i' ) ;
   var oMatch = oRegex.exec( window.top.location.search ) ;
  
   if ( oMatch && oMatch.length > 1 )
    return decodeURIComponent( oMatch[1] ) ;
   else
    return '' ;
  }
  var GetBasePath=function(){
   var con=GetUrlParam( 'Connector' );
   return con.split("fckeditor")[0].toString();
  }
    var deleteFloder=function(){
      gDeleteFloderPath="/"+GetUrlParam("Type")+gDeleteFloderPath;
      

alert("提交的路径名:"+gDeleteFloderPath);

    LoadFolders(sActiveFolder);
   
    }
  </script>
  <style>
    .popMenu {  
     BORDER: black 1px solid;
     VISIBILITY: hidden;
     WIDTH: 80px; CURSOR: default;
     LINE-HEIGHT: 19px;
     FONT-FAMILY: "宋体";
     font-size:12px;
     POSITION: absolute;
     BACKGROUND-COLOR: menu;
     TEXT-ALIGN: left;
     padding:1px;  
  }
  .popMenuItem { 
  border:1px;
     padding:1 5 0 18;
  margin:0px;
  display:block;
  }
  </style>
 </head>
 <body class="FileArea">
  <table id="tableFiles" cellSpacing="0" cellPadding="0" width="100%"
   border="0">
   <tr id="trUp" style="DISPLAY: none">
    <td width="16">
     <a id="linkUpIcon" href="#"><img alt=""
       src="images/FolderUp.gif" width="16" height="16" border="0">
     </a>
    </td>
    <td nowrap width="100%">
     &nbsp;
     <a id="linkUp" href="#">..</a>
    </td>
   </tr>
  </table>
  <div class="popMenu" id="popMenu"
   οnmοuseοver="popMenu.highLightEvent(event)"
   οnmοuseοut="popMenu.lowLightEvent(event)">
   <DIV class=popMenuItem οnclick='deleteFloder();'>
    删除
   </div>
  </div>
 </body>
</html>

 

 

二、找到fckeditor/editor/filemanager/browser/default/frmresourceslist.html 右边的浏览文件夹及文件页面

替换为下面代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This page shows all resources available in a folder in the File Browser.
-->
<html>
 <head>
  <title>Resources</title>
  <link href="browser.css" type="text/css" rel="stylesheet">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="js/common.js"></script>
  <script type="text/javascript" src="js/syncSubmit.js"></script>
  <script type="text/javascript">
 if(window.HTMLElement) {
    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
        var r=this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df=r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df,this);
        return sHTML;
        });

    HTMLElement.prototype.__defineGetter__("outerHTML",function(){
     var attr;
        var attrs=this.attributes;
        var str="<"+this.tagName.toLowerCase();
        for(var i=0;i<attrs.length;i++){
            attr=attrs[i];
            if(attr.specified)
                str+=" "+attr.name+'="'+attr.value+'"';
            }
        if(!this.canHaveChildren)
            return str+">";
        return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
        });
       
 HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
  switch(this.tagName.toLowerCase()){
            case "area":
            case "base":
         case "basefont":
            case "col":
            case "frame":
            case "hr":
            case "img":
            case "br":
            case "input":
            case "isindex":
            case "link":
            case "meta":
            case "param":
            return false;
        }
        return true;

     });
}

 

  
  
  
  
var popMenuHtmlStr;
var oListManager = new Object() ;

oListManager.Clear = function()
{
 document.body.innerHTML = '' ;
}

function ProtectPath(path)
{
 path = path.replace( g, '') ;
 path = path.replace( /'/g, '///'') ;
 return path ;
}

oListManager.GetFolderRowHtml = function( folderName, folderPath )
{
 // Build the link to view the folder.
 var path=ProtectPath( folderPath )
 var sLink = '<a href="#" οnclick="OpenFolder(/'' + ProtectPath( folderPath ) + '/');return false;" οncοntextmenu=/'gDeleteFloderPath="'+path+'";return popMenu.show(event,"popMenu")/'>' ;

 return '<tr>' +
   '<td width="16">' +
    sLink +
    '<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><//a>' +
   '<//td><td nowrap colspan="2">&nbsp;' +
    sLink +
    folderName +
    '<//a>' +
  '<//td><//tr>' ;
}

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
 // Build the link to view the folder.
 var path=ProtectPath( fileUrl )
 var sLink = '<a href="#" οnclick="OpenFile(/'' + path + '/');return false;" οncοntextmenu=/'gDeleteFloderPath="'+path+'";return popMenu.show(event,"popMenu")/'>' ;

 // Get the file icon.
 var sIcon = oIcons.GetIcon( fileName ) ;

 return '<tr>' +
   '<td width="16">' +
    sLink +
    '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><//a>' +
   '<//td><td>&nbsp;' +
    sLink +
    fileName +
    '<//a>' +
   '<//td><td align="right" nowrap>&nbsp;' +
    fileSize +
    ' KB' +
  '<//td><//tr>' ;
}

function OpenFolder( folderPath )
{
 // Load the resources list for this folder.
 window.parent.frames['frmFolders'].LoadFolders( folderPath ) ;
}

function OpenFile( fileUrl )
{
 window.top.opener.SetUrl( encodeURI( fileUrl ).replace( '#', '%23' ) ) ;
 window.top.close() ;
 window.top.opener.focus() ;
}

function LoadResources( resourceType, folderPath )
{
 oListManager.Clear() ;
 oConnector.ResourceType = resourceType ;
 oConnector.CurrentFolder = folderPath ;
 oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
 LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function GetFoldersAndFilesCallBack( fckXml )
{
 if ( oConnector.CheckError( fckXml ) != 0 )
  return ;

 // Get the current folder path.
 var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
 if ( oFolderNode == null )
 {
  alert( 'The server didn/'t reply with a proper XML data. Please check your configuration.' ) ;
  return ;
 }
 var sCurrentFolderPath = oFolderNode.attributes.getNamedItem('path').value ;
 var sCurrentFolderUrl = oFolderNode.attributes.getNamedItem('url').value ;

// var dTimer = new Date() ;
 var oHtml = new StringBuilder( popMenuHtmlStr+'<table id="tableFiles" cellspacing="1" cellpadding="0" width="100%" border="0">' ) ;

 // Add the Folders.
 var oNodes ;
 oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
 for ( var i = 0 ; i < oNodes.length ; i++ )
 {
  var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
  oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
 }

 // Add the Files.
 oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
 for ( var j = 0 ; j < oNodes.length ; j++ )
 {
  var oNode = oNodes[j] ;
  var sFileName = oNode.attributes.getNamedItem('name').value ;
  var sFileSize = oNode.attributes.getNamedItem('size').value ;

  // Get the optional "url" attribute. If not available, build the url.
  var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ;
  var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : sCurrentFolderUrl + sFileName ;

  oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) ) ;
 }

 oHtml.Append( '<//table>' ) ;
 document.body.innerHTML = oHtml.ToString() ;

// window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;

}
/**
 *author zhcn
 */

 var popMenu = {
 
 show : function(evt, popMenuTargetId) {
  var event = window.event || evt;
  var x = document.body.clientWidth - event.clientX;
  var y = document.body.clientHeight - event.clientY;
  var popMenuTarget = document.getElementById(popMenuTargetId.toString());
  if (x < popMenuTarget.offsetWidth) {
   popMenuTarget.style.left = document.body.scrollLeft + event.clientX
     - popMenuTarget.offsetWidth;

  } else
   popMenuTarget.style.left = document.body.scrollLeft + event.clientX;
  if (y < popMenuTarget.offsetHeight) {
   popMenuTarget.style.top = document.body.scrollTop + event.clientY
     - popMenuTarget.offsetHeight;
  } else
   popMenuTarget.style.top = document.body.scrollTop + event.clientY;
  popMenuTarget.style.visibility = "visible";
  return false;
 },
 hidden : function(popMenuTargetId) {
  /* 隐藏菜单 */
  var popMenuTarget = document.getElementById(popMenuTargetId);
  popMenuTarget.style.visibility = "hidden";
 },
 highLightEvent : function(evt) {
  /* 菜单高亮效果 */
  var event = window.event || evt;
  var element = event.srcElement || event.target;
  if (element.className == "popMenuItem") {
   element.style.backgroundColor = "#84C1FF";
   element.style.color = "white";
  }
 },
 lowLightEvent : function(evt) {
  /* 菜单高亮还原效果 */
  var event = window.event || evt;
  var element = event.srcElement || event.target;
  if (element.className == "popMenuItem") {
   element.style.backgroundColor = "";
   element.style.color = "black";
  }
 }
}
  
   var gDeleteFloderPath=null;
    function GetUrlParam( paramName )
  {
   var oRegex = new RegExp( '[/?&]' + paramName + '=([^&]+)', 'i' ) ;
   var oMatch = oRegex.exec( window.top.location.search ) ;
  
   if ( oMatch && oMatch.length > 1 )
    return decodeURIComponent( oMatch[1] ) ;
   else
    return '' ;
  }
  var GetBasePath=function(){
   var con=GetUrlParam( 'Connector' );
   return con.split("fckeditor")[0].toString();
  }
    var deleteFloder=function(){
      gDeleteFloderPath="/"+GetUrlParam("Type")+gDeleteFloderPath;

alert("提交的路径名:"+gDeleteFloderPath);
                Refresh();
  
     
    }
   
    
  
window.onload = function()
{
 popMenuHtmlStr=document.getElementById("popMenu").outerHTML;
 window.top.IsLoadedResourcesList = true ;
document.onclick =function(){
 popMenu.hidden("popMenu")};

}
 </script>
  <style>
    .popMenu {BORDER: black 1px solid;VISIBILITY: hidden; WIDTH: 80px; CURSOR: default;
     LINE-HEIGHT: 19px;
     FONT-FAMILY: "宋体";
     font-size:12px;
     POSITION: absolute;
     BACKGROUND-COLOR: menu;
     TEXT-ALIGN: left;
     padding:1px;  
  }
  .popMenuItem { 
  border:1px;
     padding:1 5 0 18;
  margin:0px;
  display:block;
  }
  </style>
 </head>
 <body class="FileArea" width="100%">
  <div class="popMenu" id="popMenu"
   οnmοuseοver="popMenu.highLightEvent(event)"
   οnmοuseοut="popMenu.lowLightEvent(event)">
   <DIV class=popMenuItem οnclick='deleteFloder();'>
    删除
   </div>
  </div>
 </body>
</html>

 

 

三.具体实现及如何删除请看以下说明

你实现一个Ajax的提交代码把两张页面中的

alert("提交的路径名:"+gDeleteFloderPath);

替换掉就行了

gDeleteFloderPath这就是你所需要的删除文件夹的路径

这个第三条我也不会写。如果有强人来看请帮忙写一下。谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值