diff options
| author | Robot Odoo <xmo+roboto@odoo.com> | 2019-01-17 19:17:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-17 19:17:22 +0100 |
| commit | 22efdfbecc1e8c688000be98903a5a355d1ece8a (patch) | |
| tree | e097625171b2b67ed5f5288ced67446608b9f633 /addons/web_editor/static/lib/summernote/src/js/defaults.js | |
| parent | f50fbc6d168f0d17fa1e932b4ecc968a92b02b65 (diff) | |
| parent | eb0ea8efbe932c140302e9f8da33a839bcd73146 (diff) | |
[IMP] web_editor,*: Refactoring the wysiwyg editor and 'html' field
_Task #1878502_
- The refactoring allows for the update of the _Summernote_ library.
- A new structure was created by transforming all the plugins in the library using the odoo inheritance system. Plugins are easier to implement with the `AbstractPlugin` to add Odoo behaviors.
- The cleanup allowed us to remove some of the code that was in `web_editor` but only used in `website` or in `mass_mailing`. Some parts are still in `web_editor` but will be moved at a later time.
- The refactoring also had to be done in order to create a set of unit tests. Each behavior can be tested, including the behaviors performed as a consequence of keyboard interactions (for instance: Enter, Tab...).
- From now on, the methods of the library (in this case _Summernote_) can no longer be called by other modules or files. Only the `wysiwyg` widgets can access it, to simplify the updating process. The `wysiwyg` object serves as an interface. A lot of tests are done, ensuring the consistency of outside behavior.
- Depending on the options the snippets will be loaded or not, the editor will be in an iframe or not... all of this is transparent from the outside.
- Regarding iframes, all controllers related to editing have been removed: the new API no longer needs them. This speeds up loading, eases testing and removes complexity for the same features.
**PUBLIC FEATURES**
There are several public methods on the `Wysiwyg` class:
- `Wysiwyg.prepare (WidgetParent)` which returns a deferred resolved when the library (xml, lazy, assets...) is loaded.
- `Wysiwyg.getRange (DOM)` returns the range (selection in the dom)
- `Wysiwyg.setRange (startNode, startOffset, endNode, endOffset)` which creates a range (selection in the dom)
- `Wysiwyg.setRangeFromNode (DOM, options)` that creates a range from an element (option available to select all, start or end)
A jQuery selector was added: `:o_editable`, which indicates whether the current element is editable. That is, if it is contained in a tag with the attribute `contentEditable = "true"` or in a tag with the class `o_editable`.
Several methods are also present:
- `focusIn`: makes a focus and places the cursor at the beginning of the element
- `focusInEnd`: makes a focus and places the cursor at the end of the element
- `selectContent`: makes a focus and selects the content
**HTML FIELD**
The HTML field can receive different options:
- `style-inline:` {boolean} transforms a class into an inline style when saving and vice versa when reading.
- `no-attachment`: {boolean} prevents the use of attachments (in media dialog)
- `cssEdit`: {xml_id} to use a template containing the css to loaded in an iframe when editing
- `cssReadonly`: {xml_id} to use a template containing the css to load into an iframe when viewing in readonly
- `snippets`: {xml_id} snippets template (can be used with or without `cssEdit`)
- `wrapper`: {template} qweb static template (containing a tag: `id = "wrapper"`) that will include the content during editing (removed on save)
**MASS MAILING**
A widget was created for `mass mailing`. There are now two fields: `body_html` and `body_arch`.
`body_arch` contains the code with the class without conversion into inline style, useful when editing and one with the inline style that is visible in readonly mode and sent by email.
Advantage: no spreading errors, able to update css/theme, able to do more changes when converting to inline style so that a maximum of mail clients have an impeccable rendering.
**REMAINING KNOW ISSUES**
These will be fixed in a subsequent commit.
- A few committed changes made during the development of this refactoring were lost in the process and should be reapplied.
- Some minor (mostly range) issues remain with Firefox.
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr
closes odoo/odoo#29775
Diffstat (limited to 'addons/web_editor/static/lib/summernote/src/js/defaults.js')
| -rw-r--r-- | addons/web_editor/static/lib/summernote/src/js/defaults.js | 416 |
1 files changed, 0 insertions, 416 deletions
diff --git a/addons/web_editor/static/lib/summernote/src/js/defaults.js b/addons/web_editor/static/lib/summernote/src/js/defaults.js deleted file mode 100644 index 9d8e0bab661..00000000000 --- a/addons/web_editor/static/lib/summernote/src/js/defaults.js +++ /dev/null @@ -1,416 +0,0 @@ -define('summernote/defaults', function () { - /** - * @class defaults - * - * @singleton - */ - var defaults = { - /** @property */ - version: '@VERSION', - - /** - * - * for event options, reference to EventHandler.attach - * - * @property {Object} options - * @property {String/Number} [options.width=null] set editor width - * @property {String/Number} [options.height=null] set editor height, ex) 300 - * @property {String/Number} options.minHeight set minimum height of editor - * @property {String/Number} options.maxHeight - * @property {String/Number} options.focus - * @property {Number} options.tabsize - * @property {Boolean} options.styleWithSpan - * @property {Object} options.codemirror - * @property {Object} [options.codemirror.mode='text/html'] - * @property {Object} [options.codemirror.htmlMode=true] - * @property {Object} [options.codemirror.lineNumbers=true] - * @property {String} [options.lang=en-US] language 'en-US', 'ko-KR', ... - * @property {String} [options.direction=null] text direction, ex) 'rtl' - * @property {Array} [options.toolbar] - * @property {Boolean} [options.airMode=false] - * @property {Array} [options.airPopover] - * @property {Fucntion} [options.onInit] initialize - * @property {Fucntion} [options.onsubmit] - */ - options: { - width: null, // set editor width - height: null, // set editor height, ex) 300 - - minHeight: null, // set minimum height of editor - maxHeight: null, // set maximum height of editor - - focus: false, // set focus to editable area after initializing summernote - - tabsize: 4, // size of tab ex) 2 or 4 - styleWithSpan: true, // style with span (Chrome and FF only) - - disableLinkTarget: false, // hide link Target Checkbox - disableDragAndDrop: false, // disable drag and drop event - disableResizeEditor: false, // disable resizing editor - disableResizeImage: false, // disable resizing image - - shortcuts: true, // enable keyboard shortcuts - - textareaAutoSync: true, // enable textarea auto sync - - placeholder: false, // enable placeholder text - prettifyHtml: true, // enable prettifying html while toggling codeview - - iconPrefix: 'fa fa-', // prefix for css icon classes - - icons: { - font: { - bold: 'bold', - italic: 'italic', - underline: 'underline', - clear: 'eraser', - height: 'text-height', - strikethrough: 'strikethrough', - superscript: 'superscript', - subscript: 'subscript' - }, - image: { - image: 'picture-o', - floatLeft: 'align-left', - floatRight: 'align-right', - floatNone: 'align-justify', - shapeRounded: 'square', - shapeCircle: 'circle-o', - shapeThumbnail: 'picture-o', - shapeNone: 'times', - remove: 'trash-o' - }, - link: { - link: 'link', - unlink: 'unlink', - edit: 'edit' - }, - table: { - table: 'table' - }, - hr: { - insert: 'minus' - }, - style: { - style: 'magic' - }, - lists: { - unordered: 'list-ul', - ordered: 'list-ol' - }, - options: { - help: 'question', - fullscreen: 'arrows-alt', - codeview: 'code' - }, - paragraph: { - paragraph: 'align-left', - outdent: 'outdent', - indent: 'indent', - left: 'align-left', - center: 'align-center', - right: 'align-right', - justify: 'align-justify' - }, - color: { - recent: 'font' - }, - history: { - undo: 'undo', - redo: 'repeat' - }, - misc: { - check: 'check' - } - }, - - dialogsInBody: false, // false will add dialogs into editor - - codemirror: { // codemirror options - mode: 'text/html', - htmlMode: true, - lineNumbers: true - }, - - // language - lang: 'en-US', // language 'en-US', 'ko-KR', ... - direction: null, // text direction, ex) 'rtl' - - // toolbar - toolbar: [ - ['style', ['style']], - ['font', ['bold', 'italic', 'underline', 'clear']], - // ['font', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']], - ['fontname', ['fontname']], - ['fontsize', ['fontsize']], - ['color', ['color']], - ['para', ['ul', 'ol', 'paragraph']], - ['height', ['height']], - ['table', ['table']], - ['insert', ['link', 'picture', 'hr']], - ['view', ['fullscreen', 'codeview']], - ['help', ['help']] - ], - - plugin : { }, - - // air mode: inline editor - airMode: false, - // airPopover: [ - // ['style', ['style']], - // ['font', ['bold', 'italic', 'underline', 'clear']], - // ['fontname', ['fontname']], - // ['color', ['color']], - // ['para', ['ul', 'ol', 'paragraph']], - // ['height', ['height']], - // ['table', ['table']], - // ['insert', ['link', 'picture']], - // ['help', ['help']] - // ], - airPopover: [ - ['color', ['color']], - ['font', ['bold', 'underline', 'clear']], - ['para', ['ul', 'paragraph']], - ['table', ['table']], - ['insert', ['link', 'picture']] - ], - - // style tag - styleTags: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], - - // default fontName - defaultFontName: 'Helvetica Neue', - - // fontName - fontNames: [ - 'Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', - 'Helvetica Neue', 'Helvetica', 'Impact', 'Lucida Grande', - 'Tahoma', 'Times New Roman', 'Verdana' - ], - fontNamesIgnoreCheck: [], - - fontSizes: ['8', '9', '10', '11', '12', '14', '18', '24', '36'], - - // pallete colors(n x n) - colors: [ - ['#000000', '#424242', '#636363', '#9C9C94', '#CEC6CE', '#EFEFEF', '#F7F7F7', '#FFFFFF'], - ['#FF0000', '#FF9C00', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#9C00FF', '#FF00FF'], - ['#F7C6CE', '#FFE7CE', '#FFEFC6', '#D6EFD6', '#CEDEE7', '#CEE7F7', '#D6D6E7', '#E7D6DE'], - ['#E79C9C', '#FFC69C', '#FFE79C', '#B5D6A5', '#A5C6CE', '#9CC6EF', '#B5A5D6', '#D6A5BD'], - ['#E76363', '#F7AD6B', '#FFD663', '#94BD7B', '#73A5AD', '#6BADDE', '#8C7BC6', '#C67BA5'], - ['#CE0000', '#E79439', '#EFC631', '#6BA54A', '#4A7B8C', '#3984C6', '#634AA5', '#A54A7B'], - ['#9C0000', '#B56308', '#BD9400', '#397B21', '#104A5A', '#085294', '#311873', '#731842'], - ['#630000', '#7B3900', '#846300', '#295218', '#083139', '#003163', '#21104A', '#4A1031'] - ], - - // lineHeight - lineHeights: ['1.0', '1.2', '1.4', '1.5', '1.6', '1.8', '2.0', '3.0'], - - // insertTable max size - insertTableMaxSize: { - col: 10, - row: 10 - }, - - // image - maximumImageFileSize: null, // size in bytes, null = no limit - - // callbacks - oninit: null, // initialize - onfocus: null, // editable has focus - onblur: null, // editable out of focus - onenter: null, // enter key pressed - onkeyup: null, // keyup - onkeydown: null, // keydown - onImageUpload: null, // imageUpload - onImageUploadError: null, // imageUploadError - onMediaDelete: null, // media delete - onToolbarClick: null, - onsubmit: null, - - /** - * manipulate link address when user create link - * @param {String} sLinkUrl - * @return {String} - */ - onCreateLink: function (sLinkUrl) { - if (sLinkUrl.indexOf('@') !== -1 && sLinkUrl.indexOf(':') === -1) { - sLinkUrl = 'mailto:' + sLinkUrl; - } - - return sLinkUrl; - }, - - keyMap: { - pc: { - 'ENTER': 'insertParagraph', - 'CTRL+Z': 'undo', - 'CTRL+Y': 'redo', - 'TAB': 'tab', - 'SHIFT+TAB': 'untab', - 'CTRL+B': 'bold', - 'CTRL+I': 'italic', - 'CTRL+U': 'underline', - 'CTRL+SHIFT+S': 'strikethrough', - 'CTRL+BACKSLASH': 'removeFormat', - 'CTRL+SHIFT+L': 'justifyLeft', - 'CTRL+SHIFT+E': 'justifyCenter', - 'CTRL+SHIFT+R': 'justifyRight', - 'CTRL+SHIFT+J': 'justifyFull', - 'CTRL+SHIFT+NUM7': 'insertUnorderedList', - 'CTRL+SHIFT+NUM8': 'insertOrderedList', - 'CTRL+LEFTBRACKET': 'outdent', - 'CTRL+RIGHTBRACKET': 'indent', - 'CTRL+NUM0': 'formatPara', - 'CTRL+NUM1': 'formatH1', - 'CTRL+NUM2': 'formatH2', - 'CTRL+NUM3': 'formatH3', - 'CTRL+NUM4': 'formatH4', - 'CTRL+NUM5': 'formatH5', - 'CTRL+NUM6': 'formatH6', - 'CTRL+ENTER': 'insertHorizontalRule', - 'CTRL+K': 'showLinkDialog' - }, - - mac: { - 'ENTER': 'insertParagraph', - 'CMD+Z': 'undo', - 'CMD+SHIFT+Z': 'redo', - 'TAB': 'tab', - 'SHIFT+TAB': 'untab', - 'CMD+B': 'bold', - 'CMD+I': 'italic', - 'CMD+U': 'underline', - 'CMD+SHIFT+S': 'strikethrough', - 'CMD+BACKSLASH': 'removeFormat', - 'CMD+SHIFT+L': 'justifyLeft', - 'CMD+SHIFT+E': 'justifyCenter', - 'CMD+SHIFT+R': 'justifyRight', - 'CMD+SHIFT+J': 'justifyFull', - 'CMD+SHIFT+NUM7': 'insertUnorderedList', - 'CMD+SHIFT+NUM8': 'insertOrderedList', - 'CMD+LEFTBRACKET': 'outdent', - 'CMD+RIGHTBRACKET': 'indent', - 'CMD+NUM0': 'formatPara', - 'CMD+NUM1': 'formatH1', - 'CMD+NUM2': 'formatH2', - 'CMD+NUM3': 'formatH3', - 'CMD+NUM4': 'formatH4', - 'CMD+NUM5': 'formatH5', - 'CMD+NUM6': 'formatH6', - 'CMD+ENTER': 'insertHorizontalRule', - 'CMD+K': 'showLinkDialog' - } - } - }, - - // default language: en-US - lang: { - 'en-US': { - font: { - bold: 'Bold', - italic: 'Italic', - underline: 'Underline', - clear: 'Remove Font Style', - height: 'Line Height', - name: 'Font Family', - strikethrough: 'Strikethrough', - subscript: 'Subscript', - superscript: 'Superscript', - size: 'Font Size' - }, - image: { - image: 'Picture', - insert: 'Insert Image', - resizeFull: 'Resize Full', - resizeHalf: 'Resize Half', - resizeQuarter: 'Resize Quarter', - floatLeft: 'Float Left', - floatRight: 'Float Right', - floatNone: 'Float None', - shapeRounded: 'Shape: Rounded', - shapeCircle: 'Shape: Circle', - shapeThumbnail: 'Shape: Thumbnail', - shapeNone: 'Shape: None', - dragImageHere: 'Drag image or text here', - dropImage: 'Drop image or Text', - selectFromFiles: 'Select from files', - maximumFileSize: 'Maximum file size', - maximumFileSizeError: 'Maximum file size exceeded.', - url: 'Image URL', - remove: 'Remove Image' - }, - link: { - link: 'Link', - insert: 'Insert Link', - unlink: 'Unlink', - edit: 'Edit', - textToDisplay: 'Text to display', - url: 'To what URL should this link go?', - openInNewWindow: 'Open in new window' - }, - table: { - table: 'Table' - }, - hr: { - insert: 'Insert Horizontal Rule' - }, - style: { - style: 'Style', - normal: 'Paragraph', - blockquote: 'Quote', - pre: 'Code', - h1: 'Header 1', - h2: 'Header 2', - h3: 'Header 3', - h4: 'Header 4', - h5: 'Header 5', - h6: 'Header 6' - }, - lists: { - unordered: 'Unordered list', - ordered: 'Ordered list' - }, - options: { - help: 'Help', - fullscreen: 'Full Screen', - codeview: 'Code View' - }, - paragraph: { - paragraph: 'Paragraph', - outdent: 'Outdent', - indent: 'Indent', - left: 'Align left', - center: 'Align center', - right: 'Align right', - justify: 'Justify full' - }, - color: { - recent: 'Recent Color', - more: 'More Color', - background: 'Background Color', - foreground: 'Foreground Color', - transparent: 'Transparent', - setTransparent: 'Set transparent', - reset: 'Reset', - resetToDefault: 'Reset to default' - }, - shortcut: { - shortcuts: 'Keyboard shortcuts', - close: 'Close', - textFormatting: 'Text formatting', - action: 'Action', - paragraphFormatting: 'Paragraph formatting', - documentStyle: 'Document Style', - extraKeys: 'Extra keys' - }, - history: { - undo: 'Undo', - redo: 'Redo' - } - } - } - }; - - return defaults; -}); |
