You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.4 KiB

3 years ago
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title></title>
  6. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  7. <script type="text/javascript" src="../internal.js"></script>
  8. <style type="text/css">
  9. *{margin:0;padding:0;color: #838383;}
  10. table{font-size: 12px;margin: 10px;line-height: 30px}
  11. .txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;}
  12. </style>
  13. </head>
  14. <body>
  15. <table>
  16. <tr>
  17. <td><label for="text"> <var id="lang_input_text"></var></label></td>
  18. <td><input class="txt" id="text" type="text" disabled="true"/></td>
  19. </tr>
  20. <tr>
  21. <td><label for="href"> <var id="lang_input_url"></var></label></td>
  22. <td><input class="txt" id="href" type="text" /></td>
  23. </tr>
  24. <tr>
  25. <td><label for="title"> <var id="lang_input_title"></var></label></td>
  26. <td><input class="txt" id="title" type="text"/></td>
  27. </tr>
  28. <tr>
  29. <td colspan="2">
  30. <label for="target"><var id="lang_input_target"></var></label>
  31. <input id="target" type="checkbox"/>
  32. </td>
  33. </tr>
  34. <tr>
  35. <td colspan="2" id="msg"></td>
  36. </tr>
  37. </table>
  38. <script type="text/javascript">
  39. editor.setOpt('allowLinkProtocols', ['http:', 'https:', '#', '/', 'ftp:', 'mailto:', 'tel:']);
  40. var allowLinkProtocols = editor.getOpt('allowLinkProtocols');
  41. var range = editor.selection.getRange(),
  42. link = range.collapsed ? editor.queryCommandValue( "link" ) : editor.selection.getStart(),
  43. url,
  44. text = $G('text'),
  45. rangeLink = domUtils.findParentByTagName(range.getCommonAncestor(),'a',true),
  46. orgText;
  47. link = domUtils.findParentByTagName( link, "a", true );
  48. if(link){
  49. url = utils.html(link.getAttribute( '_href' ) || link.getAttribute( 'href', 2 ));
  50. if(rangeLink === link && !link.getElementsByTagName('img').length){
  51. text.removeAttribute('disabled');
  52. orgText = text.value = link[browser.ie ? 'innerText':'textContent'];
  53. }else{
  54. text.setAttribute('disabled','true');
  55. text.value = lang.validLink;
  56. }
  57. }else{
  58. if(range.collapsed){
  59. text.removeAttribute('disabled');
  60. text.value = '';
  61. }else{
  62. text.setAttribute('disabled','true');
  63. text.value = lang.validLink;
  64. }
  65. }
  66. $G("title").value = url ? link.title : "";
  67. $G("href").value = url ? url: '';
  68. $G("target").checked = url && link.target == "_blank" ? true : false;
  69. $focus($G("href"));
  70. function handleDialogOk(){
  71. var href =$G('href').value.replace(/^\s+|\s+$/g, '');
  72. if(href){
  73. if(!hrefStartWith(href, allowLinkProtocols)) {
  74. href = "http://" + href;
  75. }
  76. var obj = {
  77. 'href' : href,
  78. 'target' : $G("target").checked ? "_blank" : '_self',
  79. 'title' : $G("title").value.replace(/^\s+|\s+$/g, ''),
  80. '_href':href
  81. };
  82. //修改链接内容的情况太特殊了,所以先做到这里了
  83. //todo:情况多的时候,做到command里
  84. if(orgText && text.value != orgText){
  85. link[browser.ie ? 'innerText' : 'textContent'] = obj.textValue = text.value;
  86. range.selectNode(link).select()
  87. }
  88. if(range.collapsed){
  89. obj.textValue = text.value;
  90. }
  91. editor.execCommand('link',utils.clearEmptyAttrs(obj) );
  92. dialog.close();
  93. }
  94. }
  95. dialog.onok = handleDialogOk;
  96. $G('href').onkeydown = $G('title').onkeydown = function(evt){
  97. evt = evt || window.event;
  98. if (evt.keyCode == 13) {
  99. handleDialogOk();
  100. return false;
  101. }
  102. };
  103. $G('href').onblur = function(){
  104. if(!hrefStartWith(this.value, allowLinkProtocols)){
  105. $G("msg").innerHTML = "<span style='color: red'>"+lang.httpPrompt+"</span>";
  106. }else{
  107. $G("msg").innerHTML = "";
  108. }
  109. };
  110. function hrefStartWith(href,arr){
  111. href = href.replace(/^\s+|\s+$/g, '');
  112. for(var i=0,ai;ai=arr[i++];){
  113. if(href.indexOf(ai)==0){
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. </script>
  120. </body>
  121. </html>