var module=angular.module("ngRateIt",["ng"]);module.directive("ngRateIt",["$q",function(a){"use strict";var b=function(b,c,d){d.readOnly||(b.readOnly=function(){return!1}),d.resetable||(b.resetable=function(){return!0}),d.beforeRated||(b.beforeRated=function(){var b=a.defer();return b.resolve(),b.promise}),d.rated||(b.rated=function(){}),d.beforeReset||(b.beforeReset=function(){var b=a.defer();return b.resolve(),b.promise}),d.reset||(b.reset=function(){}),d.over||(b.over=function(){})};return{scope:{ngModel:"=",min:"=?min",max:"=?max",step:"=?step",readOnly:"&?readOnly",pristine:"=?pristine",resetable:"&?resetable",starWidth:"=?starWidth",starHeight:"=?starHeight",rated:"=?rated",reset:"=?reset",over:"=?over",beforeRated:"=?beforeRated",beforeReset:"=?beforeReset"},templateUrl:"ngRateIt/ng-rate-it.html",require:"ngModel",replace:!0,link:b,controller:"ngRateItController"}}]).controller("ngRateItController",["$scope","$timeout",function(a,b){"use strict";a.isHovering=!1,a.offsetLeft=0,a.orgValue=angular.copy(a.ngModel),a.hoverValue=0,a.min=a.min||0,a.max=a.max||5,a.step=a.step||.5,a.pristine=a.orgValue===a.ngModel,a.starWidth=a.starWidth||16,a.starHeight=a.starHeight||16,a.resetCssOffset=4;var c=a.$watch("ngModel",function(){a.pristine=a.orgValue===a.ngModel});a.removeRating=function(){a.resetable()&&!a.readOnly()&&a.beforeReset().then(function(){a.ngModel=a.min,a.reset()})},a.setValue=function(){if(a.isHovering&&!a.readOnly()){var c=angular.copy(a.min+a.hoverValue);a.beforeRated(c).then(function(){a.ngModel=c,a.isHovering=!1,b(function(){a.rated()})})}},a.onEnter=function(b){a.isHovering=!0,a.offsetLeft=0;for(var c=b.originalTarget||b.srcElement;c&&!isNaN(c.offsetLeft)&&!isNaN(c.offsetTop);)a.offsetLeft+=c.offsetLeft-c.scrollLeft,c=c.offsetParent},a.onHover=function(b){a.isHovering=!0,a.hoverValue=Math.round((b.clientX-a.offsetLeft)/a.starWidth/a.step)*a.step,a.over(b,a.hoverValue)},a.onLeave=function(){a.isHovering=!1,a.hoverValue=0},a.$on("$destroy",function(){c()})}]).run(["$templateCache",function(a){"use strict";a.put("ngRateIt/ng-rate-it.html",'<div class="ngrateit" ng-class="{\'ngrateit-readonly\': readOnly()}"><a class="ngrateit-background ngrateit-reset" ng-mouseenter="resetCssOffset=5;" ng-mouseleave="resetCssOffset=4;" ng-if="!readOnly() && resetable()" ng-click="removeRating()" ng-style="{\'width\': starWidth+\'px\', \'height\': starHeight+\'px\', \'background-position\': \'0 \'+(-resetCssOffset*starHeight)+\'px\'}"></a><div class="ngrateit-star_wrapper" ng-click="setValue()" ng-mouseenter="onEnter($event)" ng-mousemove="onHover($event)" ng-mouseleave="onLeave();" ng-style="{\'width\': ((max-min)*starWidth)+\'px\', \'height\': starHeight+\'px\'}"><div class="ngrateit-background"></div>'+"<div class=\"ngrateit-value\" ng-hide=\"!readOnly() && hoverValue>0 && hoverValue!==(ngModel-min)\" ng-style=\"{'width': (ngModel-min)*starWidth+'px', 'background-position': '0 '+(-2*starHeight)+'px'}\"></div><div class=\"ngrateit-hover\" ng-if=\"!readOnly() && hoverValue!==(ngModel-min)\" ng-style=\"{'width': hoverValue*starWidth+'px', 'background-position': '0 '+(-3*starHeight)+'px'}\" ></div></div></div>")}]);