Browse Source

Wed IDE加载优化

xuxueli 7 years ago
parent
commit
48d30d7750

+ 23 - 5
xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/jobcode.index.ftl View File

109
     </div>
109
     </div>
110
 	
110
 	
111
 <@netCommon.commonScript />
111
 <@netCommon.commonScript />
112
+
113
+
114
+    <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" />
115
+    <#assign glueTypeIdeMode = "text/x-java" />
116
+
117
+    <#if jobInfo.glueType == "GLUE_GROOVY" >
118
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" />
119
+        <#assign glueTypeIdeMode = "text/x-java" />
120
+    <#elseif jobInfo.glueType == "GLUE_SHELL" >
121
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/shell/shell.js" />
122
+        <#assign glueTypeIdeMode = "text/x-sh" />
123
+    <#elseif jobInfo.glueType == "GLUE_PYTHON" >
124
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" />
125
+        <#assign glueTypeIdeMode = "text/x-python" />
126
+    <#elseif jobInfo.glueType == "GLUE_NODEJS" >
127
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js" />
128
+        <#assign glueTypeIdeMode = "text/javascript" />
129
+    </#if>
130
+
131
+
112
 <script src="${request.contextPath}/static/plugins/codemirror/lib/codemirror.js"></script>
132
 <script src="${request.contextPath}/static/plugins/codemirror/lib/codemirror.js"></script>
113
-<script src="${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js"></script>
114
-<script src="${request.contextPath}/static/plugins/codemirror/mode/shell/shell.js"></script>
115
-<script src="${request.contextPath}/static/plugins/codemirror/mode/python/python.js"></script>
116
-<script src="${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js"></script>
133
+<script src="${glueTypeModeSrc}"></script>
117
 <script src="${request.contextPath}/static/plugins/codemirror/addon/hint/show-hint.js"></script>
134
 <script src="${request.contextPath}/static/plugins/codemirror/addon/hint/show-hint.js"></script>
118
 <script src="${request.contextPath}/static/plugins/codemirror/addon/hint/anyword-hint.js"></script>
135
 <script src="${request.contextPath}/static/plugins/codemirror/addon/hint/anyword-hint.js"></script>
136
+
119
 <script>
137
 <script>
120
 var id = '${jobInfo.id}';
138
 var id = '${jobInfo.id}';
121
-var glueType = '${jobInfo.glueType}';
139
+var ideMode = '${glueTypeIdeMode}';
122
 </script>
140
 </script>
123
 <script src="${request.contextPath}/static/js/jobcode.index.1.js"></script>
141
 <script src="${request.contextPath}/static/js/jobcode.index.1.js"></script>
124
 
142
 

+ 13 - 21
xxl-job-admin/src/main/webapp/static/js/jobcode.index.1.js View File

8
 	});*/
8
 	});*/
9
 
9
 
10
 	var codeEditor;
10
 	var codeEditor;
11
-	function initIde(glueType, glueSource) {
12
-		var ideMode = "text/x-java";
13
-		if ('GLUE_GROOVY'==glueType){
14
-			ideMode = "text/x-java";
15
-		} else if ('GLUE_SHELL'==glueType){
16
-			ideMode = "text/x-sh";
17
-		} else if ('GLUE_PYTHON'==glueType){
18
-			ideMode = "text/x-python";
19
-		} else if ('GLUE_NODEJS'==glueType){
20
-			ideMode = "text/javascript"
11
+	function initIde(glueSource) {
12
+		if (codeEditor == null) {
13
+            codeEditor = CodeMirror(document.getElementById("ideWindow"), {
14
+                mode : ideMode,
15
+                lineNumbers : true,
16
+                matchBrackets : true,
17
+                value: glueSource
18
+            });
19
+		} else {
20
+            codeEditor.setValue(glueSource);
21
 		}
21
 		}
22
-
23
-		codeEditor = CodeMirror(document.getElementById("ideWindow"), {
24
-			mode : ideMode,
25
-			lineNumbers : true,
26
-			matchBrackets : true,
27
-			value: glueSource
28
-		});
29
 	}
22
 	}
30
 
23
 
31
-	initIde(glueType, $("#version_now").val());
24
+	initIde($("#version_now").val());
32
 
25
 
33
 	// code change
