init

          (function() {
              /**
               * update:
               * 1.0: show(pos),  去loading...動(dòng)畫
               * 1.1: 去掉loading動(dòng)畫背景,否則在等待js加載時(shí)點(diǎn)不到東東
               * 1.2: window.App = new Object() script.async = true; loadJs+loading
               * 1.3: showLoading可控制在加載js時(shí)是否顯示loading動(dòng)畫
               * 1.4: 去掉 keepFlow,后臺(tái)已經(jīng)作了保持會(huì)話的功能
               * 1.41: cild_direct由 upingan改為 upingannew 臨時(shí)不用cdn [注釋1.41]
               * 1.49: 屏蔽對(duì)移動(dòng)設(shè)備的判斷條件if(!IS_NATIVE)
               */
              var version = "Upa1.50";
              //
              window.App = new Object();
              var showLoading = false;
              var cild_direct = "upingannew/";
              //這個(gè)也用于搜索替換
              var ua = navigator.userAgent.toUpperCase();
              var IS_ANDROID = ua.indexOf('ANDROID') != -1;
              // 當(dāng)前環(huán)境是否為IOS平臺(tái)
              var IS_IOS = ua.indexOf('IPHONE OS') != -1;
              var IS_NATIVE = (IS_ANDROID || IS_IOS) ? true : false;
              // alert('IS_IOS: '+IS_IOS)
              if(IS_IOS && ua.indexOf('SAFARI') != -1) {
                  IS_NATIVE = false;
                  IS_IOS = false;
              }
              if(IS_ANDROID && !window.android) {
                  IS_NATIVE = false;
                  IS_ANDROID = false;
              }
              /**
               * 獲取URL參數(shù)
               * @return {String} name
               */
              var getmtParam = function(name) {
                  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
                  var r = window.location.search.substr(1).match(reg);
                  if(r) {
                      return decodeURI(r[2]);
                  }
                  return null;
              }
              var mtype = null;
              var isInitPage = true;
              /**
               * Cookie操作
               */
              var Cookie = function(key, value, options) {
                  if(arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
                      options = options || {};

                      if(value === null || value === undefined) {
                          options.expires = -1;
                      }

                      if( typeof options.expires === 'number') {
                          var days = options.expires, t = options.expires = new Date();
                          t.setDate(t.getDate() + days);
                      }
                      value = String(value);

                      return (document.cookie = [encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''));
                  }
                  options = value || {};
                  var decode = options.raw ? function(s) {
                      return s;
                  } : decodeURIComponent;
                  var pairs = document.cookie.split('; ');
                  for(var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
                      if(decode(pair[0]) === key)
                          return decode(pair[1] || '');
                  }
                  return null;
              }
              //--- 外部app修復(fù) IS_NATIVE的標(biāo)識(shí)
              //--- 外部app修復(fù) IS_NATIVE的標(biāo)識(shí)
              if(IS_ANDROID || IS_IOS) {
                  mtype = getmtParam('mt') || Cookie('mt') || null;
                  if(mtype == null) {//來(lái)自與平安應(yīng)用,無(wú)參數(shù)
                      IS_NATIVE = true;
                      if(IS_ANDROID) {
                          IS_ANDROID = true;
                          IS_IOS = false;
                      }
                      if(IS_IOS) {
                          IS_ANDROID = false;
                          IS_IOS = true;
                      }
                  } else {//來(lái)自與平安應(yīng)用
                      IS_NATIVE = false;
                      IS_IOS = false;
                  }
              }

              /**
               * 頁(yè)面初始化, 動(dòng)態(tài)加載
               */
              var location = window.location;
              // 協(xié)議
              var protocol = location.protocol;
              // 主機(jī)名
              var host = location.host;

              //stz+20130718 協(xié)議和域名
              function getHostWithProtocol() {
                  var origin = location.origin, host = location.host;
                  if(!origin) {
                      var protocol = location.protocol;
                      protocol = protocol == "http:" ? "http://" : protocol == "https:" ? "https://" : "file:///";
                      origin = protocol + (host || location.hostname);
                  }
                  return origin;
              }

              // 加載一個(gè)腳本文件
              function _loadJsFile(url, callback) {
                  var script = document.createElement("script");
                  if(script.readyState) {
                      script.onreadystatechange = function() {
                          if(script.readyState == "loaded" || script.readyState == "complete") {
                              callback.call();
                          }
                      }
                  } else {
                      script.onload = callback;
                  }
                  script.type = "text/javascript";
                  script.async = true;
                  //+20130815
                  script.src = url;
                  //url.indexOf('?') != -1 ? url + '&v=' + version : url + '?v=' + version;
                  document.getElementsByTagName("head")[0].appendChild(script);
              }

              // 加載腳本文件列表
              function _loadJsList(urls, statechange, _index) {
                  if(showLoading && AheadHandle.loadingBee && AheadHandle.loadingBee.canvas) {
                      AheadHandle.loadingBee.show();
                      showLoading = false; //130826 show一次就夠了
                  }
                  var index = _index || 0;
                  if(urls[index]) {
                      _loadJsFile(urls[index], function() {
                          _loadJsList(urls, statechange, index + 1);
                      });
                  }

                  if(statechange) {
                      statechange(index);
                  }
              }

              var allHost = getHostWithProtocol();
              // 根據(jù)域名解析文件url
              function _parse(urls, type) {
                  var _urls = [], url = "";

                  if( typeof urls == "string") {
                      urls = [urls];
                  }

                  for(var i = 0, len = urls.length; i < len; i++) {
                      url = urls[i];
                      if(!url) {
                          //
                      } else if(/^(http|https)/.test(url)) {// 完整的URL
                          _urls.push(url);
                      } else if(/^\//.test(url)) {// 以根目錄為路徑
                          _urls.push(protocol + "http://" + host + url);
                      } else {
                          _urls.push(url);
                      }
                  }

                  return _urls;
              }

              // 加載一個(gè)css文件
              function loadCSS(urls) {
                  var html = [];
                  urls = _parse(urls, "css");
                  for(var i = 0, len = urls.length; i < len; i++) {
                      html.push("<link type=\"text/css\" rel=\"stylesheet\" href=\"" + urls[i] + "\" />");
                  }
                  document.write(html.join(""));
              }

              // 加載腳本文件
              function loadJs(urls, callback, dontevent, showLoad) {
                  showLoading = showLoad;
                  urls = _parse(urls, "js");
                  if(!dontevent) {
                      var _callback = callback, len = urls.length;
                      callback = function(index) {
                          if(_callback) {
                              _callback(index);
                          }

                          if(index == len) {
                              if(AheadHandle.loadingBee && AheadHandle.loadingBee.canvas) {
                                  AheadHandle.loadingBee.hide();
                              }
                              //App.onload(); //stz
                              //App.alert('body:'+ document.getElementsByTagName('body') +' , links: '+ document.getElementsByTagName('link').length);
                              // keepFlow();
                          }
                      }
                  }
                  _loadJsList(urls, callback);
              }


              window.loadCSS = loadCSS;
              window.loadJs = loadJs;
              window.getDiffFrameUrl = function(prefix) {
                  var b = navigator.userAgent.toLowerCase();
                  browser = {
                      safari : /webkit/.test(b),
                      opera : /opera/.test(b),
                      msie : /msie/.test(b) && !/opera/.test(b),
                      mozilla : /mozilla/.test(b) && !/compatible/.test(b),
                      winphone : window.navigator.msPointerEnabled
                  };
                  prefix = !prefix ? '' : prefix;
                  var url = prefix+'../../mobile/common_js/zepto.min.1.0rc1.js';
                  //js/third-party/zepto.min.1.0rc1.js
                  //http://a.tbcdn.cn/mw/base/libs/zepto/1.0.0/zepto.js
                  if(browser.msie || browser.winphone) {
                      url = prefix+'http://script2.pingan.com/app_js/toubao/v20/js/jquery-1.4.4.js';
                  }
                  return url;
              }
              /**
               * ============================================= 蜜蜂類
               */
              function loadingBee(options) {
                  var options = options || {};
                  this.path = options.path || '../../common_images/';
                  this.images = options.images || ['loading.gif'];
                  this.width = options.width || 230;
                  this.height = options.height || 230;
                  this.FPS = options.width || 5;
                  this._curFrame = 0;
                  this._playTime = 0;
                  this.canvas = null;
                  this.loadingBg = null;
                  this._init();
              }


              loadingBee.prototype = {
                  _init : function() {
                      var loadedNum = 0, arrowImage = [];
                      var self = this;

                      for(var i = 0, len = this.images.length; i < len; i++) {
                          arrowImage[i] = new Image();
                          //打算用背景方式,無(wú)需關(guān)心圖片是否加載成功了,因?yàn)椴粫?huì)出現(xiàn)異常,最多是某幀不出現(xiàn)而已
                          arrowImage[i].src = this._getCDNPicURL(this.path + this.images[i]);
                          if(i == len - 1) {
                              self.images = arrowImage.slice(0);
                              self._creatMovie();
                          }
                      }
                  },
                  /**
                   * 獲取cdn圖片地址
                   * @param {String} fileName 圖片在本地相對(duì)于根目錄的位置,如 images/themes/default/images/member/drawUpIcon.png
                   * @return {String} 真實(shí)地址
                   */
                  _getCDNPicURL : function(fileName) {
                      var oldfileName = fileName;
                      var origin = location.origin, host = location.host;
                      if(!origin) {//android 不識(shí)別 location.origin
                          var protocol = location.protocol;
                          protocol = protocol == "http:" ? "http://" : protocol == "https:" ? "https://" : "file:///";
                          origin = protocol + (host || location.hostname);
                      }
                      return fileName;
                  },
                  /**
                   * 通過(guò)畢包實(shí)現(xiàn)的事件代理
                   * @param {Function} func
                   * @param {Object} scope
                   */
                  // _delegate : function(func, scope) {
                  // scope = scope || window;
                  // if(arguments.length > 2) {
                  // var args = Array.prototype.slice.call(arguments, 2);
                  // return function() {
                  // return func.apply(scope, args);
                  // }
                  // } else {
                  // return function() {
                  // return func.call(scope);
                  // }
                  // }
                  // },
                  _creatMovie : function() {
                      this.movieCreated = true;
                      var screenW = 640, screenH = document.documentElement.clientHeight;
                      //stz mf 201300730: ie10設(shè)置固定寬度才行!
                      //var screenW = document.body.clientWidth, screenH = document.body.clientHeight; //stz mf 201300730
                      var canvas = document.createElement('div');
                      var canvasCont = document.createElement('div');
                      canvasCont.className = 'comBeeLoading';
                      // canvasCont.innerText = 'loading';
                      // this.canvasCont = canvasCont;
                      canvasCont.innerHTML = '<div class="comTable"><span class="comTableCell loadingWord">&nbsp;</span><span class="comTableCell loadingDot"><span></span></span></div>'
                      canvas.appendChild(canvasCont);
                      this.loadingDot = canvasCont.children[0].children[1].children[0];
                      document.body.appendChild(canvas);
                      canvas.callTimes = 0;
                      this.canvas = canvas;
                      // this.loadingBg = document.getElementById('loadingBeeBg');
                      canvas.style.cssText = 'width:' + this.width + 'px; height:' + this.height + 'px;position:absolute;display:none;z-index:1002;left:' + (screenW - this.width) / 2 + 'px; top:' + (screenH - this.height) / 2 + 'px;';
                      loadingBee.instance = this;
                  },
                  show : function(pos) {//pos + 2013-08-10 {top:200px, left:100px}默認(rèn)居中
                      var canvas = this.canvas, ctx = canvas.style;
                      canvas.callTimes++;
                      if(!loadingBee.movIntval) {
                          canvas.style.display = 'block';
                          // this.loadingBg.style.display = 'block';
                          var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
                          //stz:+201300730||document.documentElement.scrollTop兼容ie10.因html5是屬于非怪異(非quirk)模式,這時(shí)documentElement有值,body沒有。而在怪異模式正好相反
                          // if(scrollTop>0){
                          // ctx.top = scrollTop+(document.documentElement.clientHeight-this.height)/2+20+'px';
                          // }else{ //+ 2013521: 蜜蜂已經(jīng)下去又拖到頂部時(shí) 重新把蜜蜂提上來(lái)點(diǎn)
                          // ctx.top = (document.documentElement.clientHeight-this.height)/2+20+'px';
                          // }
                          if(pos && pos.top) {
                              ctx.top = pos.top + 'px';
                          } else {
                              ctx.top = scrollTop + (document.documentElement.clientHeight - this.height) / 2 + 30 + 'px';
                          }
                          ctx.background = "url(" + this.images[0].src + ") no-repeat center center";
                          // var self = this, frameInval = parseInt(1000/this.FPS), frameLen = 3;
                          // var teststz = document.getElementById('teststz');
                          // loadingBee.movIntval = setInterval(function(){
                          // ctx.top = scrollTop+(document.documentElement.clientHeight-self.height)/2+30+'px';
                          // // console.log(self._curFrame)
                          // if(self._curFrame==0){
                          // self.loadingDot.innerText = ''; //canvasCont
                          // }else{
                          // self.loadingDot.innerText = self.loadingDot.innerText+'.';
                          // }
                          // self._curFrame++;
                          // self._curFrame%=frameLen+1;
                          // self._playTime+=frameInval;
                          // }, frameInval);
                          loadingBee.movIntval = true;
                      }
                  },
                  hide : function() {//return;
                      var canvas = this.canvas;
                      canvas.callTimes--;
                      if(canvas.callTimes > 0) {
                          return;
                      } else {
                          canvas.callTimes = 0;
                      }
                      canvas.style.display = 'none';
                      // this.loadingBg.style.display = 'none';
                      if(loadingBee.movIntval) {
                          clearInterval(loadingBee.movIntval);
                          loadingBee.movIntval = null;
                          this._curFrame = 0;
                          this._playTime = 0;
                      }
                  },
                  hideAll : function() {//return;
                      var canvas = this.canvas;
                      canvas.callTimes = 0;
                      canvas.style.display = 'none';
                      // this.loadingBg.style.display = 'none';
                      if(loadingBee.movIntval) {
                          clearInterval(loadingBee.movIntval);
                          loadingBee.movIntval = null;
                          this._curFrame = 0;
                          this._playTime = 0;
                      }
                  }
              };

              //if(!IS_NATIVE) {      //屏蔽對(duì)移動(dòng)設(shè)備的判斷條件
                  window.AheadHandle = {};
                  window.bodyLoadStart_inv = setInterval(function() {
                      if(document.body) {//||!document.body document.getElementsByTagName('header')
                          clearInterval(window.bodyLoadStart_inv);
                          window.bodyLoadStart_inv = null;
                          // var canvasbg = document.createElement('div');
                          // canvasbg.id = 'loadingBeeBg';
                          // canvasbg.className = 'com_shadowbg';
                          // // canvasbg.style.display = 'block';
                          // document.body.insertBefore(canvasbg,null); //prepend
                          // // if(!IS_NATIVE) {
                          // // AheadHandle.loadingBee.show();
                          // // }
                          // // AheadHandle.loadingBee.show();
                          AheadHandle.loadingBee = loadingBee.instance ? loadingBee.instance : new loadingBee();
                          // window.loadingCreat_inv = setInterval(function(){
                          // if( AheadHandle.loadingBee.canvas ){
                          // clearInterval(window.loadingCreat_inv);
                          // window.loadingCreat_inv = null;
                          // AheadHandle.loadingBee.show();
                          // }
                          // },50);
                      }
                  }, 0);
                  window.getmtParam = getmtParam();
              //}
              // function bodyLoadStart(){
              // if(!AheadHandle.loadingBee.canvas){ //||!document.body
              // setTimeout(bodyLoadStart,50);
              // } else{
              // AheadHandle.loadingBee.show();
              // }
              // }
              // bodyLoadStart();
          })();

          posted on 2014-06-26 09:42 koradji 閱讀(149) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          db2

          dos

          Groovy

          Hibernate

          java

          WAS

          web application

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 靖安县| 巢湖市| 那曲县| 久治县| 通山县| 广州市| 贞丰县| 陇南市| 柞水县| 哈密市| 安康市| 自贡市| 施甸县| 上栗县| 兴隆县| 沙雅县| 古丈县| 瑞安市| 廊坊市| 陆河县| 江阴市| 庄浪县| 金华市| 孝昌县| 琼中| 柳林县| 兴山县| 阜康市| 西丰县| 四会市| 昭觉县| 子洲县| 白沙| 达日县| 清徐县| 西和县| 太保市| 上思县| 天长市| 张掖市| 岐山县|