feat: 后端全量更新 - 含所有本次需求

- Contract.php: 返回合约账户余额(balance_contract)
- My.php: 地址管理增加BTC/ETH
- AppContract.php: 一键平仓(closeall)
- AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2)
- site.php: 手续费减半(0.018→0.009)
- agent_permission_setup.sql: 代理权限SQL
- crypto_news_crawler.py: 新闻自动采集脚本
This commit is contained in:
li
2026-03-30 20:16:32 +08:00
commit 1b24994e74
6721 changed files with 1308571 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+611
View File
@@ -0,0 +1,611 @@
/*!jQuery Knob*/
/**
* Downward compatible, touchable dial
*
* Version: 1.2.12
* Requires: jQuery v1.7+
*
* Copyright (c) 2012 Anthony Terrien
* Under MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* Thanks to vor, eskimoblood, spiffistan, FabrizioC
*/
(function(factory) {
if (typeof exports === 'object') {
// CommonJS
module.exports = factory(require('jquery'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
} (function($) {
/**
* Kontrol library
*/
"use strict";
/**
* Definition of globals and core
*/
var k = {},
// kontrol
max = Math.max,
min = Math.min;
k.c = {};
k.c.d = $(document);
k.c.t = function(e) {
return e.originalEvent.touches.length - 1;
};
/**
* Kontrol Object
*
* Definition of an abstract UI control
*
* Each concrete component must call this one.
* <code>
* k.o.call(this);
* </code>
*/
k.o = function() {
var s = this;
this.o = null; // array of options
this.$ = null; // jQuery wrapped element
this.i = null; // mixed HTMLInputElement or array of HTMLInputElement
this.g = null; // deprecated 2D graphics context for 'pre-rendering'
this.v = null; // value ; mixed array or integer
this.cv = null; // change value ; not commited value
this.x = 0; // canvas x position
this.y = 0; // canvas y position
this.w = 0; // canvas width
this.h = 0; // canvas height
this.$c = null; // jQuery canvas element
this.c = null; // rendered canvas context
this.t = 0; // touches index
this.isInit = false;
this.fgColor = null; // main color
this.pColor = null; // previous color
this.dH = null; // draw hook
this.cH = null; // change hook
this.eH = null; // cancel hook
this.rH = null; // release hook
this.scale = 1; // scale factor
this.relative = false;
this.relativeWidth = false;
this.relativeHeight = false;
this.$div = null; // component div
this.run = function() {
var cf = function(e, conf) {
var k;
for (k in conf) {
s.o[k] = conf[k];
}
s._carve().init();
s._configure()._draw();
};
if (this.$.data('kontroled')) return;
this.$.data('kontroled', true);
this.extend();
this.o = $.extend({
// Config
min: this.$.data('min') !== undefined ? this.$.data('min') : 0,
max: this.$.data('max') !== undefined ? this.$.data('max') : 100,
stopper: true,
readOnly: this.$.data('readonly') || (this.$.attr('readonly') === 'readonly'),
// UI
cursor: this.$.data('cursor') === true && 30 || this.$.data('cursor') || 0,
thickness: this.$.data('thickness') && Math.max(Math.min(this.$.data('thickness'), 1), 0.01) || 0.35,
lineCap: this.$.data('linecap') || 'butt',
width: this.$.data('width') || 200,
height: this.$.data('height') || 200,
displayInput: this.$.data('displayinput') == null || this.$.data('displayinput'),
displayPrevious: this.$.data('displayprevious'),
fgColor: this.$.data('fgcolor') || '#87CEEB',
inputColor: this.$.data('inputcolor'),
font: this.$.data('font') || 'Arial',
fontWeight: this.$.data('font-weight') || 'bold',
inline: false,
step: this.$.data('step') || 1,
rotation: this.$.data('rotation'),
// Hooks
draw: null,
// function () {}
change: null,
// function (value) {}
cancel: null,
// function () {}
release: null,
// function (value) {}
// Output formatting, allows to add unit: %, ms ...
format: function(v) {
return v;
},
parse: function(v) {
return parseFloat(v);
}
},
this.o);
// finalize options
this.o.flip = this.o.rotation === 'anticlockwise' || this.o.rotation === 'acw';
if (!this.o.inputColor) {
this.o.inputColor = this.o.fgColor;
}
// routing value
if (this.$.is('fieldset')) {
// fieldset = array of integer
this.v = {};
this.i = this.$.find('input');
this.i.each(function(k) {
var $this = $(this);
s.i[k] = $this;
s.v[k] = s.o.parse($this.val());
$this.bind('change blur',
function() {
var val = {};
val[k] = $this.val();
s.val(s._validate(val));
});
});
this.$.find('legend').remove();
} else {
// input = integer
this.i = this.$;
this.v = this.o.parse(this.$.val());
this.v === '' && (this.v = this.o.min);
this.$.bind('change blur',
function() {
s.val(s._validate(s.o.parse(s.$.val())));
});
} ! this.o.displayInput && this.$.hide();
// adds needed DOM elements (canvas, div)
this.$c = $(document.createElement('canvas')).attr({
width: this.o.width,
height: this.o.height
});
// wraps all elements in a div
// add to DOM before Canvas init is triggered
this.$div = $('<div style="' + (this.o.inline ? 'display:inline;': '') + 'width:' + this.o.width + 'px;height:' + this.o.height + 'px;' + '"></div>');
this.$.wrap(this.$div).before(this.$c);
this.$div = this.$.parent();
if (typeof G_vmlCanvasManager !== 'undefined') {
G_vmlCanvasManager.initElement(this.$c[0]);
}
this.c = this.$c[0].getContext ? this.$c[0].getContext('2d') : null;
if (!this.c) {
throw {
name: "CanvasNotSupportedException",
message: "Canvas not supported. Please use excanvas on IE8.0.",
toString: function() {
return this.name + ": " + this.message
}
}
}
// hdpi support
this.scale = (window.devicePixelRatio || 1) / (this.c.webkitBackingStorePixelRatio || this.c.mozBackingStorePixelRatio || this.c.msBackingStorePixelRatio || this.c.oBackingStorePixelRatio || this.c.backingStorePixelRatio || 1);
// detects relative width / height
this.relativeWidth = this.o.width % 1 !== 0 && this.o.width.indexOf('%');
this.relativeHeight = this.o.height % 1 !== 0 && this.o.height.indexOf('%');
this.relative = this.relativeWidth || this.relativeHeight;
// computes size and carves the component
this._carve();
// prepares props for transaction
if (this.v instanceof Object) {
this.cv = {};
this.copy(this.v, this.cv);
} else {
this.cv = this.v;
}
// binds configure event
this.$.bind("configure", cf).parent().bind("configure", cf);
// finalize init
this._listen()._configure()._xy().init();
this.isInit = true;
this.$.val(this.o.format(this.v));
this._draw();
return this;
};
this._carve = function() {
if (this.relative) {
var w = this.relativeWidth ? this.$div.parent().width() * parseInt(this.o.width) / 100 : this.$div.parent().width(),
h = this.relativeHeight ? this.$div.parent().height() * parseInt(this.o.height) / 100 : this.$div.parent().height();
// apply relative
this.w = this.h = Math.min(w, h);
} else {
this.w = this.o.width;
this.h = this.o.height;
}
// finalize div
this.$div.css({
'width': this.w + 'px',
'height': this.h + 'px'
});
// finalize canvas with computed width
this.$c.attr({
width: this.w,
height: this.h
});
// scaling
if (this.scale !== 1) {
this.$c[0].width = this.$c[0].width * this.scale;
this.$c[0].height = this.$c[0].height * this.scale;
this.$c.width(this.w);
this.$c.height(this.h);
}
return this;
};
this._draw = function() {
// canvas pre-rendering
var d = true;
s.g = s.c;
s.clear();
s.dH && (d = s.dH());
d !== false && s.draw();
};
this._touch = function(e) {
var touchMove = function(e) {
var v = s.xy2val(e.originalEvent.touches[s.t].pageX, e.originalEvent.touches[s.t].pageY);
if (v == s.cv) return;
if (s.cH && s.cH(v) === false) return;
s.change(s._validate(v));
s._draw();
};
// get touches index
this.t = k.c.t(e);
// First touch
touchMove(e);
// Touch events listeners
k.c.d.bind("touchmove.k", touchMove).bind("touchend.k",
function() {
k.c.d.unbind('touchmove.k touchend.k');
s.val(s.cv);
});
return this;
};
this._mouse = function(e) {
var mouseMove = function(e) {
var v = s.xy2val(e.pageX, e.pageY);
if (v == s.cv) return;
if (s.cH && (s.cH(v) === false)) return;
s.change(s._validate(v));
s._draw();
};
// First click
mouseMove(e);
// Mouse events listeners
k.c.d.bind("mousemove.k", mouseMove).bind(
// Escape key cancel current change
"keyup.k",function(e) {
if (e.keyCode === 27) {
k.c.d.unbind("mouseup.k mousemove.k keyup.k");
if (s.eH && s.eH() === false) return;
s.cancel();
}
}).bind("mouseup.k",function(e) {
k.c.d.unbind('mousemove.k mouseup.k keyup.k');
s.val(s.cv);
});
return this;
};
this._xy = function() {
var o = this.$c.offset();
this.x = o.left;
this.y = o.top;
return this;
};
this._listen = function() {
if (!this.o.readOnly) {
this.$c.bind("mousedown",function(e) {
e.preventDefault();
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
s._xy()._mouse(e);
}).bind("touchstart",function(e) {
e.preventDefault();
s._xy()._touch(e);
});
this.listen();
} else {
this.$.attr('readonly', 'readonly');
}
if (this.relative) {
$(window).resize(function() {
s._carve().init();
s._draw();
});
}
return this;
};
this._configure = function() {
// Hooks
if (this.o.draw) this.dH = this.o.draw;
if (this.o.change) this.cH = this.o.change;
if (this.o.cancel) this.eH = this.o.cancel;
if (this.o.release) this.rH = this.o.release;
if (this.o.displayPrevious) {
this.pColor = this.h2rgba(this.o.fgColor, "0.4");
this.fgColor = this.h2rgba(this.o.fgColor, "0.6");
} else {
this.fgColor = this.o.fgColor;
}
return this;
};
this._clear = function() {
this.$c[0].width = this.$c[0].width;
};
this._validate = function(v) {
var val = (~~ (((v < 0) ? -0.5 : 0.5) + (v / this.o.step))) * this.o.step;
return Math.round(val * 100) / 100;
};
// Abstract methods
this.listen = function() {}; // on start, one time
this.extend = function() {}; // each time configure triggered
this.init = function() {}; // each time configure triggered
this.change = function(v) {}; // on change
this.val = function(v) {}; // on release
this.xy2val = function(x, y) {}; //
this.draw = function() {}; // on change / on release
this.clear = function() {
this._clear();
};
// Utils
this.h2rgba = function(h, a) {
var rgb;
h = h.substring(1, 7);
rgb = [parseInt(h.substring(0, 2), 16), parseInt(h.substring(2, 4), 16), parseInt(h.substring(4, 6), 16)];
return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + a + ")";
};
this.copy = function(f, t) {
for (var i in f) {
t[i] = f[i];
}
};
};
/**
* k.Dial
*/
k.Dial = function() {
k.o.call(this);
this.startAngle = null;
this.xy = null;
this.radius = null;
this.lineWidth = null;
this.cursorExt = null;
this.w2 = null;
this.PI2 = 2 * Math.PI;
this.extend = function() {
this.o = $.extend({
bgColor: this.$.data('bgcolor') || '#EEEEEE',
angleOffset: this.$.data('angleoffset') || 0,
angleArc: this.$.data('anglearc') || 360,
inline: true
},
this.o);
};
this.val = function(v, triggerRelease) {
if (null != v) {
// reverse format
v = this.o.parse(v);
if (triggerRelease !== false && v != this.v && this.rH && this.rH(v) === false) {
return;
}
this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
this.v = this.cv;
this.$.val(this.o.format(this.v));
this._draw();
} else {
return this.v;
}
};
this.xy2val = function(x, y) {
var a, ret;
a = Math.atan2(x - (this.x + this.w2), -(y - this.y - this.w2)) - this.angleOffset;
if (this.o.flip) {
a = this.angleArc - a - this.PI2;
}
if (this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) {
// if isset angleArc option, set to min if .5 under min
a = 0;
} else if (a < 0) {
a += this.PI2;
}
ret = (a * (this.o.max - this.o.min) / this.angleArc) + this.o.min;
this.o.stopper && (ret = max(min(ret, this.o.max), this.o.min));
return ret;
};
this.listen = function() {
// bind MouseWheel
var s = this, mwTimerStop, mwTimerRelease, mw = function(e) {
e.preventDefault();
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
var ori = e.originalEvent,
deltaX = ori.detail || ori.wheelDeltaX,
deltaY = ori.detail || ori.wheelDeltaY,
v = s._validate(s.o.parse(s.$.val())) + (deltaX > 0 || deltaY > 0 ? s.o.step: deltaX < 0 || deltaY < 0 ? -s.o.step: 0);
v = max(min(v, s.o.max), s.o.min);
s.val(v, false);
if (s.rH) {
// Handle mousewheel stop
clearTimeout(mwTimerStop);
mwTimerStop = setTimeout(function() {
s.rH(v);
mwTimerStop = null;
},
100);
// Handle mousewheel releases
if (!mwTimerRelease) {
mwTimerRelease = setTimeout(function() {
if (mwTimerStop) s.rH(v);
mwTimerRelease = null;
},
200);
}
}
if (s.cH) {
s.cH(v);
}
},
kval,
to,
m = 1,
kv = {
37 : -s.o.step,
38 : s.o.step,
39 : s.o.step,
40 : -s.o.step
};
this.$.bind("keydown",function(e) {
var kc = e.keyCode;
// numpad support
if (kc >= 96 && kc <= 105) {
kc = e.keyCode = kc - 48;
}
kval = parseInt(String.fromCharCode(kc));
if (isNaN(kval)) { (kc !== 13) // enter
&& kc !== 8 // bs
&& kc !== 9 // tab
&& kc !== 189 // -
&& (kc !== 190 || s.$.val().match(/\./)) // . allowed once
&& e.preventDefault();
// arrows
if ($.inArray(kc, [37, 38, 39, 40]) > -1) {
e.preventDefault();
var v = s.o.parse(s.$.val()) + kv[kc] * m;
s.o.stopper && (v = max(min(v, s.o.max), s.o.min));
s.change(s._validate(v));
s._draw();
// long time keydown speed-up
to = window.setTimeout(function() {
m *= 2;
},
30);
}
}
}).bind("keyup",function(e) {
if (isNaN(kval)) {
if (to) {
window.clearTimeout(to);
to = null;
m = 1;
s.val(s.$.val());
}
} else {
// kval postcond
(s.$.val() > s.o.max && s.$.val(s.o.max)) || (s.$.val() < s.o.min && s.$.val(s.o.min));
}
});
this.$c.bind("mousewheel DOMMouseScroll", mw);
this.$.bind("mousewheel DOMMouseScroll", mw);
};
this.init = function() {
if (this.v < this.o.min || this.v > this.o.max) {
this.v = this.o.min;
}
this.$.val(this.v);
this.w2 = this.w / 2;
this.cursorExt = this.o.cursor / 100;
this.xy = this.w2 * this.scale;
this.lineWidth = this.xy * this.o.thickness;
this.lineCap = this.o.lineCap;
this.radius = this.xy - this.lineWidth / 2;
this.o.angleOffset && (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
this.o.angleArc && (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2: this.o.angleArc);
// deg to rad
this.angleOffset = this.o.angleOffset * Math.PI / 180;
this.angleArc = this.o.angleArc * Math.PI / 180;
// compute start and end angles
this.startAngle = 1.5 * Math.PI + this.angleOffset;
this.endAngle = 1.5 * Math.PI + this.angleOffset + this.angleArc;
var s = max(String(Math.abs(this.o.max)).length, String(Math.abs(this.o.min)).length, 2) + 2;
this.o.displayInput && this.i.css({
'width': ((this.w / 2 + 4) >> 0) + 'px',
'height': ((this.w / 3) >> 0) + 'px',
'position': 'absolute',
'vertical-align': 'middle',
'margin-top': ((this.w / 3) >> 0) + 'px',
'margin-left': '-' + ((this.w * 3 / 4 + 2) >> 0) + 'px',
'border': 0,
'background': 'none',
'font': this.o.fontWeight + ' ' + ((this.w / s) >> 0) + 'px ' + this.o.font,
'text-align': 'center',
'color': this.o.inputColor || this.o.fgColor,
'padding': '0px',
'-webkit-appearance': 'none'
}) || this.i.css({
'width': '0px',
'visibility': 'hidden'
});
};
this.change = function(v) {
this.cv = v;
this.$.val(this.o.format(v));
};
this.angle = function(v) {
return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
};
this.arc = function(v) {
var sa, ea;
v = this.angle(v);
if (this.o.flip) {
sa = this.endAngle + 0.00001;
ea = sa - v - 0.00001;
} else {
sa = this.startAngle - 0.00001;
ea = sa + v + 0.00001;
}
this.o.cursor && (sa = ea - this.cursorExt) && (ea = ea + this.cursorExt);
return {
s: sa,
e: ea,
d: this.o.flip && !this.o.cursor
};
};
this.draw = function() {
var c = this.g,
// context
a = this.arc(this.cv),
// Arc
pa,
// Previous arc
r = 1;
c.lineWidth = this.lineWidth;
c.lineCap = this.lineCap;
if (this.o.bgColor !== "none") {
c.beginPath();
c.strokeStyle = this.o.bgColor;
c.arc(this.xy, this.xy, this.radius, this.endAngle - 0.00001, this.startAngle + 0.00001, true);
c.stroke();
}
if (this.o.displayPrevious) {
pa = this.arc(this.v);
c.beginPath();
c.strokeStyle = this.pColor;
c.arc(this.xy, this.xy, this.radius, pa.s, pa.e, pa.d);
c.stroke();
r = this.cv == this.v;
}
c.beginPath();
c.strokeStyle = r ? this.o.fgColor: this.fgColor;
c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d);
c.stroke();
};
this.cancel = function() {
this.val(this.v);
};
};
$.fn.dial = $.fn.knob = function(o) {
return this.each(function() {
var d = new k.Dial();
d.o = o;
d.$ = $(this);
d.run();
}).parent();
};
}));
+504
View File
@@ -0,0 +1,504 @@
/**
* 区域/全局 loading 效果<layui组件,依赖jQuery>
* @version v1.3 最新版
* @author jlx (neusofts#neusofts.com)
* @extends {jQuery.fn.loading}
* @param {String|Object=} arg1 调用方法名<均为空参则默认show,其他方法:toggle,hide,hideAll,destroy,destroyAll>,若为一个Object参数则更新全局配置&show<返回loading>
* @param {Object=} arg2 若arg1为{String}arg2为{Object},则优先私有配置
* @property {String=''} overlayClassName 自定义遮罩层className,可多个,默认空String
* @property {String=''} imgClassName 自定义image的className,可多个,默认空String
* @property {String='#fff'} background 自定义遮罩层背景色,默认#fff
* @property {Number=0.6} opacity 自定义遮罩层的透明度,默认0.6 <为0时无遮罩层>
* @property {String=''} text 自定义loading文本,默认空String<非空时参考offsetTop设置>
* @property {String=''} textCss 自定义loading文本样式,默认空String<高优先级>
* @property {String=''} textClassName 自定义文本的className,可多个,默认空String
* @property {String=''} title 自定义div、img、text的title,默认空String
* @property {Number=0} offsetTop 自定义图片+文本模式的top偏移量<text为空建议不设置offsetTop>
* @property {Number=0|String=''|null} imgSrc 自定义loading图片路径,默认为图片序列的0索引<0-10>,可配索引或图片url路径<为null时无图片>
* @property {Function=} beforeShow 自定义loading显示前的回调,默认空Function,参数1=this,参数2=jQuery
* @property {Function=} afterShow 自定义loading显示后的回调,默认空Function,参数1=this,参数2=jQuery,参数3=$loading
* @property {Number=19999999+1} imgZIndex 自定义图片的z-index值,默认19999999+1
* @property {Number=19999999} overlayZIndex 自定义遮罩层的z-index值,默认19999999
* @property {Function=} afterHide 自定义loading隐藏/销毁后的回调,默认空Function,参数1=this,参数2=jQuery,参数3=$loading(销毁时无参数3)
* @property {Function=} afterHideAll 自定义全部loading隐藏/销毁后的回调,默认空Function,参数1=this,参数2=jQuery,参数3=$loading(销毁时无参数3)
* @property {Number=600} animateTime 自定义loading显示/隐藏的动画时长 <为0时无动画>,默认600
* @property {Boolean=false} clickHide 自定义单击loading遮罩层/图片/文字是否隐藏loading,默认false
* @property {Boolean=false} inheritRadius 自定义遮罩层是否继承父节点的边框效果,默认false
* @event hide,hideAll,destroy,destroyAll 均监听$(obj)的lay-loading(.hide | .hideAll | .destroy | .destroyAll)事件,参数event, loadingObj
* @return {Object|jQuery|Object<Array>} 返回<loading | loadingArr | jQuery | Error>对象
* @example
* $('body').loading(str?: string = 'show'); // 创建/显示loading <body,html,window,document均处理为body>
* $('body|other').loading({...}); // 注:更新全局配置 + show
* $('body|other').loading('show', {...}); // 创建/显示 + 局部配置优先
* var loadingObj = $('body|other').loading('hide').show(); // 隐藏 -> 显示
* var loadingObj = $('body|other').loading('show', {afterHide: function (loadingObj, jQueryObj, $loading) {...}});
*/
+(function (global, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function (jQuery) {
if (typeof jQuery === 'undefined') {
// require('jQuery')
if (typeof window !== 'undefined') {
jQuery = require('jquery');
} else {
jQuery = require('jquery')(global);
}
}
return factory(jQuery);
};
}else {
// Browser globals
factory(jQuery);
}
} (this, function ($) {
'use strict';
var _ = $.extend
, W = window // BOM/DOM
, fnName = {}
, lang = {Illegal_operation: '非法操作'} // 外部语言包模块
, _toString = Object.prototype.toString
, ds = { // 外部工具模块
getTime: function (arg) {
return arg ? (+ new Date(arg)) : (+ new Date());
},
is: {
string: function (str) {
return _toString.call(str) == '[object String]';
},
number: function (num) {
return _toString.call(num) == '[object Number]';
},
plainObject: function (obj) {
if (obj === undefined) {
return false;
} else {
return _toString.call(obj) === '[object Object]';
}
},
'undefined': function (v) {
return v === undefined || v === null;
},
'function': function (fun) {
return _toString.call(fun) === '[object Function]';
}
},
loadImage: function (url, callback, error) {
if (!url) {
return callback({src: url});
}
var imgObj;
imgObj = new Image();
imgObj.src = url;
if (imgObj.complete && callback) {
return callback(imgObj);
}
imgObj.onload = function () {
imgObj.onload = null;
callback && callback(imgObj);
};
imgObj.onerror = function (e) {
imgObj.onerror = null;
error && error(e);
};
return imgObj;
}
};
_($.fn, {
loading: function () {
var nodeNames = 'BODY,HTML,#document,undefined'
, $that = nodeNames.indexOf(this[0].nodeName) > -1 ? $('body') : this // 多集合仅保留body对象
, isBODY = $that[0].nodeName == 'BODY'
, arg1 = arguments[0], arg2 = arguments[1]
, loadingClassName = 'lay-loading' // 注:hideAll等操作的索引,若冲突请自行改之
, eventNameResize = 'resize.' + loadingClassName
, eventNameClick = 'click.'+ loadingClassName +'.clickHide'
, zIndex = 19999999
, errorFn = function () {
throw new Error(lang.Illegal_operation);
}
, imgUrl = '/assets/addons/btpanel/images/loading/loading'
, imgSrcArr = [
imgUrl + '.gif',
imgUrl + '-bars.gif'
].concat(function () { for (var arr = [], i = 0; i <= 8; i++) { arr.push(imgUrl + '-' + i + '.gif'); }; return arr; }())
, pteMethods = {
resize: function () {
if (!this || !this instanceof $) return;
var offsetTop = this.settings && (this.settings.offsetTop || 0);
var $objs = this.$this.children('.' + loadingClassName + ':visible');
var hasImgSrc = !ds.is['undefined'](this.settings.imgSrc);
var imageH = 0, $parent = {}, parentW = 0, parentH = 0, isFixed, offsetP, safariBug, parentPosition;
var isSafari = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent); // !document.documentMode;
$objs.each(function (key, divAndimg) {
$parent = $(divAndimg).parent();
parentPosition = ('fixed,relative').indexOf($parent.css('position'));
isFixed = parentPosition > -1 || $parent[0] === $(this)[0].offsetParent;
safariBug = parentPosition < 0 && $parent[0].offsetParent !== $('body')[0] && isSafari;
// console.log(parentPosition); // -1 -1
// console.log($parent[0]); // YS-in YS-in
// console.log($(this)[0].offsetParent); // body YS-in
// console.log($parent[0].offsetParent); // body YS-out
offsetP = isFixed || safariBug ? { top: 0, left: 0 } : { top: $parent[0].offsetTop, left: $parent[0].offsetLeft };
parentW = $parent.outerWidth();
parentH = $parent.outerHeight();
if ($parent[0].nodeName == 'BODY') {
if ($(divAndimg).is('div')) {
$(divAndimg).css({
width: '100%',
height: '100%',
position: 'fixed'
});
} else if ($(divAndimg).is('img')) {
imageH = $(divAndimg).height();
$(divAndimg).css({
position: 'fixed',
top: $(W).height() / 2 - $(divAndimg).height() / 2 - offsetTop,
left: $(W).width() / 2 - $(divAndimg).width() / 2
});
} else {
$(divAndimg).css({
position: 'fixed',
top: $(W).height() / 2 + (imageH ? 6 : ( - $(divAndimg).height() / 2)) + imageH / 2 - offsetTop,
left: $(W).width() / 2 - $(divAndimg).width() / 2
});
}
} else {
if ($(divAndimg).is('div')) {
$(divAndimg).css({
width: parentW,
height: parentH,
top: offsetP.top,
left: offsetP.left
});
} else if ($(divAndimg).is('img')) {
imageH = $(divAndimg).height();
$(divAndimg).css({
top: parentH / 2 - $(divAndimg).height() / 2 + offsetP.top - offsetTop,
left: parentW / 2 - $(divAndimg).width() / 2 + offsetP.left
});
} else {
imageH = hasImgSrc ? imageH : 0;
$(divAndimg).css({
top: parentH / 2 + imageH / 2 + (imageH ? 6 : ( - $(divAndimg).height() / 2)) + offsetP.top - offsetTop,
left: parentW / 2 - $(divAndimg).width() / 2 + offsetP.left
});
}
}
});
return this;
},
subsequent: function () {
var $loading = arguments[0];
var that = $loading.parent().data('loading') || this;
var time = that.settings.animateTime;
var $this = that.$this;
var fn = that.settings[arguments[1]]
var operate = arguments[2];
var method = arguments[3];
var isAuto = arguments[4];
if (arguments[1] === 'afterHideAll') {
fn = fnName.settings.afterHideAll;
}
$loading.fadeOut(time, function () {
$(this)[operate]();
});
W.setTimeout(function () {
!isAuto && fn && fn(that, $this, operate == 'hide' ? $loading : undefined);
!isAuto && $this.trigger(loadingClassName + '.' + method, that);
}, time);
return that;
}
};
fnName.settings = fnName.settings || {
'overlayClassName': '',
'imgClassName': '',
'background': '#fff',
'opacity': 0.6,
'text': '',
'textCss': '', // {}
'textClassName': '',
'title': '',
'offsetTop': 0, // img&text的top偏移量
'imgSrc': imgSrcArr[0], // 注:默认以图片居中为主,若img&text同时微调可设置offsetTop
'beforeShow': function () {},
'afterShow': function () {},
'imgZIndex': zIndex + 1, // text共用
'overlayZIndex': zIndex,
'afterHide': function () {},
'afterHideAll': function () {},
'animateTime': 600,
'clickHide': !1, //可配置afterHide为reload需求
'inheritRadius': false
}
var initialCss = {
'top': -zIndex,
'left': -zIndex,
'z-index': 0,
'position': 'absolute',
'padding': 'initial',
'margin': 'initial',
'border': 'initial',
'width': 'initial',
'min-width': 'initial',
'max-width': 'initial',
'height': 'initial',
'min-height': 'initial',
'max-height': 'initial',
'opacity': 'initial'
}
, overlayStyle = {
'background': '#fff',
'height': 0, // resize value
'width': 0, // resize value
'top': 0, // resize value <html除外, 子标签在body内>
'left': 0, // resize value <html除外, 子标签在body内>
'z-index': 0,
'opacity': 0,
'position': 'absolute',
'border-radius': 0,
'padding': 'initial',
'margin': 'initial',
'border': 'initial'
}
, imageStyle = _({}, initialCss)
, textStyle = _({}, initialCss, {
'background': 'initial',
'overflow': 'initial',
'white-space': 'nowrap',
'line-height': '120%',
'text-align': 'center',
'vertical-align': 'middle'
});
function Class(options) {
if (options && options.imgSrc !== null && ds.is.number(options.imgSrc)) {
options.imgSrc = imgSrcArr[options.imgSrc]; // undefined时$.extend不覆盖默认配置
}
this.hasNewSetting = ds.is.plainObject(options);
this.$this = options.$this;
this.settings = _({}, fnName.settings, this.hasNewSetting ? options : {});
this.settings.overlayStyle = overlayStyle;
this.settings.imageStyle = imageStyle;
this.settings.textStyle = textStyle;
}
_(Class.prototype, {
show: function () {
var _this = this;
var $this = this.$this;
var settings = this.settings;
var beforeShow = settings.beforeShow;
var overlayStyle = settings.overlayStyle;
var imageStyle = settings.imageStyle;
var textStyle = settings.textStyle;
var textCss = settings.textCss || {};
var $loadingObjSingle = $this.children('.' + loadingClassName);
var hasImgSrc = !ds.is['undefined'](settings.imgSrc);
beforeShow && beforeShow(this, $this);
if (!this.hasNewSetting && $loadingObjSingle.size() > 0) {
pteMethods.subsequent.apply(this, [
$loadingObjSingle,
'afterShow',
'show',
'show'
]);
$(W).trigger(eventNameResize);
} else {
this.destroy('auto'), ds.loadImage(hasImgSrc ? settings.imgSrc : null, function (imgObj) {
// create时不考虑动画
var $overlay = $('<div></div>');
var $image = $('<img />');
var $text = $('<span></span>');
var text = $.trim(settings.text);
var overlayW = isBODY ? window.screen.availWidth : $this.outerWidth();
var overlayH = isBODY ? window.screen.availHeight : $this.outerHeight();
overlayStyle['background'] = settings['background'];
overlayStyle['z-index'] = settings['overlayZIndex'];
overlayStyle['opacity'] = settings['opacity'];
overlayStyle['height'] = overlayH;
overlayStyle['width'] = overlayW;
if (settings.inheritRadius) {
// For IE
overlayStyle['border-top-left-radius'] = $this.css('border-top-left-radius');
overlayStyle['border-top-right-radius'] = $this.css('border-top-right-radius');
overlayStyle['border-bottom-left-radius'] = $this.css('border-bottom-left-radius');
overlayStyle['border-bottom-right-radius'] = $this.css('border-bottom-right-radius');
}
imageStyle['z-index'] = settings['imgZIndex'];
textStyle['z-index'] = settings['imgZIndex'];
$overlay
.addClass(loadingClassName)
.addClass(settings.overlayClassName)
.css(overlayStyle)
.attr('title', settings.title)
.appendTo($this).hide();
imgObj.src && $image
.addClass(loadingClassName)
.addClass(settings.imgClassName)
.css(imageStyle)
.attr('src', imgObj.src)
.attr('title', settings.title)
.appendTo($this).hide();
$text
.addClass(loadingClassName)
.addClass(settings.textClassName)
.css(_({}, textStyle, textCss))
.html(text)
.attr('title', settings.title)
.appendTo($this).hide();
setTimeout(function () {
$overlay[!settings['opacity'] ? 'remove' : 'show']();
$image[!hasImgSrc ? 'remove' : 'show']();
$text[!text.length ? 'remove' : 'show']();
$(W).trigger(eventNameResize);
settings.afterShow && settings.afterShow(_this, $this);
$this.trigger(loadingClassName + '.' + 'show', _this);
}, 0.1e3);
}, function (e) {
throw new Error(e);
});
}
return {
hide: errorFn,
hideAll: errorFn,
destroy: errorFn,
destroyAll: errorFn
};
},
toggle: function () {
if (this.$this.children('.' + loadingClassName + ':visible').size() > 0) {
return this.hide();
} else {
return this.show();
}
},
hide: function () {
return pteMethods.subsequent.apply(this, [
this.$this.children('.' + loadingClassName),
'afterHide',
'hide',
'hide'
]);
},
hideAll: function () {
return pteMethods.subsequent.apply(this, [
$('.' + loadingClassName),
'afterHideAll',
'hide',
'hideAll'
]);
},
// <传入新配置/销毁后> 新建将启用最新全局配置
destroy: function (isAuto) {
return pteMethods.subsequent.apply(this, [
this.$this.children('.' + loadingClassName),
'afterHide',
'remove',
'destroy',
isAuto
]);
},
destroyAll: function () {
return pteMethods.subsequent.apply(this, [
$('.' + loadingClassName),
'afterHideAll',
'remove',
'destroyAll'
]);
}
});
// 一个{}参数:更新全局配置&show <兼容IE8>
if (ds.is.plainObject(arg1)) {
if (arg1.imgSrc) {
arg1.imgSrc = imgSrcArr[arg1.imgSrc];
}
return $that.loading('show', _(fnName.settings, arg1));
}
// arg1为string默认调用方法 & arg2默认为局部配置
if (ds.is.string(arg1) || !arg1) {
var loading = {}, loadingArr = [], rdm;
arg1 = arg1 ? arg1 : 'show';
$that.each(function (index, obj) {
if (arg2) {
arg2.$this = $(obj);
if (arg2.afterHideAll) {
fnName.settings.afterHideAll = arg2.afterHideAll;
}
} else {
arg2 = {$this: $(obj)};
}
rdm = '.rdm' + ds.getTime() + index;
loading = new Class(arg2);
$(obj).data('loading', loading);
ds.is['function'](loading[arg1]) && loading[arg1]();
loadingArr.push(loading);
// 单击div/img/text是否隐藏
$(obj).off(eventNameClick).on(eventNameClick, '.' + loadingClassName, function (e) {
loading.settings.clickHide && $(obj).data('loading').hide();
e.stopPropagation();
return false;
});
// resize监听
$(W).off(eventNameResize + rdm).on(eventNameResize + rdm, function () {
pteMethods.resize.call($(obj).data('loading') || null);
});
});
}
return loadingArr.length > 1 ? loadingArr : loadingArr[0];
}
});
return $;
}));