mui_app_rails 0.0.1 → 0.0.2

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 +4 -4
  2. data/app/assets/javascripts/mui_app_rails/mui.js +6013 -1
  3. data/app/assets/javascripts/mui_app_rails/mui.min.js +8 -0
  4. data/app/assets/javascripts/mui_app_rails.js +1 -1
  5. data/app/assets/stylesheets/mui_app_rails/mui.css +3742 -0
  6. data/app/assets/stylesheets/mui_app_rails/mui.min.css +5 -0
  7. data/lib/mui_app_rails/engine.rb +12 -0
  8. data/lib/mui_app_rails/version.rb +1 -1
  9. data/lib/mui_app_rails.rb +1 -1
  10. metadata +17 -99
  11. data/app/assets/javascripts/mui_app_rails/actions.js +0 -26
  12. data/app/assets/javascripts/mui_app_rails/ajax.plugin.js +0 -3
  13. data/app/assets/javascripts/mui_app_rails/input.plugin.js +0 -232
  14. data/app/assets/javascripts/mui_app_rails/modals.js +0 -37
  15. data/app/assets/javascripts/mui_app_rails/mui.active.js +0 -30
  16. data/app/assets/javascripts/mui_app_rails/mui.ajax.5+.js +0 -27
  17. data/app/assets/javascripts/mui_app_rails/mui.ajax.js +0 -277
  18. data/app/assets/javascripts/mui_app_rails/mui.animation.js +0 -39
  19. data/app/assets/javascripts/mui_app_rails/mui.animationframe.js +0 -72
  20. data/app/assets/javascripts/mui_app_rails/mui.back.5+.js +0 -108
  21. data/app/assets/javascripts/mui_app_rails/mui.back.js +0 -56
  22. data/app/assets/javascripts/mui_app_rails/mui.class.js +0 -40
  23. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.js +0 -894
  24. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.pullrefresh.js +0 -150
  25. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.slider.js +0 -361
  26. data/app/assets/javascripts/mui_app_rails/mui.class.scroll.slider.old.js +0 -332
  27. data/app/assets/javascripts/mui_app_rails/mui.detect.5+.js +0 -18
  28. data/app/assets/javascripts/mui_app_rails/mui.detect.js +0 -50
  29. data/app/assets/javascripts/mui_app_rails/mui.dialog.alert.js +0 -27
  30. data/app/assets/javascripts/mui_app_rails/mui.dialog.confirm.js +0 -27
  31. data/app/assets/javascripts/mui_app_rails/mui.dialog.prompt.js +0 -33
  32. data/app/assets/javascripts/mui_app_rails/mui.dialog.toast.js +0 -20
  33. data/app/assets/javascripts/mui_app_rails/mui.event.js +0 -160
  34. data/app/assets/javascripts/mui_app_rails/mui.fixed.animation.js +0 -22
  35. data/app/assets/javascripts/mui_app_rails/mui.fixed.classlist.js +0 -50
  36. data/app/assets/javascripts/mui_app_rails/mui.fixed.fastclick.js +0 -64
  37. data/app/assets/javascripts/mui_app_rails/mui.fixed.js +0 -40
  38. data/app/assets/javascripts/mui_app_rails/mui.fixed.keyboard.js +0 -56
  39. data/app/assets/javascripts/mui_app_rails/mui.gestures.drag.js +0 -48
  40. data/app/assets/javascripts/mui_app_rails/mui.gestures.flick.js +0 -30
  41. data/app/assets/javascripts/mui_app_rails/mui.gestures.hold.js +0 -41
  42. data/app/assets/javascripts/mui_app_rails/mui.gestures.js +0 -207
  43. data/app/assets/javascripts/mui_app_rails/mui.gestures.longtap.js +0 -43
  44. data/app/assets/javascripts/mui_app_rails/mui.gestures.swipe.js +0 -29
  45. data/app/assets/javascripts/mui_app_rails/mui.gestures.tap.js +0 -40
  46. data/app/assets/javascripts/mui_app_rails/mui.init.5+.js +0 -441
  47. data/app/assets/javascripts/mui_app_rails/mui.init.js +0 -100
  48. data/app/assets/javascripts/mui_app_rails/mui.init.pullrefresh.js +0 -57
  49. data/app/assets/javascripts/mui_app_rails/mui.jsonp.js +0 -108
  50. data/app/assets/javascripts/mui_app_rails/mui.layout.js +0 -22
  51. data/app/assets/javascripts/mui_app_rails/mui.namespace.js +0 -35
  52. data/app/assets/javascripts/mui_app_rails/mui.number.js +0 -93
  53. data/app/assets/javascripts/mui_app_rails/mui.offcanvas.js +0 -497
  54. data/app/assets/javascripts/mui_app_rails/mui.pullrefresh.js +0 -157
  55. data/app/assets/javascripts/mui_app_rails/mui.target.js +0 -58
  56. data/app/assets/javascripts/mui_app_rails/mui.view.js +0 -172
  57. data/app/assets/javascripts/mui_app_rails/popovers.js +0 -278
  58. data/app/assets/javascripts/mui_app_rails/pullrefresh.5+.js +0 -238
  59. data/app/assets/javascripts/mui_app_rails/push.js +0 -479
  60. data/app/assets/javascripts/mui_app_rails/segmented-controllers.js +0 -99
  61. data/app/assets/javascripts/mui_app_rails/sliders.js +0 -362
  62. data/app/assets/javascripts/mui_app_rails/switches.js +0 -165
  63. data/app/assets/javascripts/mui_app_rails/tableviews.js +0 -512
  64. data/app/assets/stylesheets/mui_app_rails/badges.scss +0 -88
  65. data/app/assets/stylesheets/mui_app_rails/bars.scss +0 -312
  66. data/app/assets/stylesheets/mui_app_rails/base.scss +0 -196
  67. data/app/assets/stylesheets/mui_app_rails/buttons.scss +0 -205
  68. data/app/assets/stylesheets/mui_app_rails/cards.scss +0 -62
  69. data/app/assets/stylesheets/mui_app_rails/forms.scss +0 -452
  70. data/app/assets/stylesheets/mui_app_rails/fullscreen.scss +0 -35
  71. data/app/assets/stylesheets/mui_app_rails/grid.scss +0 -75
  72. data/app/assets/stylesheets/mui_app_rails/hack.scss +0 -14
  73. data/app/assets/stylesheets/mui_app_rails/icon.scss +0 -170
  74. data/app/assets/stylesheets/mui_app_rails/iscroll.scss +0 -43
  75. data/app/assets/stylesheets/mui_app_rails/loadings.scss +0 -111
  76. data/app/assets/stylesheets/mui_app_rails/mixins.scss +0 -212
  77. data/app/assets/stylesheets/mui_app_rails/modals.scss +0 -34
  78. data/app/assets/stylesheets/mui_app_rails/mui.scss +0 -46
  79. data/app/assets/stylesheets/mui_app_rails/normalize.scss +0 -425
  80. data/app/assets/stylesheets/mui_app_rails/number.scss +0 -70
  81. data/app/assets/stylesheets/mui_app_rails/off-canvas.scss +0 -84
  82. data/app/assets/stylesheets/mui_app_rails/os.scss +0 -12
  83. data/app/assets/stylesheets/mui_app_rails/pagination.scss +0 -155
  84. data/app/assets/stylesheets/mui_app_rails/popovers.scss +0 -198
  85. data/app/assets/stylesheets/mui_app_rails/pullrefreshs.scss +0 -98
  86. data/app/assets/stylesheets/mui_app_rails/push.scss +0 -63
  87. data/app/assets/stylesheets/mui_app_rails/scroll.scss +0 -95
  88. data/app/assets/stylesheets/mui_app_rails/segmented-controls.scss +0 -150
  89. data/app/assets/stylesheets/mui_app_rails/slider-cell.scss +0 -20
  90. data/app/assets/stylesheets/mui_app_rails/sliders.scss +0 -133
  91. data/app/assets/stylesheets/mui_app_rails/switches.scss +0 -115
  92. data/app/assets/stylesheets/mui_app_rails/table-views.scss +0 -482
  93. data/app/assets/stylesheets/mui_app_rails/toast.scss +0 -16
  94. data/app/assets/stylesheets/mui_app_rails/type.scss +0 -23
  95. data/app/assets/stylesheets/mui_app_rails/variables.scss +0 -64
