diff --git a/index.js b/index.js index 65e8326..e17eef1 100644 --- a/index.js +++ b/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) { diff --git a/lib/proto/attach-link.js b/lib/proto/attach-link.js index d8ca18d..f0ad789 100644 --- a/lib/proto/attach-link.js +++ b/lib/proto/attach-link.js @@ -56,6 +56,8 @@ var linkAction = function(el, event) { module.exports = function(el) { var that = this + el.setAttribute("data-pjax-enabled", "true"); + on(el, "click", function(event) { linkAction.call(that, el, event) }) diff --git a/lib/proto/parse-element.js b/lib/proto/parse-element.js index a6311d2..4f7a8cd 100644 --- a/lib/proto/parse-element.js +++ b/lib/proto/parse-element.js @@ -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.getAttribute("data-pjax-enabled")) { + this.attachLink(el) + } break case "form": diff --git a/lib/proto/refresh.js b/lib/proto/refresh.js new file mode 100644 index 0000000..39c271b --- /dev/null +++ b/lib/proto/refresh.js @@ -0,0 +1,6 @@ + +var parseDom = require("./parse-dom") + +module.exports = function(el) { + parseDom(document); +}