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,157 +0,0 @@
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);
@@ -1,58 +0,0 @@
1
- /**
2
- * mui target(action>popover>modal>tab>toggle)
3
- */
4
- (function($, window, document) {
5
- /**
6
- * targets
7
- */
8
- $.targets = {};
9
- /**
10
- * target handles
11
- */
12
- $.targetHandles = [];
13
- /**
14
- * register target
15
- * @param {type} target
16
- * @returns {$.targets}
17
- */
18
- $.registerTarget = function(target) {
19
-
20
- target.index = target.index || 1000;
21
-
22
- $.targetHandles.push(target);
23
-
24
- $.targetHandles.sort(function(a, b) {
25
- return a.index - b.index;
26
- });
27
-
28
- return $.targetHandles;
29
- };
30
- window.addEventListener('touchstart', function(event) {
31
- var target = event.target;
32
- var founds = {};
33
- for (; target && target !== document; target = target.parentNode) {
34
- var isFound = false;
35
- $.each($.targetHandles, function(index, targetHandle) {
36
- var name = targetHandle.name;
37
- if (!isFound && !founds[name] && targetHandle.hasOwnProperty('handle')) {
38
- $.targets[name] = targetHandle.handle(event, target);
39
- if ($.targets[name]) {
40
- founds[name] = true;
41
- if (targetHandle.isContinue !== true) {
42
- isFound = true;
43
- }
44
- }
45
- } else {
46
- if (!founds[name]) {
47
- if (targetHandle.isReset !== false)
48
- $.targets[name] = false;
49
- }
50
- }
51
- });
52
- if (isFound) {
53
- break;
54
- }
55
- }
56
-
57
- });
58
- })(mui, window, document);
@@ -1,172 +0,0 @@
1
- /**
2
- * <div class=“mui-views">
3
- <div class=“mui-view">
4
- <div class=“mui-navbar">
5
- <div class=“mui-navbar-inner”>
6
- <div class=“mui-navbar-left”></div>
7
- <div class=“mui-navbar-center”></div>
8
- <div class=“mui-navbar-right”></div>
9
- </div>
10
- <div class=“mui-navbar-inner”>
11
- <div class=“mui-navbar-left”></div>
12
- <div class=“mui-navbar-center”></div>
13
- <div class=“mui-navbar-right”></div>
14
- </div>
15
- </div>
16
- <div class=“mui-pages”>
17
- <div class=“mui-page”>
18
- <div class=“mui-page-content"></div>
19
- </div>
20
- <div class=“mui-page”>
21
- <div class=“mui-page-content"></div>
22
- </div>
23
- </div>
24
- </div>
25
- </div>
26
- * @param {Object} $
27
- * @param {Object} window
28
- */
29
- (function($, window) {
30
- var CLASS_PAGE_LEFT = $.className('page-left');
31
- var CLASS_PAGE_CENTER = $.className('page-center');
32
-
33
- var CLASS_TRANSITIONING = $.className('transitioning');
34
-
35
- var SELECTOR_NAVBAR = $.classSelector('.navbar');
36
- var SELECTOR_PAGES = $.classSelector('.pages');
37
- var SELECTOR_PAGE_LEFT = '.' + CLASS_PAGE_LEFT;
38
- var SELECTOR_PAGE_CENTER = '.' + CLASS_PAGE_CENTER;
39
-
40
- var View = $.Class.extend({
41
- init: function(element, options) {
42
- this.view = this.element;
43
-
44
- this.options = $.extend({
45
- swipeBackPageActiveArea: 30,
46
- hardwareAccelerated: true
47
- }, options);
48
-
49
- this.navbars = this.querySelector(SELECTOR_NAVBAR);
50
- this.pages = this.querySelector(SELECTOR_PAGES);
51
-
52
- this.maxScrollX = this.view.offsetWidth;
53
- this.x = this.y = 0;
54
- this.translateZ = this.options.hardwareAccelerated ? ' translateZ(0)' : '';
55
- this.moved = this.dragging = false;
56
- this.activePage = this.previousPage = null;
57
-
58
- this.initEvent();
59
- },
60
- initEvent: function() {
61
- this.view.addEventListener('drag', this);
62
- this.view.addEventListener('dragend', this);
63
- },
64
- handleEvent: function(event) {
65
- switch (e.type) {
66
- case 'drag':
67
- this._drag(event);
68
- break;
69
- case 'dragend':
70
- this._dragend(event);
71
- break;
72
- }
73
- },
74
- _drag: function(event) {
75
- var detail = event.detail;
76
- if (!this.dragging) {
77
- if ((detail.start.x - this.view.offsetLeft) < this.options.swipeBackPageActiveArea) {
78
- this.previousPage = this.pages.querySelector(SELECTOR_PAGE_LEFT);
79
- this.activePage = this.pages.querySelector(SELECTOR_PAGE_CENTER);
80
- this.previousPageStyle = this.previousPage.style;
81
- this.activePageStyle = this.activePage.style;
82
-
83
- this.previousPage.classList.remove(CLASS_TRANSITIONING);
84
- this.activePage.classList.remove(CLASS_TRANSITIONING);
85
-
86
- if (this.previousPage && this.activePage) {
87
- this.dragging = true;
88
- $.gestures.touch.lockDirection = true; //锁定方向
89
- $.gestures.touch.startDirection = detail.direction;
90
- }
91
- }
92
- }
93
- if (this.dragging) {
94
- var deltaX = 0;
95
- if (!this.moved) { //start
96
- deltaX = detail.deltaX;
97
- } else { //move
98
- deltaX = detail.deltaX - detail.lastDeltaX;
99
- }
100
-
101
- var newX = this.x + deltaX;
102
-
103
- if (newX > 0 || newX < this.maxScrollX) {
104
- newX = newX > 0 ? 0 : this.maxScrollX;
105
- }
106
-
107
- event.stopPropagation();
108
- detail.gesture.preventDefault();
109
-
110
- if (!this.requestAnimationFrame) {
111
- this._updateTranslate();
112
- }
113
-
114
- this.moved = true;
115
- this.x = newX;
116
- this.y = 0;
117
- }
118
- },
119
- _dragend: function(event) {
120
- if (!this.dragging) {
121
- this.dragging = this.moved = false;
122
-
123
- event.stopPropagation();
124
-
125
- var detail = event.detail;
126
-
127
- this._clearRequestAnimationFrame();
128
-
129
- this.previousPage.classList.add(CLASS_TRANSITIONING);
130
- this.activePage.classList.add(CLASS_TRANSITIONING);
131
-
132
-
133
-
134
- return;
135
- }
136
- },
137
- _clearRequestAnimationFrame: function() {
138
- if (this.requestAnimationFrame) {
139
- cancelAnimationFrame(this.requestAnimationFrame);
140
- this.requestAnimationFrame = null;
141
- }
142
- },
143
- _getTranslateStr: function(x, y) {
144
- if (this.options.hardwareAccelerated) {
145
- return 'translate3d(' + x + 'px,' + y + 'px,0px) ' + this.translateZ;
146
- }
147
- return 'translate(' + x + 'px,' + y + 'px) ';
148
- },
149
-
150
- _updateTranslate: function() {
151
- var self = this;
152
- if (self.x !== self.lastX || self.y !== self.lastY) {
153
- self.setTranslate(self.x, self.y);
154
- }
155
- self.requestAnimationFrame = requestAnimationFrame(function() {
156
- self._updateTranslate();
157
- });
158
- },
159
- setTranslate: function(x, y) {
160
- this.x = x;
161
- this.y = y;
162
- this.previousPageStyle['webkitTransform'] = this._getTranslateStr(x, y);
163
- this.activePageStyle['webkitTransform'] = this._getTranslateStr(x, y);
164
-
165
- if (this.navbars) {
166
- this.navbars.setTranslate(x, y);
167
- }
168
- this.lastX = this.x;
169
- this.lastY = this.y;
170
- },
171
- });
172
- })(mui, window);
@@ -1,278 +0,0 @@
1
- /**
2
- * Popovers
3
- * @param {type} $
4
- * @param {type} window
5
- * @param {type} document
6
- * @param {type} name
7
- * @param {type} undefined
8
- * @returns {undefined}
9
- */
10
- (function($, window, document, name) {
11
-
12
- var CLASS_POPOVER = $.className('popover');
13
- var CLASS_POPOVER_ARROW = $.className('popover-arrow');
14
- var CLASS_ACTION_POPOVER = $.className('popover-action');
15
- var CLASS_BACKDROP = $.className('backdrop');
16
- var CLASS_BAR_POPOVER = $.className('bar-popover');
17
- var CLASS_BAR_BACKDROP = $.className('bar-backdrop');
18
- var CLASS_ACTION_BACKDROP = $.className('backdrop-action');
19
- var CLASS_ACTIVE = $.className('active');
20
- var CLASS_BOTTOM = $.className('bottom');
21
-
22
-
23
-
24
- var handle = function(event, target) {
25
- if (target.tagName === 'A' && target.hash) {
26
- $.targets._popover = document.getElementById(target.hash.replace('#', ''));
27
- if ($.targets._popover && $.targets._popover.classList.contains(CLASS_POPOVER)) {
28
- return target;
29
- } else {
30
- $.targets._popover = null;
31
- }
32
- }
33
- return false;
34
- };
35
-
36
- $.registerTarget({
37
- name: name,
38
- index: 60,
39
- handle: handle,
40
- target: false,
41
- isReset: false,
42
- isContinue: true
43
- });
44
-
45
- var fixedPopoverScroll = function(isPopoverScroll) {
46
- // if (isPopoverScroll) {
47
- // document.body.setAttribute('style', 'overflow:hidden;');
48
- // } else {
49
- // document.body.setAttribute('style', '');
50
- // }
51
- };
52
- var onPopoverShown = function(e) {
53
- this.removeEventListener('webkitTransitionEnd', onPopoverShown);
54
- this.addEventListener('touchmove', $.preventDefault);
55
- $.trigger(this, 'shown', this);
56
- }
57
- var onPopoverHidden = function(e) {
58
- setStyle(this,'none');
59
- this.removeEventListener('webkitTransitionEnd', onPopoverHidden);
60
- this.removeEventListener('touchmove', $.preventDefault);
61
- fixedPopoverScroll(false);
62
- $.trigger(this, 'hidden', this);
63
- };
64
-
65
- var backdrop = (function() {
66
- var element = document.createElement('div');
67
- element.classList.add(CLASS_BACKDROP);
68
- element.addEventListener('touchmove', $.preventDefault);
69
- element.addEventListener('tap', function(e) {
70
- var popover = $.targets._popover;
71
- if (popover) {
72
- popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
73
- popover.classList.remove(CLASS_ACTIVE);
74
- removeBackdrop(popover);
75
- document.body.setAttribute('style', ''); //webkitTransitionEnd有时候不触发?
76
- }
77
- });
78
-
79
- return element;
80
- }());
81
- var removeBackdrop = function(popover) {
82
- backdrop.setAttribute('style', 'opacity:0');
83
- $.targets.popover = $.targets._popover = null; //reset
84
- setTimeout(function() {
85
- if (!popover.classList.contains(CLASS_ACTIVE) && backdrop.parentNode && backdrop.parentNode === document.body) {
86
- document.body.removeChild(backdrop);
87
- }
88
- }, 350);
89
- };
90
- window.addEventListener('tap', function(e) {
91
- if (!$.targets.popover) {
92
- return;
93
- }
94
- var toggle = false;
95
- var target = e.target;
96
- for (; target && target !== document; target = target.parentNode) {
97
- if (target === $.targets.popover) {
98
- toggle = true;
99
- }
100
- }
101
- if (toggle) {
102
- e.detail.gesture.preventDefault(); //fixed hashchange
103
- togglePopover($.targets._popover, $.targets.popover);
104
- }
105
-
106
- });
107
-
108
- var togglePopover = function(popover, anchor) {
109
- //remove一遍,以免来回快速切换,导致webkitTransitionEnd不触发,无法remove
110
- popover.removeEventListener('webkitTransitionEnd', onPopoverShown);
111
- popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
112
- backdrop.classList.remove(CLASS_BAR_BACKDROP);
113
- backdrop.classList.remove(CLASS_ACTION_BACKDROP);
114
- var _popover = document.querySelector($.classSelector('.popover.active'));
115
- if (_popover) {
116
- // _popover.setAttribute('style', '');
117
- _popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
118
- _popover.classList.remove(CLASS_ACTIVE);
119
- // _popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
120
- // fixedPopoverScroll(false);
121
- //同一个弹出则直接返回,解决同一个popover的toggle
122
- if (popover === _popover) {
123
- removeBackdrop(_popover);
124
- return;
125
- }
126
- }
127
- var isActionSheet = false;
128
- if (popover.classList.contains(CLASS_BAR_POPOVER) || popover.classList.contains(CLASS_ACTION_POPOVER)) { //navBar
129
- if (popover.classList.contains(CLASS_ACTION_POPOVER)) { //action sheet popover
130
- isActionSheet = true;
131
- backdrop.classList.add(CLASS_ACTION_BACKDROP);
132
- } else { //bar popover
133
- backdrop.classList.add(CLASS_BAR_BACKDROP);
134
- // if (anchor) {
135
- // if (anchor.parentNode) {
136
- // var offsetWidth = anchor.offsetWidth;
137
- // var offsetLeft = anchor.offsetLeft;
138
- // var innerWidth = window.innerWidth;
139
- // popover.style.left = (Math.min(Math.max(offsetLeft, defaultPadding), innerWidth - offsetWidth - defaultPadding)) + "px";
140
- // } else {
141
- // //TODO anchor is position:{left,top,bottom,right}
142
- // }
143
- // }
144
- }
145
- }
146
- setStyle(popover, 'block'); //actionsheet transform
147
- popover.offsetHeight;
148
- popover.classList.add(CLASS_ACTIVE);
149
- backdrop.setAttribute('style', '');
150
- document.body.appendChild(backdrop);
151
- fixedPopoverScroll(true);
152
- calPosition(popover, anchor, isActionSheet); //position
153
- backdrop.classList.add(CLASS_ACTIVE);
154
- popover.addEventListener('webkitTransitionEnd', onPopoverShown);
155
- };
156
- var setStyle = function(popover, display, top, left) {
157
- var style = popover.style;
158
- if (typeof display !== 'undefined')
159
- style.display = display;
160
- if (typeof top !== 'undefined')
161
- style.top = top + 'px';
162
- if (typeof left !== 'undefined')
163
- style.left = left + 'px';
164
- };
165
- var calPosition = function(popover, anchor, isActionSheet) {
166
- if (!popover || !anchor) {
167
- return;
168
- }
169
- var wWidth = window.innerWidth;
170
- var wHeight = window.innerHeight;
171
-
172
- var pWidth = popover.offsetWidth;
173
- var pHeight = popover.offsetHeight;
174
- if (isActionSheet) { //actionsheet
175
- setStyle(popover, 'block', (wHeight - pHeight + window.pageYOffset), (wWidth - pWidth) / 2)
176
- return;
177
- }
178
- var aWidth = anchor.offsetWidth;
179
- var aHeight = anchor.offsetHeight;
180
- var offset = $.offset(anchor);
181
-
182
- var arrow = popover.querySelector('.' + CLASS_POPOVER_ARROW);
183
- if (!arrow) {
184
- arrow = document.createElement('div');
185
- arrow.className = CLASS_POPOVER_ARROW;
186
- popover.appendChild(arrow);
187
- }
188
- var arrowSize = arrow && arrow.offsetWidth / 2 || 0;
189
-
190
-
191
-
192
- var pTop = 0;
193
- var pLeft = 0;
194
- var diff = 0;
195
- var arrowLeft = 0;
196
- var defaultPadding = popover.classList.contains(CLASS_ACTION_POPOVER) ? 0 : 5;
197
-
198
- var position = 'top';
199
- if ((pHeight + arrowSize) < (offset.top - window.pageYOffset)) { //top
200
- pTop = offset.top - pHeight - arrowSize;
201
- } else if ((pHeight + arrowSize) < (wHeight - (offset.top - window.pageYOffset) - aHeight)) { //bottom
202
- position = 'bottom';
203
- pTop = offset.top + aHeight + arrowSize;
204
- } else { //middle
205
- position = 'middle';
206
- pTop = Math.max((wHeight - pHeight) / 2 + window.pageYOffset, 0);
207
- pLeft = Math.max((wWidth - pWidth) / 2 + window.pageXOffset, 0);
208
- }
209
- if (position === 'top' || position === 'bottom') {
210
- pLeft = aWidth / 2 + offset.left - pWidth / 2;
211
- diff = pLeft;
212
- if (pLeft < defaultPadding) pLeft = defaultPadding;
213
- if (pLeft + pWidth > wWidth) pLeft = wWidth - pWidth - defaultPadding;
214
-
215
- if (arrow) {
216
- if (position === 'top') {
217
- arrow.classList.add(CLASS_BOTTOM);
218
- } else {
219
- arrow.classList.remove(CLASS_BOTTOM);
220
- }
221
- diff = diff - pLeft;
222
- arrowLeft = (pWidth / 2 - arrowSize / 2 + diff);
223
- arrowLeft = Math.max(Math.min(arrowLeft, pWidth - arrowSize * 2 - 6), 6);
224
- arrow.setAttribute('style', 'left:' + arrowLeft + 'px');
225
- }
226
- } else if (position === 'middle') {
227
- arrow.setAttribute('style', 'display:none');
228
- }
229
- setStyle(popover, 'block', pTop, pLeft);
230
- };
231
-
232
- $.createMask = function(callback) {
233
- var element = document.createElement('div');
234
- element.classList.add(CLASS_BACKDROP);
235
- element.addEventListener('touchmove', $.preventDefault);
236
- element.addEventListener('tap', function() {
237
- mask.close();
238
- });
239
- var mask = [element];
240
- mask._show = false;
241
- mask.show = function() {
242
- mask._show = true;
243
- element.setAttribute('style', 'opacity:1');
244
- document.body.appendChild(element);
245
- return mask;
246
- };
247
- mask._remove = function() {
248
- if (mask._show) {
249
- mask._show = false;
250
- element.setAttribute('style', 'opacity:0');
251
- setTimeout(function() {
252
- document.body.removeChild(element);
253
- }, 350);
254
- }
255
- return mask;
256
- };
257
- mask.close = function() {
258
- if (callback) {
259
- if (callback() !== false) {
260
- mask._remove();
261
- }
262
- } else {
263
- mask._remove();
264
- }
265
- };
266
- return mask;
267
- };
268
- $.fn.popover = function() {
269
- var args = arguments;
270
- this.each(function() {
271
- $.targets._popover = this;
272
- if (args[0] === 'show' || args[0] === 'hide' || args[0] === 'toggle') {
273
- togglePopover(this, args[1]);
274
- }
275
- });
276
- };
277
-
278
- })(mui, window, document, 'popover');