mui_app_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +34 -0
  3. data/app/assets/fonts/mui.ttf +0 -0
  4. data/app/assets/javascripts/mui_app_rails/actions.js +26 -0
  5. data/app/assets/javascripts/mui_app_rails/ajax.plugin.js +3 -0
  6. data/app/assets/javascripts/mui_app_rails/input.plugin.js +232 -0
  7. data/app/assets/javascripts/mui_app_rails/modals.js +37 -0
  8. data/app/assets/javascripts/mui_app_rails/mui.active.js +30 -0
  9. data/app/assets/javascripts/mui_app_rails/mui.ajax.5+.js +27 -0
  10. data/app/assets/javascripts/mui_app_rails/mui.ajax.js +277 -0
  11. data/app/assets/javascripts/mui_app_rails/mui.animation.js +39 -0
  12. data/app/assets/javascripts/mui_app_rails/mui.animationframe.js +72 -0
  13. data/app/assets/javascripts/mui_app_rails/mui.back.5+.js +108 -0
  14. data/app/assets/javascripts/mui_app_rails/mui.back.js +56 -0
  15. data/app/assets/javascripts/mui_app_rails/mui.class.js +40 -0
  16. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.js +894 -0
  17. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.pullrefresh.js +150 -0
  18. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.slider.js +361 -0
  19. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.slider.old.js +332 -0
  20. data/app/assets/javascripts/mui_app_rails/mui.detect.5+.js +18 -0
  21. data/app/assets/javascripts/mui_app_rails/mui.detect.js +50 -0
  22. data/app/assets/javascripts/mui_app_rails/mui.dialog.alert.js +27 -0
  23. data/app/assets/javascripts/mui_app_rails/mui.dialog.confirm.js +27 -0
  24. data/app/assets/javascripts/mui_app_rails/mui.dialog.prompt.js +33 -0
  25. data/app/assets/javascripts/mui_app_rails/mui.dialog.toast.js +20 -0
  26. data/app/assets/javascripts/mui_app_rails/mui.event.js +160 -0
  27. data/app/assets/javascripts/mui_app_rails/mui.fixed.animation.js +22 -0
  28. data/app/assets/javascripts/mui_app_rails/mui.fixed.classlist.js +50 -0
  29. data/app/assets/javascripts/mui_app_rails/mui.fixed.fastclick.js +64 -0
  30. data/app/assets/javascripts/mui_app_rails/mui.fixed.js +40 -0
  31. data/app/assets/javascripts/mui_app_rails/mui.fixed.keyboard.js +56 -0
  32. data/app/assets/javascripts/mui_app_rails/mui.gestures.drag.js +48 -0
  33. data/app/assets/javascripts/mui_app_rails/mui.gestures.flick.js +30 -0
  34. data/app/assets/javascripts/mui_app_rails/mui.gestures.hold.js +41 -0
  35. data/app/assets/javascripts/mui_app_rails/mui.gestures.js +207 -0
  36. data/app/assets/javascripts/mui_app_rails/mui.gestures.longtap.js +43 -0
  37. data/app/assets/javascripts/mui_app_rails/mui.gestures.swipe.js +29 -0
  38. data/app/assets/javascripts/mui_app_rails/mui.gestures.tap.js +40 -0
  39. data/app/assets/javascripts/mui_app_rails/mui.init.5+.js +441 -0
  40. data/app/assets/javascripts/mui_app_rails/mui.init.js +100 -0
  41. data/app/assets/javascripts/mui_app_rails/mui.init.pullrefresh.js +57 -0
  42. data/app/assets/javascripts/mui_app_rails/mui.js +396 -0
  43. data/app/assets/javascripts/mui_app_rails/mui.jsonp.js +108 -0
  44. data/app/assets/javascripts/mui_app_rails/mui.layout.js +22 -0
  45. data/app/assets/javascripts/mui_app_rails/mui.namespace.js +35 -0
  46. data/app/assets/javascripts/mui_app_rails/mui.number.js +93 -0
  47. data/app/assets/javascripts/mui_app_rails/mui.offcanvas.js +497 -0
  48. data/app/assets/javascripts/mui_app_rails/mui.pullrefresh.js +157 -0
  49. data/app/assets/javascripts/mui_app_rails/mui.target.js +58 -0
  50. data/app/assets/javascripts/mui_app_rails/mui.view.js +172 -0
  51. data/app/assets/javascripts/mui_app_rails/popovers.js +278 -0
  52. data/app/assets/javascripts/mui_app_rails/pullrefresh.5+.js +238 -0
  53. data/app/assets/javascripts/mui_app_rails/push.js +479 -0
  54. data/app/assets/javascripts/mui_app_rails/segmented-controllers.js +99 -0
  55. data/app/assets/javascripts/mui_app_rails/sliders.js +362 -0
  56. data/app/assets/javascripts/mui_app_rails/switches.js +165 -0
  57. data/app/assets/javascripts/mui_app_rails/tableviews.js +512 -0
  58. data/app/assets/javascripts/mui_app_rails.js +1 -0
  59. data/app/assets/stylesheets/mui_app_rails/badges.scss +88 -0
  60. data/app/assets/stylesheets/mui_app_rails/bars.scss +312 -0
  61. data/app/assets/stylesheets/mui_app_rails/base.scss +196 -0
  62. data/app/assets/stylesheets/mui_app_rails/buttons.scss +205 -0
  63. data/app/assets/stylesheets/mui_app_rails/cards.scss +62 -0
  64. data/app/assets/stylesheets/mui_app_rails/forms.scss +452 -0
  65. data/app/assets/stylesheets/mui_app_rails/fullscreen.scss +35 -0
  66. data/app/assets/stylesheets/mui_app_rails/grid.scss +75 -0
  67. data/app/assets/stylesheets/mui_app_rails/hack.scss +14 -0
  68. data/app/assets/stylesheets/mui_app_rails/icon.scss +170 -0
  69. data/app/assets/stylesheets/mui_app_rails/iscroll.scss +43 -0
  70. data/app/assets/stylesheets/mui_app_rails/loadings.scss +111 -0
  71. data/app/assets/stylesheets/mui_app_rails/mixins.scss +212 -0
  72. data/app/assets/stylesheets/mui_app_rails/modals.scss +34 -0
  73. data/app/assets/stylesheets/mui_app_rails/mui.scss +46 -0
  74. data/app/assets/stylesheets/mui_app_rails/normalize.scss +425 -0
  75. data/app/assets/stylesheets/mui_app_rails/number.scss +70 -0
  76. data/app/assets/stylesheets/mui_app_rails/off-canvas.scss +84 -0
  77. data/app/assets/stylesheets/mui_app_rails/os.scss +12 -0
  78. data/app/assets/stylesheets/mui_app_rails/pagination.scss +155 -0
  79. data/app/assets/stylesheets/mui_app_rails/popovers.scss +198 -0
  80. data/app/assets/stylesheets/mui_app_rails/pullrefreshs.scss +98 -0
  81. data/app/assets/stylesheets/mui_app_rails/push.scss +63 -0
  82. data/app/assets/stylesheets/mui_app_rails/scroll.scss +95 -0
  83. data/app/assets/stylesheets/mui_app_rails/segmented-controls.scss +150 -0
  84. data/app/assets/stylesheets/mui_app_rails/slider-cell.scss +20 -0
  85. data/app/assets/stylesheets/mui_app_rails/sliders.scss +133 -0
  86. data/app/assets/stylesheets/mui_app_rails/switches.scss +115 -0
  87. data/app/assets/stylesheets/mui_app_rails/table-views.scss +482 -0
  88. data/app/assets/stylesheets/mui_app_rails/toast.scss +16 -0
  89. data/app/assets/stylesheets/mui_app_rails/type.scss +23 -0
  90. data/app/assets/stylesheets/mui_app_rails/variables.scss +64 -0
  91. data/app/assets/stylesheets/mui_app_rails.css +3 -0
  92. data/lib/mui_app_rails/engine.rb +5 -0
  93. data/lib/mui_app_rails/version.rb +3 -0
  94. data/lib/mui_app_rails.rb +5 -0
  95. metadata +179 -0
