主题: file_manager 有直接插件的形式吗? |
作者: mickypc, 发布日期: 2010-05-22 17:12:19, 浏览数: 6538 |
file_manager好像只有在上传图片的插件中的浏览服务器调用了, 在link的插件里能不能调用了呢?或者直接调用flie_manager的插件呢? |
作者: Roddy, 发布日期: 2010-05-23 12:25:45 |
1. 在link里使用,请参考plugins/image/image.html里的代码,地址inputbox的id必须是url。 2. 直接打开请参考以下代码。 KE.util.openFileManager = function(id) { var fileManager = new KE.dialog({ id : id, cmd : 'file_manager', file : 'file_manager/file_manager.html?id=' + id + '&ver=' + KE.version, width : 500, height : 400, loadingMode : true, title : '浏览服务器', noButton : '取消' }); fileManager.show(); }; |
回复 |
作者: mickypc, 发布日期: 2010-05-25 10:13:37 |
谢谢,我把改过的代码,贴出来,希望对别人有用。 kindeditor/plugins/link/link.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Flash</title> <style type="text/css" rel="stylesheet"> body { font-size:12px; font-family: "sans serif",tahoma,verdana,helvetica; margin:0; background-color:#F0F0EE; overflow:hidden; } label { cursor:pointer; } .main { margin: 10px; } .tab-navi { width:100%; overflow:hidden; margin-bottom:10px; } .tab-navi ul { list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; display:block; float:left; width:100%; border-bottom:1px solid #888888; } .tab-navi li { border: 1px solid #888888; margin:0 -1px -1px 0; float: left; padding: 5px; background-color: #F0F0EE; text-align: center; width: 120px; font-weight: normal; cursor: pointer; } .tab-navi li.selected { background-color: #E0E0E0; font-weight: bold; cursor: default; } .table { list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; display:block; } .table li { padding:0; margin-bottom:10px; display:list-item; line-height:1.5; } .table li label { font-weight:bold; } .table li input { vertical-align:middle; } .table li img { vertical-align:middle; } </style> <script type="text/javascript"> var KE = parent.KE; location.href.match(/\?id=([\w-]+)/i); var id = RegExp.$1; var fileManager = null; var allowUpload = (typeof KE.g[id].allowUpload == 'undefined') ? true : KE.g[id].allowUpload; var allowFileManager = (typeof KE.g[id].allowFileManager == 'undefined') ? false : KE.g[id].allowFileManager; var referMethod = (typeof KE.g[id].referMethod == 'undefined') ? '' : KE.g[id].referMethod; var fileUploadJson = (typeof KE.g[id].imageUploadJson == 'undefined') ? '../../php/upload_json.php' : KE.g[id].fileUploadJson; KE.event.ready(function() { var hyperLink = KE.$('url', document); var linkType = KE.$('linkType', document); var linkTitle = KE.$('imgTitle', document); var typeBox = KE.$('type', document); var fileBox = KE.$('myFile', document); var tabNavi = KE.$('tabNavi', document); var viewServer = KE.$('viewServer', document); var liList = tabNavi.getElementsByTagName('li'); var selectTab = function(num) { for (var i = 0, len = liList.length; i < len; i++) { var li = liList[i]; if (i === num) { li.className = 'selected'; li.onclick = null; } else { if (allowUpload) { li.className = ''; li.onclick = (function (i) { return function() { if (!fileManager) selectTab(i); }; })(i); } else { li.parentNode.removeChild(li); } } KE.$('tab' + (i + 1), document).style.display = 'none'; } typeBox.value = num + 1; KE.$('tab' + (num + 1), document).style.display = ''; } if (!allowFileManager) { viewServer.parentNode.removeChild(viewServer); hyperLink.style.width = '300px'; } selectTab(0); var linkNode = KE.plugin['link'].getSelectedNode(id); if (linkNode) { var tempDiv = KE.$$('div', KE.g[id].iframeDoc); tempDiv.appendChild(linkNode.cloneNode(false)); var linkHtml = tempDiv.innerHTML; var src = linkNode.href; if (linkHtml.match(/kesrc="([^"]+)"/i)) src = RegExp.$1; var target = linkNode.target; hyperLink.value = src; linkType.value = target == '_blank' ? target : ''; var range = KE.g[id].keRange; range.selectTextNode(linkNode); KE.g[id].keSel.addRange(range); } KE.event.add(viewServer, 'click', function () { if (fileManager) return false; fileManager = new KE.dialog({ id : id, cmd : 'file_manager', file : 'file_manager/file_manager.html?id=' + id + '&ver=' + KE.version +'&type=file', width : 500, height : 400, loadingMode : true, title : '浏览服务器', noButton : '取消', afterHide : function() { fileManager = null; } }); fileManager.show(); }); KE.event.add(fileBox, 'change', function () { var filename = fileBox.value; var i = filename.lastIndexOf('\\'); if (i != -1) { filename = filename.substring(i+1); } linkTitle.value = filename; }); KE.$('uploadForm', document).action = fileUploadJson; KE.$('referMethod', document).value = referMethod; KE.util.hideLoadingPage(id); }, window, document); </script> </head> <body> <div class="main"> <div id="tabNavi" class="tab-navi"> <ul> <li>网络上的链接</li> <li>电脑里的文件</li> </ul> </div> <iframe name="uploadIframe" id="uploadIframe" style="display:none;"></iframe> <input type="hidden" id="type" name="type" value="" /> <form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data" target="uploadIframe"> <input type="hidden" id="editorId" name="id" value="" /> <input type="hidden" id="referMethod" name="referMethod" value="" /> <ul class="table"> <li> <div id="tab1" style="display:none;"> <label for="url">URL地址</label> <input type="text" id="url" name="url" value="http://" style="width:230px" /> <input type="button" id="viewServer" name="viewServer" value="浏览..." /> </div> <div id="tab2" style="display:none;"> <label for="myFile">文件地址</label> <input type="file" id="myFile" name="myFile" style="width:300px;"/> <br><span style="font-size: 12px;">注意:上传的文件会存到您的网络硬盘中,如果您在网络硬盘中删除了该文件,此链接将会失效。</span> </div> </li> <li> <label for="imgTitle">显示文字</label> <input id="imgTitle" name="imgTitle" style="width:300px"> </li> <li> <label for="linkType">打开类型</label> <select id="linkType" name="linkType"> <option value="_blank">新窗口</option> <option value="">当前窗口</option> </select> </li> </ul> </form> </div> </body> </html> kindeditor.js KE.plugin['link'] = { getSelectedNode : function(id) { var g = KE.g[id]; var range = g.keRange; var startNode = range.startNode; var startPos = range.startPos; var endNode = range.endNode; var endPos = range.endPos; var inlineTagHash = KE.util.arrayToHash(g.inlineTags); var findLinkNode = function(node) { while (node) { if (node.nodeType == 1) { var tagName = node.tagName.toLowerCase(); if (tagName == 'a') return node; } node = node.parentNode; } return null; }; var startLink = findLinkNode(startNode); var endLink = findLinkNode(endNode); if (startLink && endLink && startLink === endLink) { return startLink; } }, init : function(id) { var self = this; KE.g[id].contextmenuItems.push({ text : KE.lang['editLink'], click : function(id, menu) { KE.util.select(id); menu.hide(); self.click(id); }, cond : function(id) { return self.getSelectedNode(id); } }); }, click : function(id) { KE.util.selection(id); this.dialog = new KE.dialog({ id : id, cmd : 'link', file : 'link/link.html?id=' + id + '&ver=' + KE.version, width : 400, height : 180, loadingMode : true, title : KE.lang['link'], yesButton : KE.lang['yes'], noButton : KE.lang['no'] }); this.dialog.show(); }, exec : function(id) { var self = this; var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe); var type = KE.$('type', dialogDoc).value; var target = KE.$('linkType', dialogDoc).value; var title = KE.$('imgTitle', dialogDoc).value; if (type == 2) { KE.$('editorId', dialogDoc).value = id; var uploadIframe = KE.$('uploadIframe', dialogDoc); KE.util.showLoadingPage(id); var onloadFunc = function() { KE.event.remove(uploadIframe, 'load', onloadFunc); var uploadDoc = KE.util.getIframeDoc(uploadIframe); var data = KE.util.parseJson(uploadDoc.body.innerHTML); KE.util.hideLoadingPage(id); if (typeof data === 'object' && 'error' in data) { if (data.error === 0) { if (title == '') title = data.url; self.insert(id, data.url, title, target); } else { alert(data.message); return false; } } }; KE.event.add(uploadIframe, 'load', onloadFunc); dialogDoc.uploadForm.submit(); return; } else { var url = KE.$('url', dialogDoc).value; if (title == '') title = url; this.insert(id, url, title, target); } }, insert : function(id, url, title, target) { var g = KE.g[id]; KE.util.select(id); var range = g.keRange; var startNode = range.startNode; var endNode = range.endNode; var iframeDoc = g.iframeDoc; if (!url.match(/.+/) || url.match(/^\w+:\/\/\/?$/)) { alert(KE.lang['invalidUrl']); window.focus(); this.dialog.yesButton.focus(); return false; } var node = range.getParentElement(); while (node) { if (node.tagName.toLowerCase() == 'a' || node.tagName.toLowerCase() == 'body') break; node = node.parentNode; } node = node.parentNode; var isItem = (startNode.nodeType == 1 && startNode === endNode); var isEmpty = !isItem; if (!isItem) isEmpty = KE.browser.IE ? g.range.text === '' : g.range.toString() === ''; if (isEmpty) { var html = '<a href="' + url + '"'; if (target) html += ' target="' + target + '"'; html += '>' + title + '</a>'; KE.util.insertHtml(id, html); } else { iframeDoc.execCommand('createlink', false, '__ke_temp_url__'); var arr = node.getElementsByTagName('a'); for (var i = 0, l = arr.length; i < l; i++) { if (arr[i].href.match(/\/?__ke_temp_url__$/)) { arr[i].href = url; arr[i].setAttribute('kesrc', url); if (target) arr[i].target = target; } } if (KE.browser.WEBKIT && isItem && startNode.tagName.toLowerCase() == 'img') { var parent = startNode.parentNode; if (parent.tagName.toLowerCase() != 'a') { var a = KE.$$('a', iframeDoc); parent.insertBefore(a, startNode); a.appendChild(startNode); parent = a; } parent.href = url; parent.setAttribute('kesrc', url); if (target) parent.target = target; g.keSel.addRange(range); } } KE.history.add(id); KE.layout.hide(id); KE.util.focus(id); } }; |
回复 |