Skip to content

Instantly share code, notes, and snippets.

@BrianSipple
Last active December 27, 2016 05:58
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 BrianSipple/29d081c431ef919e814c31e5b7def2ad to your computer and use it in GitHub Desktop.
Save BrianSipple/29d081c431ef919e814c31e5b7def2ad to your computer and use it in GitHub Desktop.
ember-2.10-dynamic-use-xlink:href-attribute
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
import Ember from 'ember';
const { Component, computed, get } = Ember;
const PATH_PREFIX = '#';
export default Component.extend({
symbolID: '',
simpleBinding: '#circle',
computedBinding: computed('fileName', {
get() {
return `${PATH_PREFIX}${get(this, 'symbolID')}`;
}
})
});
<h3>Direct Usage:</h3>
<svg><use xlink:href="#circle"></use></svg>
<h3>Dynamic Usage:</h3>
<svg><use xlink:href={{simpleBinding}}></use></svg>
<svg><use xlink:href={{computedBinding}}></use></svg>
<svg xmlns="http://www.w3.org/2000/svg" style="position: absolute; top: 0; left: 0; width: 0; height: 0;">
<defs>
<symbol id="circle" viewBox="0 0 50 50">
<circle cx="25" cy="25" r="10" fill="blue"> </circle>
</symbol>
</defs>
</svg>
<h1>Rendering SVG &lt;use&gt; content with a Dynamic <code>xlink:href</code> attribute</h1>
<br>
<br>
{{svg-use-test symbolID="circle"}}
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment