Skip to content

Instantly share code, notes, and snippets.

@timfish
Created July 31, 2018 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timfish/f69a0638f89b05f0dab44e95fa00b3a7 to your computer and use it in GitHub Desktop.
Save timfish/f69a0638f89b05f0dab44e95fa00b3a7 to your computer and use it in GitHub Desktop.
remove svg wrappers
<template>
<require from="./svg-rect"></require>
<svg width="100" height="100" style="background-color:lightblue">
<svg-rect rect.bind="{x: 5, y: 5, width: 30, height: 20}"></svg-rect>
</svg>
</template>
import { Container, inject, ViewResources } from 'aurelia-framework'
@inject(Container)
export class App {
constructor(container) {
const resources: ViewResources = container.get(ViewResources);
resources.registerViewEngineHooks({
beforeCreate: (view, s, f) => {
for(var i = 0; i < f.children[0].children.length; i++){
f.appendChild(f.children[0].children[i])
};
}
});
}
}
<!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>
<template>
<svg>
<rect x.bind="rect.x" y.bind="rect.y" width.bind="rect.width" height.bind="rect.height" style="background-color:red"></rect>
</svg>
</template>
import {containerless, bindable} from 'aurelia-framework'
@containerless
export class SvgRect {
@bindable rect;
constructor(){
}
attached(){
}
}
import {inject, customAttribute} from 'aurelia-framework';
@customAttribute('svg-remove')
@inject(Element)
export class SvgRemove {
constructor(element){
this.element = element;
}
attached(){
for(var i = 0; i< this.element.children.length; i++){
this.element.parentNode.appendChild(this.element.children[i])
}
this.element.remove();
console.log(this.element.children)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment