Last active
August 29, 2015 14:02
-
-
Save adrianvlupu/0ff9e3074a04867345cb to your computer and use it in GitHub Desktop.
Numeric Spinner Directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input id="{{id}}" type="text" name="" ng-model="value" /> | |
<span class="add" ng-click="add()">+</span> | |
<span class="remove" ng-click="subtract()">-</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../_references.js" /> | |
mainModule.directive('numericSpinner', function () { | |
return { | |
restrict: 'E', | |
templateUrl: '/Application/Directives/NumericSpinner.html', | |
scope: { | |
minValue: '@minValue', | |
defaultValue: '@defaultValue', | |
id: '@textId', | |
value: '=ngModel' | |
}, | |
link: function ($scope, $elem, $attrs) { | |
$scope.value = $scope.defaultValue; | |
$scope.add = function () { | |
$scope.value++; | |
}; | |
$scope.subtract = function () { | |
if ($scope.value > $scope.minValue) | |
$scope.value--; | |
}; | |
$elem.find('input').bind('mousewheel DOMMouseScroll', function (event, delta) { | |
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) { | |
$scope.value++; | |
$scope.$apply(); | |
} | |
else { | |
if ($scope.value > $scope.minValue) { | |
$scope.value--; | |
$scope.$apply(); | |
} | |
} | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment