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

Commit 5f457a0

Browse files
committed
Merge branch 'history-test'
2 parents c72dda5 + d888fd5 commit 5f457a0

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

builder/lib/builder.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ protected function generateViewAllPages() {
214214

215215
// get all the rendered partials that match
216216
$sid = $this->gatherPartialsByMatch($patternType, $patternSubType);
217+
$sid["patternPartial"] = $subItem["patternPartial"];
217218

218219
// render the viewall template
219220
$v = $this->mfs->render('viewall',$sid);

public/styleguide/js/native.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/styleguide/js/styleguide.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@
365365

366366
document.getElementById("sg-viewport").contentWindow.location.assign(iFramePath);
367367

368+
history.replaceState({ "pattern": patternName }, null, null);
369+
368370
//IFrame functionality
369371

370372
//Scripts to run after the page has loaded into the iframe
@@ -496,19 +498,16 @@ function receiveIframeMessage(event) {
496498

497499
} else if (event.data.patternpartial != undefined) {
498500

499-
// make sure the pop pattern doesn't fire
500-
urlHandler.doPop = false;
501-
502501
if (!urlHandler.skipBack) {
503502
var iFramePath = urlHandler.getFileName(event.data.patternpartial);
504503
urlHandler.pushPattern(event.data.patternpartial);
505504
if (wsnConnected) {
506505
wsn.send( '{"url": "'+iFramePath+'", "patternpartial": "'+event.data.patternpartial+'" }' );
507506
}
507+
508508
}
509509

510510
// reset the defaults
511-
urlHandler.doPop = true;
512511
urlHandler.skipBack = false;
513512

514513
}

public/styleguide/js/url-handler.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
var urlHandler = {
1414

1515
// if true it'll make sure iFrames and history aren't updated on back button click
16-
doPop: true,
1716
skipBack: false,
1817

1918
/**
@@ -120,42 +119,56 @@ var urlHandler = {
120119
* @param {String} the shorthand partials syntax for a given pattern
121120
*/
122121
pushPattern: function (pattern) {
123-
History.pushState({ "pattern": pattern }, null, window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"?p="+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);
127+
} else {
128+
history.pushState(data, "", window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"?p="+pattern);
129+
}
124130
},
125131

126132
/**
127133
* based on a click forward or backward modify the url and iframe source
128134
* @param {Object} event info like state and properties set in pushState()
129135
*/
130-
popPattern: function (state) {
136+
popPattern: function (e) {
131137

132-
if (state.data == null) {
133-
return;
134-
}
138+
var state = e.state;
135139

136-
// make sure that the iframe message stuff is skipped
137-
this.skipBack = true;
140+
if (state == null) {
141+
var rVars = this.getRequestVars();
142+
if ((rVars.p != undefined) || (rVars.pattern != undefined)) {
143+
var patternName = (rVars.p != undefined) ? rVars.p : rVars.pattern;
144+
} else {
145+
this.skipBack = false;
146+
return;
147+
}
148+
} else if (state != null) {
149+
var patternName = state.pattern;
150+
}
138151

139152
var iFramePath = "";
140-
iFramePath = this.getFileName(state.data.pattern);
153+
iFramePath = this.getFileName(patternName);
141154
if (iFramePath == "") {
142155
iFramePath = window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"styleguide/html/styleguide.html";
143156
}
144157

145158
document.getElementById("sg-viewport").contentWindow.location.replace(iFramePath);
146159

147160
if (wsnConnected) {
148-
wsn.send( '{"url": "'+iFramePath+'", "patternpartial": "'+state.data.pattern+'" }' );
161+
wsn.send( '{"url": "'+iFramePath+'", "patternpartial": "'+patternName+'" }' );
149162
}
150163

151164
}
152-
165+
153166
}
154167

155-
History.Adapter.bind(window,'statechange',function(){
156-
if (urlHandler.doPop) {
157-
var state = History.getState();
158-
urlHandler.popPattern(state);
159-
}
160-
urlHandler.doPop = true;
161-
});
168+
/**
169+
* handle the onpopstate event
170+
*/
171+
window.onpopstate = function (event) {
172+
urlHandler.skipBack = true;
173+
urlHandler.popPattern(event);
174+
}

source/_patternlab-files/index.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
</div>
3232
<!--end iFrame-->
3333

34-
<script src="styleguide/js/native.history.js"></script>
3534
<script src="styleguide/js/data-saver.js"></script>
3635
{{> patternPaths }}
3736
{{> viewAllPaths }}

source/_patternlab-files/viewall.mustache

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,23 @@
2424

2525
</div><!--end .sg-main-->
2626
<script>
27+
2728
var body = document.getElementsByTagName('body');
2829
body[0].onclick = function() {
29-
parent.postMessage({"bodyclick":"bodyclick"},window.location.protocol+"//"+window.location.host)
30+
parent.postMessage( { "bodyclick":"bodyclick" }, window.location.protocol+"//"+window.location.host)
3031
};
32+
3133
var els = document.getElementsByClassName("patternLink");
3234
for (i in els) {
3335
els[i].onclick = function() {
34-
parent.postMessage({"patternpartial":this.getAttribute("data-patternpartial")},window.location.protocol+"//"+window.location.host);
36+
parent.postMessage( { "patternpartial": this.getAttribute("data-patternpartial") }, window.location.protocol+"//"+window.location.host);
3537
return false;
3638
}
3739
}
40+
41+
// alert the iframe parent that the pattern has loaded. for page follow.
42+
parent.postMessage( { "url": window.location.host, "patternpartial": "{{ patternPartial }}" },window.location.protocol+"//"+window.location.host);
43+
3844
</script>
3945
</body>
4046
</html>

0 commit comments

Comments
 (0)