Last active
September 29, 2017 23:35
-
-
Save freshcutdevelopment/b7520cd0dd7c3a0e3b974787dca5ddee to your computer and use it in GitHub Desktop.
List group - Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {bindable, processContent} from 'aurelia-templating'; | |
import {FEATURE} from 'aurelia-pal'; | |
//This custom attribute was created by Jeremy Danyow as a part of this | |
//stackoverflow answer https://stackoverflow.com/questions/43306744/using-custom-element-content-as-item-template/43325889#43325889 | |
@processContent(makePartReplacementFromContent) | |
export class ListGroup { | |
@bindable itemsSource = null; | |
@bindable defaultValue = model => ""; | |
} | |
function makePartReplacementFromContent(viewCompiler, viewResources, element, behaviorInstruction) { | |
const content = element.firstElementChild; | |
if (content) { | |
//note: In the latest version of aurelia this can be done in a cleaner way using DOM.createTemplateElement() method. | |
const template = document.createElement('template'); | |
// support browsers that do not have a real <template> element implementation (IE) | |
FEATURE.ensureHTMLTemplateElement(template); | |
// indicate the part this <template> replaces. | |
template.setAttribute('replace-part', 'item-template'); | |
// replace the element's content with the <template> | |
element.insertBefore(template, content); | |
element.removeChild(content); | |
template.content.appendChild(content); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment