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

Commit b681be8

Browse files
committed
making sure history is tracked on internal link clicks
1 parent d67cfcd commit b681be8

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

source/_patternlab-files/pattern-header-footer/footer.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
parent.postMessage( { "bodyclick": "bodyclick" }, targetOrigin)
2222
};
2323

24+
// find all links and add an onclick handler for replacing the iframe address so the history works
25+
var aTags = document.getElementsByTagName('a');
26+
for (a in aTags) {
27+
aTags[a].onclick = function(e) {
28+
e.preventDefault();
29+
window.location.replace(this.getAttribute("href"));
30+
};
31+
}
32+
2433
// watch the iframe source so that it can be sent back to everyone else.
2534
function receiveIframeMessage(event) {
2635

source/_patternlab-files/styleguide.mustache

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
parent.postMessage( { "bodyclick": "bodyclick" }, targetOrigin)
3838
};
3939
40+
// find all links and add an onclick handler for replacing the iframe address so the history works
41+
var aTags = document.getElementsByTagName('a');
42+
for (a in aTags) {
43+
aTags[a].onclick = function(e) {
44+
e.preventDefault();
45+
if (this.getAttribute("class") != "patternLink") {
46+
window.location.replace(this.getAttribute("href"));
47+
}
48+
};
49+
}
50+
51+
4052
var els = document.getElementsByClassName("patternLink");
4153
for (i in els) {
4254
els[i].onclick = function() {

source/_patternlab-files/viewall.mustache

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
parent.postMessage( { "bodyclick":"bodyclick" }, targetOrigin)
3939
};
4040
41+
// find all links and add an onclick handler for replacing the iframe address so the history works
42+
var aTags = document.getElementsByTagName('a');
43+
for (a in aTags) {
44+
aTags[a].onclick = function(e) {
45+
e.preventDefault();
46+
if ((self != top) && (this.getAttribute("class") != "patternLink")) {
47+
window.location.replace(this.getAttribute("href"));
48+
}
49+
};
50+
}
51+
4152
var els = document.getElementsByClassName("patternLink");
4253
for (i in els) {
4354
els[i].onclick = function() {

0 commit comments

Comments
 (0)