26
 	// code change
34
 	$(".source_version").click(function(){
27
 	$(".source_version").click(function(){
35
-		var glueType = $(this).attr('glueType');
36
 		var sourceId = $(this).attr('version');
28
 		var sourceId = $(this).attr('version');
37
 		var temp = $( "#" + sourceId ).val();
29
 		var temp = $( "#" + sourceId ).val();
38
 
30
 
39
-		codeEditor.setValue('');
40
-		initIde(glueType, temp);
31
+		//codeEditor.setValue('');
32
+		initIde(temp);
41
 	});
33
 	});
42
 
34
 
43
 	// code source save
35
 	// code source save

+ 32 - 65
xxl-job-admin/src/main/webapp/static/plugins/codemirror/mode/javascript/javascript.js View File

11
 })(function(CodeMirror) {
11
 })(function(CodeMirror) {
12
 "use strict";
12
 "use strict";
13
 
13
 
14
+function expressionAllowed(stream, state, backUp) {
15
+  return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
16
+    (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
17
+}
18
+
14
 CodeMirror.defineMode("javascript", function(config, parserConfig) {
19
 CodeMirror.defineMode("javascript", function(config, parserConfig) {
15
   var indentUnit = config.indentUnit;
20
   var indentUnit = config.indentUnit;
16
   var statementIndent = parserConfig.statementIndent;
21
   var statementIndent = parserConfig.statementIndent;
36
       "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
41
       "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
37
       "this": kw("this"), "class": kw("class"), "super": kw("atom"),
42
       "this": kw("this"), "class": kw("class"), "super": kw("atom"),
38
       "yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
43
       "yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
39
-      "await": C
44
+      "await": C, "async": kw("async")
40
     };
45
     };
41
 
46
 
42
     // Extend the 'normal' keywords with the TypeScript language extensions
47
     // Extend the 'normal' keywords with the TypeScript language extensions
43
     if (isTS) {
48
     if (isTS) {
44
-      var type = {type: "variable", style: "type"};
49
+      var type = {type: "variable", style: "variable-3"};
45
       var tsKeywords = {
50
       var tsKeywords = {
46
         // object-like things
51
         // object-like things
47
         "interface": kw("class"),
52
         "interface": kw("class"),
49
         "namespace": C,
54
         "namespace": C,
50
         "module": kw("module"),
55
         "module": kw("module"),
51
         "enum": kw("module"),
56
         "enum": kw("module"),
57
+        "type": kw("type"),
52
 
58
 
53
         // scope modifiers
59
         // scope modifiers
54
         "public": kw("modifier"),
60
         "public": kw("modifier"),
55
         "private": kw("modifier"),
61
         "private": kw("modifier"),
56
         "protected": kw("modifier"),
62
         "protected": kw("modifier"),
57
         "abstract": kw("modifier"),
63
         "abstract": kw("modifier"),
58
-        "readonly": kw("modifier"),
64
+
65
+        // operators
66
+        "as": operator,
59
 
67
 
60
         // types
68
         // types
61
         "string": type, "number": type, "boolean": type, "any": type
69
         "string": type, "number": type, "boolean": type, "any": type
143
       return ret("operator", "operator", stream.current());
151
       return ret("operator", "operator", stream.current());
144
     } else if (wordRE.test(ch)) {
152
     } else if (wordRE.test(ch)) {
145
       stream.eatWhile(wordRE);
153
       stream.eatWhile(wordRE);
146
-      var word = stream.current()
147
-      if (state.lastType != ".") {
148
-        if (keywords.propertyIsEnumerable(word)) {
149
-          var kw = keywords[word]
150
-          return ret(kw.type, kw.style, word)
151
-        }
152
-        if (word == "async" && stream.match(/^\s*[\(\w]/, false))
153
-          return ret("async", "keyword", word)
154
-      }
155
-      return ret("variable", "variable", word)
154
+      var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
155
+      return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
156
+                     ret("variable", "variable", word);
156
     }
157
     }
157
   }
158
   }
158
 
159
 
360
     }
361
     }
361
     if (type == "function") return cont(functiondef);
362
     if (type == "function") return cont(functiondef);
362
     if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
363
     if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
363
-    if (type == "variable") {
364
-      if (isTS && value == "type") {
365
-        cx.marked = "keyword"
366
-        return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
367
-      } if (isTS && value == "declare") {
368
-        cx.marked = "keyword"
369
-        return cont(statement)
370
-      } else {
371
-        return cont(pushlex("stat"), maybelabel);
372
-      }
373
-    }
374
-    if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"),
364
+    if (type == "variable") return cont(pushlex("stat"), maybelabel);
365
+    if (type == "switch") return cont(pushlex("form"), parenExpr, pushlex("}", "switch"), expect("{"),
375
                                       block, poplex, poplex);
366
                                       block, poplex, poplex);
376
     if (type == "case") return cont(expression, expect(":"));
367
     if (type == "case") return cont(expression, expect(":"));
377
     if (type == "default") return cont(expect(":"));
368
     if (type == "default") return cont(expect(":"));
380
     if (type == "class") return cont(pushlex("form"), className, poplex);
371
     if (type == "class") return cont(pushlex("form"), className, poplex);
381
     if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
372
     if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
382
     if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
373
     if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
383
-    if (type == "module") return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
374
+    if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
375
+    if (type == "type") return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
384
     if (type == "async") return cont(statement)
376
     if (type == "async") return cont(statement)
385
     if (value == "@") return cont(expression, statement)
377
     if (value == "@") return cont(expression, statement)
386
     return pass(pushlex("stat"), expression, expect(";"), poplex);
378
     return pass(pushlex("stat"), expression, expect(";"), poplex);
398
   function expressionInner(type, noComma) {
390
   function expressionInner(type, noComma) {
399
     if (cx.state.fatArrowAt == cx.stream.start) {
391
     if (cx.state.fatArrowAt == cx.stream.start) {
400
       var body = noComma ? arrowBodyNoComma : arrowBody;
392
       var body = noComma ? arrowBodyNoComma : arrowBody;
401
-      if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);
393
+      if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
402
       else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
394
       else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
403
     }
395
     }
404
 
396
 
433
     var expr = noComma == false ? expression : expressionNoComma;
425
     var expr = noComma == false ? expression : expressionNoComma;
434
     if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
426
     if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
435
     if (type == "operator") {
427
     if (type == "operator") {
436
-      if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
428
+      if (/\+\+|--/.test(value)) return cont(me);
437
       if (value == "?") return cont(expression, expect(":"), expr);
429
       if (value == "?") return cont(expression, expect(":"), expr);
438
       return cont(expr);
430
       return cont(expr);
439
     }
431
     }
442
     if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
434
     if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
443
     if (type == ".") return cont(property, me);
435
     if (type == ".") return cont(property, me);
444
     if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
436
     if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
445
-    if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
446
   }
437
   }
447
   function quasi(type, value) {
438
   function quasi(type, value) {
448
     if (type != "quasi") return pass();
439
     if (type != "quasi") return pass();
467
   function maybeTarget(noComma) {
458
   function maybeTarget(noComma) {
468
     return function(type) {
459
     return function(type) {
469
       if (type == ".") return cont(noComma ? targetNoComma : target);
460
       if (type == ".") return cont(noComma ? targetNoComma : target);
470
-      else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
471
       else return pass(noComma ? expressionNoComma : expression);
461
       else return pass(noComma ? expressionNoComma : expression);
472
     };
462
     };
473
   }
463
   }
502
     } else if (type == "[") {
492
     } else if (type == "[") {
503
       return cont(expression, expect("]"), afterprop);
493
       return cont(expression, expect("]"), afterprop);
504
     } else if (type == "spread") {
494
     } else if (type == "spread") {
505
-      return cont(expression, afterprop);
495
+      return cont(expression);
506
     } else if (type == ":") {
496
     } else if (type == ":") {
507
       return pass(afterprop)
497
       return pass(afterprop)
508
     }
498
     }
549
       if (value == "?") return cont(maybetype);
539
       if (value == "?") return cont(maybetype);
550
     }
540
     }
