Patch 51 #52
15
index.js
15
index.js
@@ -1,3 +1,7 @@
|
||||
var clone = require('./lib/clone.js')
|
||||
var executeScripts = require('./lib/execute-scripts.js')
|
||||
|
||||
var forEachEls = require("./lib/foreach-els.js")
|
||||
|
||||
var newUid = require("./lib/uniqueid.js")
|
||||
|
||||
@@ -5,6 +9,7 @@ var on = require("./lib/events/on.js")
|
||||
// var off = require("./lib/events/on.js")
|
||||
var trigger = require("./lib/events/trigger.js")
|
||||
|
||||
|
||||
var Pjax = function(options) {
|
||||
this.firstrun = true
|
||||
|
||||
@@ -18,7 +23,7 @@ var Pjax = function(options) {
|
||||
|
||||
on(window, "popstate", function(st) {
|
||||
if (st.state) {
|
||||
var opt = Pjax.clone(this.options)
|
||||
var opt = clone(this.options)
|
||||
opt.url = st.state.url
|
||||
opt.title = st.state.title
|
||||
opt.history = false
|
||||
@@ -49,11 +54,11 @@ Pjax.prototype = {
|
||||
attachLink: require("./lib/proto/attach-link.js"),
|
||||
|
||||
forEachSelectors: function(cb, context, DOMcontext) {
|
||||
return require("./lib/foreach-selectors.js")(this.options.selectors, cb, context, DOMcontext)
|
||||
return require("./lib/foreach-selectors.js").bind(this)(this.options.selectors, cb, context, DOMcontext)
|
||||
},
|
||||
|
||||
switchSelectors: function(selectors, fromEl, toEl, options) {
|
||||
return require("./lib/switches-selectors.js")(this.options.switches, this.options.switchesOptions, selectors, fromEl, toEl, options)
|
||||
return require("./lib/switches-selectors.js").bind(this)(this.options.switches, this.options.switchesOptions, selectors, fromEl, toEl, options)
|
||||
},
|
||||
|
||||
// too much problem with the code below
|
||||
@@ -118,8 +123,8 @@ Pjax.prototype = {
|
||||
|
||||
// execute scripts when DOM have been completely updated
|
||||
this.options.selectors.forEach(function(selector) {
|
||||
Pjax.forEachEls(document.querySelectorAll(selector), function(el) {
|
||||
Pjax.executeScripts(el)
|
||||
forEachEls(document.querySelectorAll(selector), function(el) {
|
||||
executeScripts(el)
|
||||
})
|
||||
})
|
||||
// }
|
||||
|
||||
@@ -1,9 +1,41 @@
|
||||
var tape = require("tape")
|
||||
|
||||
// var switchesSelectors = require("../../lib/switches-selectors.js")
|
||||
var switchesSelectors = require("../../lib/switches-selectors.js")
|
||||
|
||||
// @author darylteo
|
||||
tape("test switchesSelectors", function(t) {
|
||||
t.fail()
|
||||
// switchesSelectors relies on a higher level function callback
|
||||
// should really be passed in instead so I'll leave it here as a TODO:
|
||||
var pjax = {
|
||||
onSwitch: function() {
|
||||
console.log('Switched')
|
||||
}
|
||||
}
|
||||
|
||||
var tmpEl = document.implementation.createHTMLDocument()
|
||||
|
||||
// a div container is used because swapping the containers
|
||||
// will generate a new element, so things get weird
|
||||
// using "body" generates a lot of testling cruft that I don't
|
||||
// want so let's avoid that
|
||||
var container = document.createElement("div")
|
||||
container.innerHTML = "<p>Original Text</p><span>No Change</span>"
|
||||
document.body.appendChild(container)
|
||||
|
||||
var container2 = tmpEl.createElement("div")
|
||||
container2.innerHTML = "<p>New Text</p><span>New Span</span>"
|
||||
tmpEl.body.appendChild(container2)
|
||||
|
||||
switchesSelectors.bind(pjax)(
|
||||
{}, // switches
|
||||
{}, // switchesOptions
|
||||
['p'], //selectors,
|
||||
tmpEl, // fromEl
|
||||
document, // toEl,
|
||||
{} // options
|
||||
)
|
||||
|
||||
t.equals(container.innerHTML, '<p>New Text</p><span>No Change</span>', 'Elements correctly switched')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user