This commit is contained in:
Lars Jung 2016-07-23 11:18:18 +02:00
parent 3fe1b2d6f8
commit c486962ff8
2 changed files with 16 additions and 19 deletions

View file

@ -3,4 +3,5 @@ const {test, assert} = require('scar');
test('window is global object', () => { test('window is global object', () => {
assert.ok(global.window); assert.ok(global.window);
assert.equal(global.window, global.window.window); assert.equal(global.window, global.window.window);
assert.ok(global.window.document);
}); });

View file

@ -1,12 +1,7 @@
const win = global.window; const win = global.window;
const doc = win.document; const doc = win.document;
let title; const pinned = {};
let htmlId;
let htmlClasses;
let bodyId;
let bodyClasses;
let $pinnedElements;
const attr = (el, name, value) => { const attr = (el, name, value) => {
if (typeof el === 'string') { if (typeof el === 'string') {
@ -29,26 +24,27 @@ const rootChildren = () => {
}; };
const pinHtml = () => { const pinHtml = () => {
title = doc.title; pinned.title = doc.title;
htmlId = attr('html', 'id'); pinned.htmlId = attr('html', 'id');
htmlClasses = attr('html', 'class'); pinned.htmlClasses = attr('html', 'class');
bodyId = attr('body', 'id'); pinned.bodyId = attr('body', 'id');
bodyClasses = attr('body', 'class'); pinned.bodyClasses = attr('body', 'class');
$pinnedElements = rootChildren(); pinned.els = rootChildren();
// console.log('pinned', pinned);
}; };
const restoreHtml = () => { const restoreHtml = () => {
doc.title = title; doc.title = pinned.title;
attr('html', 'id', htmlId); attr('html', 'id', pinned.htmlId);
attr('html', 'class', htmlClasses); attr('html', 'class', pinned.htmlClasses);
attr('body', 'id', bodyId); attr('body', 'id', pinned.bodyId);
attr('body', 'class', bodyClasses); attr('body', 'class', pinned.bodyClasses);
rootChildren().forEach(el => { rootChildren().forEach(el => {
if ($pinnedElements.indexOf(el) <= 0) { if (pinned.els.indexOf(el) < 0) {
el.remove(); el.remove();
} }
}); });
win.localStorage.clear(); // win.localStorage.clear();
}; };
module.exports = { module.exports = {