| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /*
- * Created with Sublime Text 3.
- * license: http://www.lovewebgames.com/jsmodule/index.html
- * github: https://github.com/tianxiangbing/loading
- * User: 田想兵
- * Date: 2015-08-05
- * Time: 11:27:55
- * Contact: 55342775@qq.com
- * desc:请尽量使用github上的代码,会修复一些问题,关注https://github.com/tianxiangbing/loading
- */
- ;
- (function (root, factory) {
- //amd
- if (typeof define === 'function' && define.amd) {
- define(['jquery'], factory);
- } else if (typeof exports === 'object') { //umd
- module.exports = factory($);
- } else {
- root.Loading = factory(window.Zepto || window.jQuery || $);
- }
- })(window, function ($) {
- var Loading = function () { };
- Loading.prototype = {
- loadingTpl: '<div class="ui-loading"><div class="ui-loading-mask"></div><i></i></div>',
- stop: function () {
- this.loading.remove();
- this.loading = null;
- },
- start: function () {
- var _this = this;
- var loading = this.loading;
- if (!loading) {
- loading = $(_this.loadingTpl);
- $('body').append(loading);
- }
- this.loading = loading;
- //console.log(cw,ch)
- this.setPosition();
- },
- setPosition: function () {
- var _this = this;
- var loading = this.loading;
- var target = _this.target;
- var content = $(target);
- var ch = $(content).outerHeight();
- var cw = $(content).outerWidth();
- if ($(target)[0].tagName == "HTML") {
- ch = Math.max($(target).height(), $(window).height());
- cw = Math.max($(target).width(), $(window).width());
- }
- loading.height(ch).width(cw);
- loading.find('div').height(ch).width(cw);
- if (ch < 100) {
- loading.find('i').height(ch).width(ch);
- }
- var offset = $(content).offset();
- loading.css({
- top: offset.top,
- left: offset.left
- });
- var icon = loading.find('i');
- var h = ch,
- w = cw,
- top = 0,
- left = 0;
- if ($(target)[0].tagName == "HTML") {
- h = $(window).height();
- w = $(window).width();
- top = (h - icon.height()) / 2 + $(window).scrollTop();
- left = (w - icon.width()) / 2 + $(window).scrollLeft();
- } else {
- top = (h - icon.height()) / 2;
- left = (w - icon.width()) / 2;
- }
- icon.css({
- top: top,
- left: left
- })
- },
- init: function (settings) {
- settings = settings || {};
- this.loadingTpl = settings.loadingTpl || this.loadingTpl;
- this.target = settings.target || 'html';
- this.bindEvent();
- },
- bindEvent: function () {
- var _this = this;
- $(this.target).on('stop', function () {
- _this.stop();
- });
- $(window).on('resize', function () {
- _this.loading && _this.setPosition();
- });
- }
- }
- return Loading;
- });
- function loadingxmsl(xmslid,reload){
- var load = new Loading();
- load.init({
- target: this.document.documentElement
- });
- var start=false;
- var od=setInterval(function() {
- $.ajax({
- url:"/wd/js/loading/loadXmsl.jsp",
- data:{"xmslid":xmslid},
- type:'post',
- async:false,
- success:function(data){
- data=JSON.parse(data.trim());
- if(data.status=='none'){
- clearInterval(od);
- if(start&&reload){
- load.stop();
- window.location.reload();
- }
- }else{
- if(!start){
- load.start();
- start=true;
- }else{
-
- }
- var msg=$(".ui-loading>div.msg");
- if(msg.length==0){
- msg=$("<div class='msg' align='center' style='background:white;position:absolute;bottom:2em;left:0;right:0'>");
- $(".ui-loading").append(msg);
- }
- msg.html("正在:<strong>"+data.desc+"</strong>");
- }
- }
- })
- }, 1000);
- }
- function loadXmslStatus(xmslid){
- loadingxmsl(xmslid,true)
- $("form[name='xmslframe']").each(function(){
- var fr=this;
- fr.addEventListener("submit",function(){
- loadingxmsl(xmslid);
- });
- })
- }
|