mui_app_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +34 -0
- data/app/assets/fonts/mui.ttf +0 -0
- data/app/assets/javascripts/mui_app_rails/actions.js +26 -0
- data/app/assets/javascripts/mui_app_rails/ajax.plugin.js +3 -0
- data/app/assets/javascripts/mui_app_rails/input.plugin.js +232 -0
- data/app/assets/javascripts/mui_app_rails/modals.js +37 -0
- data/app/assets/javascripts/mui_app_rails/mui.active.js +30 -0
- data/app/assets/javascripts/mui_app_rails/mui.ajax.5+.js +27 -0
- data/app/assets/javascripts/mui_app_rails/mui.ajax.js +277 -0
- data/app/assets/javascripts/mui_app_rails/mui.animation.js +39 -0
- data/app/assets/javascripts/mui_app_rails/mui.animationframe.js +72 -0
- data/app/assets/javascripts/mui_app_rails/mui.back.5+.js +108 -0
- data/app/assets/javascripts/mui_app_rails/mui.back.js +56 -0
- data/app/assets/javascripts/mui_app_rails/mui.class.js +40 -0
- data/app/assets/javascripts/mui_app_rails/mui.class.scroll.js +894 -0
- data/app/assets/javascripts/mui_app_rails/mui.class.scroll.pullrefresh.js +150 -0
- data/app/assets/javascripts/mui_app_rails/mui.class.scroll.slider.js +361 -0
- data/app/assets/javascripts/mui_app_rails/mui.class.scroll.slider.old.js +332 -0
- data/app/assets/javascripts/mui_app_rails/mui.detect.5+.js +18 -0
- data/app/assets/javascripts/mui_app_rails/mui.detect.js +50 -0
- data/app/assets/javascripts/mui_app_rails/mui.dialog.alert.js +27 -0
- data/app/assets/javascripts/mui_app_rails/mui.dialog.confirm.js +27 -0
- data/app/assets/javascripts/mui_app_rails/mui.dialog.prompt.js +33 -0
- data/app/assets/javascripts/mui_app_rails/mui.dialog.toast.js +20 -0
- data/app/assets/javascripts/mui_app_rails/mui.event.js +160 -0
- data/app/assets/javascripts/mui_app_rails/mui.fixed.animation.js +22 -0
- data/app/assets/javascripts/mui_app_rails/mui.fixed.classlist.js +50 -0
- data/app/assets/javascripts/mui_app_rails/mui.fixed.fastclick.js +64 -0
- data/app/assets/javascripts/mui_app_rails/mui.fixed.js +40 -0
- data/app/assets/javascripts/mui_app_rails/mui.fixed.keyboard.js +56 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.drag.js +48 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.flick.js +30 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.hold.js +41 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.js +207 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.longtap.js +43 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.swipe.js +29 -0
- data/app/assets/javascripts/mui_app_rails/mui.gestures.tap.js +40 -0
- data/app/assets/javascripts/mui_app_rails/mui.init.5+.js +441 -0
- data/app/assets/javascripts/mui_app_rails/mui.init.js +100 -0
- data/app/assets/javascripts/mui_app_rails/mui.init.pullrefresh.js +57 -0
- data/app/assets/javascripts/mui_app_rails/mui.js +396 -0
- data/app/assets/javascripts/mui_app_rails/mui.jsonp.js +108 -0
- data/app/assets/javascripts/mui_app_rails/mui.layout.js +22 -0
- data/app/assets/javascripts/mui_app_rails/mui.namespace.js +35 -0
- data/app/assets/javascripts/mui_app_rails/mui.number.js +93 -0
- data/app/assets/javascripts/mui_app_rails/mui.offcanvas.js +497 -0
- data/app/assets/javascripts/mui_app_rails/mui.pullrefresh.js +157 -0
- data/app/assets/javascripts/mui_app_rails/mui.target.js +58 -0
- data/app/assets/javascripts/mui_app_rails/mui.view.js +172 -0
- data/app/assets/javascripts/mui_app_rails/popovers.js +278 -0
- data/app/assets/javascripts/mui_app_rails/pullrefresh.5+.js +238 -0
- data/app/assets/javascripts/mui_app_rails/push.js +479 -0
- data/app/assets/javascripts/mui_app_rails/segmented-controllers.js +99 -0
- data/app/assets/javascripts/mui_app_rails/sliders.js +362 -0
- data/app/assets/javascripts/mui_app_rails/switches.js +165 -0
- data/app/assets/javascripts/mui_app_rails/tableviews.js +512 -0
- data/app/assets/javascripts/mui_app_rails.js +1 -0
- data/app/assets/stylesheets/mui_app_rails/badges.scss +88 -0
- data/app/assets/stylesheets/mui_app_rails/bars.scss +312 -0
- data/app/assets/stylesheets/mui_app_rails/base.scss +196 -0
- data/app/assets/stylesheets/mui_app_rails/buttons.scss +205 -0
- data/app/assets/stylesheets/mui_app_rails/cards.scss +62 -0
- data/app/assets/stylesheets/mui_app_rails/forms.scss +452 -0
- data/app/assets/stylesheets/mui_app_rails/fullscreen.scss +35 -0
- data/app/assets/stylesheets/mui_app_rails/grid.scss +75 -0
- data/app/assets/stylesheets/mui_app_rails/hack.scss +14 -0
- data/app/assets/stylesheets/mui_app_rails/icon.scss +170 -0
- data/app/assets/stylesheets/mui_app_rails/iscroll.scss +43 -0
- data/app/assets/stylesheets/mui_app_rails/loadings.scss +111 -0
- data/app/assets/stylesheets/mui_app_rails/mixins.scss +212 -0
- data/app/assets/stylesheets/mui_app_rails/modals.scss +34 -0
- data/app/assets/stylesheets/mui_app_rails/mui.scss +46 -0
- data/app/assets/stylesheets/mui_app_rails/normalize.scss +425 -0
- data/app/assets/stylesheets/mui_app_rails/number.scss +70 -0
- data/app/assets/stylesheets/mui_app_rails/off-canvas.scss +84 -0
- data/app/assets/stylesheets/mui_app_rails/os.scss +12 -0
- data/app/assets/stylesheets/mui_app_rails/pagination.scss +155 -0
- data/app/assets/stylesheets/mui_app_rails/popovers.scss +198 -0
- data/app/assets/stylesheets/mui_app_rails/pullrefreshs.scss +98 -0
- data/app/assets/stylesheets/mui_app_rails/push.scss +63 -0
- data/app/assets/stylesheets/mui_app_rails/scroll.scss +95 -0
- data/app/assets/stylesheets/mui_app_rails/segmented-controls.scss +150 -0
- data/app/assets/stylesheets/mui_app_rails/slider-cell.scss +20 -0
- data/app/assets/stylesheets/mui_app_rails/sliders.scss +133 -0
- data/app/assets/stylesheets/mui_app_rails/switches.scss +115 -0
- data/app/assets/stylesheets/mui_app_rails/table-views.scss +482 -0
- data/app/assets/stylesheets/mui_app_rails/toast.scss +16 -0
- data/app/assets/stylesheets/mui_app_rails/type.scss +23 -0
- data/app/assets/stylesheets/mui_app_rails/variables.scss +64 -0
- data/app/assets/stylesheets/mui_app_rails.css +3 -0
- data/lib/mui_app_rails/engine.rb +5 -0
- data/lib/mui_app_rails/version.rb +3 -0
- data/lib/mui_app_rails.rb +5 -0
- metadata +179 -0
@@ -0,0 +1,497 @@
|
|
1
|
+
/**
|
2
|
+
* off-canvas
|
3
|
+
* @param {type} $
|
4
|
+
* @param {type} window
|
5
|
+
* @param {type} document
|
6
|
+
* @param {type} action
|
7
|
+
* @returns {undefined}
|
8
|
+
*/
|
9
|
+
(function($, window, document, name) {
|
10
|
+
var CLASS_OFF_CANVAS_LEFT = $.className('off-canvas-left');
|
11
|
+
var CLASS_OFF_CANVAS_RIGHT = $.className('off-canvas-right');
|
12
|
+
var CLASS_ACTION_BACKDEOP = $.className('off-canvas-backdrop');
|
13
|
+
var CLASS_OFF_CANVAS_WRAP = $.className('off-canvas-wrap');
|
14
|
+
|
15
|
+
var CLASS_SLIDE_IN = $.className('slide-in');
|
16
|
+
var CLASS_ACTIVE = $.className('active');
|
17
|
+
|
18
|
+
|
19
|
+
var CLASS_TRANSITIONING = $.className('transitioning');
|
20
|
+
|
21
|
+
var SELECTOR_INNER_WRAP = $.classSelector('.inner-wrap');
|
22
|
+
|
23
|
+
|
24
|
+
var OffCanvas = $.Class.extend({
|
25
|
+
init: function(element, options) {
|
26
|
+
this.wrapper = this.element = element;
|
27
|
+
this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
|
28
|
+
this.classList = this.wrapper.classList;
|
29
|
+
if (this.scroller) {
|
30
|
+
this.options = $.extend(true, {
|
31
|
+
dragThresholdX: 10
|
32
|
+
}, options);
|
33
|
+
document.body.classList.add($.className('fullscreen')); //fullscreen
|
34
|
+
this.refresh();
|
35
|
+
this.initEvent();
|
36
|
+
}
|
37
|
+
},
|
38
|
+
refresh: function(offCanvas) {
|
39
|
+
// offCanvas && !offCanvas.classList.contains(CLASS_ACTIVE) && this.classList.remove(CLASS_ACTIVE);
|
40
|
+
this.slideIn = this.classList.contains(CLASS_SLIDE_IN);
|
41
|
+
this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
|
42
|
+
// !offCanvas && this.scroller.classList.remove(CLASS_TRANSITIONING);
|
43
|
+
// !offCanvas && this.scroller.setAttribute('style', '');
|
44
|
+
this.offCanvasLefts = this.wrapper.querySelectorAll('.' + CLASS_OFF_CANVAS_LEFT);
|
45
|
+
this.offCanvasRights = this.wrapper.querySelectorAll('.' + CLASS_OFF_CANVAS_RIGHT);
|
46
|
+
if (offCanvas) {
|
47
|
+
if (offCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT)) {
|
48
|
+
this.offCanvasLeft = offCanvas;
|
49
|
+
} else if (offCanvas.classList.contains(CLASS_OFF_CANVAS_RIGHT)) {
|
50
|
+
this.offCanvasRight = offCanvas;
|
51
|
+
}
|
52
|
+
} else {
|
53
|
+
this.offCanvasRight = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT);
|
54
|
+
this.offCanvasLeft = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT);
|
55
|
+
}
|
56
|
+
this.offCanvasRightWidth = this.offCanvasLeftWidth = 0;
|
57
|
+
this.offCanvasLeftSlideIn = this.offCanvasRightSlideIn = false;
|
58
|
+
if (this.offCanvasRight) {
|
59
|
+
this.offCanvasRightWidth = this.offCanvasRight.offsetWidth;
|
60
|
+
this.offCanvasRightSlideIn = this.slideIn && (this.offCanvasRight.parentNode === this.wrapper);
|
61
|
+
// this.offCanvasRight.classList.remove(CLASS_TRANSITIONING);
|
62
|
+
// this.offCanvasRight.classList.remove(CLASS_ACTIVE);
|
63
|
+
// this.offCanvasRight.setAttribute('style', '');
|
64
|
+
}
|
65
|
+
if (this.offCanvasLeft) {
|
66
|
+
this.offCanvasLeftWidth = this.offCanvasLeft.offsetWidth;
|
67
|
+
this.offCanvasLeftSlideIn = this.slideIn && (this.offCanvasLeft.parentNode === this.wrapper);
|
68
|
+
// this.offCanvasLeft.classList.remove(CLASS_TRANSITIONING);
|
69
|
+
// this.offCanvasLeft.classList.remove(CLASS_ACTIVE);
|
70
|
+
// this.offCanvasLeft.setAttribute('style', '');
|
71
|
+
}
|
72
|
+
this.backdrop = this.scroller.querySelector('.' + CLASS_ACTION_BACKDEOP);
|
73
|
+
|
74
|
+
this.options.dragThresholdX = this.options.dragThresholdX || 10;
|
75
|
+
|
76
|
+
this.visible = false;
|
77
|
+
this.startX = null;
|
78
|
+
this.lastX = null;
|
79
|
+
this.offsetX = null;
|
80
|
+
this.lastTranslateX = null;
|
81
|
+
},
|
82
|
+
handleEvent: function(e) {
|
83
|
+
switch (e.type) {
|
84
|
+
case 'touchstart':
|
85
|
+
var tagName = e.target && e.target.tagName;
|
86
|
+
if (tagName !== 'INPUT' && tagName !== 'TEXTAREA' && tagName !== 'SELECT') {
|
87
|
+
e.preventDefault();
|
88
|
+
}
|
89
|
+
break;
|
90
|
+
case 'webkitTransitionEnd': //有个bug需要处理,需要考虑假设没有触发webkitTransitionEnd的情况
|
91
|
+
if (e.target === this.scroller) {
|
92
|
+
this._dispatchEvent();
|
93
|
+
}
|
94
|
+
break;
|
95
|
+
case 'drag':
|
96
|
+
var detail = e.detail;
|
97
|
+
if (!this.startX) {
|
98
|
+
this.startX = detail.move.x;
|
99
|
+
this.lastX = this.startX;
|
100
|
+
} else {
|
101
|
+
this.lastX = detail.move.x;
|
102
|
+
}
|
103
|
+
if (!this.isDragging && Math.abs(this.lastX - this.startX) > this.options.dragThresholdX && (detail.direction === 'left' || (detail.direction === 'right'))) {
|
104
|
+
if (this.slideIn) {
|
105
|
+
if (this.classList.contains(CLASS_ACTIVE)) {
|
106
|
+
this.scroller = this.offCanvasRight && this.offCanvasRight.classList.contains(CLASS_ACTIVE) ? this.offCanvasRight : this.offCanvasLeft;
|
107
|
+
} else {
|
108
|
+
if (detail.direction === 'left' && this.offCanvasRight) {
|
109
|
+
this.scroller = this.offCanvasRight;
|
110
|
+
} else if (detail.direction === 'right' && this.offCanvasLeft) {
|
111
|
+
this.scroller = this.offCanvasLeft;
|
112
|
+
} else {
|
113
|
+
this.scroller = null;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
if (this.scroller) {
|
118
|
+
this.startX = this.lastX;
|
119
|
+
this.isDragging = true;
|
120
|
+
|
121
|
+
$.gestures.touch.lockDirection = true; //锁定方向
|
122
|
+
$.gestures.touch.startDirection = detail.direction;
|
123
|
+
|
124
|
+
this.scroller.classList.remove(CLASS_TRANSITIONING);
|
125
|
+
this.offsetX = this.getTranslateX();
|
126
|
+
this._initOffCanvasVisible();
|
127
|
+
}
|
128
|
+
}
|
129
|
+
if (this.isDragging) {
|
130
|
+
this.updateTranslate(this.offsetX + (this.lastX - this.startX));
|
131
|
+
detail.gesture.preventDefault();
|
132
|
+
e.stopPropagation();
|
133
|
+
}
|
134
|
+
break;
|
135
|
+
case 'dragend':
|
136
|
+
if (this.isDragging) {
|
137
|
+
var detail = e.detail;
|
138
|
+
var direction = detail.direction;
|
139
|
+
this.isDragging = false;
|
140
|
+
this.scroller.classList.add(CLASS_TRANSITIONING);
|
141
|
+
var ratio = 0;
|
142
|
+
var x = this.getTranslateX();
|
143
|
+
|
144
|
+
if (!this.slideIn) {
|
145
|
+
if (x >= 0) {
|
146
|
+
ratio = (this.offCanvasLeftWidth && (x / this.offCanvasLeftWidth)) || 0;
|
147
|
+
} else {
|
148
|
+
ratio = (this.offCanvasRightWidth && (x / this.offCanvasRightWidth)) || 0;
|
149
|
+
}
|
150
|
+
if (ratio === 0) {
|
151
|
+
this.openPercentage(0);
|
152
|
+
this._dispatchEvent(); //此处不触发webkitTransitionEnd,所以手动dispatch
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
if (ratio > 0 && ratio < 0.5 && direction === 'right') {
|
156
|
+
this.openPercentage(0);
|
157
|
+
} else if (ratio > 0.5 && direction === 'left') {
|
158
|
+
this.openPercentage(100);
|
159
|
+
} else if (ratio < 0 && ratio > -0.5 && direction === 'left') {
|
160
|
+
this.openPercentage(0);
|
161
|
+
} else if (direction === 'right' && ratio < 0 && ratio > -0.5) {
|
162
|
+
this.openPercentage(0);
|
163
|
+
} else if (ratio < 0.5 && direction === 'right') {
|
164
|
+
this.openPercentage(-100);
|
165
|
+
} else if (direction === 'right' && ratio >= 0 && (ratio >= 0.5 || detail.flick)) {
|
166
|
+
this.openPercentage(100);
|
167
|
+
} else if (direction === 'left' && ratio <= 0 && (ratio <= -0.5 || detail.flick)) {
|
168
|
+
this.openPercentage(-100);
|
169
|
+
} else {
|
170
|
+
this.openPercentage(0);
|
171
|
+
}
|
172
|
+
if (ratio === 1 || ratio === -1) { //此处不触发webkitTransitionEnd,所以手动dispatch
|
173
|
+
this._dispatchEvent();
|
174
|
+
}
|
175
|
+
} else {
|
176
|
+
if (x >= 0) {
|
177
|
+
ratio = (this.offCanvasRightWidth && (x / this.offCanvasRightWidth)) || 0;
|
178
|
+
} else {
|
179
|
+
ratio = (this.offCanvasLeftWidth && (x / this.offCanvasLeftWidth)) || 0;
|
180
|
+
}
|
181
|
+
if (ratio >= 0.5 && direction === 'left') {
|
182
|
+
this.openPercentage(0);
|
183
|
+
} else if (ratio > 0 && ratio <= 0.5 && direction === 'left') {
|
184
|
+
this.openPercentage(-100);
|
185
|
+
} else if (ratio >= 0.5 && direction === 'right') {
|
186
|
+
this.openPercentage(0);
|
187
|
+
} else if (ratio >= -0.5 && ratio < 0 && direction === 'left') {
|
188
|
+
this.openPercentage(100);
|
189
|
+
} else if (ratio > 0 && ratio <= 0.5 && direction === 'right') {
|
190
|
+
this.openPercentage(-100);
|
191
|
+
} else if (ratio <= -0.5 && direction === 'right') {
|
192
|
+
this.openPercentage(0);
|
193
|
+
} else if (ratio >= -0.5 && direction === 'right') {
|
194
|
+
this.openPercentage(100);
|
195
|
+
} else if (ratio <= -0.5 && direction === 'left') {
|
196
|
+
this.openPercentage(0);
|
197
|
+
} else if (ratio >= -0.5 && direction === 'left') {
|
198
|
+
this.openPercentage(-100);
|
199
|
+
} else {
|
200
|
+
this.openPercentage(0);
|
201
|
+
}
|
202
|
+
if (ratio === 1 || ratio === -1 || ratio === 0) {
|
203
|
+
this._dispatchEvent();
|
204
|
+
return;
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
}
|
209
|
+
break;
|
210
|
+
}
|
211
|
+
},
|
212
|
+
_dispatchEvent: function() {
|
213
|
+
if (this.classList.contains(CLASS_ACTIVE)) {
|
214
|
+
$.trigger(this.wrapper, 'shown', this);
|
215
|
+
} else {
|
216
|
+
$.trigger(this.wrapper, 'hidden', this);
|
217
|
+
}
|
218
|
+
},
|
219
|
+
_initOffCanvasVisible: function() {
|
220
|
+
if (!this.visible) {
|
221
|
+
this.visible = true;
|
222
|
+
if (this.offCanvasLeft) {
|
223
|
+
this.offCanvasLeft.style.visibility = 'visible';
|
224
|
+
}
|
225
|
+
if (this.offCanvasRight) {
|
226
|
+
this.offCanvasRight.style.visibility = 'visible';
|
227
|
+
}
|
228
|
+
}
|
229
|
+
},
|
230
|
+
initEvent: function() {
|
231
|
+
var self = this;
|
232
|
+
if (self.backdrop) {
|
233
|
+
self.backdrop.addEventListener('tap', function(e) {
|
234
|
+
self.close();
|
235
|
+
e.detail.gesture.preventDefault();
|
236
|
+
});
|
237
|
+
}
|
238
|
+
if (this.classList.contains($.className('draggable'))) {
|
239
|
+
this.wrapper.addEventListener('touchstart', this); //临时处理
|
240
|
+
this.wrapper.addEventListener('drag', this);
|
241
|
+
this.wrapper.addEventListener('dragend', this);
|
242
|
+
}
|
243
|
+
this.wrapper.addEventListener('webkitTransitionEnd', this);
|
244
|
+
},
|
245
|
+
openPercentage: function(percentage) {
|
246
|
+
var p = percentage / 100;
|
247
|
+
if (!this.slideIn) {
|
248
|
+
if (this.offCanvasLeft && percentage >= 0) {
|
249
|
+
this.updateTranslate(this.offCanvasLeftWidth * p);
|
250
|
+
this.offCanvasLeft.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
|
251
|
+
} else if (this.offCanvasRight && percentage <= 0) {
|
252
|
+
this.updateTranslate(this.offCanvasRightWidth * p);
|
253
|
+
this.offCanvasRight.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
|
254
|
+
}
|
255
|
+
this.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
|
256
|
+
} else {
|
257
|
+
if (this.offCanvasLeft && percentage >= 0) {
|
258
|
+
p = p === 0 ? -1 : 0;
|
259
|
+
this.updateTranslate(this.offCanvasLeftWidth * p);
|
260
|
+
this.offCanvasLeft.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
|
261
|
+
} else if (this.offCanvasRight && percentage <= 0) {
|
262
|
+
p = p === 0 ? 1 : 0;
|
263
|
+
this.updateTranslate(this.offCanvasRightWidth * p);
|
264
|
+
this.offCanvasRight.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
|
265
|
+
}
|
266
|
+
this.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
|
267
|
+
}
|
268
|
+
|
269
|
+
},
|
270
|
+
updateTranslate: function(x) {
|
271
|
+
if (x !== this.lastTranslateX) {
|
272
|
+
if (!this.slideIn) {
|
273
|
+
if ((!this.offCanvasLeft && x > 0) || (!this.offCanvasRight && x < 0)) {
|
274
|
+
this.setTranslateX(0);
|
275
|
+
return;
|
276
|
+
}
|
277
|
+
if (this.leftShowing && x > this.offCanvasLeftWidth) {
|
278
|
+
this.setTranslateX(this.offCanvasLeftWidth);
|
279
|
+
return;
|
280
|
+
}
|
281
|
+
if (this.rightShowing && x < -this.offCanvasRightWidth) {
|
282
|
+
this.setTranslateX(-this.offCanvasRightWidth);
|
283
|
+
return;
|
284
|
+
}
|
285
|
+
this.setTranslateX(x);
|
286
|
+
if (x >= 0) {
|
287
|
+
this.leftShowing = true;
|
288
|
+
this.rightShowing = false;
|
289
|
+
if (x > 0) {
|
290
|
+
if (this.offCanvasLeft) {
|
291
|
+
$.each(this.offCanvasLefts, function(index, offCanvas) {
|
292
|
+
if (offCanvas === this.offCanvasLeft) {
|
293
|
+
this.offCanvasLeft.style.zIndex = 0;
|
294
|
+
} else {
|
295
|
+
offCanvas.style.zIndex = -1;
|
296
|
+
}
|
297
|
+
}.bind(this));
|
298
|
+
}
|
299
|
+
if (this.offCanvasRight) {
|
300
|
+
this.offCanvasRight.style.zIndex = -1;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
} else {
|
304
|
+
this.rightShowing = true;
|
305
|
+
this.leftShowing = false;
|
306
|
+
if (this.offCanvasRight) {
|
307
|
+
$.each(this.offCanvasRights, function(index, offCanvas) {
|
308
|
+
if (offCanvas === this.offCanvasRight) {
|
309
|
+
offCanvas.style.zIndex = 0;
|
310
|
+
} else {
|
311
|
+
offCanvas.style.zIndex = -1;
|
312
|
+
}
|
313
|
+
}.bind(this));
|
314
|
+
}
|
315
|
+
if (this.offCanvasLeft) {
|
316
|
+
this.offCanvasLeft.style.zIndex = -1;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
} else {
|
320
|
+
if (this.scroller.classList.contains(CLASS_OFF_CANVAS_RIGHT)) {
|
321
|
+
if (x < 0) {
|
322
|
+
this.setTranslateX(0);
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
if (x > this.offCanvasRightWidth) {
|
326
|
+
this.setTranslateX(this.offCanvasRightWidth);
|
327
|
+
return;
|
328
|
+
}
|
329
|
+
} else {
|
330
|
+
if (x > 0) {
|
331
|
+
this.setTranslateX(0);
|
332
|
+
return;
|
333
|
+
}
|
334
|
+
if (x < -this.offCanvasLeftWidth) {
|
335
|
+
this.setTranslateX(-this.offCanvasLeftWidth);
|
336
|
+
return;
|
337
|
+
}
|
338
|
+
}
|
339
|
+
this.setTranslateX(x);
|
340
|
+
}
|
341
|
+
this.lastTranslateX = x;
|
342
|
+
}
|
343
|
+
},
|
344
|
+
setTranslateX: $.animationFrame(function(x) {
|
345
|
+
if (this.scroller) {
|
346
|
+
this.scroller.style.webkitTransform = 'translate3d(' + x + 'px,0,0)';
|
347
|
+
}
|
348
|
+
}),
|
349
|
+
getTranslateX: function() {
|
350
|
+
if (this.scroller) {
|
351
|
+
var result = $.parseTranslateMatrix($.getStyles(this.scroller, 'webkitTransform'));
|
352
|
+
return (result && result.x) || 0;
|
353
|
+
}
|
354
|
+
return 0;
|
355
|
+
},
|
356
|
+
isShown: function(direction) {
|
357
|
+
var shown = false;
|
358
|
+
if (!this.slideIn) {
|
359
|
+
var x = this.getTranslateX();
|
360
|
+
if (direction === 'right') {
|
361
|
+
shown = this.classList.contains(CLASS_ACTIVE) && x < 0;
|
362
|
+
} else if (direction === 'left') {
|
363
|
+
shown = this.classList.contains(CLASS_ACTIVE) && x > 0;
|
364
|
+
} else {
|
365
|
+
shown = this.classList.contains(CLASS_ACTIVE) && x !== 0;
|
366
|
+
}
|
367
|
+
} else {
|
368
|
+
if (direction === 'left') {
|
369
|
+
shown = this.classList.contains(CLASS_ACTIVE) && this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE);
|
370
|
+
} else if (direction === 'right') {
|
371
|
+
shown = this.classList.contains(CLASS_ACTIVE) && this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE);
|
372
|
+
} else {
|
373
|
+
shown = this.classList.contains(CLASS_ACTIVE) && (this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE) || this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE));
|
374
|
+
}
|
375
|
+
}
|
376
|
+
return shown;
|
377
|
+
},
|
378
|
+
close: function() {
|
379
|
+
this._initOffCanvasVisible();
|
380
|
+
if (this.slideIn) {
|
381
|
+
this.scroller = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE) || this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE);
|
382
|
+
}
|
383
|
+
if (this.scroller) {
|
384
|
+
this.scroller.classList.add(CLASS_TRANSITIONING);
|
385
|
+
this.openPercentage(0);
|
386
|
+
}
|
387
|
+
},
|
388
|
+
show: function(direction) {
|
389
|
+
this._initOffCanvasVisible();
|
390
|
+
if (this.isShown(direction)) {
|
391
|
+
return false;
|
392
|
+
}
|
393
|
+
if (!direction) {
|
394
|
+
direction = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT) ? 'right' : 'left';
|
395
|
+
}
|
396
|
+
if (this.slideIn) {
|
397
|
+
this.scroller = direction === 'right' ? this.offCanvasRight : this.offCanvasLeft;
|
398
|
+
}
|
399
|
+
if (this.scroller) {
|
400
|
+
this.scroller.classList.add(CLASS_TRANSITIONING);
|
401
|
+
this.openPercentage(direction === 'left' ? 100 : -100);
|
402
|
+
}
|
403
|
+
return true;
|
404
|
+
},
|
405
|
+
toggle: function(directionOrOffCanvas) {
|
406
|
+
var direction = directionOrOffCanvas;
|
407
|
+
if (directionOrOffCanvas && directionOrOffCanvas.classList) {
|
408
|
+
direction = directionOrOffCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT) ? 'left' : 'right';
|
409
|
+
this.refresh(directionOrOffCanvas);
|
410
|
+
}
|
411
|
+
if (!this.show(direction)) {
|
412
|
+
this.close();
|
413
|
+
}
|
414
|
+
}
|
415
|
+
});
|
416
|
+
|
417
|
+
//hash to offcanvas
|
418
|
+
var findOffCanvasContainer = function(target) {
|
419
|
+
parentNode = target.parentNode;
|
420
|
+
if (parentNode) {
|
421
|
+
if (parentNode.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
|
422
|
+
return parentNode;
|
423
|
+
} else {
|
424
|
+
parentNode = parentNode.parentNode;
|
425
|
+
if (parentNode.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
|
426
|
+
return parentNode;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
}
|
430
|
+
};
|
431
|
+
var handle = function(event, target) {
|
432
|
+
if (target.tagName === 'A' && target.hash) {
|
433
|
+
var offcanvas = document.getElementById(target.hash.replace('#', ''));
|
434
|
+
if (offcanvas) {
|
435
|
+
var container = findOffCanvasContainer(offcanvas);
|
436
|
+
if (container) {
|
437
|
+
$.targets._container = container;
|
438
|
+
return offcanvas;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
}
|
442
|
+
return false;
|
443
|
+
};
|
444
|
+
|
445
|
+
$.registerTarget({
|
446
|
+
name: name,
|
447
|
+
index: 60,
|
448
|
+
handle: handle,
|
449
|
+
target: false,
|
450
|
+
isReset: false,
|
451
|
+
isContinue: true
|
452
|
+
});
|
453
|
+
|
454
|
+
window.addEventListener('tap', function(e) {
|
455
|
+
if (!$.targets.offcanvas) {
|
456
|
+
return;
|
457
|
+
}
|
458
|
+
//TODO 此处类型的代码后续考虑统一优化(target机制),现在的实现费力不讨好
|
459
|
+
var target = e.target;
|
460
|
+
for (; target && target !== document; target = target.parentNode) {
|
461
|
+
if (target.tagName === 'A' && target.hash && target.hash === ('#' + $.targets.offcanvas.id)) {
|
462
|
+
e.detail.gesture.preventDefault(); //fixed hashchange
|
463
|
+
$($.targets._container).offCanvas().toggle($.targets.offcanvas);
|
464
|
+
$.targets.offcanvas = $.targets._container = null;
|
465
|
+
break;
|
466
|
+
}
|
467
|
+
}
|
468
|
+
});
|
469
|
+
|
470
|
+
$.fn.offCanvas = function(options) {
|
471
|
+
var offCanvasApis = [];
|
472
|
+
this.each(function() {
|
473
|
+
var offCanvasApi = null;
|
474
|
+
var self = this;
|
475
|
+
//hack old version
|
476
|
+
if (!self.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
|
477
|
+
self = findOffCanvasContainer(self);
|
478
|
+
}
|
479
|
+
var id = self.getAttribute('data-offCanvas');
|
480
|
+
if (!id) {
|
481
|
+
id = ++$.uuid;
|
482
|
+
$.data[id] = offCanvasApi = new OffCanvas(self, options);
|
483
|
+
self.setAttribute('data-offCanvas', id);
|
484
|
+
} else {
|
485
|
+
offCanvasApi = $.data[id];
|
486
|
+
}
|
487
|
+
if (options === 'show' || options === 'close' || options === 'toggle') {
|
488
|
+
offCanvasApi.toggle();
|
489
|
+
}
|
490
|
+
offCanvasApis.push(offCanvasApi);
|
491
|
+
});
|
492
|
+
return offCanvasApis.length === 1 ? offCanvasApis[0] : offCanvasApis;
|
493
|
+
};
|
494
|
+
$.ready(function() {
|
495
|
+
$($.classSelector('.off-canvas-wrap')).offCanvas();
|
496
|
+
});
|
497
|
+
})(mui, window, document, 'offcanvas');
|
@@ -0,0 +1,157 @@
|
|
1
|
+
(function($, document, undefined) {
|
2
|
+
var CLASS_PULL_TOP_POCKET = $.className('pull-top-pocket');
|
3
|
+
var CLASS_PULL_BOTTOM_POCKET = $.className('pull-bottom-pocket');
|
4
|
+
var CLASS_PULL = $.className('pull');
|
5
|
+
var CLASS_PULL_LOADING = $.className('pull-loading');
|
6
|
+
var CLASS_PULL_CAPTION = $.className('pull-caption');
|
7
|
+
|
8
|
+
var CLASS_ICON = $.className('icon');
|
9
|
+
var CLASS_SPINNER = $.className('spinner');
|
10
|
+
var CLASS_ICON_PULLDOWN = $.className('icon-pulldown');
|
11
|
+
|
12
|
+
var CLASS_BLOCK = $.className('block');
|
13
|
+
var CLASS_HIDDEN = $.className('hidden');
|
14
|
+
var CLASS_VISIBILITY = $.className('visibility');
|
15
|
+
|
16
|
+
var CLASS_LOADING_UP = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_ICON_PULLDOWN;
|
17
|
+
var CLASS_LOADING_DOWN = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_ICON_PULLDOWN;
|
18
|
+
var CLASS_LOADING = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_SPINNER;
|
19
|
+
|
20
|
+
var pocketHtml = ['<div class="' + CLASS_PULL + '">', '<div class="{icon}"></div>', '<div class="' + CLASS_PULL_CAPTION + '">{contentrefresh}</div>', '</div>'].join('');
|
21
|
+
|
22
|
+
var PullRefresh = {
|
23
|
+
init: function(element, options) {
|
24
|
+
this._super(element, $.extend(true, {
|
25
|
+
scrollY: true,
|
26
|
+
scrollX: false,
|
27
|
+
indicators: true,
|
28
|
+
down: {
|
29
|
+
height: 50,
|
30
|
+
contentdown: '下拉可以刷新',
|
31
|
+
contentover: '释放立即刷新',
|
32
|
+
contentrefresh: '正在刷新...'
|
33
|
+
},
|
34
|
+
up: {
|
35
|
+
height: 50,
|
36
|
+
auto: false,
|
37
|
+
contentdown: '上拉显示更多',
|
38
|
+
contentrefresh: '正在加载...',
|
39
|
+
contentnomore: '没有更多数据了',
|
40
|
+
duration: 300
|
41
|
+
}
|
42
|
+
}, options));
|
43
|
+
},
|
44
|
+
_init: function() {
|
45
|
+
this._super();
|
46
|
+
this._initPocket();
|
47
|
+
},
|
48
|
+
_initPulldownRefresh: function() {
|
49
|
+
this.pulldown = true;
|
50
|
+
this.pullPocket = this.topPocket;
|
51
|
+
this.pullPocket.classList.add(CLASS_BLOCK);
|
52
|
+
this.pullPocket.classList.add(CLASS_VISIBILITY);
|
53
|
+
this.pullCaption = this.topCaption;
|
54
|
+
this.pullLoading = this.topLoading;
|
55
|
+
},
|
56
|
+
_initPullupRefresh: function() {
|
57
|
+
this.pulldown = false;
|
58
|
+
this.pullPocket = this.bottomPocket;
|
59
|
+
this.pullPocket.classList.add(CLASS_BLOCK);
|
60
|
+
this.pullPocket.classList.add(CLASS_VISIBILITY);
|
61
|
+
this.pullCaption = this.bottomCaption;
|
62
|
+
this.pullLoading = this.bottomLoading;
|
63
|
+
},
|
64
|
+
_initPocket: function() {
|
65
|
+
var options = this.options;
|
66
|
+
if (options.down && options.down.hasOwnProperty('callback')) {
|
67
|
+
this.topPocket = this.scroller.querySelector('.' + CLASS_PULL_TOP_POCKET);
|
68
|
+
if (!this.topPocket) {
|
69
|
+
this.topPocket = this._createPocket(CLASS_PULL_TOP_POCKET, options.down, CLASS_LOADING_DOWN);
|
70
|
+
this.wrapper.insertBefore(this.topPocket, this.wrapper.firstChild);
|
71
|
+
}
|
72
|
+
this.topLoading = this.topPocket.querySelector('.' + CLASS_PULL_LOADING);
|
73
|
+
this.topCaption = this.topPocket.querySelector('.' + CLASS_PULL_CAPTION);
|
74
|
+
}
|
75
|
+
if (options.up && options.up.hasOwnProperty('callback')) {
|
76
|
+
this.bottomPocket = this.scroller.querySelector('.' + CLASS_PULL_BOTTOM_POCKET);
|
77
|
+
if (!this.bottomPocket) {
|
78
|
+
this.bottomPocket = this._createPocket(CLASS_PULL_BOTTOM_POCKET, options.up, CLASS_LOADING);
|
79
|
+
this.scroller.appendChild(this.bottomPocket);
|
80
|
+
}
|
81
|
+
this.bottomLoading = this.bottomPocket.querySelector('.' + CLASS_PULL_LOADING);
|
82
|
+
this.bottomCaption = this.bottomPocket.querySelector('.' + CLASS_PULL_CAPTION);
|
83
|
+
//TODO only for h5
|
84
|
+
this.wrapper.addEventListener('scrollbottom', this);
|
85
|
+
}
|
86
|
+
},
|
87
|
+
_createPocket: function(clazz, options, iconClass) {
|
88
|
+
var pocket = document.createElement('div');
|
89
|
+
pocket.className = clazz;
|
90
|
+
pocket.innerHTML = pocketHtml.replace('{contentrefresh}', options.contentrefresh).replace('{icon}', iconClass);
|
91
|
+
return pocket;
|
92
|
+
},
|
93
|
+
_resetPullDownLoading: function() {
|
94
|
+
var loading = this.pullLoading;
|
95
|
+
if (loading) {
|
96
|
+
this.pullCaption.innerHTML = this.options.down.contentdown;
|
97
|
+
loading.style.webkitTransition = "";
|
98
|
+
loading.style.webkitTransform = "";
|
99
|
+
loading.style.webkitAnimation = "";
|
100
|
+
loading.className = CLASS_LOADING_DOWN;
|
101
|
+
}
|
102
|
+
},
|
103
|
+
_setCaption: function(title, reset) {
|
104
|
+
if (this.loading) {
|
105
|
+
return;
|
106
|
+
}
|
107
|
+
var options = this.options;
|
108
|
+
var pocket = this.pullPocket;
|
109
|
+
var caption = this.pullCaption;
|
110
|
+
var loading = this.pullLoading;
|
111
|
+
var isPulldown = this.pulldown;
|
112
|
+
if (pocket) {
|
113
|
+
if (reset) {
|
114
|
+
var self = this;
|
115
|
+
setTimeout(function() {
|
116
|
+
caption.innerHTML = self.lastTitle = title;
|
117
|
+
if (isPulldown) {
|
118
|
+
loading.className = CLASS_LOADING_DOWN;
|
119
|
+
} else {
|
120
|
+
loading.className = CLASS_LOADING;
|
121
|
+
}
|
122
|
+
loading.style.webkitAnimation = "";
|
123
|
+
loading.style.webkitTransition = "";
|
124
|
+
loading.style.webkitTransform = "";
|
125
|
+
}, 100);
|
126
|
+
} else {
|
127
|
+
if (title !== this.lastTitle) {
|
128
|
+
caption.innerHTML = title;
|
129
|
+
if (isPulldown) {
|
130
|
+
if (title === options.down.contentrefresh) {
|
131
|
+
loading.className = CLASS_LOADING;
|
132
|
+
loading.style.webkitAnimation = "spinner-spin 1s step-end infinite";
|
133
|
+
} else if (title === options.down.contentover) {
|
134
|
+
loading.className = CLASS_LOADING_UP;
|
135
|
+
loading.style.webkitTransition = "-webkit-transform 0.3s ease-in";
|
136
|
+
loading.style.webkitTransform = "rotate(180deg)";
|
137
|
+
} else if (title === options.down.contentdown) {
|
138
|
+
loading.className = CLASS_LOADING_DOWN;
|
139
|
+
loading.style.webkitTransition = "-webkit-transform 0.3s ease-in";
|
140
|
+
loading.style.webkitTransform = "rotate(0deg)";
|
141
|
+
}
|
142
|
+
} else {
|
143
|
+
if (title === options.up.contentrefresh) {
|
144
|
+
loading.className = CLASS_LOADING + ' ' + CLASS_VISIBILITY;
|
145
|
+
} else {
|
146
|
+
loading.className = CLASS_LOADING + ' ' + CLASS_HIDDEN;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
this.lastTitle = title;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
}
|
155
|
+
};
|
156
|
+
$.PullRefresh = PullRefresh;
|
157
|
+
})(mui, document);
|