Skip to content

Instantly share code, notes, and snippets.

@ewized
Last active December 1, 2019 15:22
Show Gist options
  • Save ewized/339643fd86f631103864d80638f70da7 to your computer and use it in GitHub Desktop.
Save ewized/339643fd86f631103864d80638f70da7 to your computer and use it in GitHub Desktop.
Script that will install base_elements from the latest release version
'use strict'
// Import the script from the url
function importScript(url) {
const request = new XMLHttpRequest()
request.onload = () => eval(request.responseText)
request.open('GET', url, true)
request.send()
}
// Change XMLHttpRequest to include origin header
// https://github.com/Rob--W/cors-anywhere/#documentation
(function() {
const cors_api_host = 'cors-anywhere.herokuapp.com'
const cors_api_url = 'https://' + cors_api_host + '/'
const slice = [].slice
const origin = window.location.protocol + '//' + window.location.host
const open = XMLHttpRequest.prototype.open
XMLHttpRequest.prototype.open = function() {
const args = slice.call(arguments)
let targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1])
if (targetOrigin && targetOrigin[0].toLowerCase() !== origin && targetOrigin[1] !== cors_api_host) {
args[1] = cors_api_url + args[1]
}
return open.apply(this, args)
}
})()
// Set the font aweseome url prefix to a cdn
window.BASE_ELEMENTS_FONT_PREFIX = 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts'
// Import the bundle that is generated from GitHub Releases
importScript('https://github.com/ewized/base-elements/releases/latest/download/base_elements.bundle.js')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment