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

Function createPopup

examples/hello-mui/js/mui.js:7414–7488  ·  view source on GitHub ↗
(html, callback)

Source from the content-addressed store, hash-verified

7412 };
7413
7414 var createPopup = function(html, callback) {
7415 var popupElement = document.createElement('div');
7416 popupElement.className = CLASS_POPUP;
7417 popupElement.innerHTML = html;
7418 var removePopupElement = function() {
7419 popupElement.parentNode && popupElement.parentNode.removeChild(popupElement);
7420 popupElement = null;
7421 };
7422 popupElement.addEventListener($.EVENT_MOVE, $.preventDefault);
7423 popupElement.addEventListener('webkitTransitionEnd', function(e) {
7424 if (popupElement && e.target === popupElement && popupElement.classList.contains(CLASS_POPUP_OUT)) {
7425 removePopupElement();
7426 }
7427 });
7428 popupElement.style.display = 'block';
7429 document.body.appendChild(popupElement);
7430 popupElement.offsetHeight;
7431 popupElement.classList.add(CLASS_POPUP_IN);
7432
7433 if (!backdrop.classList.contains(CLASS_ACTIVE)) {
7434 backdrop.style.display = 'block';
7435 document.body.appendChild(backdrop);
7436 backdrop.offsetHeight;
7437 backdrop.classList.add(CLASS_ACTIVE);
7438 }
7439 var btns = $.qsa('.' + CLASS_POPUP_BUTTON, popupElement);
7440 var input = popupElement.querySelector('.' + CLASS_POPUP_INPUT + ' input');
7441 var popup = {
7442 element: popupElement,
7443 close: function(index, animate) {
7444 if (popupElement) {
7445 var result = callback && callback({
7446 index: index || 0,
7447 value: input && input.value || ''
7448 });
7449 if (result === false) { //返回false则不关闭当前popup
7450 return;
7451 }
7452 if (animate !== false) {
7453 popupElement.classList.remove(CLASS_POPUP_IN);
7454 popupElement.classList.add(CLASS_POPUP_OUT);
7455 } else {
7456 removePopupElement();
7457 }
7458 popupStack.pop();
7459 //如果还有其他popup,则不remove backdrop
7460 if (popupStack.length) {
7461 popupStack[popupStack.length - 1]['show'](animate);
7462 } else {
7463 backdrop.classList.remove(CLASS_ACTIVE);
7464 }
7465 }
7466 }
7467 };
7468 var handleEvent = function(e) {
7469 popup.close(btns.indexOf(e.target));
7470 };
7471 $(popupElement).on('tap', '.' + CLASS_POPUP_BUTTON, handleEvent);

Callers 3

createAlertFunction · 0.70
createConfirmFunction · 0.70
createPromptFunction · 0.70

Calls 3

callbackFunction · 0.85
removePopupElementFunction · 0.70
$Function · 0.70

Tested by

no test coverage detected