Merge pull request #93 from BehindTheMath/bugfix/add-switchElementsAlt
Add switchElementsAlt() to the default switches Fixes #83.
This commit was merged in pull request #93.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/* global _gaq: true, ga: true */
|
||||
|
||||
var defaultSwitches = require("../switches")
|
||||
|
||||
module.exports = function(options){
|
||||
this.options = options
|
||||
this.options.elements = this.options.elements || "a[href], form[action]"
|
||||
@@ -27,10 +29,10 @@ module.exports = function(options){
|
||||
// if you set head.outerHTML, a new body tag is appended, so the dom get 2 body
|
||||
// & it break the switchFallback which replace head & body
|
||||
if (!this.options.switches.head) {
|
||||
this.options.switches.head = this.switchElementsAlt
|
||||
this.options.switches.head = defaultSwitches.switchElementsAlt
|
||||
}
|
||||
if (!this.options.switches.body) {
|
||||
this.options.switches.body = this.switchElementsAlt
|
||||
this.options.switches.body = defaultSwitches.switchElementsAlt
|
||||
}
|
||||
if (typeof options.analytics !== "function") {
|
||||
options.analytics = function() {}
|
||||
|
||||
@@ -15,6 +15,20 @@ module.exports = {
|
||||
this.onSwitch()
|
||||
},
|
||||
|
||||
switchElementsAlt: function(oldEl, newEl) {
|
||||
oldEl.innerHTML = newEl.innerHTML
|
||||
|
||||
// Copy attributes from the new element to the old one
|
||||
if (newEl.hasAttributes()) {
|
||||
const attrs = newEl.attributes;
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
oldEl.attributes.setNamedItem(attrs[i])
|
||||
}
|
||||
}
|
||||
|
||||
this.onSwitch()
|
||||
},
|
||||
|
||||
sideBySide: function(oldEl, newEl, options, switchOptions) {
|
||||
var forEach = Array.prototype.forEach
|
||||
var elsToRemove = []
|
||||
|
||||
Reference in New Issue
Block a user