MCPcopy
hub / github.com/dcloudio/mui / togglePopover

Function togglePopover

js/popovers.js:100–149  ·  view source on GitHub ↗
(popover, anchor, state)

Source from the content-addressed store, hash-verified

98 });
99
100 var togglePopover = function(popover, anchor, state) {
101 if ((state === 'show' && popover.classList.contains(CLASS_ACTIVE)) || (state === 'hide' && !popover.classList.contains(CLASS_ACTIVE))) {
102 return;
103 }
104 removeBackdropTimer && removeBackdropTimer.cancel(); //取消remove的timer
105 //remove一遍,以免来回快速切换,导致webkitTransitionEnd不触发,无法remove
106 popover.removeEventListener('webkitTransitionEnd', onPopoverShown);
107 popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
108 backdrop.classList.remove(CLASS_BAR_BACKDROP);
109 backdrop.classList.remove(CLASS_ACTION_BACKDROP);
110 var _popover = document.querySelector($.classSelector('.popover.active'));
111 if (_popover) {
112 // _popover.setAttribute('style', '');
113 _popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
114 _popover.classList.remove(CLASS_ACTIVE);
115 // _popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
116 //同一个弹出则直接返回,解决同一个popover的toggle
117 if (popover === _popover) {
118 removeBackdrop(_popover);
119 return;
120 }
121 }
122 var isActionSheet = false;
123 if (popover.classList.contains(CLASS_BAR_POPOVER) || popover.classList.contains(CLASS_ACTION_POPOVER)) { //navBar
124 if (popover.classList.contains(CLASS_ACTION_POPOVER)) { //action sheet popover
125 isActionSheet = true;
126 backdrop.classList.add(CLASS_ACTION_BACKDROP);
127 } else { //bar popover
128 backdrop.classList.add(CLASS_BAR_BACKDROP);
129 // if (anchor) {
130 // if (anchor.parentNode) {
131 // var offsetWidth = anchor.offsetWidth;
132 // var offsetLeft = anchor.offsetLeft;
133 // var innerWidth = window.innerWidth;
134 // popover.style.left = (Math.min(Math.max(offsetLeft, defaultPadding), innerWidth - offsetWidth - defaultPadding)) + "px";
135 // } else {
136 // //TODO anchor is position:{left,top,bottom,right}
137 // }
138 // }
139 }
140 }
141 setStyle(popover, 'block'); //actionsheet transform
142 popover.offsetHeight;
143 popover.classList.add(CLASS_ACTIVE);
144 backdrop.setAttribute('style', '');
145 document.body.appendChild(backdrop);
146 calPosition(popover, anchor, isActionSheet); //position
147 backdrop.classList.add(CLASS_ACTIVE);
148 popover.addEventListener('webkitTransitionEnd', onPopoverShown);
149 };
150 var setStyle = function(popover, display, top, left) {
151 var style = popover.style;
152 if (typeof display !== 'undefined')

Callers 1

popovers.jsFile · 0.70

Calls 3

removeBackdropFunction · 0.70
setStyleFunction · 0.70
calPositionFunction · 0.70

Tested by

no test coverage detected