vimo-dt
Version:
A Vue2.x UI Project For Mobile & HyBrid
115 lines (85 loc) • 4.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _loading = require('../loading/loading.vue');
var _loading2 = _interopRequireDefault(_loading);
var _GeneratePopUpInstance = require('../../util/GeneratePopUpInstance.js');
var _GeneratePopUpInstance2 = _interopRequireDefault(_GeneratePopUpInstance);
var _type = require('../../util/type');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var indicatorPresentWaitTime = 70;
var indicatorPresentThrottleTime = 500;
var indicatorDismissDebounceTime = 500;
var debounce = require('lodash.debounce');
var throttle = require('lodash.throttle');
var startTime = void 0;
var LoadingInstance = function (_GeneratePopUpInstanc) {
_inherits(LoadingInstance, _GeneratePopUpInstanc);
function LoadingInstance() {
_classCallCheck(this, LoadingInstance);
return _possibleConstructorReturn(this, (LoadingInstance.__proto__ || Object.getPrototypeOf(LoadingInstance)).apply(this, arguments));
}
_createClass(LoadingInstance, [{
key: 'normalizeOptions',
value: function normalizeOptions() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if ((0, _type.isString)(options)) {
options = { content: options };
}
var defaultOptions = {
isReverse: false,
dismissOnPageChange: false
};
if ((0, _type.isBlank)(options)) {
options = defaultOptions;
}
if ((0, _type.isObject)(options)) {
options = Object.assign({}, defaultOptions, options);
}
if ((0, _type.isBoolean)(options)) {
options = {
isReverse: options,
dismissOnPageChange: false
};
}
var cssClass = 'indicator';
if (options.isReverse) {
cssClass += ' reverse';
}
options.cssClass = cssClass;
options.showBackdrop = false;
options.scrollControl = false;
options.dismissOnPageChange = true;
options.mode = 'ios';
options.spinner = 'ios';
options.duration = 10000;
return options;
}
}]);
return LoadingInstance;
}(_GeneratePopUpInstance2.default);
var _present = LoadingInstance.prototype.present;
var _dismiss = LoadingInstance.prototype.dismiss;
var _dismissDebounce = debounce(_dismiss, indicatorDismissDebounceTime);
var _presentDebounce = debounce(throttle(_present, indicatorPresentThrottleTime, {
leading: true,
trailing: false
}), indicatorPresentWaitTime);
LoadingInstance.prototype.present = function () {
startTime = new Date().getTime();
_presentDebounce.call.apply(_presentDebounce, [this].concat(Array.prototype.slice.call(arguments)));
};
LoadingInstance.prototype.dismiss = function () {
var now = new Date().getTime();
if (now - startTime < indicatorPresentWaitTime) {
_presentDebounce.cancel();
} else {
_dismissDebounce.call(this);
}
};
exports.default = new LoadingInstance(_loading2.default, 'loadingPortal');