| | |
| | | window.jvbQuill = function(form) { |
| | | const textareas = form.querySelectorAll('textarea[data-editor=true]'); |
| | | const instances = []; |
| | | |
| | | textareas.forEach(textarea => { |
| | | let container, editor, toolbar; |
| | |
| | | editor.className = 'editor'; |
| | | toolbar = document.createElement('div'); |
| | | toolbar.className = 'toolbar'; |
| | | const image = textarea.dataset.allowimage === true ? `<button type="button" class="ql-jvb_image">\n ${dashboardSettings.icons.image}\n </button>` : ''; |
| | | const image = textarea.dataset.allowimage === true ? `<button type="button" class="ql-jvb_image">\n ${window.getIcon('image')}\n </button>` : ''; |
| | | toolbar.id = `toolbar-${textarea.id}`; |
| | | toolbar.innerHTML = ` |
| | | <span class="ql-formats"> |
| | |
| | | h1: function() { this.quill.format('header', 1); }, |
| | | h2: function() { this.quill.format('header', 2); }, |
| | | h3: function() { this.quill.format('header', 3); }, |
| | | jvb_bold: function() {this.quill.format('bold', true)}, |
| | | jvb_italic: function() {this.quill.format('italic', true)}, |
| | | jvb_strike: function() {this.quill.format('strike', true)}, |
| | | jvb_underline: function() {this.quill.format('underline', true)}, |
| | | 'jvb_bold': function() {this.quill.format('bold', true)}, |
| | | 'jvb_italic': function() {this.quill.format('italic', true)}, |
| | | 'jvb_strike': function() {this.quill.format('strike', true)}, |
| | | 'jvb_underline': function() {this.quill.format('underline', true)}, |
| | | 'jvb_align': function(value) { |
| | | this.quill.format('align', value === this.quill.getFormat().list ? false : value); |
| | | }, |
| | |
| | | if (value) { |
| | | const range = this.quill.getSelection(); |
| | | if (range == null || range.length === 0) return; |
| | | // Get the existing link if any |
| | | const preview = this.quill.getText(range.index, range.length); |
| | | const existingLink = this.quill.getFormat(range).link; |
| | | |
| | | // Create modal for link input |
| | |
| | | formData.append('post_id', objectID); |
| | | } |
| | | |
| | | // Show loading state |
| | | if (window.jvbLoading) { |
| | | window.jvbLoading.showLoading('Uploading image...', 'Processing Upload'); |
| | | } |
| | | |
| | | try { |
| | | const response = await fetch( |
| | | `${jvbSettings.api}uploads/`, |
| | |
| | | 'italic': true |
| | | }, true); |
| | | } finally { |
| | | if (window.jvbLoading) { |
| | | window.jvbLoading.hide(); |
| | | } |
| | | input.remove(); |
| | | } |
| | | }; |
| | |
| | | } |
| | | }); |
| | | |
| | | instances.push(quill); |
| | | |
| | | quill.on('selection-change', function(range) { |
| | | const alignmentTools = toolbar.querySelector('.ql-align'); |
| | | if (alignmentTools) { |
| | |
| | | textarea.dispatchEvent(new Event('change', { bubbles: true })); |
| | | }); |
| | | }); |
| | | return instances; |
| | | }; |