]> _ Git - cubist_cms-back.git/commitdiff
wip #3939 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Oct 2020 17:29:56 +0000 (19:29 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Oct 2020 17:29:56 +0000 (19:29 +0200)
src/resources/views/fields/code.blade.php

index 71a003a0cf775e461a2577b51a2a79624aee9109..25bc2eab6d41ec10601a87705ffa9620edc86bc5 100644 (file)
@@ -4,6 +4,7 @@
 @include('crud::fields.inc.translatable_icon')
 <textarea
     class="code"
+    data-language="{{$field['language']}}"
     name="{{ $field['name'] }}"
         @include('crud::fields.inc.attributes')
 
 {{-- Extra CSS and JS for this particular field --}}
 {{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
 @if ($crud->checkIfFieldIsFirstOfItsType($field))
-textarea.code{
-        font-family: Courier, monospace;
-}
+
+    @push('crud_fields_styles')
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/codemirror.min.css"
+              integrity="sha512-xIf9AdJauwKIVtrVRZ0i4nHP61Ogx9fSRAkCLecmE2dL/U8ioWpDvFCAy4dcfecN72HHB9+7FfQj3aiO68aaaw=="
+              crossorigin="anonymous"/>
+    @endpush
+    @push('crud_fields_scripts')
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/codemirror.min.js"
+                integrity="sha512-WWC1A/JchDFZ2ZGaNyMC7CmPFXGLI/6Ih7WN6YG0DX1NGMkW5lqCVFxCmEx3e56Z7iqdQGpO0f+m2t9CJhdb2Q=="
+                crossorigin="anonymous"></script>
+        <script>
+            jQuery(document).ready(function ($) {
+                function initMirrorCode() {
+                    $('textarea.code').each(function () {
+                        if ($(this).data('mirrorcodeok') === true) {
+                            return;
+                        }
+                        $(this).data('mirrorcodeok', true);
+                        CodeMirror.fromTextArea($(this).get(0), {
+                            lineNumbers: true,
+                            mode: $(this).data('language'),
+                        });
+                    });
+                }
+
+                initMirrorCode();
+                $(document).on('cubist.bunchmultiple.added', function () {
+                    initMirrorCode();
+                });
+            })
+
+
+        </script>
+    @endpush
 @endif