Last active
August 6, 2020 20:49
-
-
Save jbmoelker/9471081 to your computer and use it in GitHub Desktop.
viewBox is an AngularJS directive which adds support for using an expression for the SVG viewBox, by using `data-view-box` which sets `viewBox` attribute. Code borrowed from http://stackoverflow.com/a/14596319
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
angular | |
.module('directives.viewBox', []) | |
.directive('viewBox', [ | |
/** | |
* @ngdoc directive | |
* @name directives.viewBox.directive:viewBox | |
* @description | |
* Supports using expression for SVG viewBox, by | |
* using `data-view-box` which sets `viewBox` attribute. | |
* Code borrowed from http://stackoverflow.com/a/14596319 | |
* @element SVG | |
* @example | |
<doc:example> | |
<doc:source> | |
<svg data-view-box="{{ APP_VIEWPORT.viewBox }}"></svg> | |
</doc:source> | |
</doc:example> | |
*/ | |
function () { | |
'use strict'; | |
return { | |
link: function (scope, element, attributes) { | |
attributes.$observe('viewBox', function(value) { | |
element.attr('viewBox', value); | |
}); | |
} | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment