Skip to content

Commit

Permalink
fix trigger of page transition only for click of left mouse button (F…
Browse files Browse the repository at this point in the history
…irefox only issue)
  • Loading branch information
gmrchk committed Nov 1, 2018
1 parent 2c897cc commit 6cfb046
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 79 deletions.
76 changes: 39 additions & 37 deletions dist/swup.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,50 +527,52 @@ var Swup = function () {
value: function linkClickHandler(event) {
// no control key pressed
if (!event.metaKey) {
this.triggerEvent('clickLink', event);
var link = new _Link2.default();
event.preventDefault();
link.setPath(event.delegateTarget.href);

if (link.getAddress() == this.currentUrl || link.getAddress() == '') {
// link to the same URL
if (link.getHash() != '') {
// link to the same URL with hash
this.triggerEvent('samePageWithHash', event);
var element = document.querySelector(link.getHash());
if (element != null) {
// referenced element found
if (this.options.scroll) {
var top = element.getBoundingClientRect().top + window.pageYOffset;
this.scrollTo(document.body, top);
if (event.button === 0) {
this.triggerEvent('clickLink', event);
var link = new _Link2.default();
event.preventDefault();
link.setPath(event.delegateTarget.href);

if (link.getAddress() == this.currentUrl || link.getAddress() == '') {
// link to the same URL
if (link.getHash() != '') {
// link to the same URL with hash
this.triggerEvent('samePageWithHash', event);
var element = document.querySelector(link.getHash());
if (element != null) {
// referenced element found
if (this.options.scroll) {
var top = element.getBoundingClientRect().top + window.pageYOffset;
this.scrollTo(document.body, top);
}
history.replaceState({
url: link.getAddress() + link.getHash(),
random: Math.random(),
source: "swup"
}, document.title, link.getAddress() + link.getHash());
} else {
// referenced element not found
console.warn('Element for offset not found (' + link.getHash() + ')');
}
history.replaceState({
url: link.getAddress() + link.getHash(),
random: Math.random(),
source: "swup"
}, document.title, link.getAddress() + link.getHash());
} else {
// referenced element not found
console.warn('Element for offset not found (' + link.getHash() + ')');
// link to the same URL without hash
this.triggerEvent('samePage', event);
if (this.options.scroll) {
this.scrollTo(document.body, 0, 1);
}
}
} else {
// link to the same URL without hash
this.triggerEvent('samePage', event);
if (this.options.scroll) {
this.scrollTo(document.body, 0, 1);
// link to different url
if (link.getHash() != '') {
this.scrollToElement = link.getHash();
}
}
} else {
// link to different url
if (link.getHash() != '') {
this.scrollToElement = link.getHash();
}

// get custom transition from data
var customTransition = event.delegateTarget.dataset.swupTransition;
// get custom transition from data
var customTransition = event.delegateTarget.dataset.swupTransition;

// load page
this.loadPage({ url: link.getAddress(), customTransition: customTransition }, false);
// load page
this.loadPage({ url: link.getAddress(), customTransition: customTransition }, false);
}
}
} else {
// open in new tab (do nothing)
Expand Down
Loading

0 comments on commit 6cfb046

Please sign in to comment.