Skip to content

Instantly share code, notes, and snippets.

@rhrn
Created January 30, 2014 14:45
Show Gist options
  • Save rhrn/8710033 to your computer and use it in GitHub Desktop.
Save rhrn/8710033 to your computer and use it in GitHub Desktop.
Angular.js directives
fzapp.directive('xspin', [function() {
return {
scope: true,
link: function(scope, element, attrs) {
var spinner, options = {lines:10, width: 1, length: 1, radius: 7};
if (attrs.xspin) {
options = angular.extend(options, angular.fromJson(attrs.xspin));
}
spinner = new Spinner(options);
scope.$on('xspinStart', function() {
spinner.spin(element[0]);
});
scope.$on('xspinStop', function() {
spinner.stop();
});
}
};
}]);
fzapp.directive('translate', ['localization', '$interpolate', function(localization, $interpolate) {
return {
compile: function(element, attrs) {
element.html(localization.translate(element.html()));
if (attrs.translate) {
return {
post: function(scope, element, attrs) {
var fn = $interpolate(element.html());
var off = scope.$watch(attrs.translate, function(data) {
element.html(fn(angular.extend(scope, data)));
off();
});
}
};
}
}
};
}]);
fzapp.directive('placeholder', ['localization', function(localization) {
return {
compile: function(element, attrs) {
attrs.$set('placeholder', localization.translate(attrs.placeholder));
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment