Browse Source

CodeMirror syntax switch (html, js, css)

Vova Tkach 5 years ago
parent
commit
4b8d0fe431
3 changed files with 15 additions and 1 deletions
  1. 8 0
      assets/cp.scripts.js
  2. 0 0
      assets/cp.scripts.js.go
  3. 7 1
      modules/module_template.go

+ 8 - 0
assets/cp.scripts.js

@@ -3602,10 +3602,18 @@
 		function MakeTextAreasTmplEditor() {
 			$('textarea.tmpl-editor').each(function() {
 				var targetTextArea = $(this)[0];
+				var targetFileExt = $(this).data('emode');
+				var targetEditorMode = 'text/html';
+				if(targetFileExt == 'js') {
+					targetEditorMode = 'javascript';
+				} else if(targetFileExt == 'css') {
+					targetEditorMode = 'css';
+				}
 				CodeMirror.fromTextArea(targetTextArea, {
 					lineNumbers: true,
 					lineWrapping: true,
 					viewportMargin: Infinity,
+					mode: targetEditorMode,
 				}).on('change', function(editor){
 					targetTextArea.value = editor.getValue();
 				});

File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


+ 7 - 1
modules/module_template.go

@@ -5,6 +5,7 @@ import (
 	"io/ioutil"
 	"net/url"
 	"os"
+	"path/filepath"
 	"strings"
 
 	"golang-fave/assets"
@@ -69,6 +70,11 @@ func (this *Modules) RegisterModule_Template() *Module {
 				fcont := []byte(``)
 				fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + selected_file)
 
+				fext := filepath.Ext(selected_file)
+				if len(fext) > 2 {
+					fext = fext[1:]
+				}
+
 				content += builder.DataForm(wrap, []builder.DataFormField{
 					{
 						Kind:  builder.DFKHidden,
@@ -97,7 +103,7 @@ func (this *Modules) RegisterModule_Template() *Module {
 					{
 						Kind: builder.DFKText,
 						CallBack: func(field *builder.DataFormField) string {
-							return `<div class="form-group last"><div class="row"><div class="col-12"><textarea class="form-control tmpl-editor" id="lbl_content" name="content" placeholder="" autocomplete="off">` + html.EscapeString(string(fcont)) + `</textarea></div></div></div>`
+							return `<div class="form-group last"><div class="row"><div class="col-12"><textarea class="form-control tmpl-editor" id="lbl_content" name="content" data-emode="` + fext + `" placeholder="" autocomplete="off">` + html.EscapeString(string(fcont)) + `</textarea></div></div></div>`
 						},
 					},
 					{

Some files were not shown because too many files changed in this diff