Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created November 14, 2012 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/4075196 to your computer and use it in GitHub Desktop.
Save Raynos/4075196 to your computer and use it in GitHub Desktop.
var Module = require("thirdparty")
var instance = Module(...)
// instance damn better well be a DOM element
// We already injected the relevant style so it's save to inject it into the DOM
// and it will be styled immediately
document.body.appendChild(instance)
// If this was a naughty thing it's ok because we prefixed the selectors
// So the naughty css only applies to the children of the prefix
instance.className = "thirdparty-container")
document.body.appendChild(instance)
<html>
<head>
<script src="bundled/head.js"></script>
</head>
<body>
<script src="bundled/body.js"></script>
</body>
</html>
// A string containing css
var css = require("thirdparty/css/standard.css")
, ownCss = require("./css/style.css")
, Sheet = require("style-sheet")
, rework = require("rework")
// Sheet(String) returns a <style>string inlined</style> element
var sheet = Sheet(css)
, mySheet = Sheet(ownCss)
document.head.appendChild(sheet)
document.head.appendChild(mySheet)
// or prefix naughty third party css
// rework is a library to do prefixing selectors
var css = rework(require("thirdparty/css/naughty.css"))
.use(rework.prefixSelector(".thirdparty-container"))
.toString()
var sheet = Sheet(css)
document.head.appendChild(sheet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment