core.min.js
14.7 KB
var Core={};function initMatching(){var e=navigator.userAgent;Core.isIos=e.match(/i[^;]+;( U;)? CPU.+Mac OS X/)!=null;Core.isAndroid=e.indexOf("Android")>-1||e.indexOf("Linux")>-1;Core.isFile=location.href.indexOf("file")==0;Core.isWeixin=e.indexOf("MicroMessenger")!=-1;var t=window.devicePixelRatio;Core.ratio=t;var a=localStorage.getItem("last_server");if(a&&a.indexOf("http:")==0){if(Core.isFile){Core.server=a}else if(location.href.indexOf(a)==-1){location.href=location.href.replace(Core.server,a)}}var i=null;if(location.hash.indexOf("app_id")!=-1){i=location.hash.match(/.*%7C(\d+)_(\d+)&/)}else{i=location.search.match(/.*%7C(\d+)_(\d+)&/)}if(i&&i.length==3){Core.sdk_w=parseInt(i[1]);Core.sdk_h=parseInt(i[2]);if(Core.isIos&&e.indexOf("iPad")!=-1&&Core.sdk_h<600){Core.sdk_w*=2;Core.sdk_h*=2}}if(location.href.indexOf("callBackUrl")!=-1){try{Core.Data.back_url=unescape(location.href.match(/callBackUrl=([^&]+)/)[1])}catch(e){}}var o=$("head");if(Core.isAndroid){$("html").attr("data-useragent","android");if(t>1.5){$('<meta name="viewport" content="target-densitydpi=340;initial-scale=1.0"/>').appendTo(o)}else if(t<1){$('<meta name="viewport" content="target-densitydpi=280;initial-scale=1.0"/>').appendTo(o)}else if(t==1){$('<meta name="viewport" content="target-densitydpi=300;initial-scale=1.0"/>').appendTo(o)}else{$('<meta name="viewport" content="target-densitydpi=340;initial-scale=1"/>').appendTo(o)}}var r=null;if(Core.isIos){$("html").attr("data-useragent","ios");if(!Core.sdk_w)Core.sdk_w=600;_scale=1;if(t>1.5){_scale=2.3/t}else if(t<1){_scale=1.5/t}else{_scale=1}if(e.indexOf("iPad")!=-1&&Core.sdk_w>768){Core.sdk_w=Core.sdk_w/2;Core.sdk_h=Core.sdk_h/2/_scale}else{Core.sdk_h=Core.sdk_h*_scale}r=Core.sdk_w*_scale;Core.ios_w=r;$('meta[name="viewport"]').attr("content","width="+r+",maximum-scale="+_scale+",user-scalable=no");$(window.document).on("touchmove",function(e){if(e.target.tagName!="IFRAME")e.preventDefault()});$("body").addClass("ios");if($("div")[0].getAttribute("class")!="mask"){$("div")[0].remove()}}}(function(){if(typeof localStorage=="undefined"){localStorage={setItem:function(){console.log("localStorage not support!")},getItem:function(){console.log("localStorage not support!")}}}var e=navigator.userAgent;Core.isIos=e.match(/i[^;]+;( U;)? CPU.+Mac OS X/)!=null;Core.isAndroid=e.indexOf("Android")>-1||e.indexOf("Linux")>-1;Core.isFile=location.href.indexOf("file")==0;Core.isWeixin=e.indexOf("MicroMessenger")!=-1;var t=window.devicePixelRatio;Core.ratio=t;Core.server="http://youyu.9133.com";var a=localStorage.getItem("last_server");if(a&&a.indexOf("http:")==0){if(Core.isFile){Core.server=a}else if(location.href.indexOf(a)==-1){location.href=location.href.replace(Core.server,a)}}var i=null;if(location.hash.indexOf("app_id")!=-1){i=location.hash.match(/.*%7C(\d+)_(\d+)&/)}else{i=location.search.match(/.*%7C(\d+)_(\d+)&/)}if(i&&i.length==3){Core.sdk_w=parseInt(i[1]);Core.sdk_h=parseInt(i[2]);if(Core.isIos&&e.indexOf("iPad")!=-1&&Core.sdk_h<600){Core.sdk_w*=2;Core.sdk_h*=2}}if(location.href.indexOf("callBackUrl")!=-1){try{Core.Data.back_url=unescape(location.href.match(/callBackUrl=([^&]+)/)[1])}catch(e){}}var o=$("head");if(Core.isAndroid){$("html").attr("data-useragent","android");if(t>1.5){$('<meta name="viewport" content="target-densitydpi=340;initial-scale=1.0"/>').appendTo(o)}else if(t<1){$('<meta name="viewport" content="target-densitydpi=280;initial-scale=1.0"/>').appendTo(o)}else if(t==1){$('<meta name="viewport" content="target-densitydpi=300;initial-scale=1.0"/>').appendTo(o)}else{$('<meta name="viewport" content="target-densitydpi=340;initial-scale=1"/>').appendTo(o)}}var r=null;if(Core.isIos){$("html").attr("data-useragent","ios");if(!Core.sdk_w)Core.sdk_w=600;_scale=1;if(t>1.5){_scale=2/t}else if(t<1){_scale=1.5/t}else{_scale=1}if(e.indexOf("iPad")!=-1&&Core.sdk_w>768){Core.sdk_w=Core.sdk_w/2;Core.sdk_h=Core.sdk_h/2/_scale}else{Core.sdk_h=Core.sdk_h*_scale}r=Core.sdk_w*_scale;Core.ios_w=r;$('meta[name="viewport"]').attr("content","width="+r+",maximum-scale="+_scale+",user-scalable=no");$(window.document).on("touchmove",function(e){if(e.target.tagName!="IFRAME")e.preventDefault()});$("body").addClass("ios");if($("div")[0].getAttribute("class")!="mask"){$("div")[0].remove()}}})();(function(e,t){var a={},i=null;t.Data={};t.cur_mod=null;t.last_mod=null;t.getTemplate=function(e){var t=$("#"+e+"_template").html();return t};t.getMod=function(e){if(!e in a){console.error("没有对应的模块id的section:"+e);return}return a[e]};t.registerMod=function(e,t){if($("#"+e).length==0)console.error("没有对应的模块id的section:"+e);if(a[e])console.error("模块已经存在:"+e);a[e]=new t(e);a[e].init()};t.back=function(){if(!t.cur_mod||t.cur_mod=="")t.cur_mod="home";var e=$("#"+t.cur_mod);var a=e.find(".op-back");if(a.length==0){location.href="sdk://exit?action=login"}else{var i=a.attr("href");if(i.indexOf("#")==0){location.hash=i}else{location.href=i}}};t.clearFrame=function(){var e=$("#frame iframe");e.remove()};t.updateData=function(e){var t=Core.Data.app_id;if(!e){Core.Data.username=null;Core.Data.nickname=null;return}Core.Data=e;Core.Data.app_id=t;Core.Data.open_id=Core.Data.open_id+"";Core.Data.timestamp=Core.Data.timestamp+"";if(e.face){Core.Data.face=Core.server+e.face}};t.updateMod=function(e){if(!e in a){console.error("没有对应的模块id的section:"+e);return}location.hash="#"+e+"&force"};t.clearMods=function(){for(var e in a){a[e].isValid=false}};t.showMod=function(e){if(!e in a){console.error("没有对应的模块id的section:"+e);return}location.hash="#"+e};t.showTips=function(e,t,a){if(typeof e=="object")e=e.msg;if(t==undefined)t=1;if(a==undefined)a=4e3;var o=$("#alert");if(t)o.removeClass("alert-error").addClass("alert-success");else o.removeClass("alert-success").addClass("alert-error");if(i!=null){$("#alert span").html(e);clearTimeout(i);i=null;i=setTimeout(function(){$("#alert").hide();i=null},a);return}$("#alert span").html(e);o.show();i=setTimeout(function(){$("#alert").hide();i=null},a)};t.isValid=function(e){var t=true;e.find("input[required]").each(function(){if(!t){return}if($(this).val()==""){$(this).focus();t=false}});if(!t){Core.showTips("请先填写相应信息!",false,2e3);return false}return true};t.goTo=function(e){if(!t.Data.game_url){e="sdk://open?url="+encodeURIComponent(e)}location.href=e};t.getCookie=function(e){var t=document.cookie.match("\\b"+e+"=([^;]*)\\b");return t?t[1]:undefined};t.GetParameter=function(e){var a="";$(e).find("input,textarea,select").each(function(){if($(this).attr("name")==undefined||$(this).attr("name")==""){return}var e=$(this).attr("type");if(e=="button"||e=="submit")return;var t=false;if(e=="checkbox"||e=="radio")t=true;var i=false;if(t){if(!$(this)[0].checked)return}a+=$(this).attr("name")+"="+encodeURIComponent($(this).val().trim())+"&"});a+="app_id="+encodeURIComponent(t.Data.app_id?t.Data.app_id:t.Data.game_id);if(a.indexOf("_xsrf")==-1){a+="&_xsrf="+t.getCookie("_xsrf")}return a};t.ajax_do=function(e,a,i){var o="";var r=null;var s="";var n=e.find("[type=submit]");var l=n.is("button")?n.html():n.attr("value");if(e[0].tagName=="FORM"||e[0].getAttribute("action")){if(e[0].disabled){Core.showTips("请求已提交,请稍候!");return}if(!t.isValid(e))return;o=t.GetParameter(e);s=e.attr("action");d="post"}else{if(e[0].disabled){Core.showTips("请求已提交,请稍候!");return}s=e.attr("href");o=e.attr("params");var d=e.attr("method");if(!d){d="get"}}if(s.indexOf("?")!=-1){s+="&format=json"}else{s+="?format=json"}if(Core.isFile){s=t.server+s}var f={type:d,url:s,dataType:"json",contentType:"application/x-www-form-urlencoded; charset=utf-8",data:o,success:function(o,r){if(o.code==-10){}else if(o.code==0){if(a&&typeof a=="function"){i?a.call(i,o):a(o)}if(typeof o.msg=="$object"&&o.msg.msg)o.msg=o.msg.msg}if(e[0].tagName=="FORM"){e[0].disabled=false;e.find("input, button").attr("disabled",null);var s=e.find("[type=submit]");if(s.is("button")){s.html(l)}else{s.attr("value",l)}}else{e[0].disabled=false}if(o.msg!=""){if(o.code!=0)t.showTips(o.msg,false)}},cache:false,timeout:1e4,error:function(a,i){var o=a.status;var r="网络不给力,请重试!"+o;if(o==403||o==401){r="请先登录!"}else if(o==408){r="请求超时,请再尝试!"}else if(o==411){r="提交内容过长。"}if(e[0].tagName=="FORM"){t.showTips(r,false,3e3);e[0].disabled=false;e.find("input, button").attr("disabled",null);var s=e.find("[type=submit]");if(s.is("button")){s.html(l)}else{s.attr("value",l)}}else{t.showTips(r,false,3e3);e[0].disabled=false}}};if(e[0].tagName=="FORM"){e[0].disabled=true;e.find("input, button").attr("disabled",true);if(n.is("button")){n.html("提交中...")}else{n.attr("value","提交中...")}}else{e[0].disabled=true}Core.showTips("加载中...",true,5e3);$.ajax(f);return false};t.load_json=function(e,a,i){var o=e.data("path");if(e.data("disabled")==true){Core.showTips("请求已提交,请稍候。");return}if(Core.isFile){o=t.server+o}var r={type:"get",url:o,dataType:"json",timeout:1e4,success:function(t){if(a&&typeof a=="function"){i?a.call(i,t):a(t)}e.data("disabled",false)},error:function(){Core.showTips("数据加载出错,请检查网络状态。",false,3e3);e.data("disabled",false)}};e.data("disabled",true);Core.showTips("加载中...",true,5e3);$.ajax(r);return false};t.load_html=function(e,a,i){var o="";var r=false;var s=e.attr("data-params-template");if(e[0].tagName=="A"){o=e.attr("href");r=e.attr("data-params-append")=="true"?true:false}else{o=e.attr("data-params-url")}if(o=="")return;if(o.indexOf("?")!=-1){o+="&format=json"}else{o+="?format=json"}if(o.indexOf("game_id")==-1){var n=t.Data.game_id?t.Data.game_id:t.Data.app_id;o+="&game_id="+n}var l="";if(s&&s!=""){l="json"}var d="";if(Core.isFile){o=t.server+o}var f={type:"get",url:o,dataType:l,contentType:"application/x-www-form-urlencoded; charset=utf-8",success:function(t){if(t.code&&t.code!=0){Core.showTips(t.msg,false);return}d=t;if(s&&s!=""){tpl=Core.getTemplate(s);var o=doT.template(tpl);t=o(d);if(r){var n=e.parent();n.is(".more")?n.replaceWith(t):e.find(".more").replaceWith(t)}else{e.html(t)}if(a&&typeof a=="function"){i?a.call(i,t):a(t)}Core.showTips("加载完毕!",true,2e3)}else{e.html(t);if(a&&typeof a=="function"){i?a.call(i,t):a(t)}Core.showTips("加载完毕!",true,2e3)}},cache:false,timeout:5e3,error:function(e){Core.showTips("json format has error")}};Core.showTips("加载中...",true,5e3);$.ajax(f)};t.isAuths=function(){if($("#login").length==1&&!t.Data.username){return false}return true};t.inherit=function(e,t){function a(){}a.prototype=t.prototype;e.superClass_=t.prototype;e.prototype=new a;e.prototype.constructor=e};t.show_anim=function(e){e.css({zIndex:2});e.show()};t.loadFinished=function(){if(Core.isAndroid){if(!Core.Data.game_url){try{return;location.href="sdk://finishLoad?action=login"}catch(e){}}}else{console.log("not wbkit browser!")}};t.finishPay=function(){var e="sdk://exit?action=pay";t.clearFrame();if(Core.Data.game_url&&Core.Data.game_url!=""){if(Core.Data.back_url){e=Core.Data.back_url}else{e=Core.Data.game_url}}else{if(Core.Data.trade_id&&Core.Data.trade_id!=""){e="sdk://pay?order_id="+Core.Data.trade_id;e+=Core.Data.current_pay_channel?"&paytype="+Core.Data.current_pay_channel.name:""}}try{location.href=e}catch(e){}};t.finishLogin=function(){var e="sdk://exit?action=login";var t="open_id="+Core.Data.open_id+"&token="+Core.Data.token+"×tamp="+Core.Data.timestamp;t+=Core.Data.login_count?"&login_count="+Core.Data.login_count:"";if(Core.Data.game_url&&Core.Data.game_url!=""){if(Core.Data.back_url){e=Core.Data.back_url}else{e=Core.Data.game_url}if(e.indexOf("?")!=-1){e+="&"}else{e+="?"}e+=t}else{e="sdk://login?"+t;e+="&login_key="+Core.Data.login_key}try{location.href=e}catch(e){}};t.hide=function(i){if(!i)i=t.cur_mod;if(!(i in a)){console.log("没有对应的模块id的section:"+i);return}var o=$(e).width();var r=$("#"+i);if(r.find("iframe").length>0){t.clearFrame()}r.css({zIndex:1});r.hide();t.last_mod=i};t.init=function(){if(localStorage.getItem("guest_n")||Core.user_names){t.isFresh=false}else{t.isFresh=true}$("#alert").on("click","",function(e){if(i){clearTimeout(i);i=null;$("#alert").hide()}});e.onhashchange=function(){var e=location.hash,i,o;var r=e.split("&");e=r[0];o=r[1];if(e==""){if(Core.start_page){e=Core.start_page}else{e="home"}}else{e=e.substring(1)}if(!(e in a)){console.log("没有对应的模块id的section:"+e);e="home"}t.hide();i=a[e];t.cur_mod=e;if(o&&o.indexOf("force")!=-1){if(i.isDef){i.show(false)}else{i.$c.find("ol").empty();i.show()}}else{i.show()}};var o=location.hash.split("&")[0];var r=null;if(o==""){if(Core.start_page){r=Core.start_page}else{r="home"}location.hash="#"+r}else{r=o.substring(1);onhashchange()}if(Core.Data.open_id&&Core.Data.open_id!=""&&$("#login").length!=0&&Core.Data.auto_login==1&&Core.Data.is_guest==0){var s=(new Date).getTime();var n=localStorage.getItem("auto");var l=parseInt(localStorage.getItem("auto_time"));if(n&&n=="true"){if(s-l>6e5){localStorage.setItem("auto_time",s);t.finishLogin()}else{localStorage.setItem("auto_time",s);t.loadFinished()}}else{localStorage.setItem("auto",true);localStorage.setItem("auto_time",s);Core.finishLogin()}}else{if($("#login").length!=0){var d=(new Date).getTime();localStorage.setItem("auto",true);localStorage.setItem("auto_time",d)}t.loadFinished()}};$(function(){var t,a,i,o,r;var s=e.devicePixelRatio;if(Core.sdk_h){if(s!=Core.ratio){a=Core.sdk_h*(Core.ratio/s)}else{a=Core.sdk_h}}else{t=$(e).width();a=$(e).height();o=document.documentElement.clientWidth;r=document.documentElement.clientHeight;if(o&&o>t)t=o;if(r&&r>a)a=r;if(a<450&&t==450){a=450}}if(Core.isIos&&$(e).width()<$("body").width()){$('meta[name="viewport"]').attr("content","width="+$("body").width()+",maximum-scale=0.5,user-scalable=no")}})})(window,Core);Module=function(e){this.isDef=null;this.isAuth=false;this.isReplace=false;this.moduleId=e;this.$c=$("#"+e);this.isValid=false};Module.prototype.init=function(){if(this.$c.attr("data-attr")=="dot"){this.isDef=true}else{this.isValid=true}if(this.$c.attr("data-replace")=="1"){this.isReplace=true}if(this.$c.attr("data-auth")=="1"){this.isAuth=true}if(this.bind&&typeof this.bind=="function")this.bind()};Module.prototype.show=function(e){if(e!=undefined)this.isValid=e;if(this.isAuth&&!Core.isAuths()){if(location.hash.indexOf("login")==-1){Core.isFresh?Core.showMod("login"):Core.showMod("login");return}}if(!this.isDef){if(this.isReplace){this.$c.find("[data-replace]").each(function(e){var t=$(this),a;var i=t.attr("data-replace");var o=t.attr(i);var r=/\{([\w]+)\}/.exec(o);if(r.length==2&&r[1]in Core.Data){a=Core.Data[r[1]];var s=o.replace(r[0],a);t.attr(i,s)}else{console.log("can not find variable in:"+o)}});this.isReplace=false}Core.show_anim(this.$c)}else{if(this.isValid){Core.show_anim(this.$c)}else{if(!this.tpl)this.tpl=doT.template(Core.getTemplate(this.moduleId));this.$c.html(this.tpl());Core.show_anim(this.$c);this.isValid=true}}if(this.show_after&&typeof this.show_after=="function")this.show_after()};