Innovenergy_trunk/frontend/node_modules/testcafe-hammerhead/lib/processing/dom/parse5-dom-adapter.js

115 lines
4.1 KiB
JavaScript
Raw Normal View History

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint hammerhead/proto-methods: 0 */
const base_dom_adapter_1 = __importDefault(require("./base-dom-adapter"));
const urlUtils = __importStar(require("../../utils/url"));
const parse5Utils = __importStar(require("../../utils/parse5"));
const namespaces_1 = require("./namespaces");
const index_1 = __importDefault(require("./index"));
const page_1 = __importDefault(require("../resources/page"));
class Parse5DomAdapter extends base_dom_adapter_1.default {
constructor(isIframe, ctx, charset, urlReplacer) {
super();
this.isIframe = isIframe;
this.ctx = ctx;
this.charset = charset;
this.urlReplacer = urlReplacer;
}
removeAttr(el, attr) {
parse5Utils.removeAttr(el, attr);
}
getAttr(el, attr) {
return parse5Utils.getAttr(el, attr);
}
getClassName(el) {
return this.getAttr(el, 'class') || '';
}
hasAttr(el, attr) {
return this.getAttr(el, attr) !== null;
}
isSVGElement(el) {
return el.namespaceURI === namespaces_1.SVG_NAMESPACE;
}
hasEventHandler(el) {
for (let i = 0; i < el.attrs.length; i++) {
if (this.EVENTS.includes(el.attrs[i].name))
return true;
}
return false;
}
getTagName(el) {
return (el.tagName || '').toLowerCase();
}
setAttr(el, attr, value) {
return parse5Utils.setAttr(el, attr, value);
}
setScriptContent(script, content) {
script.childNodes = [parse5Utils.createTextNode(content, script)];
}
getScriptContent(script) {
var _a, _b;
return ((_b = (_a = script.childNodes) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) || '';
}
getStyleContent(style) {
var _a, _b;
return ((_b = (_a = style.childNodes) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) || '';
}
setStyleContent(style, content) {
style.childNodes = [parse5Utils.createTextNode(content, style)];
}
needToProcessContent() {
return true;
}
needToProcessUrl(tagName, target) {
return !index_1.default.isIframeFlagTag(tagName) || target !== '_parent';
}
hasIframeParent() {
return this.isIframe;
}
getProxyUrl(...args) {
return urlUtils.getProxyUrl(...args);
}
isTopParentIframe() {
return false;
}
sameOriginCheck(location, checkedUrl) {
return urlUtils.sameOriginCheck(location, checkedUrl);
}
isExistingTarget(target, el) {
while (el.parentNode)
el = el.parentNode;
return !!parse5Utils.findElement(el, e => this.getAttr(e, 'name') === target);
}
processSrcdocAttr(html) {
return page_1.default.processResource(html, this.ctx, this.charset, this.urlReplacer, true);
}
}
exports.default = Parse5DomAdapter;module.exports = exports.default;