var adsense = adsense; (function(){ var tbsEngine = !!window.tbsJs || !!window.qb_bridge; //获取广告HTML adsense = function(el,pos){ $.post('/index/Pagejs/s1.html',{ isajax:1, pos:pos, env:{ tbs:tbsEngine?1:0 } },function(json){ if(json.status != 0){ return; } if('html' in json.data){ el.html("
"+json.data.html+"
"); } },"json"); } //检测加载 var checkedAdShowTime = {}; adsense.checkedAdShow = function(reload,elId,time){ var time = time || 2000; time = time?time:2000; if(elId in checkedAdShowTime){ clearTimeout(checkedAdShowTime[elId]); } checkedAdShowTime[elId] = setTimeout(function(){ delete checkedAdShowTime[elId]; if($('#'+elId).find('*').length==0){ //没有加载成功 reload(elId); } },time); } var adReloadIndex = 10000; adsense.adPushReload = {}; //队列广告 adsense.queue = function(queue,env,callback){ var env = env || {}; env.tbs = tbsEngine?1:0; var posList = []; for(var i in queue){ posList.push(i); } var callback = callback || function(){} $.post('/index/Pagejs/s2.html?r='+Math.random()+'&PHPSESSID='+getCookie('841534cee2087fb8'),{ isajax:1, pos:posList, env:env },function(json){ callback(); if(json.status != 0){ return; } for(var pos in json.data){ (function(el,code,env,pos){ var reload = function(isLoadIndex,elId){ if(elId in checkedAdShowTime){ clearTimeout(checkedAdShowTime[elId]); delete checkedAdShowTime[elId]; } env.loadIndex = env.loadIndex || 0; env.loadIndex++; var q = {}; q[pos] = el; console.log(env); adsense.queue(q,env); } var adi = ++adReloadIndex; adsense.adPushReload[adi] = reload; code = code.replace('__reload__(','adsense.adPushReload['+adi+'](true,'); code = code.replace('__checkad__(','adsense.checkedAdShow(adsense.adPushReload['+adi+'],'); el.html("
"+code+"
"); })(queue[pos],json.data[pos],$.extend({},env),pos); } },"json").error(function(){ callback(); }); } var queues = []; adsense.queueAjaxRun = function(){ var obj = queues.length > 0 ? queues[0] : false; if(obj){ adsense.queue(obj.queue,obj.env,function(){ queues.shift(); adsense.queueAjaxRun(); }); } } adsense.queueAjax = function(queue,env){ queues.push({ queue:queue, env:env }); console.log(queues.length) if(queues.length > 1){ return; } adsense.queueAjaxRun(); } //跳转 adsense.tourl = function(url){ window.location = url; } //全窗口显示 adsense.fullWindow = function(url){ var html = "
"; html += ""; html += "
"; html = $(html); var $win = $(window); html.width($win.width()); html.height($win.height()); html.find("iframe").css({ height:'100%', width:'100%', background:"url(/static/index/images/loading-2.gif) no-repeat center center" }); html.find('img').on('click',function(){ html.remove(); }); $("body").append(html); } //关闭 adsense.fullWindow.close = function(){ $(".adsense-fullWindow").remove(); } adsense.alertFullWindow = { close:function(){ $(".adsense-alertFullWindow").remove(); return false; } } //广告点击事件 adsense.clickEvent = function(guid,callback){ taskQueue.add(function($next){ $.post("/index/Pagejs/adclickevent.html"+'?isajax=1&PHPSESSID='+getCookie('841534cee2087fb8'),{guid:guid},function(json){ $next(); if(typeof callback == "function"){ callback(json); } },"josn").error(function(){ $next(); }); }); } //广告曝光事件 adsense.showEvent = function(guid,callback){ taskQueue.add(function($next){ $.post("/index/Pagejs/adshowevent.html"+'?isajax=1&PHPSESSID='+getCookie('841534cee2087fb8'),{guid:guid},function(json){ $next(); if(typeof callback == "function"){ callback(json); } },"josn").error(function(){ $next(); }); }); } //广告失败事件 adsense.errorEvent = function(){ } if(typeof adsense.onload == "function"){ adsense.onload(); } })();