Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

editor.quill.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * [Quill](http://quilljs.com/) is a lightweight WYSIWYG editing library that
  3. * will provides an attractive input where end users and easily edit complex
  4. * information in a style familiar to all word processor users.
  5. *
  6. * Quill is different from the majority of other WYSIWYG libraries in that it
  7. * does not use iframes. This makes it more approachable for extension
  8. * developers and easier to style.
  9. *
  10. * It also has support for multiple modules such as toolbars, authorship
  11. * highlighting and multiple cursors. The toolbar module is used by default by
  12. * this Editor plug-in (see options below). Please see the [Quill
  13. * documentation](http://quilljs.com/docs/modules/) for more information.
  14. *
  15. * @name Quill
  16. * @summary Quill WYSIWYG editor
  17. * @requires [Quill](http://quilljs.com)
  18. *
  19. * @depcss //cdn.quilljs.com/latest/quill.snow.css
  20. * @depjs //cdn.quilljs.com/latest/quill.min.js
  21. *
  22. * @scss editor.quill.scss
  23. *
  24. * @opt `e-type string`, `e-type node`, `e-type boolean` **`toolbar`**: Show
  25. * toolbar (`true` - default) or not (`false`). A custom toolbar can be
  26. * defined, per the Quill documentation, by passing the string or node for
  27. * the toolbar's HTML to this parameter.
  28. * @opt `e-type object` **`opts`**: Options passed directly to the Quill
  29. * configuration object. Please refer to the [Quill
  30. * documentation](http://quilljs.com/docs/configuration/) for the full range
  31. * of options.
  32. *
  33. * @method **`quill`**: Get the Quill instance used for this field, so you can
  34. * add additional modules, or perform other API operations on it directly.
  35. *
  36. * @example
  37. *
  38. * new $.fn.dataTable.Editor( {
  39. * "ajax": "/api/documents",
  40. * "table": "#documents",
  41. * "fields": [ {
  42. * "label": "Description:",
  43. * "name": "description",
  44. * "type": "quill"
  45. * },
  46. * // additional fields...
  47. * ]
  48. * } );
  49. */
  50. (function( factory ){
  51. if ( typeof define === 'function' && define.amd ) {
  52. // AMD
  53. define( ['jquery', 'datatables', 'datatables-editor'], factory );
  54. }
  55. else if ( typeof exports === 'object' ) {
  56. // Node / CommonJS
  57. module.exports = function ($, dt) {
  58. if ( ! $ ) { $ = require('jquery'); }
  59. factory( $, dt || $.fn.dataTable || require('datatables') );
  60. };
  61. }
  62. else if ( jQuery ) {
  63. // Browser standard
  64. factory( jQuery, jQuery.fn.dataTable );
  65. }
  66. }(function( $, DataTable ) {
  67. 'use strict';
  68. if ( ! DataTable.ext.editorFields ) {
  69. DataTable.ext.editorFields = {};
  70. }
  71. var _fieldTypes = DataTable.Editor ?
  72. DataTable.Editor.fieldTypes :
  73. DataTable.ext.editorFields;
  74. // Default toolbar, as Quill doesn't provide one
  75. var defaultToolbar =
  76. '<div id="toolbar-toolbar" class="toolbar">'+
  77. '<span class="ql-formats">'+
  78. '<select class="ql-font">'+
  79. '<option selected=""></option>'+
  80. '<option value="serif"></option>'+
  81. '<option value="monospace"></option>'+
  82. '</select>'+
  83. '<select class="ql-size">'+
  84. '<option value="small"></option>'+
  85. '<option selected=""></option>'+
  86. '<option value="large"></option>'+
  87. '<option value="huge"></option>'+
  88. '</select>'+
  89. '</span>'+
  90. '<span class="ql-formats">'+
  91. '<button class="ql-bold"></button>'+
  92. '<button class="ql-italic"></button>'+
  93. '<button class="ql-underline"></button>'+
  94. '<button class="ql-strike"></button>'+
  95. '</span>'+
  96. '<span class="ql-formats">'+
  97. '<select class="ql-color"></select>'+
  98. '<select class="ql-background"></select>'+
  99. '</span>'+
  100. '<span class="ql-formats">'+
  101. '<button class="ql-list" value="ordered"></button>'+
  102. '<button class="ql-list" value="bullet"></button>'+
  103. '<select class="ql-align">'+
  104. '<option selected=""></option>'+
  105. '<option value="center"></option>'+
  106. '<option value="right"></option>'+
  107. '<option value="justify"></option>'+
  108. '</select>'+
  109. '</span>'+
  110. '<span class="ql-formats">'+
  111. '<button class="ql-link"></button>'+
  112. '</span>'+
  113. '</div>';
  114. _fieldTypes.quill = {
  115. create: function ( conf ) {
  116. var safeId = DataTable.Editor.safeId( conf.id );
  117. var input = $(
  118. '<div id="'+safeId+'" class="quill-wrapper">'+
  119. (conf.toolbarHtml || defaultToolbar)+
  120. '<div class="editor"></div>'+
  121. '</div>'
  122. );
  123. conf._quill = new Quill( input.find('.editor')[0], $.extend( true, {
  124. theme: 'snow',
  125. modules: {
  126. toolbar: {
  127. container: $('div.toolbar', input)[0]
  128. }
  129. }
  130. }, conf.opts ) );
  131. return input;
  132. },
  133. get: function ( conf ) {
  134. return conf._quill.getText();
  135. },
  136. set: function ( conf, val ) {
  137. conf._quill.setText( val !== null ? val : '' );
  138. },
  139. enable: function ( conf ) {}, // not supported by Quill
  140. disable: function ( conf ) {}, // not supported by Quill
  141. // Get the Quill instance
  142. quill: function ( conf ) {
  143. return conf._quill;
  144. }
  145. };
  146. }));