Skip to content

Instantly share code, notes, and snippets.

@fabioluz
Last active August 24, 2017 12:09
Show Gist options
  • Save fabioluz/ab04facb60b39f9c6a5fc49c2fd278a6 to your computer and use it in GitHub Desktop.
Save fabioluz/ab04facb60b39f9c6a5fc49c2fd278a6 to your computer and use it in GitHub Desktop.
<template>
<require from="./my-attr"></require>
${message}
<br><br>
<select focus.bind="isFocused" my-attr>
<option>Test</option>
</select>
<br><br>
Is Focused: ${isFocused}
<br><br>
<input type="text" my-attr focus.bind="isFocused2">
<br><br>
Is Focused2: ${isFocused2}
</template>
export class App {
message = 'Hello World!';
isFocused = false;
isFocused2 = false;
}
<!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 { inject } from 'aurelia-framework';
import { Focus } from 'aurelia-templating-resources';
@inject(Focus)
export class MyAttrCustomAttribute {
constructor(focusAttr) {
this.focusAttr = focusAttr;
}
attached() {
console.log(this.focusAttr.value);
//...
//extending the change event. BE CAREFUL!
//...
const originalValueChanged = this.focusAttr.valueChanged;
this.focusAttr.valueChanged = function(newValue) {
console.log('Focus bound value has changed!'); //<-- call an event before "focus"
originalValueChanged.call(this, newValue); //<-- "focus" is enqueued
// <--- enqueue an event event here to be called after "focus"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment