Add parseDOM & (new) parseElement proto methods
This commit is contained in:
7
src/scripts/lib/proto/parse-dom.js
Normal file
7
src/scripts/lib/proto/parse-dom.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
var forEachEls = require("../foreach-els")
|
||||||
|
|
||||||
|
var parseElement = require("../parse-element")
|
||||||
|
|
||||||
|
module.exports = function(el) {
|
||||||
|
forEachEls(this.getElements(el), parseElement }, this)
|
||||||
|
}
|
||||||
14
src/scripts/lib/proto/parse-element.js
Normal file
14
src/scripts/lib/proto/parse-element.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module.exports = function(el) {
|
||||||
|
switch (el.tagName.toLowerCase()) {
|
||||||
|
case "a":
|
||||||
|
this.attachLink(el)
|
||||||
|
break
|
||||||
|
|
||||||
|
case "form":
|
||||||
|
throw "Pjax doesnt support <form> yet."
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw "Pjax can only be applied on <a> or <form> submit"
|
||||||
|
}
|
||||||
|
}
|
||||||
18
tests/scripts/lib/proto/parse-element.js
Normal file
18
tests/scripts/lib/proto/parse-element.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
var tape = require("tape")
|
||||||
|
|
||||||
|
var parseElement = require("../../../../src/scripts/lib/proto/parse-element")
|
||||||
|
var protoMock = {attachLink: function() { return true}}
|
||||||
|
tape("test parse element prototype method", function(t) {
|
||||||
|
|
||||||
|
t.doesNotThrow(function() {
|
||||||
|
var a = document.createElement("a")
|
||||||
|
parseElement.call(protoMock, a)
|
||||||
|
}, "<a> element can be parsed")
|
||||||
|
|
||||||
|
t.throws(function() {
|
||||||
|
var form = document.createElement("form")
|
||||||
|
parseElement.call(protoMock, form)
|
||||||
|
}, "<form> cannot be used (for now)")
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user