landers.response
Version:
landers.response
642 lines (581 loc) • 28.9 kB
JavaScript
;(function (root, jQuery, factory) {
if (typeof exports === 'object' && typeof module !== 'undefined') {
// CommonJS、CMD规范检查
module.exports = factory(jQuery);
} else if (typeof define === 'function' && define.amd) {
// AMD规范检查
define(factory);
} else {
root.Landers = root.Landers || {};
// 浏览器注册全局对象
Landers.animate = factory(jQuery);
}
})(this, jQuery, (function ($) {
var CALLBACKS = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oAnimationEnd animationend';
function random_number(n1, n2){
var max = Math.max(n1,n2),
min = Math.min(n1,n2);
return parseInt(Math.random()*(max-min+1)) + min;
}
/**
* [visible description]
* @return {[type]} [description]
*/
$.fn.visible = function(){
return $(this).css('visibility', 'visible');
};
/**
* [hidden description]
* @return {[type]} [description]
*/
$.fn.hidden = function(){
return $(this).css('visibility', 'hidden');
};
/**
* [boxsize description]
* @param {[type]} size [description]
* @return {[type]} [description]
*/
$.fn.boxsize = function(size) {
if (size) {
$(this).width(size.width).height(size.height);
return this;
} else {
return {
width: $(this).width(), height: $(this).height()
}
}
};
return {
effects:{
'default' : {'in':'scaleUp', out:'scaleDown', random:true},
//fade
'fade1': {'in':'fadeIn', out:'fadeOut', 'duration-out':300, random:true},
'fade2' : {'in':'pop_fadein', out:'pop_fadeout', random:true},
'fade3' : {'in':'scaleUp', out:'pop_fadeout', random:true},
'fade4' : {'in':'pop_fadein', out:'scaleDown', random:true},
//zoom
'zoom1': {'in':'scaleUp', out:'scaleDown', random:true},
'zoom2': {'in':'zoomIn', out:'zoomOut', duration:500, random:true},
'zoom3' : {'in':'pop_fadein3x', out:'pop_fadeout3x', random:true},
'zoom4': {'in':'zoomInDown', out:'zoomOutDown'},
'zoom5': {'in':'zoomInUp', out:'zoomOutUp'},
'zoom6': {'in':'zoomInLeft', out:'zoomOutRight'},
'zoom7': {'in':'zoomInRight', out:'zoomOutLeft'},
'zoom8': {'in':'bounceIn', out:'bounceOut', duration:500, random:true},
//hmove
'hmove1': {'in':'bounceInLeft', out:'bounceOutRight', 'duration-in':500, 'duration-out':1000, random:true},
'hmove2': {'in':'fadeInLeft', out:'fadeOutRight', 'duration-in':500, 'duration-out':300, random:true},
'hmove3': {'in':'slideInRight', out:'slideOutRight', 'duration-in':500, 'duration-out':400},
'hmove4': {'in':'slideInLeft', out:'slideOutLeft', 'duration-in':500, 'duration-out':400},
//vmove
'vmove1': {'in':'bounceInDown', out:'bounceOutDown', 'duration-in':500, 'duration-out':1000, random:true},
'vmove2': {'in':'fadeInDown', out:'fadeOutUp', 'duration-in':200, 'duration-out':300, random:true},
//hflip
'hflip1': {'in':'flipInY', out:'flipOutY', duration:600},
'hflip2': {'in':'flip', out:'scaleDown', 'duration-out':500},
//vflip
'vflip1': {'in':'flipInX', out:'flipOutX', duration:600, random:true},
//rotate
'rotate1': {'in':'rotateIn', out:'rotateOut', duration:500},
'rotate2': {'in':'rotateInUpLeft', out:'rotateOutUpRight', duration:500, random:true},
'rotate3': {'in':'rotateInDownLeft', out:'rotateOutUpRight', duration:500},
'rotate4': {'in':'rotateInNewspaper', out:'rotateOutNewspaper'},
//roll
'roll1': {'in':'rollIn', out:'rollOut', duration:500},
//flash
'flash1': {'in':'flash', out:'flash', duration:500}
},
random:function(){
var keys = [];
for (var i in this.effects) {
if (this.effects[i].random) keys.push(i);
}
var n = random_number(0, keys.length-1);
return keys[n];
},
attach:function(xo, xclass, duration, callback){
var me = this;
var $o = $(xo).show().visible().removeClass(xclass);
xclass += ' animated';
if (duration) {
$o.css({'animation-duration': duration + 'ms' });
$o.css({'transition-duration': duration + 'ms' });
}
$o.addClass(xclass).one(CALLBACKS, function(){
$o.removeClass(xclass);
callback && callback();
});
},
show:function(xin, effect, callback) {
var effects = this.effects[effect || 'default'];
var class_in = effects['in'];
var duration = effects['duration-in'] || effects['duration'];
this.attach(xin, class_in, duration, function(){
$(xin).show();
callback && callback();
});
},
hide:function(xout, effect, callback){
var effects = this.effects[effect || 'default'];
var class_out = effects['out'];
var duration = effects['duration-out'] || effects['duration'];
this.attach(xout, class_out, duration, function(){
$(xout).hide();
callback && callback();
});
},
transitive:function(xout, effect_out, xin, effect_in, callback, is_sync){
var me = this;
effect_out = effect_out || 'default';
effect_in = effect_in || 'default';
if (is_sync) {
me.hide(xout, effect_out);
me.show(xin, effect_in, function(){
callback && callback();
});
} else {
me.hide(xout, effect_out, function(){
me.show(xin, effect_in, function(){
callback && callback();
});
});
}
}
};
}));
; (function (window, jq) {
window.Landers = window.Landers || {};
function case_one_argument(arg){
var content = '';
if (jq.isPlainObject(arg)){
var arr = [];
for (var k in arg) {
arr.push(k + ' ' + arg[k]);
}
content = arr.join('\n');
} else if (jq.isArray(arg)) {
content = arg.join('\n');
} else {
content = arg;
}
return content;
}
function case_two_arguments(arg1, arg2) {
var content = '';
if (jq.isPlainObject(arg2)){
var arr = [];
for (var k in arg2) {
arr.push(k + ':' + arg2[k]);
}
content = arr.join(';');
} else if (jq.isArray(arg2)) {
content = arg2.join(';');
} else {
content = arg2;
}
return arg1 + ' {' + content + '}';
}
function append_style(content){
try {
//高版本浏览器
var $head = jq('head', window.document);
var $style = jq('<style></style>')
.appendTo($head)
.attr({type:'text/css'});
$style.append('\n' + content + '\n');
} catch(e) {
//低版本浏览器,如ie8
var sheets = document.styleSheets;
var sheet = sheets[0] || document.createStyleSheet();
var arr = content.match(/(.*?)\{(.*?)\}/g);
if (arr) {
for (var i=0; i<arr.length; i++) {
var match = arr[i].match(/(.*?)\{(.*?)\}/);
var k = jq.trim(match[1]),
v = jq.trim(match[2]);
sheet.addRule(k, v);
}
}
}
}
Landers.css = Landers.css || {
add:function(){
var content;
// 一个参数情况
if (arguments.length == 1) {
content = case_one_argument(arguments[0]);
}
// 两个参数情况
if (arguments.length == 2) {
content = case_two_arguments(arguments[0], arguments[1]);
}
append_style(content);
},
remove:function(k){
this.add(k, '');
}
};
})(window, jQuery);
;(function (root, jQuery, factory) {
if (typeof exports === 'object' && typeof module !== 'undefined') {
// CommonJS、CMD规范检查
module.exports = factory(jQuery);
} else if (typeof define === 'function' && define.amd) {
// AMD规范检查
define(factory);
} else {
root.Landers = root.Landers || {};
// 浏览器注册全局对象
Landers.parseArgs = factory(jQuery);
}
})(this, jQuery, (function ($) {
function get_type(xvar){
if (xvar instanceof $) {
return 'jobject';
}
if ($.isPlainObject(xvar)) {
return 'json';
}
if ($.isArray(xvar)) {
return 'array';
}
return typeof xvar;
}
return function(args, maps){
var ret = {}, enums;
maps = maps || {};
//找出enum项
for(var k in maps) {
var arr = k.match(/^__ENUM:(.*)$/);
if (arr) {
enums = enums || {};
enums[k] = eval('(' + arr[1] + ')');
}
}
for (var i=0; i<args.length; i++) {
var type = get_type(args[i]);
if (enums && (type == 'string' || type == 'number')) {
var tmp = false;
for (var j in enums) {
if ($.inArray(args[i], enums[j])) {
ret[maps[j]] = args[i];
delete enums[j];
tmp = true;
}
}
if (tmp) continue;
}
if (maps[type]) {
ret[maps[type]] = args[i];
} else {
ret[type] = args[i];
}
};
return ret;
}
}));
//Spiner
!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.Spinner=b()}(this,function(){"use strict";function a(a,b){var c,d=document.createElement(a||"div");for(c in b)d[c]=b[c];return d}function b(a){for(var b=1,c=arguments.length;c>b;b++)a.appendChild(arguments[b]);return a}function c(a,b,c,d){var e=["opacity",b,~~(100*a),c,d].join("-"),f=.01+c/d*100,g=Math.max(1-(1-a)/b*(100-f),a),h=j.substring(0,j.indexOf("Animation")).toLowerCase(),i=h&&"-"+h+"-"||"";return l[e]||(m.insertRule("@"+i+"keyframes "+e+"{0%{opacity:"+g+"}"+f+"%{opacity:"+a+"}"+(f+.01)+"%{opacity:1}"+(f+b)%100+"%{opacity:"+a+"}100%{opacity:"+g+"}}",m.cssRules.length),l[e]=1),e}function d(a,b){var c,d,e=a.style;for(b=b.charAt(0).toUpperCase()+b.slice(1),d=0;d<k.length;d++)if(c=k[d]+b,void 0!==e[c])return c;return void 0!==e[b]?b:void 0}function e(a,b){for(var c in b)a.style[d(a,c)||c]=b[c];return a}function f(a){for(var b=1;b<arguments.length;b++){var c=arguments[b];for(var d in c)void 0===a[d]&&(a[d]=c[d])}return a}function g(a,b){return"string"==typeof a?a:a[b%a.length]}function h(a){this.opts=f(a||{},h.defaults,n)}function i(){function c(b,c){return a("<"+b+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',c)}m.addRule(".spin-vml","behavior:url(#default#VML)"),h.prototype.lines=function(a,d){function f(){return e(c("group",{coordsize:k+" "+k,coordorigin:-j+" "+-j}),{width:k,height:k})}function h(a,h,i){b(m,b(e(f(),{rotation:360/d.lines*a+"deg",left:~~h}),b(e(c("roundrect",{arcsize:d.corners}),{width:j,height:d.width,left:d.radius,top:-d.width>>1,filter:i}),c("fill",{color:g(d.color,a),opacity:d.opacity}),c("stroke",{opacity:0}))))}var i,j=d.length+d.width,k=2*j,l=2*-(d.width+d.length)+"px",m=e(f(),{position:"absolute",top:l,left:l});if(d.shadow)for(i=1;i<=d.lines;i++)h(i,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(i=1;i<=d.lines;i++)h(i);return b(a,m)},h.prototype.opacity=function(a,b,c,d){var e=a.firstChild;d=d.shadow&&d.lines||0,e&&b+d<e.childNodes.length&&(e=e.childNodes[b+d],e=e&&e.firstChild,e=e&&e.firstChild,e&&(e.opacity=c))}}var j,k=["webkit","Moz","ms","O"],l={},m=function(){var c=a("style",{type:"text/css"});return b(document.getElementsByTagName("head")[0],c),c.sheet||c.styleSheet}(),n={lines:12,length:7,width:5,radius:10,rotate:0,corners:1,color:"#000",direction:1,speed:1,trail:100,opacity:.25,fps:20,zIndex:2e9,className:"iSpinner",top:"50%",left:"50%",position:"absolute"};h.defaults={},f(h.prototype,{spin:function(b){this.stop();{var c=this,d=c.opts,f=c.el=e(a(0,{className:d.className}),{position:d.position,width:0,zIndex:d.zIndex});d.radius+d.length+d.width}if(e(f,{left:d.left,top:d.top}),b&&b.insertBefore(f,b.firstChild||null),f.setAttribute("role","progressbar"),c.lines(f,c.opts),!j){var g,h=0,i=(d.lines-1)*(1-d.direction)/2,k=d.fps,l=k/d.speed,m=(1-d.opacity)/(l*d.trail/100),n=l/d.lines;!function o(){h++;for(var a=0;a<d.lines;a++)g=Math.max(1-(h+(d.lines-a)*n)%l*m,d.opacity),c.opacity(f,a*d.direction+i,g,d);c.timeout=c.el&&setTimeout(o,~~(1e3/k))}()}return c},stop:function(){var a=this.el;return a&&(clearTimeout(this.timeout),a.parentNode&&a.parentNode.removeChild(a),this.el=void 0),this},lines:function(d,f){function h(b,c){return e(a(),{position:"absolute",width:f.length+f.width+"px",height:f.width+"px",background:b,boxShadow:c,transformOrigin:"left",transform:"rotate("+~~(360/f.lines*k+f.rotate)+"deg) translate("+f.radius+"px,0)",borderRadius:(f.corners*f.width>>1)+"px"})}for(var i,k=0,l=(f.lines-1)*(1-f.direction)/2;k<f.lines;k++)i=e(a(),{position:"absolute",top:1+~(f.width/2)+"px",transform:f.hwaccel?"translate3d(0,0,0)":"",opacity:f.opacity,animation:j&&c(f.opacity,f.trail,l+k*f.direction,f.lines)+" "+1/f.speed+"s linear infinite"}),f.shadow&&b(i,e(h("#000","0 0 4px #000"),{top:"2px"})),b(d,b(i,h(g(f.color,k),"0 0 1px rgba(0,0,0,.1)")));return d},opacity:function(a,b,c){b<a.childNodes.length&&(a.childNodes[b].style.opacity=c)}});var o=e(a("group"),{behavior:"url(#default#VML)"});return!d(o,"transform")&&o.adj?i():j=d(o,"animation"),h});
; (function (window, jq) {
window.Landers = window.Landers || {};
var classname = 'landers-response';
var sizes = {
big: {width:120, height:120, icon_size:90, text_size: 18, text_bottom: 10},
small: {width:70, height:70, icon_size:54, text_size: 12, text_bottom: 4},
long: {width:200, height:75, icon_size:54, text_size: 13, text_bottom: 7},
xlong: {width:300, height:75, icon_size:54, text_size: 13, text_bottom: 7}
};
function parse_args(args){
var ret = Landers.parseArgs(args, {
'number' : 'delay',
'jobject': 'wrap',
'array' : 'data',
'json' : 'data',
'string' : 'size',
'function': 'callback',
});
ret.wrap = ret.wrap || jq('body');
return ret;
}
function str_len(s) {
return s.replace(/[\u0391-\uFFE5]/g,' ').length;
}
function is_mobile(){
return navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i);
}
/**
* [overlay description]
* @param {[type]} act [description]
* @param {[type]} opts [description]
* @return {[type]} [description]
*/
jq.fn.overlay = jq.fn.overlay || function(act, opts) {
act = act.toLowerCase();
opts = opts || {};
var $jq = $(this),
delay = 300,
data_key = 'overlay';
if (!$.isWindow($jq.get(0)) && !$jq.get(0).tagName.toLowerCase() == 'body') {
$jq.css({ position: 'relative' });
};
switch (act) {
case 'show':
var mysize = {
width: $jq.width(),
height: $jq.height(),
scroll_width: $jq.get(0).scrollWidth,
scroll_height: $jq.get(0).scrollHeight
};
var opacity = opts.alpha || opts.opacity;
if (opacity === undefined) opacity = 0.2;
if (opacity > 1) opacity = opacity / 100;
$jq.data(data_key, $('<div></div>').css({
width: '100%',
height: Math.max(mysize.height, mysize.scroll_height),
position: 'absolute',
left: '0px',
top: '0px',
filter: 'alpha(opacity=' + (opacity * 100) + ')',
opacity: opacity,
'background-color': opts.bgcolor || '#000000',
'z-index': opts.zindex || 4001
}).appendTo($jq).fadeIn(delay));
break;
case 'hide':
$($jq.data(data_key)).fadeOut(delay, function() { $(this).remove(); });
$jq.data(data_key, null);
}
return this;
};
/**
* [setCenter description]
*/
$.fn.setCenter = $.fn.setCenter || function() {
var $jq = $(this);
$jq.css({
'text-align': 'center',
'vertical-align': 'middle',
'left': '50%',
'top': '50%'
});
var pos = $jq.css('position');
if (pos == 'absolute' || pos == 'fixed') {
$jq.css({
'margin-left': -$jq.width() / 2 + 'px',
'margin-top': -$jq.height() / 2 + 'px'
});
} else {
$jq.css({
magin: '0 auto'
});
};
return $jq;
};
/**
* [showSpin description]
* @param {[type]} opts [description]
* @return {[type]} [description]
*/
$.fn.showSpin = function(opts) {
this.each(function() {
var $this = $(this),
data = $this.data();
if (data.spinner) {
data.spinner.stop();
delete data.spinner;
}
if (opts !== false) {
opts = $.extend({ color: $this.css('color') }, opts);
data.spinner = new Spinner(opts).spin(this);
}
});
return this;
};
window.Landers.response = {
mod_complete:false,
init_mod:function(){
var that = this;
if (that.mod_complete) return;
var sizeK = is_mobile() ? 1 : 1;
for (var i in sizes) {
for (var j in sizes[i]) {
sizes[i][j] *= sizeK;
}
}
var dot_class = '.' + classname;
Landers.css.add([
dot_class + '{position:fixed; overflow:hidden; z-index:5001;}',
dot_class + '.absolute{position:absolute; overflow:hidden;}',
dot_class + ' .response-mask{background-color:#000000; filter:alpha(opacity=70);opacity:0.7; width:100%; height:100%;border-radius:10px;}',
dot_class + ' .response-main{width:100%; height:100%; left:0px; top:0px; position:absolute; padding:0px}',
dot_class + ' .response-main .text{position:absolute; width:100%; left:0px; bottom:; text-align:center; color:#FFFFFF; font-family:"Microsoft Yahei"; font-size:18px; line-height:150%; letter-spacing:0px; padding:0px; float:none;}',
dot_class + ' .response-main .icon{position:relative; margin:0 auto; }',
dot_class + ' .response-main .icon.alone{position:absolute; left:50%; top:50%;}',
dot_class + ' .response-main .icon.success{background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNui8sowAAAHGSURBVFiF5Zc9L0RBFIbfKwpZQRRCKUGBWqUQShKR1RCJTiNRoBGikKg1Ko3GV8Iv2FKhWFtQ+Ej8ABRINCSER2E2ubFm5t7de23hJJPczDtn3ufMnju7GwCqZtRU1f0/AhQkYcbJXwJkJOUkdYXmeiTlBKQ92oEdLJG2eSewbTMHCFJ8DeskbUmatuifkl7T7IFNSaMO/UHSQFpHvwF8Ok7+BhgDlLRxC7Di+syBS2CimJOkeT2w5DF/AsbDeUkCLAL3HoBJoCGcVxtqijlJveb5RtJGjIZbkDQvqdWif0ialXRQohiSKeAlRPpu5gJP1YFZ9+6o+hZYtu1RfLDFGJCxJGeM7opHYNVVhA/gDhixJA8b3RVrQHMlAADnQPZHYhY48+StA20u8zDAFvDm2OwamAmNK8faD7Ofr39KXsNt4NlTlS+egd0oxr8BNAGHFQIcmX3KAhDQDeyVab5v8mNdYL9NdhD/JA75/u6PfYPahEaggPuCwegFsz62uQsg4PuiufAAXJh1kTo+DkBx9AGnFvOC0csyjgogYBA4/mF+DAxVah4VoHgSeWOeT6LyuAAC+g1Af1LmgNL8VRwp/t1/w5L4AvrA0tNR4xPOAAAAAElFTkSuQmCC) no-repeat center 40%;background-size:60% 60%;}',
dot_class + ' .response-main .icon.error{background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAApCAYAAACoYAD2AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAALUSURBVHja1Jm9SxxBGIfX7e4ggWv2ao8LHFcFrhCra0ISjoNtEkhz2B2xC/dXpBHLuFYiwkHSGAThSJNKCGzAyohGrM9CENF0Xn4T3pFxMrPzsWvivvA0c7OzjzM773w4N5vNAo9ogQXwFLTBPKiDR0KdSzAFp+AA7INv4ND1ZXMOkhUQgx54ASKPP+4MTMAu+Ax+WT3FJC14BbZnxcY2tWt8v6knm2AZvAVVxe+HNIT7NKSnNMR1+gTa9Eks0CcixzVYAx/AT5+e7IIdRQ9cgzEYgMhyJCKqP6bn5dih9ymf1zX6EuwpGvsEYksxHTG1I8cevddKsqsQPAYjUM0pyKlSe8cK0a5JsqkY4q+gX5CcTJ/al4e+mSW5ohBcvCdBzqJCdEUnydLBlTTE/XsWFHtUHPorMT3xShVFHhz9I0HOSJFHK6LkG8UsNk2ShodIzTCZ5FnPvIKQ0mVPSJ1sqdqiRKuLBKSg47Aksron9GygSexb0lLZ48m8BaaC/djQG4lQ9xx0LHqwQ3V5JBl1x0I95tUKackSNwu7Fj3Cowa+GHr0GdWpSW3UNPXF90d//GC6Kpj/sFjq2HeVSt+OrkeHipUlNXybEXnwWGWFE6Fgw2ECmER9BDkbwjMTVnAkFLxznKk60TyCAXnwOGIFF0LBc4+UohLNIxiQB48LVnAjFDzxzH1pxubWVTAgDx43suRjz9WCSZwUJBiQx61kKE3/euAXr0FDUd6gFOQadzxCOtXxmPdocJixirBc+JHquITocRnSmYRHuwDBdfBdsYy6iIoeU988qcuDiWEyDS3b/itPuq44JsEgp6hyxVmSGhkUIJhHdCDVXfLZBZ1bCmaJpi67IP7DpnSuji23XYlHws/KnbF0Lt/MszNnou89En6SIajdmZfqjFOK02Jpzt2lucEoxV1QaW7VHtz9ZOlvektzZ/4g/vvgIvnf/o/zW4ABACoGPR3pRRjzAAAAAElFTkSuQmCC) no-repeat center 40%;background-size:65% 65%;}'
]);
this.mod_complete = true;
},
create:function(size, $wrap, opts){
var that = this, html = '';
opts = opts || {};
size = sizes[size];
that.init_mod(); that.hide($wrap);
html += '<div class="' + classname + '">';
html += ' <div class="response-mask"></div>';
html += ' <div class="response-main">';
html += ' <div class="icon"></div>';
html += ' <div class="text"></div>';
html += ' </div>';
html += '</div>';
var $o = jq(html).boxsize(size).appendTo($wrap).setCenter().hide();
if ( !$o.closest('.art_dialog').length ) {
$o.css('top', '35%');
}
$o.find('.text').css({
'font-size': size.text_size + 'px',
'bottom': size.text_bottom + 'px'
});
$o.find('.icon').width(size.icon_size).height(size.icon_size);
if ($wrap.get(0).tagName.toLowerCase() != 'body') {
$o.addClass('absolute');
var top = Math.abs( ($wrap.outerHeight()- $o.height())/2 );
top += $wrap.get(0).scrollTop - parseInt($o.css('margin-top'));
$o.css('top', top );
};
var effect = opts.effect || 'default';
if (effect == 'random') effect = Landers.animate.random();
Landers.animate.show($o, effect);
return $o;
//return $o.fadeIn(600);
},
success:function(text, delay){
this.show([0, text], delay);
},
error:function(text, delay){
this.show([10, text], delay);
},
msgbox:function(rspn, delay, $wrap) {
this.show(rspn, delay, $wrap);
},
show:function(){
var that = this, opts;
var args = arguments;
if (args.length == 1) {
if (jq.isPlainObject(args[0])) {
opts = args[0];
} else {
opts = parse_args(args[0]);
}
} else {
opts = parse_args(args);
}
var data = opts.data;
var $wrap = opts.wrap;
var callback = opts.callback;
if (!data) return that.hide($wrap, 500, callback);
var is_error, text;
if (jq.isArray(data)) {
is_error = data[0];
text = data[1];
} else {
is_error = !data.success;
text = data.message;
if (!text && data.errors) {
text = [];
for (var k in data.errors) {
var t = data.errors[k][0] ? data.errors[k][0] : data.errors[k];
text.push(t);
}
if (text.length > 1) {
text = text.map(function(item, i){
return (i+1) + '. ' + item;
});
}
text = text.join('\n');
}
}
if (!text) return that.hide($wrap, 500, callback); //text为空为未定义
var len = str_len(text);
if ( len >= 42 || text.indexOf('\n') >= 0) {
that.hide($wrap, 500, callback);
if (Landers.msgbox) {
Landers.msgbox({
succes: false,
message : text
});
} else {
alert(text);
}
return;
}
if ( len >= 18) opts.size = 'xlong';
var delay = opts.delay || (opts.delay !== false ? 3000 : 0);
var icon = is_error ? 'error' : 'success';
var size = opts.size || 'long';
var $o = that.create(size, $wrap, opts);
$o.find('.text').html(text);
$o.find('.icon').addClass(icon);
if (delay >= 0) that.hide($wrap, delay, callback);
},
loading:function(){
var args = Landers.parseArgs(arguments, {
'json' : 'opts',
'function' : 'callback'
});
var opts = args.opts || {};
var callback = args.callback || opts.callback;
var that = this,
theme = opts.theme || 'ispin',
size = opts.size || 'small';
var sizeK = is_mobile() ? 1 : 1;
var $wrap = opts.wrap || jq('body'),
defaults = {lines: 12, shadow: true, speed: 1, trail: 40, hwaccel: true, color: '#fff', reshow: true},
themes = {
ispin: {
big: {width: 4 * sizeK, length: 12 * sizeK, radius: 13 * sizeK},
small: {width: 2 * sizeK, length: 7 * sizeK, radius: 7.5 * sizeK},
long:{width: 2 * sizeK, length: 6 * sizeK, radius: 7.5 * sizeK},
xlong:{width: 2 * sizeK, length: 6 * sizeK, radius: 7.5 * sizeK}
}
};
delete opts.theme; delete opts.size;
delete opts.wrap; delete opts.callback;
opts = $.extend(defaults, themes[theme][size], opts);
$wrap.data('options', opts);
if (opts.text === true) opts.text = 'LOADING';
setTimeout(function(){
var $o = that.create(size, $wrap, opts);
$wrap.overlay('show', {opacity: ~~opts.bgopacity, bgcolor:opts.bgcolor});
var $icon = $o.find('.icon').showSpin(opts);
if (opts.text) {
$o.find('.text').html(opts.text);
} else {
$icon.addClass('alone').setCenter();
}
callback && callback(function() {
var opts = parse_args(arguments);
opts.size = opts.size || 'long';
opts.wrap = $wrap;
that.show(opts);
});
}, opts.delay || 200);
},
hide: function() {
var that = this;
if (!that.mod_complete) that.init_mod();
var opts = parse_args(arguments);
var $o = opts.wrap.overlay('hide').children('.' + classname);
try {$o.find('.icon').data().stop();} catch(e){}
var _ = function(){
Landers.animate.hide($o, 'default', function(){
$o.remove();
opts.callback && opts.callback();
});
};
if (opts.delay) setTimeout(_, opts.delay); else _();
return that;
}
};
})(window, jQuery);