Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

anchor.html 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title></title>
  7. <style type="text/css">
  8. *{color: #838383;margin: 0;padding: 0}
  9. html,body {font-size: 12px;overflow: hidden; }
  10. .content{padding:5px 0 0 15px;display: flex;flex-direction: row;align-items: center;}
  11. .div-label{display: flex;flex-direction: row;align-items: center;}
  12. .div-label label{display: flex;flex-direction: row;align-items: center;margin-right: 10px;cursor: pointer;}
  13. .div-label label span{margin-left: 2px;}
  14. input {
  15. width: 210px;
  16. line-height: 20px;
  17. white-space: nowrap;
  18. display: inline-block;
  19. height: 20px;
  20. overflow: hidden;
  21. cursor: text;
  22. font-size: 13px;
  23. padding: 4px 6px;
  24. resize: none;
  25. margin-left: 4px;
  26. color: #555555;
  27. background-color: #FFF;
  28. border: solid 1px #eee;
  29. }
  30. input:focus {
  31. color: #33464F;
  32. background-color: #fff;
  33. border: solid 1px #eee;
  34. border-color: #eee;
  35. box-shadow: 0 0 0 1px rgba(51,152,204,0.5) !important;
  36. outline: 0 none;
  37. }
  38. input[type="radio"] {
  39. width: 13px;
  40. height: 21px;
  41. line-height: 21px;
  42. margin-left: 4px;
  43. cursor: pointer;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div class="content">
  49. <span><var id="lang_input_anchorName"></var></span><input id="anchorName" value="" />
  50. </div>
  51. <div class="content" style="margin-top: 5px;">
  52. <span>锚点用途:</span>
  53. <div class="div-label">
  54. <label><input type="radio" name="anchorUse" value="1" onclick="anchorUseClick(this);"><span>内部关联</span></label>
  55. <label><input type="radio" name="anchorUse" value="2" onclick="anchorUseClick(this);" checked="checked"><span>目录大纲</span></label>
  56. <label><a href="javascript:void(0);" onclick="click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid=30644&origin_eycms=1','百度编辑器的锚点用法教程')" style="text-decoration: none;">(教程)</a></label>
  57. </div>
  58. </div>
  59. <div class="content" id="anchorUse_2" style="margin-top: 5px; display: none;">
  60. <span>目录层级:</span>
  61. <div class="div-label">
  62. <label><input type="radio" name="anchorStyle" value="h2" checked="checked"><span>一级</span></label>
  63. <label><input type="radio" name="anchorStyle" value="h3"><span>二级</span></label>
  64. </div>
  65. </div>
  66. <script type="text/javascript" src="../internal.js"></script>
  67. <script type="text/javascript">
  68. var anchorInput = $G('anchorName'),
  69. node = editor.selection.getRange().getClosedNode();
  70. if(node && node.tagName == 'IMG' && (node = node.getAttribute('anchorname'))){
  71. anchorInput.value = node;
  72. }
  73. if (2 == document.querySelector('input[name="anchorUse"]:checked').value) {
  74. document.getElementById('anchorUse_2').style.display = "flex";
  75. } else {
  76. document.getElementById('anchorUse_2').style.display = "none";
  77. }
  78. function anchorUseClick(obj)
  79. {
  80. var anchorUse = obj.value;
  81. if (2 == anchorUse) {
  82. document.getElementById('anchorUse_2').style.display = "flex";
  83. } else {
  84. document.getElementById('anchorUse_2').style.display = "none";
  85. }
  86. }
  87. anchorInput.onkeydown = function(evt){
  88. evt = evt || window.event;
  89. if(evt.keyCode == 13){
  90. var anchorValue = anchorInput.value.trim();
  91. if (!anchorValue) {
  92. alert('锚点名字不能为空');
  93. anchorInput.focus();
  94. return false;
  95. }
  96. editor.execCommand('anchor', anchorValue);
  97. if (2 == document.querySelector('input[name="anchorUse"]:checked').value) {
  98. var anchorStyle = document.querySelector('input[name="anchorStyle"]:checked').value;
  99. appendHx(anchorStyle);
  100. }
  101. dialog.close();
  102. domUtils.preventDefault(evt)
  103. }
  104. };
  105. dialog.onok = function (){
  106. var anchorValue = anchorInput.value.trim();
  107. if (!anchorValue) {
  108. alert('锚点名字不能为空');
  109. anchorInput.focus();
  110. return false;
  111. }
  112. editor.execCommand('anchor', anchorValue);
  113. if (2 == document.querySelector('input[name="anchorUse"]:checked').value) {
  114. var anchorStyle = document.querySelector('input[name="anchorStyle"]:checked').value;
  115. appendHx(anchorStyle);
  116. }
  117. dialog.close();
  118. };
  119. $focus(anchorInput);
  120. // 选中锚点的文本进行段落格式化(h2/h3/h4/h5/h6)
  121. function appendHx(anchorStyle) {
  122. editor.execCommand('paragraph',anchorStyle);
  123. }
  124. // 选中文本自动出现在锚点输入框里
  125. function getText() {
  126. // 当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
  127. var range = editor.selection.getRange();
  128. range.select();
  129. var txt = editor.selection.getText();
  130. if (txt) {
  131. anchorInput.value = txt;
  132. }
  133. }
  134. // 获取选中的文本到锚点里
  135. getText();
  136. </script>
  137. <script type="text/javascript" src="../../third-party/jquery-1.10.2.min.js"></script>
  138. <script type="text/javascript" src="../../../layer-v3.1.0/layer.js"></script>
  139. <script type="text/javascript">
  140. function click_to_eyou_1575506523(url,title,width,height) {
  141. //iframe窗
  142. if (!width) width = '80%';
  143. if (!height) height = '80%';
  144. parent.layer.open({
  145. type: 2,
  146. title: title,
  147. fixed: true, //不固定
  148. shadeClose: false,
  149. shade: [0.7, '#fafafa'],
  150. maxmin: false, //开启最大化最小化按钮
  151. area: [width, height],
  152. content: url
  153. });
  154. }
  155. </script>
  156. </body>
  157. </html>