Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default provider option #52

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ npm-debug.log

examples/raw/angular*
examples/raw/hammer*
examples/lib

examples/browserify/angular*
examples/browserify/hammer*
Expand Down
34 changes: 31 additions & 3 deletions angular.hammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@
*/
angular.module('hmTouchEvents', []);


/*
* hmTouchEventsDefault provider to set any default options
* setDefaultRecognizerOptions is to set any default recognizer options for a particular event type.
*/
angular
.module('hmTouchEvents')
.provider('hmTouchEventsDefault', function() {

var defaultRecognizerOptions = {};

this.$get = function () {
return {
getDefaultRecognizer: function(eventType) {
return defaultRecognizerOptions[eventType] || null;
}
};
};

/**
* @param {String} type set an option for an <eventName>
* @param {Object} recognizer options to be set for the <eventName>
* @return None
*/
this.setDefaultRecognizerOptions = function(type, options) {
defaultRecognizerOptions[type] = options;
};
});

/**
* Iterates through each gesture type mapping and creates a directive for
* each of the
Expand All @@ -100,7 +129,7 @@
eventName = directive[1];

angular.module('hmTouchEvents')
.directive(directiveName, ['$parse', '$window', function ($parse, $window) {
.directive(directiveName, ['$parse', '$window', 'hmTouchEventsDefault', function ($parse, $window, hmTouchEventsDefault) {
return {
'restrict' : 'A',
'link' : function (scope, element, attrs) {
Expand All @@ -122,8 +151,7 @@

var hammer = element.data('hammer'),
managerOpts = angular.fromJson(attrs.hmManagerOptions),
recognizerOpts = angular.fromJson(attrs.hmRecognizerOptions);

recognizerOpts = hmTouchEventsDefault.getDefaultRecognizer(directiveName) || angular.fromJson(attrs.hmRecognizerOptions);

// Check for a manager, make one if needed and destroy it when
// the scope is destroyed
Expand Down
7 changes: 7 additions & 0 deletions examples/raw/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
* @ngInject
*/
angular.module('hmTime', ['hmTouchEvents'])
.config(function(hmTouchEventsDefaultProvider) {
hmTouchEventsDefaultProvider
.setDefaultRecognizerOptions('hmTap', {
threshold: 12,
time: 800
});
})
.controller('hmCtrl', function ($scope) {
$scope.eventType = "No events yet";
$scope.onHammer = function onHammer (event) {
Expand Down