diff --git a/Makefile b/Makefile index c8e2911..6d18a4c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,3 @@ -build: - node_modules/.bin/coffee -c ionic-rating.coffee - uglify: node_modules/.bin/uglifyjs ionic-rating.js > ionic-rating.min.js diff --git a/ionic-rating.coffee b/ionic-rating.coffee deleted file mode 100644 index eeea951..0000000 --- a/ionic-rating.coffee +++ /dev/null @@ -1,82 +0,0 @@ -angular.module 'ionic.rating', [] - -.constant 'ratingConfig', { - max: 5 - stateOn: null - stateOff: null -} - -.controller 'RatingController', ($scope, $attrs, ratingConfig) -> - ngModelCtrl = { $setViewValue: angular.noop } - - this.init = (ngModelCtrl_) -> - ngModelCtrl = ngModelCtrl_ - ngModelCtrl.$render = this.render - - this.stateOn = if angular.isDefined($attrs.stateOn) - then $scope.$parent.$eval($attrs.stateOn) - else ratingConfig.stateOn - - this.stateOff = if angular.isDefined($attrs.stateOff) - then $scope.$parent.$eval($attrs.stateOff) - else ratingConfig.stateOff - - max = if angular.isDefined($attrs.max) then $scope.$parent.$eval($attrs.max) else ratingConfig.max - - ratingStates = if angular.isDefined($attrs.ratingStates) - then $scope.$parent.$eval($attrs.ratingStates) - else new Array(max) - - $scope.range = this.buildTemplateObjects(ratingStates) - - this.buildTemplateObjects = (states) -> - for i in states.length - states[i] = angular.extend { index: 1 }, { stateOn: this.stateOn, stateOff: this.stateOff }, states[i] - return states - - $scope.rate = (value) -> - if not $scope.readonly and value >= 0 && value <= $scope.range.length - ngModelCtrl.$setViewValue value - ngModelCtrl.$render() - - $scope.reset = -> - $scope.value = ngModelCtrl.$viewValue - $scope.onLeave() - - $scope.enter = (value) -> - if not $scope.readonly - $scope.value = value - $scope.onHover({value: value}) - - $scope.onKeydown = (evt) -> - if /(37|38|39|40)/.test evt.which - evt.preventDefault() - evt.stopPropagation() - $scope.rate $scope.value + (if evt.which is 38 or evt.which is 39 then 1 : -1 ) - - this.render = -> - $scope.value = ngModelCtrl.$viewValue - - return this - -.directive 'rating', -> - return { - restrict: 'EA' - require: ['rating', 'ngModel'] - scope: - readonly: '@' - onHover: '&' - onLeave: '&' - controller: 'RatingController' - template: '
' - replace: true - link: (scope, element, attrs, ctrls) -> - ratingCtrl = ctrls[0] - ngModelCtrl = ctrls[1] - - if ngModelCtrl - ratingCtrl.init ngModelCtrl - } - diff --git a/ionic-rating.js b/ionic-rating.js index 024b1b8..a797b84 100644 --- a/ionic-rating.js +++ b/ionic-rating.js @@ -1,73 +1,81 @@ -// Generated by CoffeeScript 1.9.1 -(function() { - angular.module('ionic.rating', []).constant('ratingConfig', { - max: 5 - }).controller('RatingController', function($scope, $attrs, ratingConfig) { - var ngModelCtrl; - ngModelCtrl = { - $setViewValue: angular.noop - }; - this.init = function(ngModelCtrl_) { - var max, ratingStates; - ngModelCtrl = ngModelCtrl_; - ngModelCtrl.$render = this.render; - max = angular.isDefined($attrs.max) ? $scope.$parent.$eval($attrs.max) : ratingConfig.max; - return $scope.range = this.buildTemplateObjects(ngModelCtrl.$modelValue, max); - }; - this.buildTemplateObjects = function(stateValue, max) { - var i, j, len, states = []; +(function () { - for (j = 0; j < max; j++) { - if(stateValue > j && stateValue < j+1) - states[j] = 2; - else if(stateValue > j) - states[j] = 1; - else - states[j] = 0; - } + 'use strict'; - return states; - }; - $scope.rate = function(value) { - if (!$scope.readonly && value >= 0 && value <= $scope.range.length) { - ngModelCtrl.$setViewValue(value); - return ngModelCtrl.$render(); - } - }; - $scope.onKeydown = function(evt) { - if (/(37|38|39|40)/.test(evt.which)) { - evt.preventDefault(); - evt.stopPropagation(); - return $scope.rate($scope.value + (evt.which === 38 || evt.which === 39 ? { - 1: -1 - } : void 0)); - } - }; - this.render = function() { - return $scope.value = ngModelCtrl.$viewValue; - }; - return this; - }).directive('rating', function($timeout) { - return { - restrict: 'EA', - require: ['rating', 'ngModel'], - scope: { - readonly: '@' - }, - controller: 'RatingController', - template: '', - replace: true, - link: function(scope, element, attrs, ctrls) { - var ngModelCtrl, ratingCtrl; - ratingCtrl = ctrls[0]; - ngModelCtrl = ctrls[1]; - if (ngModelCtrl) { - $timeout(function(){ - return ratingCtrl.init(ngModelCtrl); - }) - } - } - }; - }); + angular.module('ionic.rating', []) -}).call(this); + .constant('ratingConfig', { + max: 5 + }) + + .controller('RatingController', [ '$scope', '$attrs', 'ratingConfig', function ($scope, $attrs, ratingConfig) { + var ngModelCtrl; + ngModelCtrl = { + $setViewValue: angular.noop + }; + this.init = function (ngModelCtrl_) { + var max; + ngModelCtrl = ngModelCtrl_; + ngModelCtrl.$render = this.render; + max = angular.isDefined($attrs.max) ? $scope.$parent.$eval($attrs.max) : ratingConfig.max; + return $scope.range = this.buildTemplateObjects(ngModelCtrl.$modelValue, max); + }; + this.buildTemplateObjects = function (stateValue, max) { + var j, states = []; + + for (j = 0; j < max; j++) { + if (stateValue > j && stateValue < j + 1) + states[j] = 2; + else if (stateValue > j) + states[j] = 1; + else + states[j] = 0; + } + + return states; + }; + $scope.rate = function (value) { + if (!$scope.readonly && value >= 0 && value <= $scope.range.length) { + ngModelCtrl.$setViewValue(value); + return ngModelCtrl.$render(); + } + }; + $scope.onKeydown = function (evt) { + if (/(37|38|39|40)/.test(evt.which)) { + evt.preventDefault(); + evt.stopPropagation(); + return $scope.rate($scope.value + (evt.which === 38 || evt.which === 39 ? { + 1: -1 + } : void 0)); + } + }; + this.render = function () { + return $scope.value = ngModelCtrl.$viewValue; + }; + return this; + }]) + + .directive('rating', ['$timeout', function ($timeout) { + return { + restrict: 'EA', + require: ['rating', 'ngModel'], + scope: { + readonly: '@' + }, + controller: 'RatingController', + template: '', + replace: true, + link: function (scope, element, attrs, ctrls) { + var ngModelCtrl, ratingCtrl; + ratingCtrl = ctrls[0]; + ngModelCtrl = ctrls[1]; + if (ngModelCtrl) { + $timeout(function () { + return ratingCtrl.init(ngModelCtrl); + }) + } + } + }; + }]); + +}()); \ No newline at end of file diff --git a/ionic-rating.min.js b/ionic-rating.min.js index cf76261..b8081bc 100644 --- a/ionic-rating.min.js +++ b/ionic-rating.min.js @@ -1 +1 @@ -(function(){angular.module('ionic.rating',[]).constant('ratingConfig',{max:5}).controller('RatingController',function($scope,$attrs,ratingConfig){var ngModelCtrl;ngModelCtrl={$setViewValue:angular.noop};this.init=function(ngModelCtrl_){var max,ratingStates;ngModelCtrl=ngModelCtrl_;ngModelCtrl.$render=this.render;max=angular.isDefined($attrs.max)?$scope.$parent.$eval($attrs.max):ratingConfig.max;return $scope.range=this.buildTemplateObjects(ngModelCtrl.$modelValue,max)};this.buildTemplateObjects=function(stateValue,max){var i,j,len,states=[];for(j=0;j