Skip to content

Instantly share code, notes, and snippets.

@bigopon
Last active August 27, 2017 10:22
Show Gist options
  • Save bigopon/1cc68d08b9d2c966911b63f79853ac6c to your computer and use it in GitHub Desktop.
Save bigopon/1cc68d08b9d2c966911b63f79853ac6c to your computer and use it in GitHub Desktop.
Adjust undefined binding
<template>
<a href.bind='url' ref='anchor'>Url is "${url}"</a>
<div>
</div>
<button click.delegate='url = "https://google.com"'>Home</button>
<hr/>
<img src.bind='imgUrl' style="display: block; width: 100%;"/>
<div></div>
<button click.delegate='imgUrl="https://assets.rbl.ms/4314213/980x.jpg"'>Set image src</button>
</template>
import { DOM, ObserverLocator } from 'aurelia-framework';
const dataAttributeAccessor = {
getValue: function(obj, propertyName) {
return obj.getAttribute(propertyName);
},
setValue: function(value, obj, propertyName) {
return obj.setAttribute(propertyName, value);
}
};
const specialDomAttributeAccessor = {
getValue: function(obj, propertyName) {
return obj[propertyName];
},
setValue: function(value, obj, propertyName) {
// Here is how we adjust it.
if (value == null) {
obj[propertyName] = null;
obj.removeAttribute(propertyName);
} else {
obj[propertyName] = value;
}
}
}
const propertyAccessor = {
getValue: function getValue(obj, propertyName) {
return obj[propertyName];
},
setValue: function setValue(value, obj, propertyName) {
obj[propertyName] = value;
}
};
ObserverLocator.prototype.getAccessor = function(obj, propertyName) {
if (obj instanceof DOM.Element) {
if (propertyName === 'class' || propertyName === 'style' || propertyName === 'css' || propertyName === 'value' && (obj.tagName.toLowerCase() === 'input' || obj.tagName.toLowerCase() === 'select') || propertyName === 'checked' && obj.tagName.toLowerCase() === 'input' || propertyName === 'model' && obj.tagName.toLowerCase() === 'input' || /^xlink:.+$/.exec(propertyName)) {
return this.getObserver(obj, propertyName);
}
if (/^\w+:|^data-|^aria-/.test(propertyName) || obj instanceof DOM.SVGElement && this.svgAnalyzer.isStandardSvgAttribute(obj.nodeName, propertyName)) {
return dataAttributeAccessor;
}
if (propertyName in obj) {
return specialDomAttributeAccessor;
}
}
return propertyAccessor;
};
export class App {
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
body {
padding: 20px;
}
.form-component {
display: block;
margin-bottom: 20px;
}
</style>
</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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment