Skip to content

Instantly share code, notes, and snippets.

@jsobell
Last active July 11, 2016 13:36
Show Gist options
  • Select an option

  • Save jsobell/970afb63f2bd10a90c0d5157f1833bad to your computer and use it in GitHub Desktop.

Select an option

Save jsobell/970afb63f2bd10a90c0d5157f1833bad to your computer and use it in GitHub Desktop.
Example loading script snippets
<template>
<require from='scriptinjector'></require>
<h1>${message}</h1>
<scriptinjector url="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js" is-async.bind='true'></scriptinjector>
<scriptinjector url="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" is-async.bind='true'></scriptinjector>
</template>
export class App {
message = 'Hello World!';
}
export class CloneUtility {
function clone(obj) {
if (obj === null || typeof(obj) !== 'object' || 'isActiveClone' in obj)
return obj;
if (obj instanceof Date)
var temp = new obj.constructor(); //or new Date(obj);
else
var temp = obj.constructor();
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
obj['isActiveClone'] = null;
temp[key] = clone(obj[key]);
delete obj['isActiveClone'];
}
}
return temp;
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
import {bindingMode, customElement, bindable, noView} from "aurelia-framework";
@noView()
@customElement('scriptinjector')
export class scriptinjector {
@bindable url;
@bindable isAsync;
@bindable({defaultBindingMode: bindingMode.oneWay}) scripttag;
attached() {
if (this.url) {
this.scripttag = document.createElement('script');
if (this.isAsync) {
this.scripttag.async = true;
}
this.scripttag.setAttribute('src', this.url);
document.body.appendChild(this.scripttag);
}
}
detached() {
if (this.scripttag) {
this.scripttag.remove();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment