Skip to content

Instantly share code, notes, and snippets.

@andrewchee
Created August 30, 2017 16:07
Show Gist options
  • Save andrewchee/232e163710628e311ab0c78cdd362205 to your computer and use it in GitHub Desktop.
Save andrewchee/232e163710628e311ab0c78cdd362205 to your computer and use it in GitHub Desktop.
# External stylesheets -------------------------
Utils.insertStylesheet = (url, callback) ->
styleElement = document.createElement("link")
styleElement.rel = "stylesheet"
styleElement.type = "text/css"
styleElement.href = url
styleElement.addEventListener "load", ->
callback(url) if callback
Utils.domComplete ->
document.body.appendChild(styleElement)
# Console feedback
confirm = (url) -> #optional
print "successfully added #{url}"
# Insert it
Utils.insertStylesheet("https://fonts.googleapis.com/icon?family=Material+Icons") #hosted
Utils.insertStylesheet("mdl/material.css", confirm) # local
# Test it
layer = new Layer
width: 128, height: 128
backgroundColor: ""
ignoreEvents: false
html: '<button class="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored"> <i class="material-icons">add</i> </button>'
style:
padding: '36px'
layer.center()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment