Created
January 30, 2014 14:45
-
-
Save rhrn/8710033 to your computer and use it in GitHub Desktop.
Angular.js directives
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
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(); | |
}); | |
} | |
}; | |
}]); |
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
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