attach data to pjaxified links so they can't be pjaxified twice. add simple refresh method
This commit is contained in:
2
index.js
2
index.js
@@ -44,6 +44,8 @@ Pjax.prototype = {
|
|||||||
|
|
||||||
parseDOM: require("./lib/proto/parse-dom.js"),
|
parseDOM: require("./lib/proto/parse-dom.js"),
|
||||||
|
|
||||||
|
refresh: require("./lib/proto/refresh.js"),
|
||||||
|
|
||||||
attachLink: require("./lib/proto/attach-link.js"),
|
attachLink: require("./lib/proto/attach-link.js"),
|
||||||
|
|
||||||
forEachSelectors: function(cb, context, DOMcontext) {
|
forEachSelectors: function(cb, context, DOMcontext) {
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ var linkAction = function(el, event) {
|
|||||||
module.exports = function(el) {
|
module.exports = function(el) {
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
|
el.setAttribute("data-pjax-enabled", "true");
|
||||||
|
|
||||||
on(el, "click", function(event) {
|
on(el, "click", function(event) {
|
||||||
linkAction.call(that, el, event)
|
linkAction.call(that, el, event)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
module.exports = function(el) {
|
module.exports = function(el) {
|
||||||
switch (el.tagName.toLowerCase()) {
|
switch (el.tagName.toLowerCase()) {
|
||||||
case "a":
|
case "a":
|
||||||
|
// only attach link if el does not already have link attached
|
||||||
|
if (!el.getAttribute("data-pjax-enabled")) {
|
||||||
this.attachLink(el)
|
this.attachLink(el)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case "form":
|
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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user