You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.6 KiB
62 lines
1.6 KiB
(function($, window) {
|
|
var CLASS_ACTIVE = $.className('active');
|
|
/**
|
|
* 自动消失提示框
|
|
*/
|
|
$.toast = function(message,options) {
|
|
var durations = {
|
|
'long': 3500,
|
|
'short': 2000
|
|
};
|
|
|
|
//计算显示时间
|
|
options = $.extend({
|
|
duration: 'short'
|
|
}, options || {});
|
|
|
|
|
|
if ($.os.plus && options.type !== 'div') {
|
|
//默认显示在底部;
|
|
$.plusReady(function() {
|
|
plus.nativeUI.toast(message, {
|
|
verticalAlign: 'bottom',
|
|
duration:options.duration
|
|
});
|
|
});
|
|
} else {
|
|
if (typeof options.duration === 'number') {
|
|
duration = options.duration>0 ? options.duration:durations['short'];
|
|
} else {
|
|
duration = durations[options.duration];
|
|
}
|
|
if (!duration) {
|
|
duration = durations['short'];
|
|
}
|
|
var toast = document.createElement('div');
|
|
toast.classList.add($.className('toast-container'));
|
|
toast.innerHTML = '<div class="' + $.className('toast-message') + '">' + message + '</div>';
|
|
toast.addEventListener('webkitTransitionEnd', function() {
|
|
if (!toast.classList.contains(CLASS_ACTIVE)) {
|
|
toast.parentNode.removeChild(toast);
|
|
toast = null;
|
|
}
|
|
});
|
|
//点击则自动消失
|
|
toast.addEventListener('click', function() {
|
|
toast.parentNode.removeChild(toast);
|
|
toast = null;
|
|
});
|
|
document.body.appendChild(toast);
|
|
toast.offsetHeight;
|
|
toast.classList.add(CLASS_ACTIVE);
|
|
setTimeout(function() {
|
|
toast && toast.classList.remove(CLASS_ACTIVE);
|
|
}, duration);
|
|
|
|
return {
|
|
isVisible: function() {return !!toast;}
|
|
}
|
|
}
|
|
};
|
|
|
|
})(mui, window); |