@@ -0,0 +1,50 @@
1
+ /**
2
+ * mui fixed classList
3
+ * @param {type} document
4
+ * @returns {undefined}
5
+ */
6
+ (function(document) {
7
+ if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
8
+
9
+ Object.defineProperty(HTMLElement.prototype, 'classList', {
10
+ get: function() {
11
+ var self = this;
12
+ function update(fn) {
13
+ return function(value) {
14
+ var classes = self.className.split(/\s+/),
15
+ index = classes.indexOf(value);
16
+
17
+ fn(classes, index, value);
18
+ self.className = classes.join(" ");
19
+ };
20
+ }
21
+
22
+ var ret = {
23
+ add: update(function(classes, index, value) {
24
+ ~index || classes.push(value);
25
+ }),
26
+ remove: update(function(classes, index) {
27
+ ~index && classes.splice(index, 1);
28
+ }),
29
+ toggle: update(function(classes, index, value) {
30
+ ~index ? classes.splice(index, 1) : classes.push(value);
31
+ }),
32
+ contains: function(value) {
33
+ return !!~self.className.split(/\s+/).indexOf(value);
34
+ },
35
+ item: function(i) {
36
+ return self.className.split(/\s+/)[i] || null;
37
+ }
38
+ };
39
+
40
+ Object.defineProperty(ret, 'length', {
41
+ get: function() {
42
+ return self.className.split(/\s+/).length;
43
+ }
44
+ });
45
+
46
+ return ret;
47
+ }
48
+ });
49
+ }
50
+ })(document);
@@ -0,0 +1,64 @@
1
+ /**
2
+ * fastclick(only for radio,checkbox)
3
+ */
4
+ (function($, window, name) {
5
+ if (window.FastClick) {
6
+ return;
7
+ }
8
+
9
+ var handle = function(event, target) {
10
+ if (target.tagName === 'LABEL') {
11
+ if (target.parentNode) {
12
+ target = target.parentNode.querySelector('input');
13
+ }
14
+ }
15
+ if (target && (target.type === 'radio' || target.type === 'checkbox')) {
16
+ if (!target.disabled) { //disabled
17
+ return target;
18
+ }
19
+ }
20
+ return false;
21
+ };
22
+
23
+ $.registerTarget({
24
+ name: name,
25
+ index: 40,
26
+ handle: handle,
27
+ target: false
28
+ });
29
+ var dispatchEvent = function(event) {
30
+ var targetElement = $.targets.click;
31
+ if (targetElement) {
32
+ var clickEvent, touch;
33
+ // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect
34
+ if (document.activeElement && document.activeElement !== targetElement) {
35
+ document.activeElement.blur();
36
+ }
37
+ touch = event.detail.gesture.changedTouches[0];
38
+ // Synthesise a click event, with an extra attribute so it can be tracked
39
+ clickEvent = document.createEvent('MouseEvents');
40
+ clickEvent.initMouseEvent('click', true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
41
+ clickEvent.forwardedTouchEvent = true;
42
+ targetElement.dispatchEvent(clickEvent);
43
+ }
44
+ };
45
+ window.addEventListener('tap', dispatchEvent);
46
+ window.addEventListener('doubletap', dispatchEvent);
47
+ //捕获
48
+ window.addEventListener('click', function(event) {
49
+ if ($.targets.click) {
50
+ if (!event.forwardedTouchEvent) { //stop click
51
+ if (event.stopImmediatePropagation) {
52
+ event.stopImmediatePropagation();
53
+ } else {
54
+ // Part of the hack for browsers that don't support Event#stopImmediatePropagation
55
+ event.propagationStopped = true;
56
+ }
57
+ event.stopPropagation();
58
+ event.preventDefault();
59
+ return false;
60
+ }
61
+ }
62
+ }, true);
63
+
64
+ })(mui, window, 'click');
@@ -0,0 +1,40 @@
1
+ /**
2
+ * fixed trim
3
+ * @param {type} undefined
4
+ * @returns {undefined}
5
+ */
6
+ (function(undefined) {
7
+ if (String.prototype.trim === undefined) { // fix for iOS 3.2
8
+ String.prototype.trim = function() {
9
+ return this.replace(/^\s+|\s+$/g, '');
10
+ };
11
+ }
12
+ Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
13
+ obj['__proto__'] = proto;
14
+ return obj;
15
+ };
16
+
17
+ })();
18
+ /**
19
+ * fixed CustomEvent
20
+ */
21
+ (function() {
22
+ if (typeof window.CustomEvent === 'undefined') {
23
+ function CustomEvent(event, params) {
24
+ params = params || {
25
+ bubbles: false,
26
+ cancelable: false,
27
+ detail: undefined
28
+ };
29
+ var evt = document.createEvent('Events');
30
+ var bubbles = true;
31
+ for (var name in params) {
32
+ (name === 'bubbles') ? (bubbles = !!params[name]) : (evt[name] = params[name]);
33
+ }
34
+ evt.initEvent(event, bubbles, true);
35
+ return evt;
36
+ };
37
+ CustomEvent.prototype = window.Event.prototype;
38
+ window.CustomEvent = CustomEvent;
39
+ }
40
+ })();
@@ -0,0 +1,56 @@
1
+ (function($, document) {
2
+ $(function() {
3
+ if (!$.os.ios) {
4
+ return;
5
+ }
6
+ var CLASS_FOCUSIN = $.className('focusin');
7
+ var CLASS_BAR_TAB = $.className('bar-tab');
8
+ var CLASS_BAR_FOOTER = $.className('bar-footer');
9
+ var CLASS_BAR_FOOTER_SECONDARY = $.className('bar-footer-secondary');
10
+ var CLASS_BAR_FOOTER_SECONDARY_TAB = $.className('bar-footer-secondary-tab');
11
+ // var content = document.querySelector('.' + CLASS_CONTENT);
12
+ // if (content) {
13
+ // document.body.insertBefore(content, document.body.firstElementChild);
14
+ // }
15
+ document.addEventListener('focusin', function(e) {
16
+ if ($.os.plus) { //在父webview里边不fix
17
+ if (window.plus) {
18
+ if (plus.webview.currentWebview().children().length > 0) {
19
+ return;
20
+ }
21
+ }
22
+ }
23
+ var target = e.target;
24
+ if (target.tagName && target.tagName === 'INPUT' && target.type === 'text') {
25
+ if (target.disabled || target.readOnly) {
26
+ return;
27
+ }
28
+ document.body.classList.add(CLASS_FOCUSIN);
29
+ var isFooter = false;
30
+ for (; target && target !== document; target = target.parentNode) {
31
+ var classList = target.classList;
32
+ if (classList && classList.contains(CLASS_BAR_TAB) || classList.contains(CLASS_BAR_FOOTER) || classList.contains(CLASS_BAR_FOOTER_SECONDARY) || classList.contains(CLASS_BAR_FOOTER_SECONDARY_TAB)) {
33
+ isFooter = true;
34
+ break;
35
+ }
36
+ }
37
+ if (isFooter) {
38
+ var scrollTop = document.body.scrollHeight;
39
+ var scrollLeft = document.body.scrollLeft;
40
+ setTimeout(function() {
41
+ window.scrollTo(scrollLeft, scrollTop);
42
+ }, 20);
43
+ }
44
+ }
45
+ });
46
+ document.addEventListener('focusout', function(e) {
47
+ var classList = document.body.classList;
48
+ if (classList.contains(CLASS_FOCUSIN)) {
49
+ classList.remove(CLASS_FOCUSIN);
50
+ setTimeout(function() {
51
+ window.scrollTo(document.body.scrollLeft, document.body.scrollTop);
52
+ }, 20);
53
+ }
54
+ });
55
+ });
56
+ })(mui, document);
@@ -0,0 +1,48 @@
1
+ /**
2
+ * mui gesture drag[start|left|right|up|down|end]
3
+ * @param {type} $
4
+ * @param {type} name
5
+ * @returns {undefined}
6
+ */
7
+ (function($, name) {
8
+ var handle = function(event, touch) {
9
+ switch (event.type) {
10
+ case $.EVENT_MOVE:
11
+ if (touch.direction) { //drag
12
+ //修正direction
13
+ //默认锁定单向drag(后续可能需要额外配置支持)
14
+ if (touch.lockDirection && touch.startDirection) {
15
+ if (touch.startDirection && touch.startDirection !== touch.direction) {
16
+ if (touch.startDirection === 'up' || touch.startDirection === 'down') {
17
+ touch.direction = touch.deltaY < 0 ? 'up' : 'down';
18
+ } else {
19
+ touch.direction = touch.deltaX < 0 ? 'left' : 'right';
20
+ }
21
+ }
22
+ }
23
+ if (!touch.drag) {
24
+ touch.drag = true;
25
+ $.trigger(event.target, name + 'start', touch);
26
+ }
27
+ $.trigger(event.target, name, touch);
28
+ $.trigger(event.target, name + touch.direction, touch);
29
+ }
30
+ break;
31
+ case $.EVENT_END:
32
+ case $.EVENT_CANCEL:
33
+ if (touch.drag) {
34
+ $.trigger(event.target, name + 'end', touch);
35
+ }
36
+ break;
37
+ }
38
+ };
39
+ /**
40
+ * mui gesture drag
41
+ */
42
+ $.registerGesture({
43
+ name: name,
44
+ index: 20,
45
+ handle: handle,
46
+ options: {}
47
+ });
48
+ })(mui, 'drag');
@@ -0,0 +1,30 @@
1
+ /**
2
+ * mui gesture flick[left|right|up|down]
3
+ * @param {type} $
4
+ * @param {type} name
5
+ * @returns {undefined}
6
+ */
7
+ (function($, name) {
8
+ var handle = function(event, touch) {
9
+ if (event.type === $.EVENT_END || event.type === $.EVENT_CANCEL) {
10
+ var options = this.options;
11
+ if (touch.direction && options.flickMaxTime > touch.flickTime && touch.distance > options.flickMinDistince) {
12
+ touch.flick = true;
13
+ $.trigger(event.target, name, touch);
14
+ $.trigger(event.target, name + touch.direction, touch);
15
+ }
16
+ }
17
+ };
18
+ /**
19
+ * mui gesture flick
20
+ */
21
+ $.registerGesture({
22
+ name: name,
23
+ index: 5,
24
+ handle: handle,
25
+ options: {
26
+ flickMaxTime: 200,
27
+ flickMinDistince: 10
28
+ }
29
+ });
30
+ })(mui, 'flick');
@@ -0,0 +1,41 @@
1
+ /**
2
+ * mui gesture hold
3
+ * @param {type} $
4
+ * @param {type} name
5
+ * @returns {undefined}
6
+ */
7
+ (function($, name) {
8
+ var timer;
9
+ var handle = function(event, touch) {
10
+ var options = this.options;
11
+ switch (event.type) {
12
+ case $.EVENT_START:
13
+ clearTimeout(timer);
14
+ timer = setTimeout(function() {
15
+ touch.hold = true;
16
+ $.trigger(event.target, name, touch);
17
+ }, options.holdTimeout);
18
+ break;
19
+ case $.EVENT_MOVE:
20
+ break;
21
+ case $.EVENT_END:
22
+ case $.EVENT_CANCEL:
23
+ clearTimeout(timer);
24
+ if ($.options.gestureConfig.hold && touch.hold) {
25
+ $.trigger(event.target, 'release', touch);
26
+ }
27
+ break;
28
+ }
29
+ };
30
+ /**
31
+ * mui gesture hold
32
+ */
33
+ $.registerGesture({
34
+ name: name,
35
+ index: 10,
36
+ handle: handle,
37
+ options: {
38
+ holdTimeout: 0
39
+ }
40
+ });
41
+ })(mui, 'hold');
@@ -0,0 +1,207 @@
1
+ /**
2
+ * mui gestures
3
+ * @param {type} $
4
+ * @param {type} window
5
+ * @returns {undefined}
6
+ */
7
+ (function($, window) {
8
+ $.EVENT_START = 'touchstart';
9
+ $.EVENT_MOVE = 'touchmove';
10
+ $.EVENT_END = 'touchend';
11
+ $.EVENT_CANCEL = 'touchcancel';
12
+ $.EVENT_CLICK = 'click';
13
+ /**
14
+ * Gesture preventDefault
15
+ * @param {type} e
16
+ * @returns {undefined}
17
+ */
18
+ $.preventDefault = function(e) {
19
+ e.preventDefault();
20
+ };
21
+ /**
22
+ * Gesture stopPropagation
23
+ * @param {type} e
24
+ * @returns {undefined}
25
+ */
26
+ $.stopPropagation = function(e) {
27
+ e.stopPropagation();
28
+ };
29
+
30
+ /**
31
+ * register gesture
32
+ * @param {type} gesture
33
+ * @returns {$.gestures}
34
+ */
35
+ $.registerGesture = function(gesture) {
36
+ return $.registerHandler('gestures', gesture);
37
+
38
+ };
39
+ /**
40
+ * distance
41
+ * @param {type} p1
42
+ * @param {type} p2
43
+ * @returns {Number}
44
+ */
45
+ var getDistance = function(p1, p2) {
46
+ var x = p2.x - p1.x;
47
+ var y = p2.y - p1.y;
48
+ return Math.sqrt((x * x) + (y * y));
49
+ };
50
+ /**
51
+ * angle
52
+ * @param {type} p1
53
+ * @param {type} p2
54
+ * @returns {Number}
55
+ */
56
+ var getAngle = function(p1, p2) {
57
+ return Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
58
+ };
59
+ /**
60
+ * direction
61
+ * @param {type} angle
62
+ * @returns {unresolved}
63
+ */
64
+ var getDirectionByAngle = function(angle) {
65
+ if (angle < -45 && angle > -135) {
66
+ return 'up';
67
+ } else if (angle >= 45 && angle < 135) {
68
+ return 'down';
69
+ } else if (angle >= 135 || angle <= -135) {
70
+ return 'left';
71
+ } else if (angle >= -45 && angle <= 45) {
72
+ return 'right';
73
+ }
74
+ return null;
75
+ };
76
+ /**
77
+ * detect gestures
78
+ * @param {type} event
79
+ * @param {type} touch
80
+ * @returns {undefined}
81
+ */
82
+ var detect = function(event, touch) {
83
+ if ($.gestures.stoped) {
84
+ return;
85
+ }
86
+ $.each($.gestures, function(index, gesture) {
87
+ if (!$.gestures.stoped) {
88
+ if ($.options.gestureConfig[gesture.name] !== false) {
89
+ gesture.handle(event, touch);
90
+ }
91
+ }
92
+ });
93
+ };
94
+ var detectTouchStart = function(event) {
95
+ $.gestures.stoped = false;
96
+ var now = $.now();
97
+ var point = event.touches ? event.touches[0] : event;
98
+ $.gestures.touch = {
99
+ target: event.target,
100
+ lastTarget: ($.gestures.touch && $.gestures.touch.lastTarget ? $.gestures.touch.lastTarget : null),
101
+ startTime: now,
102
+ touchTime: 0,
103
+ flickStartTime: now,
104
+ lastTapTime: ($.gestures.touch && $.gestures.touch.lastTapTime ? $.gestures.touch.lastTapTime : 0),
105
+ start: {
106
+ x: point.pageX,
107
+ y: point.pageY
108
+ },
109
+ flickStart: {
110
+ x: point.pageX,
111
+ y: point.pageY
112
+ },
113
+ flickDistanceX: 0,
114
+ flickDistanceY: 0,
115
+ move: {
116
+ x: 0,
117
+ y: 0
118
+ },
119
+ deltaX: 0,
120
+ deltaY: 0,
121
+ lastDeltaX: 0,
122
+ lastDeltaY: 0,
123
+ angle: '',
124
+ direction: '',
125
+ lockDirection: false,
126
+ startDirection: '',
127
+ distance: 0,
128
+ drag: false,
129
+ swipe: false,
130
+ hold: false,
131
+ gesture: event
132
+ };
133
+
134
+ detect(event, $.gestures.touch);
135
+ };
136
+ var detectTouchMove = function(event) {
137
+ if ($.gestures.stoped) {
138
+ return;
139
+ }
140
+ var touch = $.gestures.touch;
141
+ if (event.target != touch.target) {
142
+ return;
143
+ }
144
+ var now = $.now();
145
+ var point = event.touches ? event.touches[0] : event;
146
+ touch.touchTime = now - touch.startTime;
147
+ touch.move = {
148
+ x: point.pageX,
149
+ y: point.pageY
150
+ };
151
+ if (now - touch.flickStartTime > 300) {
152
+ touch.flickStartTime = now;
153
+ touch.flickStart = touch.move;
154
+ }
155
+ touch.distance = getDistance(touch.start, touch.move);
156
+ touch.angle = getAngle(touch.start, touch.move);
157
+ touch.direction = getDirectionByAngle(touch.angle);
158
+ touch.lastDeltaX = touch.deltaX;
159
+ touch.lastDeltaY = touch.deltaY;
160
+ touch.deltaX = touch.move.x - touch.start.x;
161
+ touch.deltaY = touch.move.y - touch.start.y;
162
+ touch.gesture = event;
163
+
164
+ detect(event, touch);
165
+ };
166
+ var detectTouchEnd = function(event) {
167
+ if ($.gestures.stoped) {
168
+ return;
169
+ }
170
+ var touch = $.gestures.touch;
171
+ if (event.target != touch.target) {
172
+ return;
173
+ }
174
+ var now = $.now();
175
+ touch.touchTime = now - touch.startTime;
176
+ touch.flickTime = now - touch.flickStartTime;
177
+ touch.flickDistanceX = touch.move.x - touch.flickStart.x;
178
+ touch.flickDistanceY = touch.move.y - touch.flickStart.y;
179
+ touch.gesture = event;
180
+
181
+ detect(event, touch);
182
+ };
183
+
184
+ window.addEventListener($.EVENT_START, detectTouchStart);
185
+ window.addEventListener($.EVENT_MOVE, detectTouchMove);
186
+ window.addEventListener($.EVENT_END, detectTouchEnd);
187
+ window.addEventListener($.EVENT_CANCEL, detectTouchEnd);
188
+ //fixed hashchange(android)
189
+ window.addEventListener($.EVENT_CLICK, function(e) {
190
+ //TODO 应该判断当前target是不是在targets.popover内部,而不是非要相等
191
+ if (($.targets.popover && e.target === $.targets.popover) || ($.targets.tab) || $.targets.offcanvas || $.targets.modal) {
192
+ e.preventDefault();
193
+ }
194
+ }, true);
195
+
196
+
197
+ //增加原生滚动识别
198
+ $.isScrolling = false;
199
+ var scrollingTimeout = null;
200
+ window.addEventListener('scroll', function() {
201
+ $.isScrolling = true;
202
+ scrollingTimeout && clearTimeout(scrollingTimeout);
203
+ scrollingTimeout = setTimeout(function() {
204
+ $.isScrolling = false;
205
+ }, 250);
206
+ });
207
+ })(mui, window);
@@ -0,0 +1,43 @@
1
+ /**
2
+ * mui gesture longtap
3
+ * @param {type} $
4
+ * @param {type} name
5
+ * @returns {undefined}
6
+ */
7
+ (function($, name) {
8
+ var timer;
9
+ var handle = function(event, touch) {
10
+ var options = this.options;
11
+ switch (event.type) {
12
+ case $.EVENT_START:
13
+ clearTimeout(timer);
14
+ timer = setTimeout(function() {
15
+ if (!touch.drag) {
16
+ $.trigger(event.target, name, touch);
17
+ }
18
+ }, options.holdTimeout);
19
+ break;
20
+ case $.EVENT_MOVE:
21
+ if (touch.distance > options.holdThreshold) {
22
+ clearTimeout(timer);
23
+ }
24
+ break;
25
+ case $.EVENT_END:
26
+ case $.EVENT_CANCEL:
27
+ clearTimeout(timer);
28
+ break;
29
+ }
30
+ };
31
+ /**
32
+ * mui gesture longtap
33
+ */
34
+ $.registerGesture({
35
+ name: name,
36
+ index: 10,
37
+ handle: handle,
38
+ options: {
39
+ holdTimeout: 500,
40
+ holdThreshold: 2
41
+ }
42
+ });
43
+ })(mui, 'longtap');
@@ -0,0 +1,29 @@
1
+ /**
2
+ * mui gesture swipe[left|right|up|down]
3
+ * @param {type} $
4
+ * @param {type} name
5
+ * @returns {undefined}
6
+ */
7
+ (function($, name) {
8
+ var handle = function(event, touch) {
9
+ if (event.type === $.EVENT_END || event.type === $.EVENT_CANCEL) {
10
+ var options = this.options;
11
+ if (touch.direction && options.swipeMaxTime > touch.touchTime && touch.distance > options.swipeMinDistince) {
12
+ touch.swipe = true;
13
+ $.trigger(event.target, name + touch.direction, touch);
14
+ }
15
+ }
16
+ };
17
+ /**
18
+ * mui gesture swipe
19
+ */
20
+ $.registerGesture({
21
+ name: name,
22
+ index: 10,
23
+ handle: handle,
24
+ options: {
25
+ swipeMaxTime: 300,
26
+ swipeMinDistince: 18
27
+ }
28
+ });
29
+ })(mui, 'swipe');
@@ -0,0 +1,40 @@
1
+ /**
2
+ * mui gesture tap and doubleTap
3
+ * @param {type} $
4
+ * @param {type} name
5
+ * @returns {undefined}
6
+ */
7
+ (function($, name) {
8
+ var handle = function(event, touch) {
9
+ //if (event.type === $.EVENT_END || event.type === $.EVENT_CANCEL) {
10
+ if (event.type === $.EVENT_END) { //ignore touchcancel
11
+ var options = this.options;
12
+ if (touch.distance < options.tapMaxDistance && touch.touchTime < options.tapMaxTime) {
13
+ if ($.options.gestureConfig.doubletap && touch.lastTarget && (touch.lastTarget === event.target)) { //same target
14
+ if (touch.lastTapTime && (touch.startTime - touch.lastTapTime) < options.tapMaxInterval) {
15
+ $.trigger(event.target, 'doubletap', touch);
16
+ touch.lastTapTime = $.now();
17
+ touch.lastTarget = event.target;
18
+ return;
19
+ }
20
+ }
21
+ $.trigger(event.target, name, touch);
22
+ touch.lastTapTime = $.now();
23
+ touch.lastTarget = event.target;
24
+ }
25
+ }
26
+ };
27
+ /**
28
+ * mui gesture tap
29
+ */
30
+ $.registerGesture({
31
+ name: name,
32
+ index: 30,
33
+ handle: handle,
34
+ options: {
35
+ tapMaxInterval: 300,
36
+ tapMaxDistance: 5,
37
+ tapMaxTime: 250
38
+ }
39
+ });
40
+ })(mui, 'tap');