Skip to content

Commit 3011fd2

Browse files
committed
updating dist js
1 parent 1e991a3 commit 3011fd2

File tree

4 files changed

+81
-45
lines changed

4 files changed

+81
-45
lines changed

dist/styleguide/js/patternlab-pattern.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ if (self != top) {
4747
};
4848
}
4949

50+
// if there are clicks on the iframe make sure the nav in the iframe parent closes
51+
var body = document.getElementsByTagName('body');
52+
body[0].onclick = function() {
53+
var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host;
54+
var obj = JSON.stringify({ "event": "patternLab.bodyClick", "bodyclick": "bodyclick" });
55+
parent.postMessage(obj,targetOrigin);
56+
};
57+
5058
}
5159

52-
// if there are clicks on the iframe make sure the nav in the iframe parent closes
53-
var body = document.getElementsByTagName('body');
54-
body[0].onclick = function() {
55-
var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host;
56-
var obj = JSON.stringify({ "event": "patternLab.bodyClick", "bodyclick": "bodyclick" });
57-
parent.postMessage(obj,targetOrigin);
58-
};
60+
5961

6062
// watch the iframe source so that it can be sent back to everyone else.
6163
function receiveIframeMessage(event) {
@@ -402,23 +404,23 @@ var modalStyleguide = {
402404
},
403405

404406
/**
405-
* toggle the modal window open and closed
407+
* toggle the modal window open and closed based on clicking the pip
408+
* @param {String} the patternPartial that identifies what needs to be toggled
406409
*/
407410
toggle: function(patternPartial) {
408411
if ((modalStyleguide.active[patternPartial] === undefined) || !modalStyleguide.active[patternPartial]) {
409412
var el = document.getElementById('sg-pattern-data-'+patternPartial);
410-
var patternData = JSON.parse(el.innerHTML);
411-
patternMarkupEl = document.querySelector('#'+patternData.patternPartial+' > .sg-pattern-example');
412-
patternData.patternMarkup = (patternMarkupEl !== null) ? patternMarkupEl.innerHTML : document.querySelector('body').innerHTML;
413-
modalStyleguide.patternQueryInfo(patternData, true);
413+
modalStyleguide.collectAndSend(el, true, false);
414414
} else {
415415
modalStyleguide.close(patternPartial);
416416
}
417417

418418
},
419419

420420
/**
421-
* open the modal window
421+
* open the modal window for a view-all entry
422+
* @param {String} the patternPartial that identifies what needs to be opened
423+
* @param {String} the content that should be inserted
422424
*/
423425
open: function(patternPartial, content) {
424426

@@ -452,7 +454,8 @@ var modalStyleguide = {
452454
},
453455

454456
/**
455-
* close the modal window
457+
* close the modal window for a view-all entry
458+
* @param {String} the patternPartial that identifies what needs to be closed
456459
*/
457460
close: function(patternPartial) {
458461

@@ -465,8 +468,26 @@ var modalStyleguide = {
465468

466469
},
467470

471+
/**
472+
* get the data that needs to be send to the viewer for rendering
473+
* @param {Element} the identifier for the element that needs to be collected
474+
* @param {Boolean} if the refresh is of a view-all view and the content should be sent back
475+
* @param {Boolean} if the text in the dropdown should be switched
476+
*/
477+
collectAndSend: function(el, iframePassback, switchText) {
478+
var patternData = JSON.parse(el.innerHTML);
479+
if (patternData.patternName !== undefined) {
480+
patternMarkupEl = document.querySelector('#'+patternData.patternPartial+' > .sg-pattern-example');
481+
patternData.patternMarkup = (patternMarkupEl !== null) ? patternMarkupEl.innerHTML : document.querySelector('body').innerHTML;
482+
modalStyleguide.patternQueryInfo(patternData, iframePassback, switchText);
483+
}
484+
},
485+
468486
/**
469487
* return the pattern info to the top level
488+
* @param {Object} the content that will be sent to the viewer for rendering
489+
* @param {Boolean} if the refresh is of a view-all view and the content should be sent back
490+
* @param {Boolean} if the text in the dropdown should be switched
470491
*/
471492
patternQueryInfo: function(patternData, iframePassback, switchText) {
472493

@@ -508,10 +529,7 @@ var modalStyleguide = {
508529

509530
// send each up to the parent to be read and compiled into panels
510531
for (i = 0; i < els.length; i++) {
511-
patternData = JSON.parse(els[i].innerHTML);
512-
patternMarkupEl = document.querySelector('#'+patternData.patternPartial+' > .sg-pattern-example');
513-
patternData.patternMarkup = (patternMarkupEl !== null) ? patternMarkupEl.innerHTML : document.querySelector('body').innerHTML;
514-
modalStyleguide.patternQueryInfo(patternData, iframePassback, data.switchText);
532+
modalStyleguide.collectAndSend(els[i], iframePassback, data.switchText);
515533
}
516534

517535
} else if ((data.event !== undefined) && (data.event == 'patternLab.patternModalInsert')) {

0 commit comments

Comments
 (0)