Commit 0c96eff0f8f737a915e92e824a8e083f8a3d74ea

Authored by Marcelo Puebla
Exists in develop

Merge branch 'master' into 'develop'

Master(mpuebla)

See merge request !18
... ... @@ -5,6 +5,7 @@
5 5 "main": "index.js",
6 6 "scripts": {
7 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",
8 9 "test": "echo \"Error: no test specified\" && exit 1",
9 10 "compile": "gulp uglify",
10 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 + });