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,512 @@
1
+ /**
2
+ * Tableviews
3
+ * @param {type} $
4
+ * @param {type} window
5
+ * @param {type} document
6
+ * @returns {undefined}
7
+ */
8
+ (function($, window, document) {
9
+
10
+ var CLASS_ACTIVE = $.className('active');
11
+ var CLASS_SELECTED = $.className('selected');
12
+ var CLASS_GRID_VIEW = $.className('grid-view');
13
+ var CLASS_RADIO_VIEW = $.className('table-view-radio');
14
+ var CLASS_TABLE_VIEW_CELL = $.className('table-view-cell');
15
+ var CLASS_COLLAPSE_CONTENT = $.className('collapse-content');
16
+ var CLASS_DISABLED = $.className('disabled');
17
+ var CLASS_TOGGLE = $.className('switch');
18
+ var CLASS_BTN = $.className('btn');
19
+
20
+ var CLASS_SLIDER_HANDLE = $.className('slider-handle');
21
+ var CLASS_SLIDER_LEFT = $.className('slider-left');
22
+ var CLASS_SLIDER_RIGHT = $.className('slider-right');
23
+ var CLASS_TRANSITIONING = $.className('transitioning');
24
+
25
+
26
+ var SELECTOR_SLIDER_HANDLE = '.' + CLASS_SLIDER_HANDLE;
27
+ var SELECTOR_SLIDER_LEFT = '.' + CLASS_SLIDER_LEFT;
28
+ var SELECTOR_SLIDER_RIGHT = '.' + CLASS_SLIDER_RIGHT;
29
+ var SELECTOR_SELECTED = '.' + CLASS_SELECTED;
30
+ var SELECTOR_BUTTON = '.' + CLASS_BTN;
31
+ var overFactor = 0.8;
32
+ var cell, a;
33
+
34
+ var isMoved = isOpened = openedActions = progress = false;
35
+ var sliderHandle = sliderActionLeft = sliderActionRight = buttonsLeft = buttonsRight = sliderDirection = sliderRequestAnimationFrame = false;
36
+ var timer = translateX = lastTranslateX = sliderActionLeftWidth = sliderActionRightWidth = 0;
37
+
38
+
39
+
40
+ var toggleActive = function(isActive) {
41
+ if (isActive) {
42
+ if (a) {
43
+ a.classList.add(CLASS_ACTIVE);
44
+ } else if (cell) {
45
+ cell.classList.add(CLASS_ACTIVE);
46
+ }
47
+ } else {
48
+ timer && timer.cancel();
49
+ if (a) {
50
+ a.classList.remove(CLASS_ACTIVE);
51
+ } else if (cell) {
52
+ cell.classList.remove(CLASS_ACTIVE);
53
+ }
54
+ }
55
+ };
56
+
57
+ var updateTranslate = function() {
58
+ if (translateX !== lastTranslateX) {
59
+ if (buttonsRight && buttonsRight.length > 0) {
60
+ progress = translateX / sliderActionRightWidth;
61
+ if (translateX < -sliderActionRightWidth) {
62
+ translateX = -sliderActionRightWidth - Math.pow(-translateX - sliderActionRightWidth, overFactor);
63
+ }
64
+ for (var i = 0, len = buttonsRight.length; i < len; i++) {
65
+ var buttonRight = buttonsRight[i];
66
+ if (typeof buttonRight._buttonOffset === 'undefined') {
67
+ buttonRight._buttonOffset = buttonRight.offsetLeft;
68
+ }
69
+ buttonOffset = buttonRight._buttonOffset;
70
+ setTranslate(buttonRight, (translateX - buttonOffset * (1 + Math.max(progress, -1))));
71
+ }
72
+ }
73
+ if (buttonsLeft && buttonsLeft.length > 0) {
74
+ progress = translateX / sliderActionLeftWidth;
75
+ if (translateX > sliderActionLeftWidth) {
76
+ translateX = sliderActionLeftWidth + Math.pow(translateX - sliderActionLeftWidth, overFactor);
77
+ }
78
+ for (var i = 0, len = buttonsLeft.length; i < len; i++) {
79
+ var buttonLeft = buttonsLeft[i];
80
+ if (typeof buttonLeft._buttonOffset === 'undefined') {
81
+ buttonLeft._buttonOffset = sliderActionLeftWidth - buttonLeft.offsetLeft - buttonLeft.offsetWidth;
82
+ }
83
+ buttonOffset = buttonLeft._buttonOffset;
84
+ if (buttonsLeft.length > 1) {
85
+ buttonLeft.style.zIndex = buttonsLeft.length - i;
86
+ }
87
+ setTranslate(buttonLeft, (translateX + buttonOffset * (1 - Math.min(progress, 1))));
88
+ }
89
+ }
90
+ setTranslate(sliderHandle, translateX);
91
+ lastTranslateX = translateX;
92
+ }
93
+ sliderRequestAnimationFrame = requestAnimationFrame(function() {
94
+ updateTranslate();
95
+ });
96
+ };
97
+ var setTranslate = function(element, x) {
98
+ if (element) {
99
+ element.style.webkitTransform = 'translate3d(' + x + 'px,0,0)';
100
+ }
101
+ };
102
+
103
+ window.addEventListener('touchstart', function(event) {
104
+ if (cell) {
105
+ toggleActive(false);
106
+ }
107
+ cell = a = false;
108
+ isMoved = isOpened = openedActions = false;
109
+ var target = event.target;
110
+ var isDisabled = false;
111
+ for (; target && target !== document; target = target.parentNode) {
112
+ if (target.classList) {
113
+ var classList = target.classList;
114
+ if ((target.tagName === 'INPUT' && target.type !== 'radio' && target.type !== 'checkbox') || target.tagName === 'BUTTON' || classList.contains(CLASS_TOGGLE) || classList.contains(CLASS_BTN) || classList.contains(CLASS_DISABLED)) {
115
+ isDisabled = true;
116
+ }
117
+ if (classList.contains(CLASS_COLLAPSE_CONTENT)) { //collapse content
118
+ break;
119
+ }
120
+ if (classList.contains(CLASS_TABLE_VIEW_CELL)) {
121
+ cell = target;
122
+ //TODO swipe to delete close
123
+ var selected = cell.parentNode.querySelector(SELECTOR_SELECTED);
124
+ if (!cell.parentNode.classList.contains(CLASS_RADIO_VIEW) && selected && selected !== cell) {
125
+ $.swipeoutClose(selected);
126
+ cell = isDisabled = false;
127
+ return;
128
+ }
129
+ if (!cell.parentNode.classList.contains(CLASS_GRID_VIEW)) {
130
+ var link = cell.querySelector('a');
131
+ if (link && link.parentNode === cell) { //li>a
132
+ a = link;
133
+ }
134
+ }
135
+ var handle = cell.querySelector(SELECTOR_SLIDER_HANDLE);
136
+ if (handle) {
137
+ toggleEvents(cell);
138
+ event.stopPropagation();
139
+ }
140
+ if (!isDisabled) {
141
+ if (handle) {
142
+ if (timer) {
143
+ timer.cancel();
144
+ }
145
+ timer = $.later(function() {
146
+ toggleActive(true);
147
+ }, 100);
148
+ } else if (!(cell.querySelector('input') || cell.querySelector(SELECTOR_BUTTON) || cell.querySelector('.' + CLASS_TOGGLE))) {
149
+ toggleActive(true);
150
+ }
151
+ }
152
+ break;
153
+ }
154
+ }
155
+ }
156
+ });
157
+ window.addEventListener('touchmove', function(event) {
158
+ toggleActive(false);
159
+ });
160
+
161
+ var handleEvent = {
162
+ handleEvent: function(event) {
163
+ switch (event.type) {
164
+ case 'drag':
165
+ this.drag(event);
166
+ break;
167
+ case 'dragend':
168
+ this.dragend(event);
169
+ break;
170
+ case 'flick':
171
+ this.flick(event);
172
+ break;
173
+ case 'swiperight':
174
+ this.swiperight(event);
175
+ break;
176
+ case 'swipeleft':
177
+ this.swipeleft(event);
178
+ break;
179
+ }
180
+ },
181
+ drag: function(event) {
182
+ if (!cell) {
183
+ return;
184
+ }
185
+ if (!isMoved) { //init
186
+ sliderHandle = sliderActionLeft = sliderActionRight = buttonsLeft = buttonsRight = sliderDirection = sliderRequestAnimationFrame = false;
187
+ sliderHandle = cell.querySelector(SELECTOR_SLIDER_HANDLE);
188
+ if (sliderHandle) {
189
+ sliderActionLeft = cell.querySelector(SELECTOR_SLIDER_LEFT);
190
+ sliderActionRight = cell.querySelector(SELECTOR_SLIDER_RIGHT);
191
+ if (sliderActionLeft) {
192
+ sliderActionLeftWidth = sliderActionLeft.offsetWidth;
193
+ buttonsLeft = sliderActionLeft.querySelectorAll(SELECTOR_BUTTON);
194
+ }
195
+ if (sliderActionRight) {
196
+ sliderActionRightWidth = sliderActionRight.offsetWidth;
197
+ buttonsRight = sliderActionRight.querySelectorAll(SELECTOR_BUTTON);
198
+ }
199
+ cell.classList.remove(CLASS_TRANSITIONING);
200
+ isOpened = cell.classList.contains(CLASS_SELECTED);
201
+ if (isOpened) {
202
+ openedActions = cell.querySelector(SELECTOR_SLIDER_LEFT + SELECTOR_SELECTED) ? 'left' : 'right';
203
+ }
204
+ }
205
+ }
206
+ var detail = event.detail;
207
+ var direction = detail.direction;
208
+ var angle = detail.angle;
209
+ if (direction === 'left' && (angle > 150 || angle < -150)) {
210
+ if (buttonsRight || (buttonsLeft && isOpened)) { //存在右侧按钮或存在左侧按钮且是已打开状态
211
+ isMoved = true;
212
+ }
213
+ } else if (direction === 'right' && (angle > -30 && angle < 30)) {
214
+ if (buttonsLeft || (buttonsRight && isOpened)) { //存在左侧按钮或存在右侧按钮且是已打开状态
215
+ isMoved = true;
216
+ }
217
+ }
218
+ if (isMoved) {
219
+ event.stopPropagation();
220
+ event.detail.gesture.preventDefault();
221
+ var translate = event.detail.deltaX;
222
+ if (isOpened) {
223
+ if (openedActions === 'right') {
224
+ translate = translate - sliderActionRightWidth;
225
+ } else {
226
+ translate = translate + sliderActionLeftWidth;
227
+ }
228
+ }
229
+ if ((translate > 0 && !buttonsLeft) || (translate < 0 && !buttonsRight)) {
230
+ if (!isOpened) {
231
+ return;
232
+ }
233
+ translate = 0;
234
+ }
235
+ if (translate < 0) {
236
+ sliderDirection = 'toLeft';
237
+ } else if (translate > 0) {
238
+ sliderDirection = 'toRight';
239
+ } else {
240
+ if (!sliderDirection) {
241
+ sliderDirection = 'toLeft';
242
+ }
243
+ }
244
+ if (!sliderRequestAnimationFrame) {
245
+ updateTranslate();
246
+ }
247
+ translateX = translate;
248
+ }
249
+ },
250
+ flick: function(event) {
251
+ if (isMoved) {
252
+ event.stopPropagation();
253
+ }
254
+ },
255
+ swipeleft: function(event) {
256
+ if (isMoved) {
257
+ event.stopPropagation();
258
+ }
259
+ },
260
+ swiperight: function(event) {
261
+ if (isMoved) {
262
+ event.stopPropagation();
263
+ }
264
+ },
265
+ dragend: function(event) {
266
+ if (!isMoved) {
267
+ return;
268
+ }
269
+ event.stopPropagation();
270
+ if (sliderRequestAnimationFrame) {
271
+ cancelAnimationFrame(sliderRequestAnimationFrame);
272
+ sliderRequestAnimationFrame = null;
273
+ }
274
+ var detail = event.detail;
275
+ isMoved = false;
276
+ var action = 'close';
277
+ var actionsWidth = sliderDirection === 'toLeft' ? sliderActionRightWidth : sliderActionLeftWidth;
278
+ var isToggle = detail.swipe || (Math.abs(translateX) > actionsWidth / 2);
279
+ if (isToggle) {
280
+ if (!isOpened) {
281
+ action = 'open';
282
+ } else if (detail.direction === 'left' && openedActions === 'right') {
283
+ action = 'open';
284
+ } else if (detail.direction === 'right' && openedActions === 'left') {
285
+ action = 'open';
286
+ }
287
+
288
+ }
289
+ cell.classList.add(CLASS_TRANSITIONING);
290
+ var buttons;
291
+ if (action === 'open') {
292
+ var newTranslate = sliderDirection === 'toLeft' ? -actionsWidth : actionsWidth;
293
+ setTranslate(sliderHandle, newTranslate);
294
+ buttons = sliderDirection === 'toLeft' ? buttonsRight : buttonsLeft;
295
+ if (typeof buttons !== 'undefined') {
296
+ var button = null;
297
+ for (var i = 0; i < buttons.length; i++) {
298
+ button = buttons[i];
299
+ setTranslate(button, newTranslate);
300
+ }
301
+ button.parentNode.classList.add(CLASS_SELECTED);
302
+ cell.classList.add(CLASS_SELECTED);
303
+ if (!isOpened) {
304
+ $.trigger(cell, sliderDirection === 'toLeft' ? 'slideleft' : 'slideright');
305
+ }
306
+ }
307
+ } else {
308
+ setTranslate(sliderHandle, 0);
309
+ sliderActionLeft && sliderActionLeft.classList.remove(CLASS_SELECTED);
310
+ sliderActionRight && sliderActionRight.classList.remove(CLASS_SELECTED);
311
+ cell.classList.remove(CLASS_SELECTED);
312
+ }
313
+ var buttonOffset;
314
+ if (buttonsLeft && buttonsLeft.length > 0 && buttonsLeft !== buttons) {
315
+ for (var i = 0, len = buttonsLeft.length; i < len; i++) {
316
+ var buttonLeft = buttonsLeft[i];
317
+ buttonOffset = buttonLeft._buttonOffset;
318
+ if (typeof buttonOffset === 'undefined') {
319
+ buttonLeft._buttonOffset = sliderActionLeftWidth - buttonLeft.offsetLeft - buttonLeft.offsetWidth;
320
+ }
321
+ setTranslate(buttonLeft, buttonOffset);
322
+ }
323
+ }
324
+ if (buttonsRight && buttonsRight.length > 0 && buttonsRight !== buttons) {
325
+ for (var i = 0, len = buttonsRight.length; i < len; i++) {
326
+ var buttonRight = buttonsRight[i];
327
+ buttonOffset = buttonRight._buttonOffset;
328
+ if (typeof buttonOffset === 'undefined') {
329
+ buttonRight._buttonOffset = buttonRight.offsetLeft;
330
+ }
331
+ setTranslate(buttonRight, -buttonOffset);
332
+ }
333
+ }
334
+ }
335
+ };
336
+
337
+ function toggleEvents(element, isRemove) {
338
+ var method = !!isRemove ? 'removeEventListener' : 'addEventListener';
339
+ element[method]('drag', handleEvent);
340
+ element[method]('dragend', handleEvent);
341
+ element[method]('swiperight', handleEvent);
342
+ element[method]('swipeleft', handleEvent);
343
+ element[method]('flick', handleEvent);
344
+ };
345
+ /**
346
+ * 打开滑动菜单
347
+ * @param {Object} el
348
+ * @param {Object} direction
349
+ */
350
+ $.swipeoutOpen = function(el, direction) {
351
+ if (!el) return;
352
+ var classList = el.classList;
353
+ if (classList.contains(CLASS_SELECTED)) return;
354
+ if (!direction) {
355
+ if (el.querySelector(SELECTOR_SLIDER_RIGHT)) {
356
+ direction = 'right';
357
+ } else {
358
+ direction = 'left';
359
+ }
360
+ }
361
+ var swipeoutAction = el.querySelector($.classSelector(".slider-" + direction));
362
+ if (!swipeoutAction) return;
363
+ swipeoutAction.classList.add(CLASS_SELECTED);
364
+ classList.add(CLASS_SELECTED);
365
+ classList.remove(CLASS_TRANSITIONING);
366
+ var buttons = swipeoutAction.querySelectorAll(SELECTOR_BUTTON);
367
+ var swipeoutWidth = swipeoutAction.offsetWidth;
368
+ var translate = (direction === 'right') ? -swipeoutWidth : swipeoutWidth;
369
+ var length = buttons.length;
370
+ var button;
371
+ for (var i = 0; i < length; i++) {
372
+ button = buttons[i];
373
+ if (direction === 'right') {
374
+ setTranslate(button, -button.offsetLeft);
375
+ } else {
376
+ setTranslate(button, (swipeoutWidth - button.offsetWidth - button.offsetLeft));
377
+ }
378
+ }
379
+ classList.add(CLASS_TRANSITIONING);
380
+ for (var i = 0; i < length; i++) {
381
+ setTranslate(buttons[i], translate);
382
+ }
383
+ setTranslate(el.querySelector(SELECTOR_SLIDER_HANDLE), translate);
384
+ };
385
+ /**
386
+ * 关闭滑动菜单
387
+ * @param {Object} el
388
+ */
389
+ $.swipeoutClose = function(el) {
390
+ if (!el) return;
391
+ var classList = el.classList;
392
+ if (!classList.contains(CLASS_SELECTED)) return;
393
+ var direction = el.querySelector(SELECTOR_SLIDER_RIGHT + SELECTOR_SELECTED) ? 'right' : 'left';
394
+ var swipeoutAction = el.querySelector($.classSelector(".slider-" + direction));
395
+ if (!swipeoutAction) return;
396
+ swipeoutAction.classList.remove(CLASS_SELECTED);
397
+ classList.remove(CLASS_SELECTED);
398
+ classList.add(CLASS_TRANSITIONING);
399
+ var buttons = swipeoutAction.querySelectorAll(SELECTOR_BUTTON);
400
+ var swipeoutWidth = swipeoutAction.offsetWidth;
401
+ var length = buttons.length;
402
+ var button;
403
+ setTranslate(el.querySelector(SELECTOR_SLIDER_HANDLE), 0);
404
+ for (var i = 0; i < length; i++) {
405
+ button = buttons[i];
406
+ if (direction === 'right') {
407
+ setTranslate(button, (-button.offsetLeft));
408
+ } else {
409
+ setTranslate(button, (swipeoutWidth - button.offsetWidth - button.offsetLeft));
410
+ }
411
+ }
412
+ };
413
+
414
+ window.addEventListener('touchend', function(event) { //使用touchend来取消高亮,避免一次点击既不触发tap,doubletap,longtap的事件
415
+ if (!cell) {
416
+ return;
417
+ }
418
+ toggleActive(false);
419
+ sliderHandle && toggleEvents(cell, true);
420
+ });
421
+ window.addEventListener('touchcancel', function(event) { //使用touchcancel来取消高亮,避免一次点击既不触发tap,doubletap,longtap的事件
422
+ if (!cell) {
423
+ return;
424
+ }
425
+ toggleActive(false);
426
+ sliderHandle && toggleEvents(cell, true);
427
+ });
428
+ var radioOrCheckboxClick = function() {
429
+ var classList = cell.classList;
430
+ if (classList.contains($.className('radio'))) {
431
+ var input = cell.querySelector('input[type=radio]');
432
+ if (input) {
433
+ // input.click();
434
+ input.checked = !input.checked;
435
+ }
436
+ } else if (classList.contains($.className('checkbox'))) {
437
+ var input = cell.querySelector('input[type=checkbox]');
438
+ if (input) {
439
+ // input.click();
440
+ input.checked = !input.checked;
441
+ }
442
+ }
443
+ };
444
+ //fixed hashchange(android)
445
+ window.addEventListener($.EVENT_CLICK, function(e) {
446
+ if (cell && cell.classList.contains($.className('collapse'))) {
447
+ e.preventDefault();
448
+ }
449
+ });
450
+ window.addEventListener('doubletap', function(event) {
451
+ if (cell) {
452
+ radioOrCheckboxClick();
453
+ }
454
+ });
455
+ window.addEventListener('tap', function(event) {
456
+ if (!cell) {
457
+ return;
458
+ }
459
+ var type = event.target && event.target.type;
460
+ if (type === 'radio' || type === 'checkbox') {
461
+ radioOrCheckboxClick();
462
+ return;
463
+ }
464
+ var isExpand = false;
465
+ var classList = cell.classList;
466
+ var ul = cell.parentNode;
467
+ if (ul && ul.classList.contains(CLASS_RADIO_VIEW)) {
468
+ if (classList.contains(CLASS_SELECTED)) {
469
+ return;
470
+ }
471
+ var selected = ul.querySelector('li' + SELECTOR_SELECTED);
472
+ if (selected) {
473
+ selected.classList.remove(CLASS_SELECTED);
474
+ }
475
+ classList.add(CLASS_SELECTED);
476
+ $.trigger(cell, 'selected', {
477
+ el: cell
478
+ });
479
+ return;
480
+ }
481
+ if (classList.contains($.className('collapse')) && !cell.parentNode.classList.contains($.className('unfold'))) {
482
+ event.detail.gesture.preventDefault();
483
+ if (!classList.contains(CLASS_ACTIVE)) { //展开时,需要收缩其他同类
484
+ var collapse = cell.parentNode.querySelector($.classSelector('.collapse.active'));
485
+ if (collapse) {
486
+ collapse.classList.remove(CLASS_ACTIVE);
487
+ }
488
+ isExpand = true;
489
+ }
490
+ classList.toggle(CLASS_ACTIVE);
491
+ if (isExpand) {
492
+ //触发展开事件
493
+ $.trigger(cell, 'expand');
494
+
495
+ //scroll
496
+ //暂不滚动
497
+ // var offsetTop = $.offset(cell).top;
498
+ // var scrollTop = document.body.scrollTop;
499
+ // var height = window.innerHeight;
500
+ // var offsetHeight = cell.offsetHeight;
501
+ // var cellHeight = (offsetTop - scrollTop + offsetHeight);
502
+ // if (offsetHeight > height) {
503
+ // $.scrollTo(offsetTop, 300);
504
+ // } else if (cellHeight > height) {
505
+ // $.scrollTo(cellHeight - height + scrollTop, 300);
506
+ // }
507
+ }
508
+ } else {
509
+ radioOrCheckboxClick();
510
+ }
511
+ });
512
+ })(mui, window, document);
@@ -0,0 +1 @@
1
+ //= require mui_app_rails/mui
@@ -0,0 +1,88 @@
1
+ //
2
+ // Badges
3
+ // --------------------------------------------------
4
+ .#{$namespace}badge {
5
+ display: inline-block;
6
+ padding: 3px 6px;
7
+ font-size: 12px;
8
+ line-height: 1;
9
+ color: #333;
10
+ background-color: rgba(0,0,0,.15);
11
+ border-radius: 100px;
12
+
13
+ // Inverted badges have no background.
14
+ &.#{$namespace}badge-inverted {
15
+ padding: 0 5px 0 0;
16
+ color: $default-color;
17
+ background-color: transparent;
18
+ }
19
+ }
20
+
21
+
22
+ // Badge modifiers
23
+ // --------------------------------------------------
24
+
25
+ // Main badge
26
+ .#{$namespace}badge-primary,.#{$namespace}badge-blue {
27
+ color: #fff;
28
+ background-color: $primary-color;
29
+
30
+ &.#{$namespace}badge-inverted {
31
+ color: $primary-color;
32
+ background-color: transparent;
33
+ }
34
+ }
35
+
36
+ // success badge
37
+ .#{$namespace}badge-success,.#{$namespace}badge-green {
38
+ color: #fff;
39
+ background-color: $positive-color;
40
+
41
+ &.#{$namespace}badge-inverted {
42
+ color: $positive-color;
43
+ background-color: transparent;
44
+ }
45
+ }
46
+ //waring
47
+ .#{$namespace}badge-warning,.#{$namespace}badge-yellow {
48
+ color: #fff;
49
+ background-color: $warning-color;
50
+
51
+ &.#{$namespace}badge-inverted {
52
+ color: $warning-color;
53
+ background-color: transparent;
54
+ }
55
+ }
56
+
57
+ // Negative badge
58
+ .#{$namespace}badge-danger,.#{$namespace}badge-red {
59
+ color: #fff;
60
+ background-color: $negative-color;
61
+
62
+ &.#{$namespace}badge-inverted {
63
+ color: $negative-color;
64
+ background-color: transparent;
65
+ }
66
+ }
67
+
68
+ .#{$namespace}badge-royal,.#{$namespace}badge-purple {
69
+ color: #fff;
70
+ background-color: $royal-color;
71
+
72
+ &.#{$namespace}badge-inverted {
73
+ color: $royal-color;
74
+ background-color: transparent;
75
+ }
76
+ }
77
+
78
+ .#{$namespace}icon .#{$namespace}badge{
79
+ position: absolute;
80
+ left: 100%;
81
+ margin-left: -10px;
82
+ top: -2px;
83
+ font-size: 10px;
84
+ line-height: 1.4;
85
+ padding: 1px 5px;
86
+ background: red;
87
+ color: white;
88
+ }