国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
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.

148 lines
4.4KB

  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  5. -->
  6. <html lang="en">
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Mentions &mdash; CKEditor Sample</title>
  10. <script src="../../../ckeditor.js"></script>
  11. <link rel="stylesheet" href="../../../samples/css/samples.css">
  12. <meta name="description" content="Try the latest sample of CKEditor 4 and learn more about customizing your WYSIWYG editor with endless possibilities.">
  13. </head>
  14. <body>
  15. <style>
  16. .adjoined-bottom:before {
  17. height: 270px;
  18. }
  19. </style>
  20. <nav class="navigation-a">
  21. <div class="grid-container">
  22. <ul class="navigation-a-left grid-width-70">
  23. <li><a href="https://ckeditor.com">Project Homepage</a></li>
  24. <li><a href="https://github.com/ckeditor/ckeditor4/issues">I found a bug</a></li>
  25. <li><a href="https://github.com/ckeditor/ckeditor4" class="icon-pos-right icon-navigation-a-github">Fork CKEditor on GitHub</a></li>
  26. </ul>
  27. <ul class="navigation-a-right grid-width-30">
  28. <li><a href="https://ckeditor.com/blog/">CKEditor Blog</a></li>
  29. </ul>
  30. </div>
  31. </nav>
  32. <header class="header-a">
  33. <div class="grid-container">
  34. <h1 class="header-a-logo grid-width-30">
  35. <img src="../../../samples/img/logo.svg" onerror="this.src='../../../samples/img/logo.png'; this.onerror=null;" alt="CKEditor Sample">
  36. </h1>
  37. </div>
  38. </header>
  39. <main>
  40. <div class="adjoined-top">
  41. <div class="grid-container">
  42. <div class="content grid-width-100">
  43. <h1>Mentions Demo</h1>
  44. <p>This sample shows Mentions feature in action. Type &#8220; @ &#8221; to open simple autocompletion with array feed, &#8220; $ &#8221; (min 1 character) to open asynchronous autocompletion with URL string feed or &#8220; # &#8221; (min 2 characters) to open asynchronous autocompletion with custom source of data.</p>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="adjoined-bottom">
  49. <div class="grid-container">
  50. <div class="grid-width-100">
  51. <div id="editor">
  52. <h1>Mentions plugin</h1>
  53. <p>Feel free to mention @anna, @cris, @thomas or anyone else.</p>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </main>
  59. <footer class="footer-a grid-container">
  60. <div class="grid-container">
  61. <p class="grid-width-100">
  62. CKEditor &ndash; The text editor for the Internet &ndash; <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
  63. </p>
  64. <p class="grid-width-100" id="copy">
  65. Copyright &copy; 2003-2020, <a class="samples" href="https://cksource.com/">CKSource</a> &ndash; Frederico Knabben. All rights reserved.
  66. </p>
  67. </div>
  68. </footer>
  69. <script>
  70. 'use strict';
  71. ( function() {
  72. var data = [
  73. { id: 1, name: 'john', fullName: 'John Doe' },
  74. { id: 2, name: 'thomas', fullName: 'Thomas Doe' },
  75. { id: 3, name: 'anna', fullName: 'Anna Doe' },
  76. { id: 4, name: 'annabelle', fullName: 'Annabelle Doe' },
  77. { id: 5, name: 'cris', fullName: 'Cris Doe' },
  78. { id: 6, name: 'julia', fullName: 'Julia Doe' }
  79. ];
  80. CKEDITOR.replace( 'editor', {
  81. height: 240,
  82. extraPlugins: 'mentions,easyimage,sourcearea,toolbar,undo,wysiwygarea,basicstyles',
  83. extraAllowedContent: 'h1',
  84. toolbar: [
  85. { name: 'document', items: [ 'Source', 'Undo', 'Redo' ] },
  86. { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike' ] },
  87. ],
  88. mentions: [
  89. {
  90. feed: CKEDITOR.tools.array.map( data, function( item ) {
  91. return item.name;
  92. } ),
  93. minChars: 0
  94. },
  95. {
  96. feed: '{encodedQuery}',
  97. marker: '$',
  98. minChars: 1,
  99. template: '<li data-id="{id}">{fullName}</li>'
  100. },
  101. {
  102. feed: dataCallback,
  103. marker: '#',
  104. template: '<li data-id="{id}">{name} ({fullName})</li>'
  105. }
  106. ],
  107. on: {
  108. instanceReady: function() {
  109. // We have to stub ajax.load function.
  110. CKEDITOR.ajax.load = function( query, callback ) {
  111. var results = data.filter( function( item ) {
  112. return item.name.indexOf( query ) === 0;
  113. } );
  114. setTimeout( function() {
  115. callback( JSON.stringify( results ) );
  116. }, Math.random() * 500 );
  117. }
  118. }
  119. }
  120. } );
  121. function dataCallback( opts, callback ) {
  122. setTimeout( function() {
  123. callback(
  124. data.filter( function( item ) {
  125. return item.name.indexOf( opts.query ) === 0;
  126. } )
  127. );
  128. }, Math.random() * 500 );
  129. }
  130. } )();
  131. </script>
  132. </body>
  133. </html>