/**
* @author Suker
*/
//重写requestAnimationFrame
var $j=jQuery.noConflict();
window.requestAnimationFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.setTimeout;
})();
//重写cancelAnimationFrame
window.cancelAnimationFrame = (function() {
return window.cancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.oCancelAnimationFrame ||
window.msCancelAnimationFrame ||
window.clearTimeout;
})();
var _getvp = document.getElementById('viewport');
if (_getvp && _getvp.content.indexOf('width=960') >= 0) {
var _ua = navigator.userAgent.toLowerCase(), _setW = window.innerWidth > window.innerHeight ? window.innerWidth : window.innerHeight;
window.glsysw = _setW > 1136 ? 1136 : (_setW == 961 ? 1136 : (_ua.indexOf('ipad') >= 0 ? 1024 : _setW));
_getvp.content = 'width=' + window.glsysw + ',user-scalable=yes';
if (_ua.indexOf('webkit') < 0) {
_getvp.content += ',uc-user-scalable=yes,target-densitydpi=high-dpi';
}
_ua = _setW = null;
}
_getvp = null;
//调出进度条
function callLoading (method) {
return;
var _getLoadingDiv = document.getElementById('loadingDiv');
if (_getLoadingDiv) {
if (method == 'close') {
document.body.removeChild(_getLoadingDiv);
}
else {
_getLoadingDiv.style.height = window.innerHeight + 'px';
}
}
else if (method == 'open') {
_getLoadingDiv = document.createElement('div');
_getLoadingDiv.id = 'loadingDiv';
_getLoadingDiv.style.position = 'absolute';
_getLoadingDiv.style.width = '100%';
_getLoadingDiv.style.height = window.innerHeight + 'px';
_getLoadingDiv.style.textAlign = 'center';
_getLoadingDiv.style.background = '#FFF';
_getLoadingDiv.style.zIndex = 1000000;
_getLoadingDiv.style.left = '0px';
_getLoadingDiv.style.top = '0px';
_getLoadingDiv.innerHTML = [
''
].join('');
document.body.appendChild(_getLoadingDiv);
}
_getLoadingDiv = null;
};
var QueryString = {
/**
* 取得查询字符串参数
* 例:假设查询字符串是?q=javascript&num=10
* var args=getQueryStringArgs();
* alert(args["q"]);
* alert(args["num"]);
*/
getQueryStringArgs: function () {
//取得查询字符串并去掉开头的问号
var qs = (location.search.length > 0 ? location.search.substring(1) : "");
//保存数据的对象
var args = {};
//取得每一项
var items = qs.split("&");
var item = null,
name = null,
value = null;
//逐个将每一项添加到args对象中
for (var i = 0; i < items.length; i++) {
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
args[name] = value;
}
return args;
},
/**
* 对getQueryStringArgs()方法进行进一步封装,简化调用
*/
getParameter: function (keyValue) {
var args = this.getQueryStringArgs();
if (args[keyValue] != undefined) {
return args[keyValue];
} else {
return "";
}
}
};
var CookieUtil = {
get: function (name){
var cookieName = encodeURIComponent(name) + "=",
cookieStart = document.cookie.indexOf(cookieName),
cookieValue = null;
if (cookieStart > -1){
var cookieEnd = document.cookie.indexOf(";", cookieStart);
if (cookieEnd == -1){
cookieEnd = document.cookie.length;
}
cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
}
return cookieValue;
},
set: function (name, value, day, path, domain, secure) {
var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
if(typeof day=="number"){
var expires = new Date();
expires.setTime(expires.getTime() + day*24*60*60*1000);
cookieText += "; expires=" + expires.toGMTString();
}
if (path) {
cookieText += "; path=" + path;
}
if (domain) {
cookieText += "; domain=" + domain;
}
if (secure) {
cookieText += "; secure";
}
document.cookie = cookieText;
},
unset: function (name, path, domain, secure){
this.set(name, "", new Date(0), path, domain, secure);
}
};
var $iframe=null;
function crossAjax(config){
document.domain='127.0.0.1'; //域名
if(!$iframe){
$iframe= $j('',{id:'crossDomain',style:'display:none;',src:server.DuopaoBlankURL}).appendTo('body').load(function(){
$iframe.win=$j(this)[0].contentWindow;
$iframe.loadReady=true;
});
}
if($iframe.loadReady){
$iframe.win.$.ajax(config);
}else{
$iframe.one('load',function(){
$iframe.win.$.ajax(config);
});
}
}
//上传积分(每一关完成都会上传积分)
var loginCounter=0;
function dp_submitScore(vLevel,vScore){
crossAjax({
url:rootIndex+'uploadscore.php',
data:{
game_code:QueryString.getParameter('game_code'),
game_level:vLevel,
game_score:vScore,
bs:QueryString.getParameter('bs')
},
type:'post',
dataType:'json',
success:function(res){
//this added by JobsFan
if (QueryString.getParameter('bs').indexOf('wx')!=-1){
//dp_share(vScore);//不能写在这里,因为游戏分享的部分可能不一样
$j(".nowrecord .num").html(vScore);
$j(".bestrecord .num").html(res.bestscore);
$j(".scoreinfo").show();
}
if(res.flag=='f0'){
if(res.ulevel>0){
// if(confirm('你的分数为'+res.uscore+',排名为第'+res.ulevel+'名,是否跳转到排行榜?')){
// location.href=rootIndex+'games/toplist?game_code='+QueryString.getParameter('game_code');
// }
}
}else if(res.flag=='f1'){
if(loginCounter==1||confirm('您尚未登录,游戏积分无法上传到排行榜,是否登录?')){
location.href=server.PageLoginURL+'?service='+encodeURIComponent(location.href);
}else{
loginCounter++;
}
}else{
alert(res.msg);
}
}
});
}
var rankLoading=false;
function dp_Ranking(show_type){
if(rankLoading){
return;
}
var game_code=QueryString.getParameter('game_code');
if(show_type==-1||true){
location.href=rootIndex+'toplist.php?game_code='+game_code;
return;
}
rankLoading=true;
crossAjax({
url:rootIndex+server.GameTop,
data:{
game_code:game_code,
pflag:true,
perPageSize:3,
pageIndex:1,
flag:true
},
success:function(result){
rankLoading=false;
var data=JSON.parse(result);
if(data.flag=='f0'||data.flag=='f1'){
var tem;
if(data.flag!='f0'){
tem='