@@ -24,10 +24,8 @@ var modalViewer = {
24
24
*/
25
25
onReady : function ( ) {
26
26
27
- if ( DataSaver . findValue ( 'modalActive' ) === 'true' ) {
28
- modalViewer . active = true ;
29
- $ ( '#sg-t-patterninfo' ) . html ( "Hide Pattern Info" ) ;
30
- }
27
+ // make sure the listener for checkpanels is set-up
28
+ Dispatcher . addListener ( 'insertPanels' , modalViewer . insert ) ;
31
29
32
30
// watch for resizes and hide the modal container as appropriate when the modal is already hidden
33
31
$ ( window ) . on ( 'resize' , function ( ) {
@@ -36,9 +34,6 @@ var modalViewer = {
36
34
}
37
35
} ) ;
38
36
39
- // make sure the listener for checkpanels is set-up
40
- Dispatcher . addListener ( 'insertPanels' , modalViewer . insert ) ;
41
-
42
37
// add the info/code panel onclick handler
43
38
$ ( '#sg-t-patterninfo' ) . click ( function ( e ) {
44
39
e . preventDefault ( ) ;
@@ -47,9 +42,6 @@ var modalViewer = {
47
42
modalViewer . toggle ( ) ;
48
43
} ) ;
49
44
50
- // make sure the modal viewer is not viewable
51
- modalViewer . hide ( ) ;
52
-
53
45
// make sure the close button handles the click
54
46
$ ( '#sg-modal-close-btn' ) . on ( 'click' , function ( e ) {
55
47
@@ -64,6 +56,15 @@ var modalViewer = {
64
56
65
57
} ) ;
66
58
59
+ // see if the modal is already active, if so update attributes as appropriate
60
+ if ( DataSaver . findValue ( 'modalActive' ) === 'true' ) {
61
+ modalViewer . active = true ;
62
+ $ ( '#sg-t-patterninfo' ) . html ( "Hide Pattern Info" ) ;
63
+ }
64
+
65
+ // make sure the modal viewer is not viewable, it's alway hidden by default. the pageLoad event determines when it actually opens
66
+ modalViewer . hide ( ) ;
67
+
67
68
// review the query strings in case there is something the modal viewer is supposed to handle by default
68
69
var queryStringVars = urlHandler . getRequestVars ( ) ;
69
70
@@ -144,10 +145,20 @@ var modalViewer = {
144
145
145
146
} ,
146
147
148
+ /**
149
+ * hide the modal window
150
+ */
147
151
hide : function ( ) {
148
152
modalViewer . slide ( $ ( '#sg-modal-container' ) . outerHeight ( ) ) ;
149
153
} ,
150
154
155
+ /**
156
+ * insert the copy for the modal window. if it's meant to be sent back to the iframe do do
157
+ * @param {String } the rendered template that should be inserted
158
+ * @param {String } the patternPartial that the rendered template is related to
159
+ * @param {Boolean } if the refresh is of a view-all view and the content should be sent back
160
+ * @param {Boolean } if the text in the dropdown should be switched
161
+ */
151
162
insert : function ( templateRendered , patternPartial , iframePassback , switchText ) {
152
163
153
164
if ( iframePassback ) {
@@ -158,10 +169,8 @@ var modalViewer = {
158
169
159
170
} else {
160
171
161
- // insert the panels
172
+ // insert the panels and open the viewer
162
173
$ ( '#sg-modal-content' ) . html ( templateRendered ) ;
163
-
164
- // with the content inserted open the modal
165
174
modalViewer . open ( ) ;
166
175
167
176
}
@@ -175,6 +184,9 @@ var modalViewer = {
175
184
176
185
/**
177
186
* refresh the modal if a new pattern is loaded and the modal is active
187
+ * @param {Object } the patternData sent back from the query
188
+ * @param {Boolean } if the refresh is of a view-all view and the content should be sent back
189
+ * @param {Boolean } if the text in the dropdown should be switched
178
190
*/
179
191
refresh : function ( patternData , iframePassback , switchText ) {
180
192
@@ -183,22 +195,24 @@ var modalViewer = {
183
195
modalViewer . hide ( ) ;
184
196
}
185
197
186
- // clear any selections that might have been made
187
- panelsViewer . clear ( ) ;
188
-
189
198
// gather the data that will fill the modal window
190
199
panelsViewer . gatherPanels ( patternData , iframePassback , switchText ) ;
191
200
192
201
} ,
193
202
194
203
/**
195
204
* slides the modal window into or out of view
205
+ * @param {Integer } where the modal window should be slide to
196
206
*/
197
207
slide : function ( pos ) {
198
208
pos = ( pos === 0 ) ? 0 : - pos ;
199
209
$ ( '#sg-modal-container' ) . css ( 'bottom' , pos ) ;
200
210
} ,
201
211
212
+ /**
213
+ * slides the modal window to a particular annotation
214
+ * @param {Integer } the number for the element that should be highlighted
215
+ */
202
216
slideToAnnotation : function ( pos ) {
203
217
204
218
// remove active class
@@ -226,6 +240,7 @@ var modalViewer = {
226
240
227
241
/**
228
242
* ask the pattern for info so we can open the modal window and populate it
243
+ * @param {Boolean } if the dropdown text should be changed
229
244
*/
230
245
queryPattern : function ( switchText ) {
231
246
@@ -249,7 +264,7 @@ var modalViewer = {
249
264
*/
250
265
receiveIframeMessage : function ( event ) {
251
266
252
- var els , i , displayNumberCheck ;
267
+ var els , i ;
253
268
254
269
// does the origin sending the message match the current host? if not dev/null the request
255
270
if ( ( window . location . protocol !== 'file:' ) && ( event . origin !== window . location . protocol + '//' + window . location . host ) ) {
@@ -276,6 +291,7 @@ var modalViewer = {
276
291
277
292
} else if ( ( data . event !== undefined ) && ( data . event == 'patternLab.annotationNumberClicked' ) ) {
278
293
294
+ // slide to a given annoation
279
295
modalViewer . slideToAnnotation ( data . displayNumber ) ;
280
296
281
297
}
0 commit comments