Comparing version 0.2.0 to 1.0.0
52
index.js
@@ -1,22 +0,46 @@ | ||
var inserted = {}; | ||
var containers = []; // will store container HTMLElement references | ||
var styleElements = []; // will store {prepend: HTMLElement, append: HTMLElement} | ||
module.exports = function (css, options) { | ||
if (inserted[css]) return; | ||
inserted[css] = true; | ||
var elem = document.createElement('style'); | ||
elem.setAttribute('type', 'text/css'); | ||
options = options || {}; | ||
if ('textContent' in elem) { | ||
elem.textContent = css; | ||
var position = options.prepend === true ? 'prepend' : 'append'; | ||
var container = options.container !== undefined ? options.container : document.querySelector('head'); | ||
var containerId = containers.indexOf(container); | ||
// first time we see this container, create the necessary entries | ||
if (containerId === -1) { | ||
containerId = containers.push(container) - 1; | ||
styleElements[containerId] = {}; | ||
} | ||
// try to get the correponding container + position styleElement, create it otherwise | ||
var styleElement; | ||
if (styleElements[containerId] !== undefined && styleElements[containerId][position] !== undefined) { | ||
styleElement = styleElements[containerId][position]; | ||
} else { | ||
elem.styleSheet.cssText = css; | ||
styleElement = styleElements[containerId][position] = createStyleElement(); | ||
if (position === 'prepend') { | ||
container.insertBefore(styleElement, container.childNodes[0]); | ||
} else { | ||
container.appendChild(styleElement); | ||
} | ||
} | ||
var head = document.getElementsByTagName('head')[0]; | ||
if (options && options.prepend) { | ||
head.insertBefore(elem, head.childNodes[0]); | ||
// actually add the stylesheet | ||
if (styleElement.styleSheet) { | ||
styleElement.styleSheet.cssText += css | ||
} else { | ||
head.appendChild(elem); | ||
styleElement.textContent += css; | ||
} | ||
return styleElement; | ||
}; | ||
function createStyleElement() { | ||
var styleElement = document.createElement('style'); | ||
styleElement.setAttribute('type', 'text/css'); | ||
return styleElement; | ||
} |
{ | ||
"name": "insert-css", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "insert a string of css into the <head>", | ||
"main": "index.js", | ||
"dependencies": {}, | ||
"scripts": { | ||
"test": "browserify test.js | tape-run", | ||
"example": "budo example.js" | ||
}, | ||
"devDependencies": { | ||
"tape": "^2.13.3", | ||
"computed-style": "~0.1.3" | ||
"browserify": "^13.0.1", | ||
"budo": "^8.3.0", | ||
"computed-style": "^0.3.0", | ||
"dom-event": "^1.0.0", | ||
"tape": "^4.6.0", | ||
"tape-run": "^2.1.4" | ||
}, | ||
@@ -16,3 +24,3 @@ "repository": { | ||
"testling" : { | ||
"files" : "test/*.js", | ||
"files" : "test.js", | ||
"browsers" : [ | ||
@@ -33,3 +41,10 @@ "ie/6..latest", | ||
"browser", | ||
"browserify" | ||
"browserify", | ||
"inject", | ||
"styles", | ||
"stylesheet", | ||
"style", | ||
"html", | ||
"head", | ||
"link" | ||
], | ||
@@ -36,0 +51,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8020
103
1
0
6
6
45
2