Sha256: 3f978d4c0026336112855b70be897830353c602cb20c97479e68b0d1a22c4874

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

"use strict";

var getTarget = function getTarget() {
  var memo = {};
  return function memorize(target) {
    if (typeof memo[target] === 'undefined') {
      var styleTarget = document.querySelector(target); // Special case to return head of iframe instead of iframe itself

      if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
        try {
          // This will throw an exception if access to iframe is blocked
          // due to cross-origin restrictions
          styleTarget = styleTarget.contentDocument.head;
        } catch (e) {
          // istanbul ignore next
          styleTarget = null;
        }
      }

      memo[target] = styleTarget;
    }

    return memo[target];
  };
}();

module.exports = function (url, options) {
  options = options || {};
  options.attributes = typeof options.attributes === 'object' ? options.attributes : {};

  if (typeof options.attributes.nonce === 'undefined') {
    var nonce = typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;

    if (nonce) {
      options.attributes.nonce = nonce;
    }
  }

  var link = document.createElement('link');
  link.rel = 'stylesheet';
  link.href = url;
  Object.keys(options.attributes).forEach(function (key) {
    link.setAttribute(key, options.attributes[key]);
  });

  if (typeof options.insert === 'function') {
    options.insert(link);
  } else {
    var target = getTarget(options.insert || 'head');

    if (!target) {
      throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
    }

    target.appendChild(link);
  }

  return function (newUrl) {
    if (typeof newUrl === 'string') {
      link.href = newUrl;
    } else {
      link.parentNode.removeChild(link);
    }
  };
};

Version data entries

18 entries across 16 versions & 6 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
optimacms-0.1.61 spec/dummy/node_modules/@rails/webpacker/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.16.1 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.15.2 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.18.4 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.18.1 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.14.0 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
tang-0.2.1 spec/tang_app/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
tang-0.2.0 spec/tang_app/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
tang-0.1.0 spec/tang_app/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
tang-0.0.9 spec/tang_app/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js
enju_library-0.3.8 spec/dummy/node_modules/style-loader/dist/runtime/injectStylesIntoLinkTag.js