@@ -858,59 +858,59 @@ Dispatcher.trigger('setupPanels');
858
858
*/
859
859
860
860
var panelsViewer = {
861
-
861
+
862
862
// set up some defaults
863
863
targetOrigin : ( window . location . protocol === 'file:' ) ? '*' : window . location . protocol + '//' + window . location . host ,
864
864
initCopy : false ,
865
865
initMoveTo : 0 ,
866
-
866
+
867
867
/**
868
868
* Check to see if all of the panels have been collected before rendering
869
869
* @param {String } the collected panels
870
870
* @param {String } the data from the pattern
871
871
* @param {Boolean } if this is going to be passed back to the styleguide
872
872
*/
873
873
checkPanels : function ( panels , patternData , iframePassback , switchText ) {
874
-
874
+
875
875
// count how many panels have rendered content
876
876
var panelContentCount = 0 ;
877
877
for ( var i = 0 ; i < panels . length ; ++ i ) {
878
878
if ( panels [ i ] . content !== undefined ) {
879
879
panelContentCount ++ ;
880
880
}
881
881
}
882
-
882
+
883
883
// see if the count of panels with content matches number of panels
884
884
if ( panelContentCount === Panels . count ( ) ) {
885
885
panelsViewer . renderPanels ( panels , patternData , iframePassback , switchText ) ;
886
886
}
887
-
887
+
888
888
} ,
889
-
889
+
890
890
/**
891
891
* Gather the panels related to the modal
892
892
* @param {String } the data from the pattern
893
893
* @param {Boolean } if this is going to be passed back to the styleguide
894
894
*/
895
895
gatherPanels : function ( patternData , iframePassback , switchText ) {
896
-
896
+
897
897
Dispatcher . addListener ( 'checkPanels' , panelsViewer . checkPanels ) ;
898
-
898
+
899
899
// set-up defaults
900
900
var template , templateCompiled , templateRendered , panel ;
901
-
901
+
902
902
// get the base panels
903
903
var panels = Panels . get ( ) ;
904
-
904
+
905
905
// evaluate panels array and create content
906
906
for ( var i = 0 ; i < panels . length ; ++ i ) {
907
-
907
+
908
908
panel = panels [ i ] ;
909
-
909
+
910
910
if ( ( panel . templateID !== undefined ) && ( panel . templateID ) ) {
911
-
911
+
912
912
if ( ( panel . httpRequest !== undefined ) && ( panel . httpRequest ) ) {
913
-
913
+
914
914
// need a file and then render
915
915
var fileName = urlHandler . getFileName ( patternData . patternPartial ) ;
916
916
var e = new XMLHttpRequest ( ) ;
@@ -926,73 +926,73 @@ var panelsViewer = {
926
926
} ) ( i , panels , patternData , iframePassback ) ;
927
927
e . open ( 'GET' , fileName . replace ( / \. h t m l / , panel . httpRequestReplace ) + '?' + ( new Date ( ) ) . getTime ( ) , true ) ;
928
928
e . send ( ) ;
929
-
929
+
930
930
} else {
931
-
931
+
932
932
// vanilla render of pattern data
933
933
template = document . getElementById ( panel . templateID ) ;
934
934
templateCompiled = Hogan . compile ( template . innerHTML ) ;
935
935
templateRendered = templateCompiled . render ( patternData ) ;
936
936
panels [ i ] . content = templateRendered ;
937
937
Dispatcher . trigger ( 'checkPanels' , [ panels , patternData , iframePassback , switchText ] ) ;
938
-
938
+
939
939
}
940
-
940
+
941
941
}
942
-
942
+
943
943
}
944
-
944
+
945
945
} ,
946
-
946
+
947
947
/**
948
948
* Render the panels that have been collected
949
949
* @param {String } the collected panels
950
950
* @param {String } the data from the pattern
951
951
* @param {Boolean } if this is going to be passed back to the styleguide
952
952
*/
953
953
renderPanels : function ( panels , patternData , iframePassback , switchText ) {
954
-
954
+
955
955
// set-up defaults
956
956
var template , templateCompiled , templateRendered ;
957
957
var annotation , comment , count , div , els , item , markup , i ;
958
958
var patternPartial = patternData . patternPartial ;
959
959
patternData . panels = panels ;
960
-
960
+
961
961
// set a default pattern description for modal pop-up
962
962
if ( ! iframePassback && ( patternData . patternDesc . length === 0 ) ) {
963
- patternData . patternDesc = "There is no description for this pattern. " ;
963
+ patternData . patternDesc = "" ;
964
964
}
965
-
965
+
966
966
// capitilize the pattern name
967
967
patternData . patternNameCaps = patternData . patternName . toUpperCase ( ) ;
968
-
968
+
969
969
// check for annotations in the given mark-up
970
970
markup = document . createElement ( 'div' ) ;
971
971
markup . innerHTML = patternData . patternMarkup ;
972
-
972
+
973
973
count = 1 ;
974
974
patternData . annotations = [ ] ;
975
975
delete patternData [ 'patternMarkup' ] ;
976
-
976
+
977
977
for ( i = 0 ; i < comments . comments . length ; ++ i ) {
978
-
978
+
979
979
item = comments . comments [ i ] ;
980
980
els = markup . querySelectorAll ( item . el ) ;
981
-
981
+
982
982
if ( els . length > 0 ) {
983
983
annotation = { 'displayNumber' : count , 'el' : item . el , 'title' : item . title , 'comment' : item . comment } ;
984
984
patternData . annotations . push ( annotation ) ;
985
985
count ++ ;
986
986
}
987
-
987
+
988
988
}
989
-
989
+
990
990
// alert the pattern that annotations should be highlighted
991
991
if ( patternData . annotations . length > 0 ) {
992
992
var obj = JSON . stringify ( { 'event' : 'patternLab.annotationsHighlightShow' , 'annotations' : patternData . annotations } ) ;
993
993
document . getElementById ( 'sg-viewport' ) . contentWindow . postMessage ( obj , panelsViewer . targetOrigin ) ;
994
994
}
995
-
995
+
996
996
// add hasComma property to lineage
997
997
if ( patternData . lineage . length > 0 ) {
998
998
for ( i = 0 ; i < patternData . lineage . length ; ++ i ) {
@@ -1001,7 +1001,7 @@ var panelsViewer = {
1001
1001
}
1002
1002
}
1003
1003
}
1004
-
1004
+
1005
1005
// add hasComma property to lineageR
1006
1006
if ( patternData . lineageR . length > 0 ) {
1007
1007
for ( i = 0 ; i < patternData . lineageR . length ; ++ i ) {
@@ -1010,72 +1010,72 @@ var panelsViewer = {
1010
1010
}
1011
1011
}
1012
1012
}
1013
-
1013
+
1014
1014
// add *Exists attributes for Hogan templates
1015
1015
// figure out if the description exists
1016
1016
patternData . patternDescExists = ( ( patternData . patternDesc . length > 0 ) || ( ( patternData . patternDescAdditions !== undefined ) && ( patternData . patternDescAdditions . length > 0 ) ) ) ;
1017
-
1017
+
1018
1018
// figure out if lineage should be drawn
1019
1019
patternData . lineageExists = ( patternData . lineage . length !== 0 ) ;
1020
-
1020
+
1021
1021
// figure out if reverse lineage should be drawn
1022
1022
patternData . lineageRExists = ( patternData . lineageR . length !== 0 ) ;
1023
-
1023
+
1024
1024
// figure out if pattern state should be drawn
1025
1025
patternData . patternStateExists = ( patternData . patternState . length > 0 ) ;
1026
-
1026
+
1027
1027
// figure if the entire desc block should be drawn
1028
1028
patternData . descBlockExists = ( patternData . patternDescExists || patternData . lineageExists || patternData . lineageRExists || patternData . patternStateExists ) ;
1029
-
1029
+
1030
1030
// figure if annotations should be drawn
1031
1031
patternData . annotationExists = ( patternData . annotations . length > 0 ) ;
1032
-
1032
+
1033
1033
// set isPatternView based on if we have to pass it back to the styleguide level
1034
1034
patternData . isPatternView = ( iframePassback === false ) ;
1035
-
1035
+
1036
1036
// render all of the panels in the base panel template
1037
1037
template = document . getElementById ( 'pl-panel-template-base' ) ;
1038
1038
templateCompiled = Hogan . compile ( template . innerHTML ) ;
1039
1039
templateRendered = templateCompiled . render ( patternData ) ;
1040
-
1040
+
1041
1041
// make sure templateRendered is modified to be an HTML element
1042
1042
div = document . createElement ( 'div' ) ;
1043
1043
div . className = 'sg-modal-content-inner' ;
1044
1044
div . innerHTML = templateRendered ;
1045
1045
templateRendered = div ;
1046
-
1046
+
1047
1047
// add click events
1048
1048
templateRendered = panelsUtil . addClickEvents ( templateRendered , patternPartial ) ;
1049
-
1049
+
1050
1050
// add onclick events to the tabs in the rendered content
1051
1051
for ( i = 0 ; i < panels . length ; ++ i ) {
1052
-
1052
+
1053
1053
panel = panels [ i ] ;
1054
-
1054
+
1055
1055
// default IDs
1056
1056
panelTab = '#sg-' + patternPartial + '-' + panel . id + '-tab' ;
1057
1057
panelBlock = '#sg-' + patternPartial + '-' + panel . id + '-panel' ;
1058
-
1058
+
1059
1059
// show default options
1060
1060
if ( ( templateRendered . querySelector ( panelTab ) !== null ) && ( panel . default ) ) {
1061
1061
templateRendered . querySelector ( panelTab ) . classList . add ( 'sg-tab-title-active' ) ;
1062
1062
templateRendered . querySelector ( panelBlock ) . style . display = 'block' ;
1063
1063
}
1064
-
1064
+
1065
1065
}
1066
-
1066
+
1067
1067
// find lineage links in the rendered content and add postmessage handlers in case it's in the modal
1068
1068
$ ( '#sg-code-lineage-fill a, #sg-code-lineager-fill a' , templateRendered ) . on ( 'click' , function ( e ) {
1069
1069
e . preventDefault ( ) ;
1070
1070
var obj = JSON . stringify ( { 'event' : 'patternLab.updatePath' , 'path' : urlHandler . getFileName ( $ ( this ) . attr ( 'data-patternpartial' ) ) } ) ;
1071
1071
document . getElementById ( 'sg-viewport' ) . contentWindow . postMessage ( obj , panelsViewer . targetOrigin ) ;
1072
1072
} ) ;
1073
-
1073
+
1074
1074
// gather panels from plugins
1075
1075
Dispatcher . trigger ( 'insertPanels' , [ templateRendered , patternPartial , iframePassback , switchText ] ) ;
1076
-
1076
+
1077
1077
}
1078
-
1078
+
1079
1079
} ;
1080
1080
1081
1081
/*!
0 commit comments