@@ -1,22 +0,0 @@
1
- /**
2
- * mui layout(offset[,position,width,height...])
3
- * @param {type} $
4
- * @param {type} window
5
- * @param {type} undefined
6
- * @returns {undefined}
7
- */
8
- (function($, window, undefined) {
9
- $.offset = function(element) {
10
- var box = {
11
- top : 0,
12
- left : 0
13
- };
14
- if ( typeof element.getBoundingClientRect !== undefined) {
15
- box = element.getBoundingClientRect();
16
- }
17
- return {
18
- top : box.top + window.pageYOffset - element.clientTop,
19
- left : box.left + window.pageXOffset - element.clientLeft
20
- };
21
- };
22
- })(mui, window);
@@ -1,35 +0,0 @@
1
- /**
2
- * mui namespace(optimization)
3
- * @param {type} $
4
- * @returns {undefined}
5
- */
6
- (function($) {
7
- $.namespace = 'mui';
8
- $.classNamePrefix = $.namespace + '-';
9
- $.classSelectorPrefix = '.' + $.classNamePrefix;
10
- /**
11
- * 返回正确的className
12
- * @param {type} className
13
- * @returns {String}
14
- */
15
- $.className = function(className) {
16
- return $.classNamePrefix + className;
17
- };
18
- /**
19
- * 返回正确的classSelector
20
- * @param {type} classSelector
21
- * @returns {String}
22
- */
23
- $.classSelector = function(classSelector) {
24
- return classSelector.replace(/\./g, $.classSelectorPrefix);
25
- };
26
- /**
27
- * 返回正确的eventName
28
- * @param {type} event
29
- * @param {type} module
30
- * @returns {String}
31
- */
32
- $.eventName = function(event, module) {
33
- return event + ($.namespace ? ('.' + $.namespace) : '') + ( module ? ('.' + module) : '');
34
- };
35
- })(mui);
@@ -1,93 +0,0 @@
1
- /**
2
- * 数字输入框
3
- * varstion 1.0.1
4
- * by Houfeng
5
- * Houfeng@DCloud.io
6
- */
7
-
8
- (function($) {
9
-
10
- var touchSupport = ('ontouchstart' in document);
11
- var tapEventName = touchSupport ? 'tap' : 'click';
12
- var changeEventName = 'change';
13
- var holderClassName = $.className('numbox');
14
- var plusClassName = $.className('numbox-btn-plus');
15
- var minusClassName = $.className('numbox-btn-minus');
16
- var inputClassName = $.className('numbox-input');
17
-
18
- var Numbox = $.Numbox = $.Class.extend({
19
- init: function(holder, options) {
20
- var self = this;
21
- options = options || {};
22
- options.step = parseInt(options.step || 1);
23
- self.options = options;
24
- self.holder = holder;
25
- self.input = $.qsa('.' + inputClassName, self.holder)[0];
26
- self.plus = $.qsa('.' + plusClassName, self.holder)[0];
27
- self.minus = $.qsa('.' + minusClassName, self.holder)[0];
28
- self.checkValue();
29
- self.initEvent();
30
- },
31
- initEvent: function() {
32
- var self = this;
33
- self.plus.addEventListener(tapEventName, function(event) {
34
- var val = parseInt(self.input.value) + self.options.step;
35
- self.input.value = val.toString();
36
- $.trigger(self.input, changeEventName, null);
37
- });
38
- self.minus.addEventListener(tapEventName, function(event) {
39
- var val = parseInt(self.input.value) - self.options.step;
40
- self.input.value = val.toString();
41
- $.trigger(self.input, changeEventName, null);
42
- });
43
- self.input.addEventListener(changeEventName, function(event) {
44
- self.checkValue();
45
- });
46
- },
47
- checkValue: function() {
48
- var self = this;
49
- var val = self.input.value;
50
- if (val == null || val == '' || isNaN(val)) {
51
- self.input.value = self.options.min || 0;
52
- self.minus.disabled = self.options.min != null;
53
- } else {
54
- var val = parseInt(val);
55
- if (self.options.max != null && !isNaN(self.options.max) && val >= parseInt(self.options.max)) {
56
- val = self.options.max;
57
- self.plus.disabled = true;
58
- } else {
59
- self.plus.disabled = false;
60
- }
61
- if (self.options.min != null && !isNaN(self.options.min) && val <= parseInt(self.options.min)) {
62
- val = self.options.min;
63
- self.minus.disabled = true;
64
- } else {
65
- self.minus.disabled = false;
66
- }
67
- self.input.value = val;
68
- }
69
- }
70
- });
71
-
72
- $.fn.numbox = function(options) {
73
- //遍历选择的元素
74
- this.each(function(i, element) {
75
- if (options) {
76
- new Numbox(element, options);
77
- } else {
78
- var optionsText = element.getAttribute('data-numbox-options');
79
- var options = optionsText ? JSON.parse(optionsText) : {};
80
- options.step = element.getAttribute('data-numbox-step') || options.step;
81
- options.min = element.getAttribute('data-numbox-min') || options.min;
82
- options.max = element.getAttribute('data-numbox-max') || options.max;
83
- new Numbox(element, options);
84
- }
85
- });
86
- return this;
87
- }
88
-
89
- //自动处理 class='mui-locker' 的 dom
90
- $.ready(function() {
91
- $('.' + holderClassName).numbox();
92
- });
93
- }(mui))
@@ -1,497 +0,0 @@
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');