Skip to content

Commit f98fd1c

Browse files
committed
adding better comments
1 parent f327c91 commit f98fd1c

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/js/modal-viewer.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ var modalViewer = {
2424
*/
2525
onReady: function() {
2626

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);
3129

3230
// watch for resizes and hide the modal container as appropriate when the modal is already hidden
3331
$(window).on('resize', function() {
@@ -36,9 +34,6 @@ var modalViewer = {
3634
}
3735
});
3836

39-
// make sure the listener for checkpanels is set-up
40-
Dispatcher.addListener('insertPanels', modalViewer.insert);
41-
4237
// add the info/code panel onclick handler
4338
$('#sg-t-patterninfo').click(function(e) {
4439
e.preventDefault();
@@ -47,9 +42,6 @@ var modalViewer = {
4742
modalViewer.toggle();
4843
});
4944

50-
// make sure the modal viewer is not viewable
51-
modalViewer.hide();
52-
5345
// make sure the close button handles the click
5446
$('#sg-modal-close-btn').on('click', function(e) {
5547

@@ -64,6 +56,15 @@ var modalViewer = {
6456

6557
});
6658

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+
6768
// review the query strings in case there is something the modal viewer is supposed to handle by default
6869
var queryStringVars = urlHandler.getRequestVars();
6970

@@ -144,10 +145,20 @@ var modalViewer = {
144145

145146
},
146147

148+
/**
149+
* hide the modal window
150+
*/
147151
hide: function() {
148152
modalViewer.slide($('#sg-modal-container').outerHeight());
149153
},
150154

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+
*/
151162
insert: function(templateRendered, patternPartial, iframePassback, switchText) {
152163

153164
if (iframePassback) {
@@ -158,10 +169,8 @@ var modalViewer = {
158169

159170
} else {
160171

161-
// insert the panels
172+
// insert the panels and open the viewer
162173
$('#sg-modal-content').html(templateRendered);
163-
164-
// with the content inserted open the modal
165174
modalViewer.open();
166175

167176
}
@@ -175,6 +184,9 @@ var modalViewer = {
175184

176185
/**
177186
* 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
178190
*/
179191
refresh: function(patternData, iframePassback, switchText) {
180192

@@ -183,22 +195,24 @@ var modalViewer = {
183195
modalViewer.hide();
184196
}
185197

186-
// clear any selections that might have been made
187-
panelsViewer.clear();
188-
189198
// gather the data that will fill the modal window
190199
panelsViewer.gatherPanels(patternData, iframePassback, switchText);
191200

192201
},
193202

194203
/**
195204
* slides the modal window into or out of view
205+
* @param {Integer} where the modal window should be slide to
196206
*/
197207
slide: function(pos) {
198208
pos = (pos === 0) ? 0 : -pos;
199209
$('#sg-modal-container').css('bottom',pos);
200210
},
201211

212+
/**
213+
* slides the modal window to a particular annotation
214+
* @param {Integer} the number for the element that should be highlighted
215+
*/
202216
slideToAnnotation: function(pos) {
203217

204218
// remove active class
@@ -226,6 +240,7 @@ var modalViewer = {
226240

227241
/**
228242
* 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
229244
*/
230245
queryPattern: function(switchText) {
231246

@@ -249,7 +264,7 @@ var modalViewer = {
249264
*/
250265
receiveIframeMessage: function(event) {
251266

252-
var els, i, displayNumberCheck;
267+
var els, i;
253268

254269
// does the origin sending the message match the current host? if not dev/null the request
255270
if ((window.location.protocol !== 'file:') && (event.origin !== window.location.protocol+'//'+window.location.host)) {
@@ -276,6 +291,7 @@ var modalViewer = {
276291

277292
} else if ((data.event !== undefined) && (data.event == 'patternLab.annotationNumberClicked')) {
278293

294+
// slide to a given annoation
279295
modalViewer.slideToAnnotation(data.displayNumber);
280296

281297
}

0 commit comments

Comments
 (0)