Switch linting to ESLint and Prettier (#191)
* Switch linting to ESLint and Prettier * Clean up config * Prettier fixes
This commit was merged in pull request #191.
This commit is contained in:
@@ -1,37 +1,59 @@
|
||||
var forEachEls = require("./foreach-els")
|
||||
var forEachEls = require("./foreach-els");
|
||||
|
||||
var defaultSwitches = require("./switches")
|
||||
var defaultSwitches = require("./switches");
|
||||
|
||||
module.exports = function(switches, switchesOptions, selectors, fromEl, toEl, options) {
|
||||
var switchesQueue = []
|
||||
module.exports = function(
|
||||
switches,
|
||||
switchesOptions,
|
||||
selectors,
|
||||
fromEl,
|
||||
toEl,
|
||||
options
|
||||
) {
|
||||
var switchesQueue = [];
|
||||
|
||||
selectors.forEach(function(selector) {
|
||||
var newEls = fromEl.querySelectorAll(selector)
|
||||
var oldEls = toEl.querySelectorAll(selector)
|
||||
var newEls = fromEl.querySelectorAll(selector);
|
||||
var oldEls = toEl.querySelectorAll(selector);
|
||||
if (this.log) {
|
||||
this.log("Pjax switch", selector, newEls, oldEls)
|
||||
this.log("Pjax switch", selector, newEls, oldEls);
|
||||
}
|
||||
if (newEls.length !== oldEls.length) {
|
||||
throw "DOM doesn’t look the same on new loaded page: ’" + selector + "’ - new " + newEls.length + ", old " + oldEls.length
|
||||
throw "DOM doesn’t look the same on new loaded page: ’" +
|
||||
selector +
|
||||
"’ - new " +
|
||||
newEls.length +
|
||||
", old " +
|
||||
oldEls.length;
|
||||
}
|
||||
|
||||
forEachEls(newEls, function(newEl, i) {
|
||||
var oldEl = oldEls[i]
|
||||
if (this.log) {
|
||||
this.log("newEl", newEl, "oldEl", oldEl)
|
||||
}
|
||||
forEachEls(
|
||||
newEls,
|
||||
function(newEl, i) {
|
||||
var oldEl = oldEls[i];
|
||||
if (this.log) {
|
||||
this.log("newEl", newEl, "oldEl", oldEl);
|
||||
}
|
||||
|
||||
var callback = (switches[selector]) ?
|
||||
switches[selector].bind(this, oldEl, newEl, options, switchesOptions[selector]) :
|
||||
defaultSwitches.outerHTML.bind(this, oldEl, newEl, options)
|
||||
var callback = switches[selector]
|
||||
? switches[selector].bind(
|
||||
this,
|
||||
oldEl,
|
||||
newEl,
|
||||
options,
|
||||
switchesOptions[selector]
|
||||
)
|
||||
: defaultSwitches.outerHTML.bind(this, oldEl, newEl, options);
|
||||
|
||||
switchesQueue.push(callback)
|
||||
}, this)
|
||||
}, this)
|
||||
switchesQueue.push(callback);
|
||||
},
|
||||
this
|
||||
);
|
||||
}, this);
|
||||
|
||||
this.state.numPendingSwitches = switchesQueue.length
|
||||
this.state.numPendingSwitches = switchesQueue.length;
|
||||
|
||||
switchesQueue.forEach(function(queuedSwitch) {
|
||||
queuedSwitch()
|
||||
})
|
||||
}
|
||||
queuedSwitch();
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user