diff --git a/dist/ng-rateit.js b/dist/ng-rateit.js index 838ca01..0d49809 100644 --- a/dist/ng-rateit.js +++ b/dist/ng-rateit.js @@ -87,8 +87,8 @@ module }); $scope.removeRating = function () { - if($scope.resetable() && !$scope.readOnly()){ - $scope.beforeReset().then(function() { + if ($scope.resetable() && !$scope.readOnly()) { + $scope.beforeReset().then(function () { $scope.ngModel = $scope.min; $scope.reset(); }); @@ -96,12 +96,12 @@ module }; $scope.setValue = function () { - if($scope.isHovering && !$scope.readOnly()){ - var tmpValue = angular.copy($scope.min+$scope.hoverValue); - $scope.beforeRated(tmpValue).then(function() { + if ($scope.isHovering && !$scope.readOnly()) { + var tmpValue = angular.copy($scope.min + $scope.hoverValue); + $scope.beforeRated(tmpValue).then(function () { $scope.ngModel = tmpValue; $scope.isHovering = false; - $timeout(function(){ + $timeout(function () { $scope.rated(); }); }); @@ -110,14 +110,14 @@ module $scope.onEnter = function (event) { $scope.isHovering = true; - $scope.offsetLeft = 0; - - var el = event.originalTarget || event.srcElement; - $scope.offsetLeft = el.getBoundingClientRect().left; + $scope.offsetLeft = 0; + + var el = event.originalTarget || event.srcElement || event.target; + $scope.offsetLeft = el.getBoundingClientRect().left; }; $scope.onHover = function (event) { $scope.isHovering = true; - $scope.hoverValue = Math.round((event.clientX-$scope.offsetLeft)/$scope.starWidth/$scope.step) * $scope.step; + $scope.hoverValue = Math.round((event.clientX - $scope.offsetLeft) / $scope.starWidth / $scope.step) * $scope.step; $scope.over(event, $scope.hoverValue); }; $scope.onLeave = function () { diff --git a/dist/ng-rateit.min.js b/dist/ng-rateit.min.js index 4fc6522..7442d32 100644 --- a/dist/ng-rateit.min.js +++ b/dist/ng-rateit.min.js @@ -1 +1 @@ -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;var c=b.originalTarget||b.srcElement;a.offsetLeft=c.getBoundingClientRect().left},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",'
'+"
0 && hoverValue!==(ngModel-min)\" ng-style=\"{'width': (ngModel-min)*starWidth+'px', 'background-position': '0 '+(-2*starHeight)+'px'}\">
")}]); \ No newline at end of file +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;var c=b.originalTarget||b.srcElement||b.target;a.offsetLeft=c.getBoundingClientRect().left},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",'
'+"
0 && hoverValue!==(ngModel-min)\" ng-style=\"{'width': (ngModel-min)*starWidth+'px', 'background-position': '0 '+(-2*starHeight)+'px'}\">
")}]); \ No newline at end of file diff --git a/example/index.html b/example/index.html index def9019..26d6cb7 100644 --- a/example/index.html +++ b/example/index.html @@ -2,9 +2,9 @@ - + - + @@ -23,40 +23,40 @@

Basic

- +

Value: {{model.basic}}

-
+

Min, Max & step

- +

Value: {{model.minMaxStep}}

-
+

Read only

- +

Value: {{model.readonly}}

-

+            

 

Is pristine

- +

Value: {{model.pristine}}

Is pristine: {{model.resetable_pristine ? 'Yes' : 'No'}}

-
+

No reset

- +

Value: {{model.resetable}}

-
+

Start height/width

@@ -68,7 +68,7 @@

Start height/width

background-image: url('bigstar.gif'); } - +

Value: {{model.heightWidth}}

 
-
+
 

Callbacks

- +

Note: The 'over' callback will be visible in the console log.

Value: {{model.resetable}}

-
+

Custom image

@@ -99,7 +99,7 @@

Custom image

background-image: url('custom.png'); } - +

Value: {{model.custom}}

 
-
+
 
diff --git a/src/ng-rateit.js b/src/ng-rateit.js index 838ca01..0d49809 100644 --- a/src/ng-rateit.js +++ b/src/ng-rateit.js @@ -87,8 +87,8 @@ module }); $scope.removeRating = function () { - if($scope.resetable() && !$scope.readOnly()){ - $scope.beforeReset().then(function() { + if ($scope.resetable() && !$scope.readOnly()) { + $scope.beforeReset().then(function () { $scope.ngModel = $scope.min; $scope.reset(); }); @@ -96,12 +96,12 @@ module }; $scope.setValue = function () { - if($scope.isHovering && !$scope.readOnly()){ - var tmpValue = angular.copy($scope.min+$scope.hoverValue); - $scope.beforeRated(tmpValue).then(function() { + if ($scope.isHovering && !$scope.readOnly()) { + var tmpValue = angular.copy($scope.min + $scope.hoverValue); + $scope.beforeRated(tmpValue).then(function () { $scope.ngModel = tmpValue; $scope.isHovering = false; - $timeout(function(){ + $timeout(function () { $scope.rated(); }); }); @@ -110,14 +110,14 @@ module $scope.onEnter = function (event) { $scope.isHovering = true; - $scope.offsetLeft = 0; - - var el = event.originalTarget || event.srcElement; - $scope.offsetLeft = el.getBoundingClientRect().left; + $scope.offsetLeft = 0; + + var el = event.originalTarget || event.srcElement || event.target; + $scope.offsetLeft = el.getBoundingClientRect().left; }; $scope.onHover = function (event) { $scope.isHovering = true; - $scope.hoverValue = Math.round((event.clientX-$scope.offsetLeft)/$scope.starWidth/$scope.step) * $scope.step; + $scope.hoverValue = Math.round((event.clientX - $scope.offsetLeft) / $scope.starWidth / $scope.step) * $scope.step; $scope.over(event, $scope.hoverValue); }; $scope.onLeave = function () {