Browse Source

initQuillRTE() global method

Vijayakrishnan 3 years ago
parent
commit
4c5124ef20
3 changed files with 49 additions and 7 deletions
  1. 1 1
      config/app.php
  2. 48 0
      js-dev/mc.js
  3. 0 6
      public/css/z.css

+ 1 - 1
config/app.php

@@ -65,7 +65,7 @@ return [
 
 
     'hrm2_url' => env('HRM2_URL'),
     'hrm2_url' => env('HRM2_URL'),
 
 
-    'asset_version' => 44,
+    'asset_version' => 45,
 
 
     'temp_dir' => env('TEMP_DIR'),
     'temp_dir' => env('TEMP_DIR'),
 
 

+ 48 - 0
js-dev/mc.js

@@ -409,6 +409,54 @@ function initQuillEdit(_selector = '.note-content[auto-edit]') {
         .attr('with-shortcuts', 1);
         .attr('with-shortcuts', 1);
 }
 }
 
 
+function initQuillRTE(_selector, _config = false, _shortcuts = false) {
+    if(!_config) _config = stagQuillConfig;
+    $(_selector).each(function() {
+
+        $(this).wrap(
+            $('<div class="border-left border-right rte-holder"/>')
+                .attr('data-shortcuts', '')
+        );
+
+        // give a unique id to this editor instance
+        var editorID = Math.ceil(Math.random() * 99999),
+            fieldName = this.name;
+
+        var ti = $('<input type="hidden" />')
+            .val(this.value)
+            .attr('name', this.name)
+            .insertBefore(this);
+        var ce = $('<div data-editor-id="' + editorID + '" data-field="' + this.name + '"/>')
+            .html(this.value)
+            .insertBefore(this);
+        $(this).remove();
+
+        var qe = new Quill('[data-editor-id="' + editorID + '"]', {
+            theme: 'snow',
+            modules: _config ? _config : stagQuillConfig
+        });
+        var toolbar = $(qe.container).prev('.ql-toolbar');
+
+        // add button for new shortcut
+        if(_shortcuts) {
+            var newSCButton = $('<button class="btn bg-white btn-sm btn-default text-primary w-auto px-2 border py-0 ' +
+                'text-sm add-shortcut" data-editor-id="' + editorID + '">+ Shortcut</button>');
+            toolbar.append(newSCButton);
+        }
+
+        qe.on('text-change', function() {
+            ti.val(qe.root.innerHTML);
+        });
+
+        $(qe.container)
+            .find('.ql-editor[contenteditable]')
+            .attr('data-field', fieldName)
+            .attr('data-editor-id', editorID)
+            .attr('with-shortcuts', 1);
+
+    });
+}
+
 var patientPresenceTimer = false;
 var patientPresenceTimer = false;
 function initFileInputs() {
 function initFileInputs() {
     $(document)
     $(document)

+ 0 - 6
public/css/z.css

@@ -1,11 +1,5 @@
 .z {
 .z {
     font-size: 0.81em;
     font-size: 0.81em;
-} .z button:not(.btn) {
-    background: #efefef;
-    border: 1px solid #767676;
-    font-size: 0.9em;
-    min-width: 60px;
-    white-space: nowrap;
 } .z button:focus {
 } .z button:focus {
     outline: none;
     outline: none;
 } .z form input {
 } .z form input {