Created
November 4, 2016 13:37
-
-
Save kiasaki/72ef003f0e078061b4789a98e3d2148e to your computer and use it in GitHub Desktop.
http://meowni.ca/posts/web-fonts/ https://github.com/GoogleChrome/devsummit/blob/master/scripts/utils.js#L34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* | |
* Copyright 2016 Google Inc. All rights reserved. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
'use strict'; | |
export function loadScript (url, async) { | |
return new Promise(function (resolve, reject) { | |
var script = document.createElement('script'); | |
script.src = url; | |
if (typeof async !== 'undefined') { | |
script.async = async; | |
} | |
script.onerror = reject; | |
script.onload = resolve; | |
document.head.appendChild(script); | |
}); | |
} | |
export function loadStyles (url) { | |
return new Promise(function (resolve, reject) { | |
var xhr = new XMLHttpRequest(); | |
xhr.returnType = 'text'; | |
xhr.onload = function () { | |
var link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.href = url; | |
document.head.appendChild(link); | |
resolve(); | |
}; | |
xhr.onerror = reject; | |
xhr.open('get', url); | |
xhr.send(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment