Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit 4bb27ac

Browse files
committed
make sure code view open auto-closes annotation view
1 parent 88fec9f commit 4bb27ac

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

public/styleguide/js/code-viewer.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ var codeViewer = {
3030

3131
e.preventDefault();
3232

33-
// make sure the annotations overlay is off before showing code view
34-
$('#sg-t-annotations').removeClass('active');
35-
annotationsViewer.commentsActive = false;
36-
var obj = JSON.stringify({ "commentToggle": "off" });
37-
document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
38-
annotationsViewer.slideComment(999);
39-
4033
// remove the class from the "eye" nav item
4134
$('#sg-t-toggle').removeClass('active');
4235

@@ -71,10 +64,22 @@ var codeViewer = {
7164
* after clicking the code view link open the panel
7265
*/
7366
openCode: function() {
67+
68+
// make sure the annotations overlay is off before showing code view
69+
$('#sg-t-annotations').removeClass('active');
70+
annotationsViewer.commentsActive = false;
71+
var obj = JSON.stringify({ "commentToggle": "off" });
72+
document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
73+
annotationsViewer.slideComment(999);
74+
75+
// tell the iframe code view has been turned on
7476
var obj = JSON.stringify({ "codeToggle": "on" });
7577
document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
78+
79+
// note it's turned on in the viewer
7680
codeViewer.codeActive = true;
7781
$('#sg-t-code').addClass('active');
82+
7883
},
7984

8085
/**
@@ -238,35 +243,30 @@ var codeViewer = {
238243
$("#sg-code-lineage").css("display","none");
239244
}
240245

241-
242-
// when clicking on a lineage item change the iframe source
243-
$('#sg-code-lineage-fill a').on("click", function(e){
244-
e.preventDefault();
245-
var obj = JSON.stringify({ "path": urlHandler.getFileName($(this).attr("data-patternpartial")) });
246-
document.getElementById("sg-viewport").contentWindow.postMessage(obj,codeViewer.targetOrigin);
247-
});
248-
249246
// draw reverse lineage
250247
if (lineageR.length !== 0) {
251248
var lineageRList = "";
252249
$("#sg-code-lineager").css("display","block");
253250
for (var i = 0; i < lineageR.length; i++) {
254251
lineageRList += (i === 0) ? "" : ", ";
255-
var cssClass = (lineageR[i].lineageState != undefined) ? lineageR[i].lineageState : "";
252+
var cssClass = (lineageR[i].lineageState != undefined) ? "sg-pattern-state "+lineageR[i].lineageState : "";
256253
lineageRList += "<a href='"+lineageR[i].lineagePath+"' class='"+cssClass+"' data-patternPartial='"+lineageR[i].lineagePattern+"'>"+lineageR[i].lineagePattern+"</a>";
257254
}
258255
$("#sg-code-lineager-fill").html(lineageRList);
259256
} else {
260257
$("#sg-code-lineager").css("display","none");
261258
}
262259

263-
// when clicking on a reverse lineage item change the iframe source
264-
$('#sg-code-lineager-fill a').on("click", function(e){
260+
// when clicking on a lineage item change the iframe source
261+
$('#sg-code-lineage-fill a, #sg-code-lineager-fill a').on("click", function(e){
265262
e.preventDefault();
266-
var obj = JSON.stringify( { "path": urlHandler.getFileName($(this).attr("data-patternpartial")) });
263+
$("#sg-code-loader").css("display","block");
264+
var obj = JSON.stringify({ "path": urlHandler.getFileName($(this).attr("data-patternpartial")) });
267265
document.getElementById("sg-viewport").contentWindow.postMessage(obj,codeViewer.targetOrigin);
268266
});
269267

268+
$('#sg-code-lineage-patternname, #sg-code-lineager-patternname').html(patternPartial);
269+
270270
// get the file name of the pattern so we can get the various editions of the code that can show in code view
271271
var fileName = urlHandler.getFileName(patternPartial);
272272

@@ -292,7 +292,9 @@ var codeViewer = {
292292

293293
// move the code into view
294294
codeViewer.slideCode(0);
295-
295+
296+
$("#sg-code-loader").css("display","none");
297+
296298
},
297299

298300
/**

0 commit comments

Comments
 (0)