Skip to content

Commit

Permalink
Rename attribute name
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Mar 6, 2017
1 parent 1e8d9aa commit 007f479
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ By default, the style-loader appends `<style>` elements to the end of the `<head

If defined, the style-loader will re-use a single `<style>` element, instead of adding/removing individual elements for each required module. **Note:** this option is on by default in IE9, which has strict limitations on the number of style tags allowed on a page. You can enable or disable it with the singleton query parameter (`?singleton` or `?-singleton`).

#### `tagAttrs`
#### `attrs`

If defined, style-loader will attach given attributes with their values on `<style>` / `<link>` element.
Usage:
```javascript
require('style-loader?{tagAttrs:{id: "style-tag-id"}}!style.scss');
require('style-loader?{attrs:{id: "style-tag-id"}}!style.scss');

// will create style tag <style id="style-tag-id">
```
Expand Down
18 changes: 8 additions & 10 deletions addStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function(list, options) {
}

options = options || {};
options.tagAttrs = typeof options.tagAttrs === "object" ? options.tagAttrs : {};
options.attrs = typeof options.attrs === "object" ? options.attrs : {};

// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
// tags it will allow on a page
Expand Down Expand Up @@ -130,28 +130,26 @@ function removeStyleElement(styleElement) {

function createStyleElement(options) {
var styleElement = document.createElement("style");
options.tagAttrs.type = "text/css";
options.attrs.type = "text/css";

attachTagAttrs(styleElement, options.tagAttrs);
attachTagAttrs(styleElement, options.attrs);
insertStyleElement(options, styleElement);
return styleElement;
}

function createLinkElement(options) {
var linkElement = document.createElement("link");
options.tagAttrs.rel = "stylesheet";
options.attrs.rel = "stylesheet";

attachTagAttrs(styleElement, options.tagAttrs);
attachTagAttrs(styleElement, options.attrs);
insertStyleElement(options, linkElement);
return linkElement;
}

function attachTagAttrs(element, attrs) {
for(var key in attrs) {
if(attrs.hasOwnProperty(key)) {
element.setAttribute(key, attrs[key]);
}
}
Object.keys(attrs).forEach(function(key) {
element.setAttribute(key, attrs[key]);
});
}

function addStyle(obj, options) {
Expand Down

0 comments on commit 007f479

Please sign in to comment.