forked from glorat/angular-counter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter.min.js
More file actions
1 lines (1 loc) · 1.79 KB
/
counter.min.js
File metadata and controls
1 lines (1 loc) · 1.79 KB
1
"use strict";angular.module("Firestitch.angular-counter",[]).directive("fsCounter",["$timeout",function($timeout){return{restrict:"A",scope:{value:"=value"},template:'<div class="fs-counter input-group" ng-class="addclass" ng-style="width"><span class="input-group-btn" ng-click="minus()"><button type="button" class="btn btn-default"><span class="glyphicon glyphicon-minus"></span></button></span><input type="text" class="form-control text-center" ng-model="value" ng-blur="blurred()" ng-change="changed()" ng-readonly="readonly"><span class="input-group-btn" ng-click="plus()"><button type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></button></span></div>',replace:!0,link:function(scope,element,attrs){var setValue,changeDelay,min=angular.isUndefined(attrs.min)?void 0:parseInt(attrs.min),max=angular.isUndefined(attrs.max)?void 0:parseInt(attrs.max),step=angular.isUndefined(attrs.step)||0===parseInt(attrs.step)?1:parseInt(attrs.step);if(setValue=function(val){var parsedVal=parseInt(val);return isNaN(parsedVal)?(console.log("parsedValue must parse to a number."),parsedVal=min||0):void 0!==min&&min>parsedVal?parsedVal=min:void 0!==max&&parsedVal>max?parsedVal=max:parsedVal},angular.isUndefined(scope.value))throw"Missing the value attribute on the counter directive.";scope.readonly=angular.isUndefined(attrs.editable)?!0:!1,scope.addclass=angular.isUndefined(attrs.addclass)?null:attrs.addclass,scope.width=angular.isUndefined(attrs.width)?{}:{width:attrs.width},scope.value=setValue(scope.value),scope.minus=function(){scope.value=setValue(scope.value-step)},scope.plus=function(){scope.value=setValue(scope.value+step)},scope.changed=function(){changeDelay=$timeout(function(){scope.value=setValue(scope.value)},1e3,!0)},scope.blurred=function(){scope.value=setValue(scope.value)}}}}]);