forked from dcloudio/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mui.back.js
55 lines (54 loc) · 1.01 KB
/
mui.back.js
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
/**
* mui back
* @param {type} $
* @param {type} window
* @returns {undefined}
*/
(function($, window) {
/**
* register back
* @param {type} back
* @returns {$.gestures}
*/
$.addBack = function(back) {
return $.addAction('backs', back);
};
/**
* default
*/
$.addBack({
name: 'browser',
index: 100,
handle: function() {
if (window.history.length > 1) {
window.history.back();
return true;
}
return false;
}
});
/**
* 后退
*/
$.back = function() {
if (typeof $.options.beforeback === 'function') {
if ($.options.beforeback() === false) {
return;
}
}
$.doAction('backs');
};
window.addEventListener('tap', function(e) {
var action = $.targets.action;
if (action && action.classList.contains($.className('action-back'))) {
$.back();
$.targets.action = false;
}
});
window.addEventListener('swiperight', function(e) {
var detail = e.detail;
if ($.options.swipeBack === true && Math.abs(detail.angle) < 3) {
$.back();
}
});
})(mui, window);