`

FCKEditor增加带确认的“删除”功能和图片预览功能

阅读更多

知识无界限,和大家一起分享。

增加"删除"功能

【frmresourceslist.html】

<script src="js/jquery-1.4.4.js" type="text/javascript"></script>


oListManager.GetFileRowHtml = function (fileName, fileUrl, fileSize) {
// Build the link to view the folder.
var sLink = '<a id="aLink" href="#" onclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;" alt="' + ProtectPath(fileUrl) + '" onmouseover="$(\'#ShowImg img\').attr(\'src\',\'' + ProtectPath(fileUrl) + '\');$(\'#ShowImg\').removeClass(\'hide\');" onmouseout="$(\'#ShowImg img\').attr(\'src\',\'images/loading.gif\');$(\'#ShowImg\').addClass(\'hide\');">';
//var sLink = '<a href="#" mce_href="#" onclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;">';

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

return '<tr>' + '<td width="16">' + sLink + '<img alt="" src="images/icons/' + sIcon + '.gif" mce_src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"> <\/a>' +
'<\/td><td> ' + sLink + fileName +
'<\/a> <a href="#" mce_href="#" onclick="if(confirm(\'您确定要删除吗?\'))deleteFile(\'' + ProtectPath(fileUrl) + '\');else return false;" style="color: #FF9933;" mce_style="color: #FF9933;"> 删除 <\/a>' + '<\/td><td align="right" nowrap> ' + fileSize + ' KB' + '<\/td><\/tr>';
}

【common.js】
//***************************** 图片删除功能 (感谢原作者)***************************************
var req; //定义变量,用来创建xmlhttprequest对象

//产生不重复的随机数
var rn = Math.ceil(Math.random() * 1000000);
var rnch = rn;

function rndnum() {
while (rn == rnch) rn = Math.ceil(Math.random() * 1000000);
rnch = rn;
return rn;
}

// 删除文件,Ajax开始
function deleteFile(file) {
var url = "FCKdel_file.aspx?filePath=" + escape(file) + "&UD=" + rndnum(); //要请求的服务端地址
if (window.XMLHttpRequest) //非IE浏览器及IE7(7.0及以上版本),用xmlhttprequest对象创建
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) //IE(6.0及以下版本)浏览器用activexobject对象创建,如果用户浏览器禁用了ActiveX,可能会失败.
{
req = new ActiveXObject("Microsoft.XMLHttp");
}

if (req) //成功创建xmlhttprequest
{
req.open("GET", url, true); //与服务端建立连接(请求方式post或get,地址,true表示异步)
req.onreadystatechange = callback; //指定回调函数
req.send(null); //发送请求
}
}

function callback() {
Refresh(); //刷新一下
}

增加预览功能

【frmresourceslist.html】

oHtml.Append('<div id="ShowImg" class="hide"><img src="images/loading.gif" width="200px" height="150px" alt="" /></div>');

【browser.css】

#ShowImg
{
border: 1px solid #D3D2BA;
background-color: #fff;
position: absolute;
top: 20px;
left: 300px;
padding:3px;
}

.hide
{
display:none;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics