@@ -47,15 +47,17 @@ if (self != top) {
47
47
} ;
48
48
}
49
49
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
+
50
58
}
51
59
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
+
59
61
60
62
// watch the iframe source so that it can be sent back to everyone else.
61
63
function receiveIframeMessage ( event ) {
@@ -402,23 +404,23 @@ var modalStyleguide = {
402
404
} ,
403
405
404
406
/**
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
406
409
*/
407
410
toggle : function ( patternPartial ) {
408
411
if ( ( modalStyleguide . active [ patternPartial ] === undefined ) || ! modalStyleguide . active [ patternPartial ] ) {
409
412
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 ) ;
414
414
} else {
415
415
modalStyleguide . close ( patternPartial ) ;
416
416
}
417
417
418
418
} ,
419
419
420
420
/**
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
422
424
*/
423
425
open : function ( patternPartial , content ) {
424
426
@@ -452,7 +454,8 @@ var modalStyleguide = {
452
454
} ,
453
455
454
456
/**
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
456
459
*/
457
460
close : function ( patternPartial ) {
458
461
@@ -465,8 +468,26 @@ var modalStyleguide = {
465
468
466
469
} ,
467
470
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
+
468
486
/**
469
487
* 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
470
491
*/
471
492
patternQueryInfo : function ( patternData , iframePassback , switchText ) {
472
493
@@ -508,10 +529,7 @@ var modalStyleguide = {
508
529
509
530
// send each up to the parent to be read and compiled into panels
510
531
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 ) ;
515
533
}
516
534
517
535
} else if ( ( data . event !== undefined ) && ( data . event == 'patternLab.patternModalInsert' ) ) {
0 commit comments