Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Last active April 25, 2017 02:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jdanyow/fa524f8b9d5787d97af6 to your computer and use it in GitHub Desktop.
Save jdanyow/fa524f8b9d5787d97af6 to your computer and use it in GitHub Desktop.
Aurelia - JQueryUI DatePicker
<template>
<require from="./datepicker"></require>
Pick a date:
<input datepicker value.bind="dateValue">
<p>${dateValue}</p>
</template>
export class App {
dateValue = null;
}
import {inject, customAttribute} from 'aurelia-framework';
@customAttribute('datepicker')
@inject(Element)
export class DatePicker {
constructor(element) {
this.element = element;
}
attached() {
$(this.element).datepicker()
.on('change', e => fireEvent(e.target, 'input'));
}
detached() {
$(this.element).datepicker('destroy')
.off('change');
}
}
function createEvent(name) {
var event = document.createEvent('Event');
event.initEvent(name, true, true);
return event;
}
function fireEvent(element, name) {
var event = createEvent(name);
element.dispatchEvent(event);
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/cupertino/jquery-ui.css">
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
/*******************************************************************************
* The following two lines enable async/await without using babel's
* "runtime" transformer. Uncomment the lines if you intend to use async/await.
*
* More info here: https://github.com/jdanyow/aurelia-plunker/issues/2
*/
//import regeneratorRuntime from 'babel-runtime/regenerator';
//window.regeneratorRuntime = regeneratorRuntime;
/******************************************************************************/
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(a => a.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment