12
12
13
13
var urlHandler = {
14
14
15
- // if true it'll make sure iFrames and history aren't updated on back button click
15
+ // set-up some default vars
16
16
skipBack : false ,
17
+ targetOrigin : ( window . location . protocol == "file:" ) ? "*" : window . location . protocol + "//" + window . location . host ,
17
18
18
19
/**
19
20
* get the real file name for a given pattern name
@@ -117,15 +118,17 @@ var urlHandler = {
117
118
/**
118
119
* push a pattern onto the current history based on a click
119
120
* @param {String } the shorthand partials syntax for a given pattern
121
+ * @param {String } the path given by the loaded iframe
120
122
*/
121
- pushPattern : function ( pattern ) {
122
- var data = { "pattern" : pattern } ;
123
- var path = window . location . protocol + "//" + window . location . host + window . location . pathname . replace ( "index.html" , "" ) + urlHandler . getFileName ( pattern ) ;
124
- if ( document . getElementById ( "sg-viewport" ) . contentWindow . location . toString ( ) != path ) {
125
- urlHandler . skipBack = true ;
126
- document . getElementById ( "sg-viewport" ) . contentWindow . location . replace ( path ) ;
123
+ pushPattern : function ( pattern , givenPath ) {
124
+ var data = { "pattern" : pattern } ;
125
+ var fileName = urlHandler . getFileName ( pattern ) ;
126
+ var expectedPath = window . location . protocol + "//" + window . location . host + window . location . pathname . replace ( "public/index.html" , "public/" ) + fileName ;
127
+ if ( givenPath != expectedPath ) {
128
+ document . getElementById ( "sg-viewport" ) . contentWindow . postMessage ( { " path" : fileName } , urlHandler . targetOrigin ) ;
127
129
} else {
128
- history . pushState ( data , "" , window . location . protocol + "//" + window . location . host + window . location . pathname . replace ( "index.html" , "" ) + "?p=" + pattern ) ;
130
+ var addressReplacement = ( window . location . protocol == "file:" ) ? null : window . location . protocol + "//" + window . location . host + window . location . pathname . replace ( "index.html" , "" ) + "?p=" + pattern ;
131
+ history . pushState ( data , null , addressReplacement ) ;
129
132
}
130
133
} ,
131
134
@@ -152,10 +155,10 @@ var urlHandler = {
152
155
var iFramePath = "" ;
153
156
iFramePath = this . getFileName ( patternName ) ;
154
157
if ( iFramePath == "" ) {
155
- iFramePath = window . location . protocol + "//" + window . location . host + window . location . pathname . replace ( "index.html" , "" ) + "styleguide/html/styleguide.html" ;
158
+ iFramePath = "styleguide/html/styleguide.html" ;
156
159
}
157
160
158
- document . getElementById ( "sg-viewport" ) . contentWindow . location . replace ( iFramePath ) ;
161
+ document . getElementById ( "sg-viewport" ) . contentWindow . postMessage ( { "path" : iFramePath } , urlHandler . targetOrigin ) ;
159
162
160
163
if ( wsnConnected ) {
161
164
wsn . send ( '{"url": "' + iFramePath + '", "patternpartial": "' + patternName + '" }' ) ;
0 commit comments