Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

feat(mdGesture): allow to change maxClickDistance through $mdGestureProvider.setMaxClickDistance #10498

Merged
merged 1 commit into from
May 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/core/services/gesture/gesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var HANDLERS = {};
* as well as other information abstracted from the DOM.
*/

var pointer, lastPointer, forceSkipClickHijack = false;
var pointer, lastPointer, forceSkipClickHijack = false, maxClickDistance = 6;

/**
* The position of the most recent click if that click was on a label element.
Expand All @@ -21,7 +21,7 @@ angular
.module('material.core.gestures', [ ])
.provider('$mdGesture', MdGestureProvider)
.factory('$$MdGestureHandler', MdGestureHandler)
.run( attachToDocument );
.run(attachToDocument );

/**
* @ngdoc service
Expand All @@ -32,6 +32,7 @@ angular
* In some scenarios on Mobile devices (without jQuery), the click events should NOT be hijacked.
* `$mdGestureProvider` is used to configure the Gesture module to ignore or skip click hijacking on mobile
* devices.
* You can also change max click distance (6px by default) if you have issues on some touch screens.
*
* <hljs lang="js">
* app.config(function($mdGestureProvider) {
Expand All @@ -40,6 +41,9 @@ angular
* // intercept click events during the capture phase.
* $mdGestureProvider.skipClickHijack();
*
* // If hijcacking clicks, change default 6px click distance
* $mdGestureProvider.setMaxClickDistance(12);
*
* });
* </hljs>
*
Expand All @@ -54,6 +58,10 @@ MdGestureProvider.prototype = {
return forceSkipClickHijack = true;
},

setMaxClickDistance: function(clickDistance) {
maxClickDistance = parseInt(clickDistance);
},

/**
* $get is used to build an instance of $mdGesture
* @ngInject
Expand Down Expand Up @@ -84,7 +92,6 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
};

if (self.isHijackingClicks) {
var maxClickDistance = 6;
self.handler('click', {
options: {
maxDistance: maxClickDistance
Expand Down