link.jsp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <%@page language="java" pageEncoding="UTF-8"%>
  2. <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  3. <c:set var="ctx" value="${pageContext.request.contextPath}" />
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  5. "http://www.w3.org/TR/html4/loose.dtd">
  6. <html>
  7. <head>
  8. <title></title>
  9. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  10. <script type="text/javascript" src="../internal.js"></script>
  11. <style type="text/css">
  12. *{margin:0;padding:0;color: #838383;}
  13. table{font-size: 12px;margin: 10px;line-height: 30px}
  14. .txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;}
  15. </style>
  16. <script type="text/javascript">
  17. function selectFile(){
  18. FlexUploadDialog({isSingle:true,callback:picCallBack});
  19. }
  20. function FlexUploadDialog(conf) {
  21. if(!conf) conf={};
  22. var url= "${ctx}/platform/system/sysFile/dialog.ht?isSingle=1";
  23. var winArgs="dialogWidth:700px;dialogHeight:500px;help:0;status:0;scroll:0;center:1";
  24. /* var rtn=window.showModalDialog(url,"",winArgs);
  25. if(rtn!=undefined){
  26. if(conf.callback){
  27. var fileIds=rtn.fileIds;
  28. var fileNames=rtn.fileNames;
  29. var filePaths=rtn.filePaths;
  30. var extPath=rtn.extPath;
  31. conf.callback.call(this,fileIds,fileNames,filePaths,extPath);
  32. }
  33. } */
  34. var that =this;
  35. DialogUtil.open({
  36. height:conf.dialogHeight,
  37. width: conf.dialogWidth,
  38. title : '文件上传',
  39. url: url,
  40. isResize: true,
  41. //自定义参数
  42. sucCall:function(rtn){
  43. if(conf.callback){
  44. var fileIds=rtn.fileIds;
  45. var fileNames=rtn.fileNames;
  46. var filePaths=rtn.filePaths;
  47. var extPath=rtn.extPath;
  48. conf.callback.call(that,fileIds,fileNames,filePaths,extPath);
  49. }
  50. }
  51. });
  52. }
  53. function picCallBack(fileIds,fileNames,filePaths){
  54. if(filePaths=="") return;
  55. $G("href").value="${ctx}/platform/system/sysFile/file_" + fileIds +".ht";
  56. };
  57. </script>
  58. </head>
  59. <body>
  60. <table>
  61. <tr>
  62. <td><label for="text"><var id="lang_input_text"></var></label></td>
  63. <td><input class="txt" id="text" type="text" disabled="true"/></td>
  64. </tr>
  65. <tr>
  66. <td><label for="href"> <var id="lang_input_url"></var></label></td>
  67. <td>
  68. <input class="txt" id="href" type="text" />
  69. <a href="javascript:;" onclick="selectFile();"><var id="lang_choose_att"></var></a>
  70. </td>
  71. </tr>
  72. <tr>
  73. <td><label for="title"> <var id="lang_input_title"></var></label></td>
  74. <td><input class="txt" id="title" type="text"/></td>
  75. </tr>
  76. <tr>
  77. <td colspan="2">
  78. <label for="target"><var id="lang_input_target"></var></label>
  79. <input id="target" type="checkbox"/>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td colspan="2" id="msg"></td>
  84. </tr>
  85. </table>
  86. <script type="text/javascript">
  87. var range = editor.selection.getRange(),
  88. link = range.collapsed ? editor.queryCommandValue( "link" ) : editor.selection.getStart(),
  89. url,
  90. text = $G('text'),
  91. rangeLink = domUtils.findParentByTagName(range.getCommonAncestor(),'a',true),
  92. orgText;
  93. link = domUtils.findParentByTagName( link, "a", true );
  94. if(link){
  95. url = link.getAttribute( 'data_ue_src' ) || link.getAttribute( 'href', 2 );
  96. if(rangeLink === link && !link.getElementsByTagName('img').length){
  97. text.removeAttribute('disabled');
  98. orgText = text.value = link[browser.ie ? 'innerText':'textContent'];
  99. }else{
  100. text.setAttribute('disabled','true');
  101. text.value = lang.validLink;
  102. }
  103. }else{
  104. if(range.collapsed){
  105. text.removeAttribute('disabled');
  106. text.value = '';
  107. }else{
  108. text.setAttribute('disabled','true');
  109. text.value = lang.validLink;
  110. }
  111. }
  112. $G("title").value = url ? link.title : "";
  113. $G("href").value = url ? url: '';
  114. $G("target").checked = url && link.target == "_blank" ? true : false;
  115. $focus($G("href"));
  116. function handleDialogOk(){
  117. var href =$G('href').value.replace(/^\s+|\s+$/g, '');
  118. if(href){
  119. if(!hrefStartWith(href,["http","/","ftp://"])) {
  120. //href = "http://" + href;
  121. href =parent.UEDITOR_CONFIG.filePath + href;
  122. }
  123. var obj = {
  124. 'href' : href,
  125. 'target' : $G("target").checked ? "_blank" : '_self',
  126. 'title' : $G("title").value.replace(/^\s+|\s+$/g, ''),
  127. 'data_ue_src':href
  128. };
  129. //修改链接内容的情况太特殊了,所以先做到这里了
  130. //todo:情况多的时候,做到command里
  131. if(orgText && text.value != orgText){
  132. link.innerHTML = text.value;
  133. range.selectNode(link).select()
  134. }
  135. if(range.collapsed){
  136. obj.textValue = text.value;
  137. }
  138. editor.execCommand('link',obj );
  139. dialog.close();
  140. }
  141. }
  142. dialog.onok = handleDialogOk;
  143. $G('href').onkeydown = $G('title').onkeydown = function(evt){
  144. evt = evt || window.event;
  145. if (evt.keyCode == 13) {
  146. handleDialogOk();
  147. return false;
  148. }
  149. };
  150. $G('href').onblur = function(){
  151. if(!hrefStartWith(this.value,["http","/","ftp://"])){
  152. $G("msg").innerHTML = "<span style='color: red'>"+lang.httpPrompt+"</span>";
  153. }else{
  154. $G("msg").innerHTML = "";
  155. }
  156. };
  157. function hrefStartWith(href,arr){
  158. href = href.replace(/^\s+|\s+$/g, '');
  159. for(var i=0,ai;ai=arr[i++];){
  160. if(href.indexOf(ai)==0){
  161. return true;
  162. }
  163. }
  164. return false;
  165. }
  166. </script>
  167. </body>
  168. </html>