(function () { 'use strict'; angular.module('app.directive') .directive('adRating', ['$parse', function ($parse) { return { scope: {}, replace: true, templateUrl: 'directive/adRating/adRating.html', link: function (scope, element, attr) { var max = 5; scope.range = []; scope.range.length = max; var attrRating = $parse(attr['adRating']); scope.$parent.$watch(function (scope) { return attrRating(scope); }, function (value) { scope.value = value = parseFloat(value) * max; for (var i = 0, n = 1; i < 5; ++i, ++n) { if (n <= value) { scope.range[i] = 'full'; } else { scope.range[i] = value > n - 1 ? 'half' : 'empty'; } } }, attrRating.literal); } }; }]); })();