Skip to content

Commit

Permalink
fix problem when '<body' string is present in DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrchk committed Oct 31, 2019
1 parent 1667b92 commit dd95dc7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions dist/swup.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,8 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
var _utils = __webpack_require__(1);

var getDataFromHtml = function getDataFromHtml(html, containers) {
var content = html.replace('<body', '<div id="swupBody"').replace('</body>', '</div>');
var fakeDom = document.createElement('div');
fakeDom.innerHTML = content;
var fakeDom = document.createElement('html');
fakeDom.innerHTML = html;
var blocks = [];

var _loop = function _loop(i) {
Expand All @@ -857,7 +856,7 @@ var getDataFromHtml = function getDataFromHtml(html, containers) {

var json = {
title: fakeDom.querySelector('title').innerText,
pageClass: fakeDom.querySelector('#swupBody').className,
pageClass: fakeDom.querySelector('body').className,
originalContent: html,
blocks: blocks
};
Expand Down
2 changes: 1 addition & 1 deletion dist/swup.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swup",
"version": "2.0.7",
"version": "2.0.8",
"description": "Complete, flexible, extensible and easy to use page transition library for your web.",
"main": "lib/index.js",
"scripts": {
Expand Down
7 changes: 3 additions & 4 deletions src/helpers/getDataFromHtml.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { queryAll } from '../utils';

const getDataFromHtml = (html, containers) => {
let content = html.replace('<body', '<div id="swupBody"').replace('</body>', '</div>');
let fakeDom = document.createElement('div');
fakeDom.innerHTML = content;
let fakeDom = document.createElement('html');
fakeDom.innerHTML = html;
let blocks = [];

for (let i = 0; i < containers.length; i++) {
Expand All @@ -20,7 +19,7 @@ const getDataFromHtml = (html, containers) => {

const json = {
title: fakeDom.querySelector('title').innerText,
pageClass: fakeDom.querySelector('#swupBody').className,
pageClass: fakeDom.querySelector('body').className,
originalContent: html,
blocks: blocks
};
Expand Down

0 comments on commit dd95dc7

Please sign in to comment.