1
- var createEditor ;
1
+ var createEditorPromise = new $ . Deferred ( ) ;
2
2
3
3
var codeMirror ;
4
4
var codeMirrorResolved ;
@@ -7,9 +7,12 @@ function replaceWithEditor(selector) {
7
7
var container = $ ( selector ) ;
8
8
var value = container . text ( ) ;
9
9
container . text ( "" ) ;
10
- var editor = createEditor ( container . get ( 0 ) , true , 1068 )
11
- editor . setValue ( value ) ;
12
- return editor ;
10
+ var editorPromise = createEditorPromise . then ( function ( createEditor ) {
11
+ var editor = createEditor ( container . get ( 0 ) , true , 1068 )
12
+ editor . setValue ( value ) ;
13
+ return editor ;
14
+ } ) ;
15
+ return editorPromise ;
13
16
}
14
17
15
18
function main ( ) {
@@ -22,63 +25,66 @@ function main() {
22
25
}
23
26
} ) ;
24
27
25
- codeMirror = replaceWithEditor ( "#yaml-config-item" ) ;
26
- codeMirror . trigger ( 'fold' , 'editor.foldLevel2' ) ;
27
-
28
- $ ( "#fold-yaml-config" ) . click ( function ( ) {
28
+ replaceWithEditor ( "#yaml-config-item" ) . then ( function ( codeMirror ) {
29
29
codeMirror . trigger ( 'fold' , 'editor.foldLevel2' ) ;
30
+
31
+ $ ( "#fold-yaml-config" ) . click ( function ( ) {
32
+ codeMirror . trigger ( 'fold' , 'editor.foldLevel2' ) ;
33
+ } ) ;
34
+
35
+ $ ( "#unfold-yaml-config" ) . click ( function ( ) {
36
+ codeMirror . trigger ( 'fold' , 'editor.unfoldAll' ) ;
37
+ } ) ;
38
+
39
+ $ ( "#copy-yaml-config" ) . click ( function ( ) {
40
+ copyToClipboard ( codeMirror . getValue ( ) ) ;
41
+ } ) ;
30
42
} ) ;
31
43
32
- $ ( "#unfold-yaml-config" ) . click ( function ( ) {
33
- codeMirror . trigger ( 'fold' , 'editor.unfoldAll' ) ;
34
- } ) ;
35
-
36
- $ ( "#copy-yaml-config" ) . click ( function ( ) {
37
- copyToClipboard ( codeMirror . getValue ( ) ) ;
38
- } ) ;
39
-
40
- codeMirrorResolved = replaceWithEditor ( "#resolved-yaml-config-item" ) ;
41
- codeMirrorResolved . trigger ( 'fold' , 'editor.foldLevel1' ) ;
42
-
43
- $ ( "#fold-resolved-yaml-config" ) . click ( function ( ) {
44
+ replaceWithEditor ( "#resolved-yaml-config-item" ) . then ( function ( codeMirrorResolved ) {
44
45
codeMirrorResolved . trigger ( 'fold' , 'editor.foldLevel1' ) ;
45
- } ) ;
46
-
47
- $ ( "#unfold-resolved-yaml-config" ) . click ( function ( ) {
48
- codeMirrorResolved . trigger ( 'fold' , 'editor.unfoldAll' ) ;
49
- } ) ;
50
-
51
- $ ( "#copy-resolved-yaml-config" ) . click ( function ( ) {
52
- copyToClipboard ( codeMirrorResolved . getValue ( ) ) ;
46
+
47
+ $ ( "#fold-resolved-yaml-config" ) . click ( function ( ) {
48
+ codeMirrorResolved . trigger ( 'fold' , 'editor.foldLevel1' ) ;
49
+ } ) ;
50
+
51
+ $ ( "#unfold-resolved-yaml-config" ) . click ( function ( ) {
52
+ codeMirrorResolved . trigger ( 'fold' , 'editor.unfoldAll' ) ;
53
+ } ) ;
54
+
55
+ $ ( "#copy-resolved-yaml-config" ) . click ( function ( ) {
56
+ copyToClipboard ( codeMirrorResolved . getValue ( ) ) ;
57
+ } ) ;
53
58
} ) ;
54
59
55
60
$ ( "#host-ref" ) . text ( "YDB Developer UI - " + window . location . hostname ) ;
56
61
57
62
$ ( ".yaml-config-item" ) . each ( function ( ) {
58
- let editor = replaceWithEditor ( this ) ;
59
-
60
- $ ( this ) . parent ( ) . find ( '. fold-yaml-config' ) . click ( function ( ) {
61
- editor . trigger ( 'fold' , 'editor.foldLevel2' ) ;
62
- } ) ;
63
-
64
- $ ( this ) . parent ( ) . find ( '.unfold-yaml-config' ) . click ( function ( ) {
65
- editor . trigger ( 'fold' , 'editor.unfoldAll' ) ;
66
- } ) ;
67
-
68
- $ ( this ) . parent ( ) . find ( '.copy-yaml-config' ) . click ( function ( ) {
69
- copyToClipboard ( editor . getValue ( ) ) ;
63
+ replaceWithEditor ( this ) . then ( function ( editor ) {
64
+ $ ( this ) . parent ( ) . find ( '.fold-yaml-config' ) . click ( function ( ) {
65
+ editor . trigger ( ' fold' , 'editor.foldLevel2' ) ;
66
+ } ) ;
67
+
68
+ $ ( this ) . parent ( ) . find ( '.unfold-yaml-config' ) . click ( function ( ) {
69
+ editor . trigger ( 'fold' , 'editor.unfoldAll' ) ;
70
+ } ) ;
71
+
72
+ $ ( this ) . parent ( ) . find ( '.copy-yaml-config' ) . click ( function ( ) {
73
+ copyToClipboard ( editor . getValue ( ) ) ;
74
+ } ) ;
70
75
} ) ;
71
76
} ) ;
72
77
}
73
78
74
79
let run = ( ) => {
75
80
require . config ( {
76
81
urlArgs : "v=0.27.0.2" ,
77
- paths : { vs : "../cms/ext/monaco-editor/vs" }
82
+ paths : { vs : "../cms/ext/monaco-editor/vs" } ,
83
+ waitSeconds : 60 // Since editor is quite large
78
84
} ) ;
79
85
80
86
require ( [ "vs/editor/editor.main" ] , function ( ) {
81
- createEditor = ( container , readOnly , width ) => {
87
+ createEditorPromise . resolve ( ( container , readOnly , width ) => {
82
88
var editor ;
83
89
container . style . border = '1px solid #eee' ;
84
90
container . style . borderRadius = '8px' ;
@@ -112,7 +118,7 @@ let run = () => {
112
118
editor . onDidContentSizeChange ( updateHeight ) ;
113
119
updateHeight ( ) ;
114
120
return editor ;
115
- }
121
+ } ) ;
116
122
117
123
$ ( document ) . ready ( main ) ;
118
124
} ) ;
0 commit comments