Commit e6371cf7ae9bb272161ddb84f2fa7510fae2b494

Authored by Marcelo Puebla
1 parent 6dd6f3aad2
Exists in develop

Agregada nueva directiva.

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