Commit c0cb35795da9df094e0a991e6905f1b60a1a09c0
Exists in
develop
Merge branch 'develop' into 'master'
Develop See merge request !19
Showing
2 changed files
 
Show diff stats
package.json
| ... | ... | @@ -4,6 +4,8 @@ | 
| 4 | 4 | "description": "Directivas para usarse en los productos Debo Suite", | 
| 5 | 5 | "main": "index.js", | 
| 6 | 6 | "scripts": { | 
| 7 | + "refresh": "gulp uglify && cp tmp/foca-directivas.js ../wrapper-demo/node_modules/foca-directivas/dist/foca-directivas.min.js", | |
| 8 | + "frefresh": "gulp uglify && cp tmp/foca-directivas.js ../wrapper-facturador/node_modules/foca-directivas/dist/foca-directivas.min.js", | |
| 7 | 9 | "test": "echo \"Error: no test specified\" && exit 1", | 
| 8 | 10 | "compile": "gulp uglify", | 
| 9 | 11 | "postinstall": "npm run compile && gulp clean-post-install", | 
src/js/onMouseHold-directive.js
| ... | ... | @@ -0,0 +1,34 @@ | 
| 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 | + }); |