Merge pull request #36 from pklada/refresh
Add simple refresh method and protect against links being bound more than once.
This commit is contained in:
2
index.js
2
index.js
@@ -44,6 +44,8 @@ Pjax.prototype = {
|
||||
|
||||
parseDOM: require("./lib/proto/parse-dom.js"),
|
||||
|
||||
refresh: require("./lib/proto/refresh.js"),
|
||||
|
||||
attachLink: require("./lib/proto/attach-link.js"),
|
||||
|
||||
forEachSelectors: function(cb, context, DOMcontext) {
|
||||
|
||||
@@ -44,8 +44,8 @@ var linkAction = function(el, event) {
|
||||
|
||||
// don’t do "nothing" if user try to reload the page by clicking the same link twice
|
||||
if (el.href === window.location.href.split("#")[0]) {
|
||||
el.setAttribute(attrClick, "refresh")
|
||||
this.refresh()
|
||||
el.setAttribute(attrClick, "reload")
|
||||
this.reload()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
module.exports = function(el) {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case "a":
|
||||
this.attachLink(el)
|
||||
// only attach link if el does not already have link attached
|
||||
if (!el.hasAttribute('data-pjax-click-state')) {
|
||||
this.attachLink(el)
|
||||
}
|
||||
break
|
||||
|
||||
case "form":
|
||||
|
||||
6
lib/proto/refresh.js
Normal file
6
lib/proto/refresh.js
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
var parseDom = require("./parse-dom")
|
||||
|
||||
module.exports = function(el) {
|
||||
parseDom(document);
|
||||
}
|
||||
@@ -12091,8 +12091,8 @@ var linkAction = function(el, event) {
|
||||
|
||||
// don’t do "nothing" if user try to reload the page by clicking the same link twice
|
||||
if (el.href === window.location.href.split("#")[0]) {
|
||||
el.setAttribute(attrClick, "refresh")
|
||||
this.refresh()
|
||||
el.setAttribute(attrClick, "reload")
|
||||
this.reload()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -12409,8 +12409,8 @@ tape("test attach link prototype method", function(t) {
|
||||
|
||||
attachLink.call({
|
||||
options: {},
|
||||
refresh: function() {
|
||||
t.equal(a.getAttribute(attr), "refresh", "triggering exact same url refresh the page")
|
||||
reload: function() {
|
||||
t.equal(a.getAttribute(attr), "reload", "triggering exact same url reload the page")
|
||||
},
|
||||
loadUrl: function() {
|
||||
t.equal(a.getAttribute(attr), "load", "triggering a internal link actually load the page")
|
||||
@@ -12444,7 +12444,7 @@ tape("test attach link prototype method", function(t) {
|
||||
|
||||
a.href = internalUri
|
||||
trigger(a, "click")
|
||||
// see refresh defined above
|
||||
// see reload defined above
|
||||
|
||||
a.href = window.location.protocol + "//" + window.location.host + "/internal"
|
||||
trigger(a, "click")
|
||||
|
||||
@@ -13,8 +13,8 @@ tape("test attach link prototype method", function(t) {
|
||||
|
||||
attachLink.call({
|
||||
options: {},
|
||||
refresh: function() {
|
||||
t.equal(a.getAttribute(attr), "refresh", "triggering exact same url refresh the page")
|
||||
reload: function() {
|
||||
t.equal(a.getAttribute(attr), "reload", "triggering exact same url reload the page")
|
||||
},
|
||||
loadUrl: function() {
|
||||
t.equal(a.getAttribute(attr), "load", "triggering a internal link actually load the page")
|
||||
@@ -48,7 +48,7 @@ tape("test attach link prototype method", function(t) {
|
||||
|
||||
a.href = internalUri
|
||||
trigger(a, "click")
|
||||
// see refresh defined above
|
||||
// see reload defined above
|
||||
|
||||
a.href = window.location.protocol + "//" + window.location.host + "/internal"
|
||||
trigger(a, "click")
|
||||
|
||||
Reference in New Issue
Block a user