Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
779 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | module.exports = function (url, options) {
|
---|
4 | options = options || {};
|
---|
5 | options.attributes = typeof options.attributes === "object" ? options.attributes : {};
|
---|
6 |
|
---|
7 | if (typeof options.attributes.nonce === "undefined") {
|
---|
8 | var nonce = typeof __webpack_nonce__ !== "undefined" ? __webpack_nonce__ : null;
|
---|
9 |
|
---|
10 | if (nonce) {
|
---|
11 | options.attributes.nonce = nonce;
|
---|
12 | }
|
---|
13 | }
|
---|
14 |
|
---|
15 | var link = document.createElement("link");
|
---|
16 | link.rel = "stylesheet";
|
---|
17 | link.href = url;
|
---|
18 | Object.keys(options.attributes).forEach(function (key) {
|
---|
19 | link.setAttribute(key, options.attributes[key]);
|
---|
20 | });
|
---|
21 | options.insert(link);
|
---|
22 | return function (newUrl) {
|
---|
23 | if (typeof newUrl === "string") {
|
---|
24 | link.href = newUrl;
|
---|
25 | } else {
|
---|
26 | link.parentNode.removeChild(link);
|
---|
27 | }
|
---|
28 | };
|
---|
29 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.