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

Commit

Permalink
feat(gestures): add provider to all config and optional skipClickHija…
Browse files Browse the repository at this point in the history
…ck()
  • Loading branch information
ThomasBurleson committed Apr 13, 2015
1 parent 4a419ea commit f28393d
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions src/core/services/gesture/gesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,56 @@
* It contains normalized x and y coordinates from DOM events,
* as well as other information abstracted from the DOM.
*/
var pointer, lastPointer;
var pointer, lastPointer, forceSkipClickHijack = false;

// Used to attach event listeners once when multiple ng-apps are running.
var isInitialized = false;

angular
.module('material.core.gestures', [ ])
.factory('$mdGesture', MdGesture)
.provider('$mdGesture', MdGestureProvider)
.factory('$$MdGestureHandler', MdGestureHandler)
.run( attachToDocument );

/**
* @ngdoc service
* @name $mdGestureProvider
* @module material.core.gestures
*
* @description
* 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.
*
* <hljs lang="js">
* app.config(function($mdGestureProvider) {
*
* // For mobile devices without jQuery loaded, do not
* // intercept click events during the capture phase.
* $mdGestureProvider.skipClickHijack();
*
* });
* </hljs>
*
*/
function MdGestureProvider() { }

MdGestureProvider.prototype = {

This comment has been minimized.

Copy link
@bocahnakal

bocahnakal Jun 20, 2015

No cpmmnt


// Publish access to setter to configure a variable BEFORE the
// $mdGesture service is instantiated...
skipClickHijack: function() {
return forceSkipClickHijack = true;
},

// $get is used to build an instance of $mdGesture
$get : ['$$MdGestureHandler', '$$rAF', '$timeout', function($$MdGestureHandler, $$rAF, $timeout) {
return new MdGesture($$MdGestureHandler, $$rAF, $timeout);
}]
};



/**
* MdGesture factory construction function
*/
Expand All @@ -29,9 +68,8 @@
var self = {
handler: addHandler,
register: register,
// TODO only hijack clicks on Android < 4.4
// TODO allow an override for this (through provider?)
isHijackingClicks: (isIos || isAndroid) && !jQuery
// On mobile w/out jQuery, we normally intercept clicks. Should we skip that?
isHijackingClicks: (isIos || isAndroid) && !jQuery && !forceSkipClickHijack
};

if (self.isHijackingClicks) {
Expand Down Expand Up @@ -393,7 +431,7 @@
return document.body.contains(node);
});

if (!isInitialized && $mdGesture.isHijackingClicks) {
if (!isInitialized && $mdGesture.isHijackingClicks ) {
/*
* If hijack clicks is true, we preventDefault any click that wasn't
* sent by ngMaterial. This is because on older Android & iOS, a false, or 'ghost',
Expand Down

0 comments on commit f28393d

Please sign in to comment.