Skip to content
Snippets Groups Projects
Commit 17930a68 authored by bartvig's avatar bartvig
Browse files

Issue #3330753: Use DOM for content check rather than HTML

parent 934dd752
No related branches found
No related tags found
1 merge request!4Issue #3330753: Use DOM for content check rather than HTML
......@@ -36,11 +36,12 @@
if (!Array.isArray(this.urls)) {
this.urls = [this.urls];
}
this.method = 'contentcheck';
this.method = 'contentcheck-flat-dom';
var _si = window._si || [];
var self = this;
this.urls.forEach(function (url) {
_si.push([self.method, self.cleanHtml(document.getElementsByTagName('body')[0], document.title ? document.title : ""), url, drupalSettings.siteimprove.token]);
let document_ = document.cloneNode(true);
_si.push([self.method, self.cleanHtml(document_), url, drupalSettings.siteimprove.token, function() { console.log('Pre-publish check ordered (flat dom version'); }]);
});
},
onhighlight: function () {
......@@ -77,25 +78,14 @@
});
},
// Clean html for contextual links, toolbar, etc.
cleanHtml: function (origHtml, origTitle) {
let html = document.createElement('html');
let head = document.createElement('head');
let title = document.createElement('title');
let body = document.createElement('body');
body.innerHTML = origHtml.innerHTML;
body.querySelector('#toolbar-administration').innerHTML = '';
body.querySelectorAll('iframe').forEach(function (item) { item.innerHTML = ''; item.src = ''; });
body.querySelectorAll('.contextual').forEach(function (item) { item.innerHTML = ''; });
body.querySelectorAll('.contextual-links').forEach(function (item) { item.innerHTML = ''; });
body.querySelectorAll('.node-preview-container').forEach(function (item) { item.innerHTML = ''; });
title.innerText = origTitle;
head.appendChild(title);
html.appendChild(head);
html.appendChild(body);
return html.innerHTML;
cleanHtml: function (origHtml) {
origHtml.querySelector('#toolbar-administration').innerHTML = '';
origHtml.querySelectorAll('iframe').forEach(function (item) { item.innerHTML = ''; item.src = ''; });
origHtml.querySelectorAll('.contextual').forEach(function (item) { item.innerHTML = ''; });
origHtml.querySelectorAll('.contextual-links').forEach(function (item) { item.innerHTML = ''; });
origHtml.querySelectorAll('.node-preview-container').forEach(function (item) { item.innerHTML = ''; });
return origHtml;
},
events: {
recheck: function () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment