weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
108 lines (84 loc) • 3.03 kB
JavaScript
/** @jsx createElement */
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.show = show;
exports.hide = hide;
exports.confirm = confirm;
exports.alert = alert;
var _rax = require('rax');
var _nukeDom = require('../../Dom/index.js');
var _nukeDom2 = _interopRequireDefault(_nukeDom);
var _dialog = require('./dialog.js');
var _dialog2 = _interopRequireDefault(_dialog);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var noop = function noop() {};
var dialogInstance = null;
var container = null;
function show() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var onConfirm = arguments[1];
var onCancel = arguments[2];
var onShow = arguments[3];
var onFail = arguments[4];
onConfirm = onConfirm || noop;
onShow = onShow || noop;
onFail = onFail || noop;
onCancel = onCancel || noop;
var duration = options.duration,
maskClosable = options.maskClosable,
contentStyle = options.contentStyle,
onMaskPress = options.onMaskPress,
type = options.type,
locale = options.locale,
others = _objectWithoutProperties(options, ['duration', 'maskClosable', 'contentStyle', 'onMaskPress', 'type', 'locale']);
var attrs = {
duration: duration,
maskClosable: maskClosable,
contentStyle: contentStyle,
onShow: onShow,
onFail: onFail,
onMaskPress: onMaskPress,
type: type
};
if (locale) {
attrs.locale = locale;
}
var dialog = (0, _rax.createElement)(_dialog2.default, _extends({}, others, attrs));
if (options.container) {
container = (0, _rax.findDOMNode)(options.container);
}
if (!container) {
container = _nukeDom2.default.createEle('div', { t: 'id', abc: '_nuke_wrap' });
document.body.appendChild(container);
}
(0, _rax.render)(dialog, container, function () {
dialogInstance = this;
dialogInstance.wrappedInstance.show();
});
}
function hide() {
dialogInstance.wrappedInstance.hide();
}
function confirm() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments[1];
show(_extends({
maskClosable: false
}, options, {
showCancelButton: true,
showConfirmButton: true
}));
}
function alert() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments[1];
show(_extends({
maskClosable: false
}, options, {
showConfirmButton: true
}));
}