551
   }
541
   }
552
-  function typeexpr(type, value) {
553
-    if (type == "variable") {
554
-      if (value == "keyof") {
555
-        cx.marked = "keyword"
556
-        return cont(typeexpr)
557
-      } else {
558
-        cx.marked = "type"
559
-        return cont(afterType)
560
-      }
561
-    }
542
+  function typeexpr(type) {
543
+    if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
562
     if (type == "string" || type == "number" || type == "atom") return cont(afterType);
544
     if (type == "string" || type == "number" || type == "atom") return cont(afterType);
563
-    if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
564
-    if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
545
+    if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex)
565
     if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
546
     if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
566
   }
547
   }
567
   function maybeReturnType(type) {
548
   function maybeReturnType(type) {
575
       return cont(typeprop)
556
       return cont(typeprop)
576
     } else if (type == ":") {
557
     } else if (type == ":") {
577
       return cont(typeexpr)
558
       return cont(typeexpr)
578
-    } else if (type == "[") {
579
-      return cont(expression, maybetype, expect("]"), typeprop)
580
     }
559
     }
581
   }
560
   }
582
   function typearg(type) {
561
   function typearg(type) {
587
     if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
566
     if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
588
     if (value == "|" || type == ".") return cont(typeexpr)
567
     if (value == "|" || type == ".") return cont(typeexpr)
589
     if (type == "[") return cont(expect("]"), afterType)
568
     if (type == "[") return cont(expect("]"), afterType)
590
-    if (value == "extends") return cont(typeexpr)
591
-  }
592
-  function maybeTypeArgs(_, value) {
593
-    if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
594
   }
569
   }
