Patch 51 #52

Merged
darylteo merged 4 commits from patch-51 into master 2016-01-05 01:15:11 -05:00
2 changed files with 44 additions and 7 deletions

View File

@@ -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") 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 off = require("./lib/events/on.js")
var trigger = require("./lib/events/trigger.js") var trigger = require("./lib/events/trigger.js")
var Pjax = function(options) { var Pjax = function(options) {
this.firstrun = true this.firstrun = true
@@ -18,7 +23,7 @@ var Pjax = function(options) {
on(window, "popstate", function(st) { on(window, "popstate", function(st) {
if (st.state) { if (st.state) {
var opt = Pjax.clone(this.options) var opt = clone(this.options)
opt.url = st.state.url opt.url = st.state.url
opt.title = st.state.title opt.title = st.state.title
opt.history = false opt.history = false
@@ -49,11 +54,11 @@ Pjax.prototype = {
attachLink: require("./lib/proto/attach-link.js"), attachLink: require("./lib/proto/attach-link.js"),
forEachSelectors: function(cb, context, DOMcontext) { 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) { 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 // too much problem with the code below
@@ -118,8 +123,8 @@ Pjax.prototype = {
// execute scripts when DOM have been completely updated // execute scripts when DOM have been completely updated
this.options.selectors.forEach(function(selector) { this.options.selectors.forEach(function(selector) {
Pjax.forEachEls(document.querySelectorAll(selector), function(el) { forEachEls(document.querySelectorAll(selector), function(el) {
Pjax.executeScripts(el) executeScripts(el)
}) })
}) })
// } // }

View File

@@ -1,9 +1,41 @@
var tape = require("tape") 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) { 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() t.end()
}) })