1
+ /*
2
+ * Project Name : Visual Python
3
+ * Description : GUI-based Python code generator
4
+ * File Name : HelpViewer.js
5
+ * Author : Black Logic
6
+ * Note : Component > HelpViewer
7
+ * License : GNU GPLv3 with Visual Python special exception
8
+ * Date : 2023. 07. 13
9
+ * Change Date :
10
+ */
11
+ //============================================================================
12
+ // [CLASS] HelpViewer
13
+ //============================================================================
14
+ define ( [
15
+ __VP_TEXT_LOADER__ ( 'vp_base/html/component/helpViewer.html' ) , // INTEGRATION: unified version of text loader
16
+ __VP_CSS_LOADER__ ( 'vp_base/css/component/popupComponent' ) , // INTEGRATION: unified version of css loader
17
+ 'vp_base/js/com/com_util' ,
18
+ 'vp_base/js/com/com_Const' ,
19
+ 'vp_base/js/com/com_String' ,
20
+ 'vp_base/js/com/component/Component' ,
21
+ 'vp_base/js/com/component/LoadingSpinner'
22
+ ] , function ( hvHtml , ppCss , com_util , com_Const , com_String , Component , LoadingSpinner ) {
23
+
24
+ /**
25
+ * HelpViewer
26
+ */
27
+ class HelpViewer extends Component {
28
+ constructor ( ) {
29
+ super ( $ ( vpConfig . parentSelector ) , { } , { } ) ;
30
+ }
31
+
32
+ _init ( ) {
33
+ this . position = {
34
+ right : 10 , top : 120
35
+ } ;
36
+ this . size = {
37
+ width : 500 ,
38
+ height : 500
39
+ } ;
40
+ }
41
+
42
+
43
+ _bindEvent ( ) {
44
+ super . _bindEvent ( ) ;
45
+ /** Implement binding events */
46
+ let that = this ;
47
+
48
+ $ ( that . wrapSelector ( '.vp-popup-maximize' ) ) . on ( 'click' , function ( ) {
49
+ // save position
50
+ that . position = $ ( that . wrapSelector ( ) ) . position ( ) ;
51
+ // save size
52
+ that . size = {
53
+ width : $ ( that . wrapSelector ( ) ) . width ( ) ,
54
+ height : $ ( that . wrapSelector ( ) ) . height ( )
55
+ }
56
+ // maximize popup
57
+ $ ( that . wrapSelector ( ) ) . css ( {
58
+ width : '100%' ,
59
+ height : '100%' ,
60
+ top : 0 ,
61
+ left : 0
62
+ } ) ;
63
+ // show / hide buttons
64
+ $ ( this ) . hide ( ) ;
65
+ $ ( that . wrapSelector ( '.vp-popup-return' ) ) . show ( ) ;
66
+ } ) ;
67
+
68
+ // Return operation
69
+ $ ( this . wrapSelector ( '.vp-popup-return' ) ) . on ( 'click' , function ( evt ) {
70
+ // return size
71
+ $ ( that . wrapSelector ( ) ) . css ( {
72
+ width : that . size . width + 'px' ,
73
+ height : that . size . height + 'px' ,
74
+ top : that . position . top ,
75
+ left : that . position . left
76
+ } ) ;
77
+ // show / hide buttons
78
+ $ ( this ) . hide ( ) ;
79
+ $ ( that . wrapSelector ( '.vp-popup-maximize' ) ) . show ( ) ;
80
+ } ) ;
81
+
82
+ $ ( that . wrapSelector ( '.vp-popup-close' ) ) . on ( 'click' , function ( ) {
83
+ that . remove ( ) ;
84
+ } ) ;
85
+
86
+ $ ( that . wrapSelector ( '.vp-popup-button' ) ) . on ( 'click' , function ( ) {
87
+ var btnType = $ ( this ) . data ( 'type' ) ;
88
+ switch ( btnType ) {
89
+ case 'cancel' :
90
+ that . remove ( ) ;
91
+ break ;
92
+ }
93
+ } ) ;
94
+
95
+ // Focus recognization
96
+ $ ( this . wrapSelector ( ) ) . on ( 'click' , function ( ) {
97
+ that . focus ( ) ;
98
+ } ) ;
99
+ }
100
+
101
+ _bindDraggable ( ) {
102
+ var that = this ;
103
+ let containment = 'body' ;
104
+ if ( vpConfig . extensionType === 'lab' || vpConfig . extensionType === 'lite' ) {
105
+ containment = '#main' ;
106
+ }
107
+ $ ( this . wrapSelector ( ) ) . draggable ( {
108
+ handle : '.vp-popup-title' ,
109
+ containment : containment ,
110
+ start : function ( evt , ui ) {
111
+ // check focused
112
+ $ ( that . eventTarget ) . trigger ( {
113
+ type : 'focus_option_page' ,
114
+ component : that
115
+ } ) ;
116
+ }
117
+ } ) ;
118
+ }
119
+
120
+ _bindResizable ( ) {
121
+ let that = this ;
122
+ $ ( this . wrapSelector ( ) ) . resizable ( {
123
+ handles : 'all' ,
124
+ start : function ( evt , ui ) {
125
+ // show / hide buttons
126
+ $ ( that . wrapSelector ( '.vp-popup-return' ) ) . hide ( ) ;
127
+ $ ( that . wrapSelector ( '.vp-popup-maximize' ) ) . show ( ) ;
128
+ }
129
+ } ) ;
130
+ }
131
+
132
+ template ( ) {
133
+ this . $pageDom = $ ( hvHtml ) ;
134
+
135
+ return this . $pageDom ;
136
+ }
137
+
138
+ render ( ) {
139
+ super . render ( ) ;
140
+
141
+ // set detailed size
142
+ $ ( this . wrapSelector ( ) ) . css ( {
143
+ width : this . size . width + 'px' ,
144
+ height : this . size . height + 'px'
145
+ } ) ;
146
+
147
+ // position
148
+ $ ( this . wrapSelector ( ) ) . css ( { top : this . position . top , right : this . position . right } ) ;
149
+
150
+ this . _bindDraggable ( ) ;
151
+ this . _bindResizable ( ) ;
152
+ }
153
+
154
+ wrapSelector ( selector = '' ) {
155
+ var sbSelector = new com_String ( ) ;
156
+ var cnt = arguments . length ;
157
+ if ( cnt < 2 ) {
158
+ // if there's no more arguments
159
+ sbSelector . appendFormat ( ".vp-popup-frame.{0} {1}" , this . uuid , selector ) ;
160
+ } else {
161
+ // if there's more arguments
162
+ sbSelector . appendFormat ( ".vp-popup-frame.{0}" , this . uuid ) ;
163
+ for ( var idx = 0 ; idx < cnt ; idx ++ ) {
164
+ sbSelector . appendFormat ( " {0}" , arguments [ idx ] ) ;
165
+ }
166
+ }
167
+ return sbSelector . toString ( ) ;
168
+ }
169
+
170
+ open ( content , useHelp = true ) {
171
+ this . show ( ) ;
172
+
173
+ let that = this ;
174
+
175
+ let code = content ;
176
+ if ( useHelp === true ) {
177
+ code = `print(help(${ content } ))` ;
178
+ }
179
+
180
+ let loadingSpinner = new LoadingSpinner ( $ ( this . wrapSelector ( '.vp-popup-body' ) ) ) ;
181
+ vpKernel . execute ( code ) . then ( function ( resultObj ) {
182
+ let { result } = resultObj ;
183
+
184
+ $ ( that . wrapSelector ( '#helpContent' ) ) . text ( result ) ;
185
+
186
+ } ) . catch ( function ( err ) {
187
+ vpLog . display ( VP_LOG_TYPE . ERROR , err ) ;
188
+ } ) . finally ( function ( ) {
189
+ loadingSpinner . remove ( ) ;
190
+ } ) ;
191
+
192
+ this . focus ( ) ;
193
+ }
194
+
195
+ generateCode ( ) {
196
+ return '' ;
197
+ }
198
+
199
+ show ( ) {
200
+ $ ( this . wrapSelector ( ) ) . show ( ) ;
201
+ }
202
+
203
+ remove ( ) {
204
+ $ ( this . wrapSelector ( ) ) . remove ( ) ;
205
+ }
206
+
207
+ focus ( ) {
208
+ $ ( '.vp-popup-frame' ) . removeClass ( 'vp-focused' ) ;
209
+ $ ( '.vp-popup-frame' ) . css ( { 'z-index' : 1200 } ) ;
210
+ $ ( this . wrapSelector ( ) ) . addClass ( 'vp-focused' ) ;
211
+ $ ( this . wrapSelector ( ) ) . css ( { 'z-index' : 1205 } ) ; // move forward
212
+ }
213
+
214
+ }
215
+
216
+ return HelpViewer ;
217
+ } ) ;
0 commit comments