595
   function vardef() {
570
   function vardef() {
596
     return pass(pattern, maybetype, maybeAssign, vardefCont);
571
     return pass(pattern, maybetype, maybeAssign, vardefCont);
649
     if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef)
624
     if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef)
650
   }
625
   }
651
   function funarg(type) {
626
   function funarg(type) {
652
-    if (type == "spread" || type == "modifier") return cont(funarg);
627
+    if (type == "spread") return cont(funarg);
653
     return pass(pattern, maybetype, maybeAssign);
628
     return pass(pattern, maybetype, maybeAssign);
654
   }
629
   }
655
   function classExpression(type, value) {
630
   function classExpression(type, value) {
667
     if (type == "{") return cont(pushlex("}"), classBody, poplex);
642
     if (type == "{") return cont(pushlex("}"), classBody, poplex);
668
   }
643
   }
669
   function classBody(type, value) {
644
   function classBody(type, value) {
670
-    if (type == "modifier" || type == "async" ||
671
-        (type == "variable" &&
672
-         (value == "static" || value == "get" || value == "set") &&
673
-         cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
674
-      cx.marked = "keyword";
675
-      return cont(classBody);
676
-    }
677
     if (type == "variable" || cx.style == "keyword") {
645
     if (type == "variable" || cx.style == "keyword") {
646
+      if ((value == "async" || value == "static" || value == "get" || value == "set" ||
647
+           (isTS && (value == "public" || value == "private" || value == "protected" || value == "readonly" || value == "abstract"))) &&
648
+          cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
649
+        cx.marked = "keyword";
650
+        return cont(classBody);
651
+      }
678
       cx.marked = "property";
652
       cx.marked = "property";
679
       return cont(isTS ? classfield : functiondef, classBody);
653
       return cont(isTS ? classfield : functiondef, classBody);
680
     }
654
     }
734
       /[,.]/.test(textAfter.charAt(0));
708
       /[,.]/.test(textAfter.charAt(0));
735
   }
709
   }
736
 
710
 
737
-  function expressionAllowed(stream, state, backUp) {
738
-    return state.tokenize == tokenBase &&
739
-      /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
740
-      (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
741
-  }
742
-
743
   // Interface
711
   // Interface
744
 
712
 
745
   return {
713
   return {
814
     jsonMode: jsonMode,
782
     jsonMode: jsonMode,
815
 
783
 
816
     expressionAllowed: expressionAllowed,
784
     expressionAllowed: expressionAllowed,
817
-
818
     skipExpression: function(state) {
785
     skipExpression: function(state) {
819
       var top = state.cc[state.cc.length - 1]
786
       var top = state.cc[state.cc.length - 1]
820
       if (top == expression || top == expressionNoComma) state.cc.pop()
787
       if (top == expression || top == expressionNoComma) state.cc.pop()
835
 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
802
 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
836
 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
803
 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
837
 
804
 
838
-});
805
+});