This repository was archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy path3dtouch.js
More file actions
147 lines (127 loc) · 4.89 KB
/
3dtouch.js
File metadata and controls
147 lines (127 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// install : cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-3dtouch.git
// link : https://github.com/EddyVerbruggen/cordova-plugin-3dtouch
angular.module('ngCordova.plugins.3dtouch', [])
.factory('$cordova3DTouch', ['$q', function ($q) {
var quickActions = [];
var quickActionHandler = {};
var createQuickActionHandler = function (quickActionHandler) {
return function (payload) {
for (var key in quickActionHandler) {
if (payload.type === key) {
quickActionHandler[key]();
}
}
};
};
return {
/*
* Checks if Cordova 3D touch is present and loaded
*
* @return promise
*/
isAvailable: function () {
var deferred = $q.defer();
if (!window.cordova) {
deferred.reject('Not supported in browser');
} else {
if (!window.ThreeDeeTouch) {
deferred.reject('Could not find 3D touch plugin');
} else {
window.ThreeDeeTouch.isAvailable(function (value) {
deferred.resolve(value);
}, function (err) {
deferred.reject(err);
});
}
}
return deferred.promise;
},
/*
* Add a quick action to menu
*
* @param string type
* @param string title
* @param string iconType (optional)
* @param string subtitle (optional)
* @param function callback (optional)
* @return promise
*/
addQuickAction: function (type, title, iconType, iconTemplate, subtitle, callback) {
var deferred = $q.defer();
var quickAction = {
type: type,
title: title,
subtitle: subtitle
};
if (iconType) {
quickAction.iconType = iconType;
}
if (iconTemplate) {
quickAction.iconTemplate = iconTemplate;
}
this.isAvailable().then(function () {
quickActions.push(quickAction);
quickActionHandler[type] = callback;
window.ThreeDeeTouch.configureQuickActions(quickActions);
window.ThreeDeeTouch.onHomeIconPressed = createQuickActionHandler(quickActionHandler);
deferred.resolve(quickActions);
},
function (err) {
deferred.reject(err);
});
return deferred.promise;
},
/*
* Add a quick action handler. Used for static quick actions
*
* @param string type
* @param function callback
* @return promise
*/
addQuickActionHandler: function (type, callback) {
var deferred = $q.defer();
this.isAvailable().then(function () {
quickActionHandler[type] = callback;
window.ThreeDeeTouch.onHomeIconPressed = createQuickActionHandler(quickActionHandler);
deferred.resolve(true);
},
function (err) {
deferred.reject(err);
});
return deferred.promise;
},
/*
* Enable link preview popup when force touch is appled to link elements
*
* @return bool
*/
enableLinkPreview: function () {
var deferred = $q.defer();
this.isAvailable().then(function () {
window.ThreeDeeTouch.enableLinkPreview();
deferred.resolve(true);
},
function (err) {
deferred.reject(err);
});
return deferred.promise;
},
/*
* Add a hanlder function for force touch events,
*
* @param function callback
* @return promise
*/
addForceTouchHandler: function (callback) {
var deferred = $q.defer();
this.isAvailable().then(function () {
window.ThreeDeeTouch.watchForceTouches(callback);
deferred.resolve(true);
},
function (err) {
deferred.reject(err);
});
return deferred.promise;
}
};
}]);