1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- (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);
|