Use document.head instead of getElementByTagName

This commit is contained in:
Maximilian Krög
2022-05-15 21:34:26 +02:00
parent 30358b61a9
commit 72d61f887d
6 changed files with 10 additions and 11 deletions

View File

@@ -107,7 +107,7 @@ const createTextStyle = function (feature, resolution, dom) {
const openSans = document.createElement('link');
openSans.href = 'https://fonts.googleapis.com/css?family=Open+Sans';
openSans.rel = 'stylesheet';
document.getElementsByTagName('head')[0].appendChild(openSans);
document.head.appendChild(openSans);
openSansAdded = true;
}
const font = weight + ' ' + size + '/' + height + ' ' + dom.font.value;

View File

@@ -39,7 +39,7 @@ export function jsonp(url, callback, opt_errback, opt_callbackParam) {
cleanup();
callback(data);
};
document.getElementsByTagName('head')[0].appendChild(script);
document.head.appendChild(script);
}
export class ResponseError extends Error {

View File

@@ -36,7 +36,7 @@ describe('ol/net', function () {
});
describe('jsonp()', function () {
const head = document.getElementsByTagName('head')[0];
const head = document.head;
const origAppendChild = head.appendChild;
const origCreateElement = document.createElement;
const origSetTimeout = setTimeout;

View File

@@ -5,7 +5,6 @@ describe('ol.render.canvas', function () {
font.href =
'https://fonts.googleapis.com/css?family=Abel&text=wmytzilWMYTZIL%40%23%2F%26%3F%24%2510';
font.rel = 'stylesheet';
const head = document.getElementsByTagName('head')[0];
describe('ol.render.canvas.registerFont()', function () {
beforeEach(function () {
@@ -65,7 +64,7 @@ describe('ol.render.canvas', function () {
});
it('triggers redraw and clear measurements for fonts that become available', function (done) {
head.appendChild(font);
document.head.appendChild(font);
render.checkedFonts.addEventListener(
'propertychange',
function onPropertyChange(e) {
@@ -75,6 +74,8 @@ describe('ol.render.canvas', function () {
);
expect(e.key).to.be('normal\nnormal\nAbel');
expect(render.textHeights).to.eql({});
document.head.removeChild(font);
done();
}
);

View File

@@ -23,7 +23,6 @@ import {get as getProjection} from '../../../../../../src/ol/proj.js';
describe('ol.renderer.canvas.VectorLayer', function () {
describe('constructor', function () {
const head = document.getElementsByTagName('head')[0];
const font = document.createElement('link');
font.href = 'https://fonts.googleapis.com/css?family=Droid+Sans';
font.rel = 'stylesheet';
@@ -156,7 +155,7 @@ describe('ol.renderer.canvas.VectorLayer', function () {
it('re-renders for fonts that become available', function (done) {
checkedFonts.values_ = {};
head.appendChild(font);
document.head.appendChild(font);
const map = new Map({
view: new View({
center: [0, 0],
@@ -182,7 +181,7 @@ describe('ol.renderer.canvas.VectorLayer', function () {
const revision = layer.getRevision();
setTimeout(function () {
expect(layer.getRevision()).to.be(revision + 1);
head.removeChild(font);
document.head.removeChild(font);
done();
}, 1600);
});

View File

@@ -24,7 +24,6 @@ import {getUid} from '../../../../../../src/ol/util.js';
describe('ol/renderer/canvas/VectorTileLayer', function () {
describe('constructor', function () {
const head = document.getElementsByTagName('head')[0];
const font = document.createElement('link');
font.href = 'https://fonts.googleapis.com/css?family=Dancing+Script';
font.rel = 'stylesheet';
@@ -200,12 +199,12 @@ describe('ol/renderer/canvas/VectorTileLayer', function () {
it('re-renders for fonts that become available', function (done) {
map.renderSync();
checkedFonts.values_ = {};
head.appendChild(font);
document.head.appendChild(font);
layerStyle[0].getText().setFont('12px "Dancing Script",sans-serif');
layer.changed();
const revision = layer.getRevision();
setTimeout(function () {
head.removeChild(font);
document.head.removeChild(font);
expect(layer.getRevision()).to.be(revision + 1);
done();
}, 1600);