Commit 9663b442f423f70691f9c3716bfabd42a66a7bbb
1 parent
e6371cf7ae
Exists in
develop
Linea al final del archivo
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
src/js/onMouseHold-directive.js
| 1 | angular.module('focaDirectivas') | 1 | angular.module('focaDirectivas') |
| 2 | .directive('onMouseHold', function ($parse, $interval) { | 2 | .directive('onMouseHold', function ($parse, $interval) { |
| 3 | var stop; | 3 | var stop; |
| 4 | 4 | ||
| 5 | var dirDefObj = { | 5 | var dirDefObj = { |
| 6 | restrict: 'A', | 6 | restrict: 'A', |
| 7 | scope: { method: '&onMouseHold' }, | 7 | scope: { method: '&onMouseHold' }, |
| 8 | link: function (scope, element, attrs) { | 8 | link: function (scope, element, attrs) { |
| 9 | 9 | ||
| 10 | var expressionHandler = scope.method(); | 10 | var expressionHandler = scope.method(); |
| 11 | var actionInterval = (attrs.mouseHoldRepeat) ? attrs.mouseHoldRepeat : 500; | 11 | var actionInterval = (attrs.mouseHoldRepeat) ? attrs.mouseHoldRepeat : 500; |
| 12 | 12 | ||
| 13 | var startAction = function () { | 13 | var startAction = function () { |
| 14 | expressionHandler(); | 14 | expressionHandler(); |
| 15 | stop = $interval(function () { | 15 | stop = $interval(function () { |
| 16 | expressionHandler(); | 16 | expressionHandler(); |
| 17 | }, actionInterval); | 17 | }, actionInterval); |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | var stopAction = function () { | 20 | var stopAction = function () { |
| 21 | if (stop) { | 21 | if (stop) { |
| 22 | $interval.cancel(stop); | 22 | $interval.cancel(stop); |
| 23 | stop = undefined; | 23 | stop = undefined; |
| 24 | } | 24 | } |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | element.bind('mousedown', startAction); | 27 | element.bind('mousedown', startAction); |
| 28 | element.bind('mouseup', stopAction); | 28 | element.bind('mouseup', stopAction); |
| 29 | element.bind('mouseout', stopAction); | 29 | element.bind('mouseout', stopAction); |
| 30 | } | 30 | } |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | return dirDefObj; | 33 | return dirDefObj; |
| 34 | }); | ||
| 34 | }); |