Use document.head instead of getElementByTagName
This commit is contained in:
@@ -107,7 +107,7 @@ const createTextStyle = function (feature, resolution, dom) {
|
|||||||
const openSans = document.createElement('link');
|
const openSans = document.createElement('link');
|
||||||
openSans.href = 'https://fonts.googleapis.com/css?family=Open+Sans';
|
openSans.href = 'https://fonts.googleapis.com/css?family=Open+Sans';
|
||||||
openSans.rel = 'stylesheet';
|
openSans.rel = 'stylesheet';
|
||||||
document.getElementsByTagName('head')[0].appendChild(openSans);
|
document.head.appendChild(openSans);
|
||||||
openSansAdded = true;
|
openSansAdded = true;
|
||||||
}
|
}
|
||||||
const font = weight + ' ' + size + '/' + height + ' ' + dom.font.value;
|
const font = weight + ' ' + size + '/' + height + ' ' + dom.font.value;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export function jsonp(url, callback, opt_errback, opt_callbackParam) {
|
|||||||
cleanup();
|
cleanup();
|
||||||
callback(data);
|
callback(data);
|
||||||
};
|
};
|
||||||
document.getElementsByTagName('head')[0].appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ResponseError extends Error {
|
export class ResponseError extends Error {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe('ol/net', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('jsonp()', function () {
|
describe('jsonp()', function () {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const head = document.head;
|
||||||
const origAppendChild = head.appendChild;
|
const origAppendChild = head.appendChild;
|
||||||
const origCreateElement = document.createElement;
|
const origCreateElement = document.createElement;
|
||||||
const origSetTimeout = setTimeout;
|
const origSetTimeout = setTimeout;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ describe('ol.render.canvas', function () {
|
|||||||
font.href =
|
font.href =
|
||||||
'https://fonts.googleapis.com/css?family=Abel&text=wmytzilWMYTZIL%40%23%2F%26%3F%24%2510';
|
'https://fonts.googleapis.com/css?family=Abel&text=wmytzilWMYTZIL%40%23%2F%26%3F%24%2510';
|
||||||
font.rel = 'stylesheet';
|
font.rel = 'stylesheet';
|
||||||
const head = document.getElementsByTagName('head')[0];
|
|
||||||
|
|
||||||
describe('ol.render.canvas.registerFont()', function () {
|
describe('ol.render.canvas.registerFont()', function () {
|
||||||
beforeEach(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) {
|
it('triggers redraw and clear measurements for fonts that become available', function (done) {
|
||||||
head.appendChild(font);
|
document.head.appendChild(font);
|
||||||
render.checkedFonts.addEventListener(
|
render.checkedFonts.addEventListener(
|
||||||
'propertychange',
|
'propertychange',
|
||||||
function onPropertyChange(e) {
|
function onPropertyChange(e) {
|
||||||
@@ -75,6 +74,8 @@ describe('ol.render.canvas', function () {
|
|||||||
);
|
);
|
||||||
expect(e.key).to.be('normal\nnormal\nAbel');
|
expect(e.key).to.be('normal\nnormal\nAbel');
|
||||||
expect(render.textHeights).to.eql({});
|
expect(render.textHeights).to.eql({});
|
||||||
|
|
||||||
|
document.head.removeChild(font);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import {get as getProjection} from '../../../../../../src/ol/proj.js';
|
|||||||
|
|
||||||
describe('ol.renderer.canvas.VectorLayer', function () {
|
describe('ol.renderer.canvas.VectorLayer', function () {
|
||||||
describe('constructor', function () {
|
describe('constructor', function () {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
|
||||||
const font = document.createElement('link');
|
const font = document.createElement('link');
|
||||||
font.href = 'https://fonts.googleapis.com/css?family=Droid+Sans';
|
font.href = 'https://fonts.googleapis.com/css?family=Droid+Sans';
|
||||||
font.rel = 'stylesheet';
|
font.rel = 'stylesheet';
|
||||||
@@ -156,7 +155,7 @@ describe('ol.renderer.canvas.VectorLayer', function () {
|
|||||||
|
|
||||||
it('re-renders for fonts that become available', function (done) {
|
it('re-renders for fonts that become available', function (done) {
|
||||||
checkedFonts.values_ = {};
|
checkedFonts.values_ = {};
|
||||||
head.appendChild(font);
|
document.head.appendChild(font);
|
||||||
const map = new Map({
|
const map = new Map({
|
||||||
view: new View({
|
view: new View({
|
||||||
center: [0, 0],
|
center: [0, 0],
|
||||||
@@ -182,7 +181,7 @@ describe('ol.renderer.canvas.VectorLayer', function () {
|
|||||||
const revision = layer.getRevision();
|
const revision = layer.getRevision();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
expect(layer.getRevision()).to.be(revision + 1);
|
expect(layer.getRevision()).to.be(revision + 1);
|
||||||
head.removeChild(font);
|
document.head.removeChild(font);
|
||||||
done();
|
done();
|
||||||
}, 1600);
|
}, 1600);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {getUid} from '../../../../../../src/ol/util.js';
|
|||||||
|
|
||||||
describe('ol/renderer/canvas/VectorTileLayer', function () {
|
describe('ol/renderer/canvas/VectorTileLayer', function () {
|
||||||
describe('constructor', function () {
|
describe('constructor', function () {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
|
||||||
const font = document.createElement('link');
|
const font = document.createElement('link');
|
||||||
font.href = 'https://fonts.googleapis.com/css?family=Dancing+Script';
|
font.href = 'https://fonts.googleapis.com/css?family=Dancing+Script';
|
||||||
font.rel = 'stylesheet';
|
font.rel = 'stylesheet';
|
||||||
@@ -200,12 +199,12 @@ describe('ol/renderer/canvas/VectorTileLayer', function () {
|
|||||||
it('re-renders for fonts that become available', function (done) {
|
it('re-renders for fonts that become available', function (done) {
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
checkedFonts.values_ = {};
|
checkedFonts.values_ = {};
|
||||||
head.appendChild(font);
|
document.head.appendChild(font);
|
||||||
layerStyle[0].getText().setFont('12px "Dancing Script",sans-serif');
|
layerStyle[0].getText().setFont('12px "Dancing Script",sans-serif');
|
||||||
layer.changed();
|
layer.changed();
|
||||||
const revision = layer.getRevision();
|
const revision = layer.getRevision();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
head.removeChild(font);
|
document.head.removeChild(font);
|
||||||
expect(layer.getRevision()).to.be(revision + 1);
|
expect(layer.getRevision()).to.be(revision + 1);
|
||||||
done();
|
done();
|
||||||
}, 1600);
|
}, 1600);
|
||||||
|
|||||||
Reference in New Issue
Block a user