//ajax/json cors跨域开关 $.support.cors = true; if (typeof console == 'undefined') { window.console = { log: function () { } } } // 360广告宏替换参数 var Macro = {start: "__EVENT_TIME_START__", end: "__EVENT_TIME_END__", x: "__OFFSET_X__", y: "__OFFSET_Y__"}; //公用 (function () { var common = { getUserId: function () { return (+new Date()) + Math.random().toString(10).substring(2, 6); }, GetQueryString: function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }, }; window.Common = common; })(); Configuration(); //根据域名配置 var proConfig; function Configuration() { // 默认配置 var proObject = { name: 'kuaiya', mini_name: '005', qid: {rewen:'mininew',toutiao:'mininew',shehui:'mininew',yule:'mininew',shipin:'mininew',tiyu:'mininew',qiche:'mininew',junshi:'mininew',yangsheng:'mininew',youxi:'mininew',guoji:'mininew',shishang:'mininew',lishi:'mininew',keji:'mininew',caijing:'mininew',xiaohua:'mininew'}, left_tab:{youxi:'游戏',yangsheng:'养生',junshi:'军事',qiche:'汽车',tiyu:'体育',shipin:'视频',yule:'娱乐',shehui:'社会', toutiao:'推荐',guoji:'国际',caijing:'财经',xiaohua:'笑话',qinggan:'情感',gaoxiao:'搞笑',lieqi:'猎奇',lvyou:'旅游',renwen:'人文'}, left_tab_more:{keji:'科技',shishang:'时尚',lishi:'历史'}, loadUrl:{online_url1:'//news.toutiaobashi.com/api/tpop/list_new/mininew/1/',online_url2:'//news.toutiaobashi.com/api/tpop/list_new/mininew/1/', hotNews:'//news.toutiaobashi.com/api/hot/limit/2',recommendUrl:'//news.toutiaobashi.com/api/tpop/list_new/mininew/1/34/10', flowUrl:'//news.toutiaobashi.com/api/daohang_news_data/mininewjx/34/11', hotUrl:'//news.toutiaobashi.com/api/wps_news_list/14/mininewhot', }, name:{'推荐':93,'社会':14,'娱乐':16,'视频':24,'搞笑':13,'猎奇':21,'图片':22,'游戏':29,'体育':17,'汽车':28,'财经':18,'健康':15, '星座':27,'军事':20,'情感':26,'国际':12,'时尚':25,'科技':19,'育儿':30,'人文':23,'旅游':31,'美文':32}, qid_index: {rewen:1,toutiao:1,shehui:1,yule:1,shipin:1,tiyu:1,qiche:1,junshi:1,yangsheng:1,youxi:1,guoji:1,shishang:1,lishi:1,keji:1,caijing:1,xiaohua:1,lieqi:1,lvyou:1,renwen:1}, typeKey: {rewen:33,toutiao:34,shehui:14,yule:16,shipin:24,tiyu:17,qiche:28,junshi:20,yangsheng:39, youxi:29,guoji:12,shishang:25,lishi:46,keji:19,caijing:18,xiaohua:13,qinggan:26,gaoxiao:13,lieqi:21,lvyou:31,renwen:23,meiwen:32}, typeKeyRow: {rewen:'',toutiao:'',shehui:'',yule:'',shipin:'',tiyu:'',qiche:'',junshi:'',yangsheng:'', youxi:'',guoji:'',shishang:'',lishi:'',keji:'',caijing:'',xiaohua:'',qinggan:'',gaoxiao:'',lieqi:'',lvyou:'',renwen:''}, // message_flow_showId:"", // bottom_right_showId:"", // top_right_showId:"", normal_baidu_smua: 'd=p&s=b&u=u3636592&w=500&h=96', //数据流百度广告 right_top_baidu_smua_1: 'd=p&s=b&u=u3678551&w=190&h=110', //右上1百度广告 hot_baidu_smua_1: 'd=p&s=b&u=u3681161&w=189&h=132', //热闻百度广告1 hot_baidu_smua_2:'d=p&s=b&u=u3681161&w=189&h=132', //热闻百度广告2 }; proConfig = proObject; }; var user_uid = Common.getUserId(); var timer0510; var clickFlag=true; //tab-hover $('body').on('click','.left_nav .nav_item',function () { var clickFlag=false; var first_nav=$('.first_nav > li.active').attr('date-type'); var scroll_con=$('.scroll_con').attr('class') if($(this).hasClass('active')){ return false; } if(timer0510){ clearInterval(timer0510); timer0510=null; } var x=0; var that = this; timer0510 = setInterval(function () { x++; if(x>2){ clearInterval(timer0510); $('.left_nav .nav_item').removeClass('active'); $(that).addClass('active'); $('.left_nav .nav_item_part').removeClass('active'); var type = $(that).attr('date-type'); if (type == 'redian') { type == 'toutiao2' } for (var i = 0; i < Mini.type_arr.length; i++) { if (type == Mini.type_arr[i]) { var flag = false; break; } else { var flag = true; } } Mini.type_arr.push(type); var method = $(that).attr('method'); var first_view = $('.left_nav li:eq(0)').attr('method'); if (type != 'toutiao' && !first_view) { $('.left_nav li:eq(0)').attr('method', 'change_view'); } Mini[method] ? Mini[method]($(that), window.event) : ''; } }, 300) }); //更多的点击事件 $(".more_tab").click(function () { $(".first_nav").toggle("nav_hide"); $(".second_nav").toggle("nav_show"); }); var tab = $(".more_tab span"); tab.click(function () { if ($(this).hasClass("rectangle1")) { $(this).removeClass("rectangle1").addClass("rectangle2") } else { $(this).addClass("rectangle1").removeClass("rectangle2") } }) //置顶 $("#container .content").scroll(function () { if ($("#container .content").scrollTop() > 100) { $(".roof_placement").fadeIn(200); } else { $(".roof_placement").fadeOut(200); } if ($("#container .content").scrollTop() > 1065) { if($(".right_pannel .case").eq(0).html()){ $("#container .show_case").css({'position': 'fixed', 'top': '50px'}); }else{ $("#container .show_case").css({'position': 'fixed', 'top': '40px'}); } $(".hot_news").css({'position': 'fixed', 'top': '10px'}); $(".showcase").css({'position': 'fixed', 'top': '290px'}); $(".news_bottom").css({'display':"block",'position': 'fixed', 'top': '430px'}); } else { $("#container .show_case").css({'position': 'static'}); $(".hot_news").css({'position': 'static'}); $(".showcase").css({'position': 'static'}); $(".news_bottom").css({'display':"none",'position': 'static'}); } }) $(".roof_placement").click(function () { $("#container .content").animate({scrollTop: 0}, 1000); return false; }) //咨询和精选切换 $(".let_bar").on("click", "a", function () { $(this).addClass("active").siblings().removeClass("active"); if ($('.let_bar .consule').hasClass('active')) { $('.cascade_flow').addClass('content_hide'); $('.content').removeClass('content_hide'); $('.left_nav').removeClass('content_hide'); $('.content').scrollTop(0); $("#container .show_case").css({'position': 'static'}); } else { $('.cascade_flow').removeClass('content_hide'); $('.content').addClass('content_hide'); $('.left_nav').addClass('content_hide'); $.ajax({ url: '//news.toutiaobashi.com/api/daohang_news_data/mininewjx/34/11', type: 'get', dataType: 'json', success: function (res) { var dataArr = res.data; Mini.flowArr.push(dataArr); $.each(dataArr, function (index, item) { $(".cascade_flow").append('
'); }); var divs = $(".cascade_flow div"); var pageWidth = 887; var boxWidth = 268; var gap = 10; var cols = 3//列数; var arr = []; //设置第一行的盒子 for (var i = 0; i < cols; i++) { //第一行盒子的top是0 divs[i].style.top = 0; //设置盒子的left值 divs[i].style.left = i * (boxWidth + gap) + "px"; //将盒子的高度添加到数组中,方便后续的排列 arr.push(divs[i].offsetHeight); } //其他的盒子 for (i = cols; i < divs.length; i++) { //1. 获取到数组最小列的下标 var index = 0;//假设数组第0项就是最小值 var min = arr[0]; //遍历数组 for (var j = 0; j < arr.length; j++) { if (min > arr[j]) { min = arr[j]; index = j; } } //2. 设置left divs[i].style.left = index * (boxWidth + gap) + "px"; //3. 设置top divs[i].style.top = min + gap + "px"; //4. 修改高度 arr[index]:最小列的高度 加上刚刚新增的盒子的高度 arr[index] += divs[i].offsetHeight + gap; } } }) } }) $('body').on('mouseout', '.left_nav .nav_item', function () { window.current_index1 = $('.left_nav .active').index(); }); $('body').on('click', '.more_nav .nav_item_part', function () { var type = $(this).attr('date-type'); for (var i = 0; i < Mini.type_arr.length; i++) { if (type == Mini.type_arr[i]) { var flag = false; break; } else { var flag = true; } } Mini.type_arr.push(type); }); // 将参数序列化,形如 ‘key1=孙平&key2=bbb’ function GetParams(temp, name) { var theRequest = new Object(); var strs = temp.split("&"); for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]); } // 获取 参数对象的指定key 的 value值 var result = theRequest[name] || null; return result; } //加载百度广告 function loadPjs(url, id, pid, op) { var scriptAd = document.createElement("script"); scriptAd.type = "text/javascript"; scriptAd.src = url; scriptAd.setAttribute('smua', op); if ($('#' + pid).length > 0) { $('#' + pid)[0].appendChild(scriptAd); } scriptAd.id = id; } function getUrlParamVal(name) { // 获取当前 URL参数集 var r = decodeURI(window.location.search); var arr1 = r.split("?"); arr1.shift(); var params = arr1.join("&"); var res = GetParams(params, name); return res; } $('body').on('mouseover', '.xxl_ad,iframe', function () { return false }); function Mini_page() { var obj = this; this.pgnum_bot = 1; this.pgnum_top = 0; this.startkey = ''; this.newkey = ''; this.uid = user_uid; this.bool = true; this.getBaiDuAd = true; this.type = 'toutiao'; this.position = ""; this.logo = ''; this.l; this.adsid = 1; this.l1 = 0; this.l2 = 7; this.refresh_dev; this.refresh_tab; this.refresh_scroll; this.type_arr = []; this.bottomOutTime = 1; this.imptk360 = []; this.ad360data = []; this.ad360index = 0; this.pos_pro = ''; this.pos_city = ''; this.rightTwiceAd = true this.flowArr = []; this.cityId=''; if (typeof Mini_page.instance === 'object') { return Mini_page.instance; } this.instance = this; this.pathname = window.location.pathname.slice(1, -1); this.refreshClick=true; } Mini_page.prototype = { // 页面初始化 bindEvent: function () { var obj = this; obj.type_arr.push(obj.type); var urlhost; if(location.host === 'news.698283.vip'){ urlhost ='prod/'+location.host+location.pathname.replace(/\//g,"."); }else{ urlhost = 'test/'+location.host+location.pathname.replace(/\//g,"."); } $.ajax({ url:'http://ads.7654.com/'+urlhost+'json?t='+new Date().getTime(), // url:'http://ads.7654.com/test/test.gamma-minipage.news.qihaxiaoshuo.com.0102.json', dataType:'json', success: function (res) { proConfig.message_flow_showId = res.l; proConfig.bottom_right_showId=res.rb; proConfig.top_right_showId=res.rt; $.ajax({ url: proConfig.loadUrl.recommendUrl, type: 'get', dataType: 'json', success: function (response) { Mini.refreshClick=false; var data = response.data.list; var orderIndex = 1; $.each(data, function (index, val) { val.indexOrder = orderIndex; orderIndex++; obj.render('.scroll_con', val, "append", 'show', true, false, 'pdata'); }); function url_scroll (arr) { $.each(arr, function (index, val) { $('body').append(''); }); }; setTimeout(function () { obj.get360Ad(obj.bottomOutTime, function (res) { var first_item_360bool_1 = true, first_item_360bool_2 = true; window.first_item_360bool_3 = true; window.first_item_360bool_4 = true; window.first_item_360bool_5 = true; window.first_item_360bool_6 = true; window.first_item_360bool_7 = true; window.first_item_360bool_8 = true; window.first_item_360bool_9 = true; window.first_item_360bool_10 = true; $.each(res, function (index, val) { obj.ad360data.push(val); obj.imptk360.push(val.imptk); }); if (res[0]) { if(res[0].type==3){ obj.renderBig360('.scroll_con .list_item:eq(0)', res[0]); }else{ obj.render360('.scroll_con .list_item:eq(0)', res[0]); } url_scroll(res[0].imptk); upload($('.scroll_con .list_item:eq(0) .img_click_gg'),'show') } if (res[1]) { obj.render360('.scroll_con .list_item:eq(2)', res[1]); url_scroll(res[1].imptk); } if (res[2]) { obj.render360('.scroll_con .list_item:eq(4)', res[2]); // url_scroll(res[2].imptk); } if (res[3]) { obj.render360('.scroll_con .list_item:eq(6)', res[3]); } if (res[4]) { obj.render360('.scroll_con .list_item:eq(8)', res[4]); } if (res[5]) { obj.render360('.scroll_con .list_item:eq(10)', res[5]); } if (res[6]) { obj.render360('.scroll_con .list_item:eq(12)', res[6]); } if (res[7]) { obj.render360('.scroll_con .list_item:eq(14)', res[7]); } if (res[8]) { obj.render360('.scroll_con .list_item:eq(16)', res[8]); } if (res[9]) { obj.render360('.scroll_con .list_item:eq(18)', res[9]); } var showRefreshBool = true; Mini.refreshClick=true; $('.content').on('scroll', function (event) { if ($(".media").eq(6)[0] && $(".media").eq(6)[0].getBoundingClientRect().top <= 862) { $(".media").removeClass("media") var SCROLL_TOP = $(this).scrollTop(); var CLIENT_HEIGHT = 600; obj.imptk360=[]; obj.bool = false; obj.pgnum_bot++; obj.bottomOutTime++; var params = { type: obj.type, startkey: obj.startkey, newkey: obj.newkey, pgnum: obj.pgnum_bot, uid: obj.user_uid, qid: '01747', pos_pro: encodeURIComponent(obj.pos_pro), pos_city: encodeURIComponent(obj.pos_city), position: encodeURIComponent(obj.position), domain: 'news.7654.com' }; obj.refresh_scroll = true; obj.fetch_data(params); } var SCROLL_TOP = $(this).scrollTop(); var thirdTop = $('.scroll_con .list_item')[4] ? $('.scroll_con .list_item')[4].getBoundingClientRect().top : 862; var fourththirdTop = $('.scroll_con .list_item')[6] ? $('.scroll_con .list_item')[6].getBoundingClientRect().top : 862; var fifthTop = $('.scroll_con .list_item')[8] ? $('.scroll_con .list_item')[8].getBoundingClientRect().top : 862; var sixthTop = $('.scroll_con .list_item')[10] ? $('.scroll_con .list_item')[10].getBoundingClientRect().top : 862; var sevenTop = $('.scroll_con .list_item')[12] ? $('.scroll_con .list_item')[12].getBoundingClientRect().top : 862; var eightTop = $('.scroll_con .list_item')[14] ? $('.scroll_con .list_item')[14].getBoundingClientRect().top : 862; var nineTop = $('.scroll_con .list_item')[16] ? $('.scroll_con .list_item')[16].getBoundingClientRect().top : 862; var tenTop = $('.scroll_con .list_item')[18] ? $('.scroll_con .list_item')[18].getBoundingClientRect().top : 862; if (thirdTop - 862 < 0 && window.first_item_360bool_3) { window.first_item_360bool_3 = false; if (obj.ad360data[2]) { url_scroll(obj.ad360data[2].imptk); } } if (fourththirdTop - 862 < 0 && window.first_item_360bool_4) { window.first_item_360bool_4 = false; if (obj.ad360data[3]) { url_scroll(obj.ad360data[3].imptk); } } if (fifthTop - 862 < 0 && window.first_item_360bool_5) { window.first_item_360bool_5 = false; if (obj.ad360data[4]) { url_scroll(obj.ad360data[4].imptk); } } if (sixthTop - 862 < 0 && window.first_item_360bool_6) { window.first_item_360bool_6 = false; if (obj.ad360data[5]) { url_scroll(obj.ad360data[5].imptk); } } if (sevenTop - 862 < 0 && window.first_item_360bool_7) { window.first_item_360bool_7 = false; if (obj.ad360data[6]) { url_scroll(obj.ad360data[6].imptk); } } if (eightTop - 862 < 0 && window.first_item_360bool_8) { window.first_item_360bool_8 = false; if (obj.ad360data[7]) { url_scroll(obj.ad360data[7].imptk); } } if (nineTop - 862 < 0 && window.first_item_360bool_9) { window.first_item_360bool_9 = false; if (obj.ad360data[8]) { url_scroll(obj.ad360data[8].imptk); } } if (tenTop - 862 < 0 && window.first_item_360bool_10) { window.first_item_360bool_10 = false; if (obj.ad360data[9]) { url_scroll(obj.ad360data[9].imptk); } } }); }, proConfig.message_flow_showId, 10); }, 1000); Mini.get360Ad(1, function (res) { if (res[0]) { $('.right_pannel .case:eq(0)').html('') url_scroll(res[0].imptk); upload($('.right_pannel .case:eq(0) .img_click_gg'),'show') } if (res[1]) { $('.right_pannel .case:eq(1)').html('') url_scroll(res[1].imptk); } }, proConfig.top_right_showId, 2); Mini.get360Ad(1, function (res) { if (res[0]) { $('.right_pannel .showcase:eq(0)').html('') url_scroll(res[0].imptk); upload($('.right_pannel .showcase:eq(0) .img_click_gg'),'show') } },"", 1); }, error: function () { } }); } }) // return var _clktk, _curl, start_time, end_time; //宏替换-1 function mouseDownMacro(el, x, y) { start_time = Math.round(new Date()); _clktk = el.data('oldclktk'); _curl = el.data("oldcurl"); if (_clktk.indexOf(Macro["start"]) > -1) { _clktk = _clktk.replace(Macro["start"], start_time); } if (_clktk.indexOf(Macro["x"]) > -1) { _clktk = _clktk.replace(Macro["x"], x); } if (_clktk.indexOf(Macro["y"]) > -1) { _clktk = _clktk.replace(Macro["y"], y); } if (_curl.indexOf(Macro["start"]) > -1) { _curl = _curl.replace(Macro["start"], start_time); } if (_curl.indexOf(Macro["x"]) > -1) { _curl = _curl.replace(Macro["x"], x); } if (_curl.indexOf(Macro["y"]) > -1) { _curl = _curl.replace(Macro["y"], y); } el.attr('data-clktk', _clktk); el.attr('href', _curl); } //宏替换-2 function mouseUpMacro(el) { end_time = Math.round(new Date()); _curl = el.attr("href"); if (_clktk.indexOf(Macro["end"]) > -1) { _clktk = _clktk.replace(Macro["end"], end_time); } if (_curl.indexOf(Macro["end"]) > -1) { _curl = _curl.replace(Macro["end"], end_time); } el.attr('data-clktk', _clktk); el.attr('href', _curl); } /*360曝光*/ var url_scroll = function (arr) { $.each(arr, function (index, val) { $('body').append(''); }); }; /*360点击曝光*/ $('body').on('mousedown', '.img_click_gg', function (e) { var x = Math.floor(e.pageX - $(this).offset().left), y = Math.floor(e.pageY - $(this).offset().top); x = x<0 ? 0:x; y = y<0 ? 0:y; mouseDownMacro($(this), x, y); }).on('click', '.img_click_gg', function () { mouseUpMacro($(this)); var str = $(this).attr('data-clktk'); if (str) { var arr = str.split(','); $.each(arr, function (index, val) { $('body').append(''); }); } upload($(this)[0],'click'); }); }, // 瀑布流初始化 waterfallInit: function () { var obj = this; $.ajax({ url: '//news.toutiaobashi.com/api/daohang_news_data/mininewjx/34/11', type: 'get', dataType: 'json', success: function (res) { var dataArr = res.data; obj.flowArr.push(dataArr); $.each(dataArr, function (index, item) { $(".cascade_flow").append(''); }); Mini.waterfall_data(); } }) }, // 瀑布流初始数据获取 waterfall_data: function (params) { var divs = $(".cascade_flow div"); var pageWidth = 887; var boxWidth = 268; var gap = 10; var cols = 3//列数; var arr = []; //设置第一行的盒子 for (var i = 0; i < cols; i++) { //第一行盒子的top是0 divs[i].style.top = 0; //设置盒子的left值 divs[i].style.left = i * (boxWidth + gap) + "px"; //将盒子的高度添加到数组中,方便后续的排列 arr.push(divs[i].offsetHeight); } //其他的盒子 for (i = cols; i < divs.length; i++) { //1. 获取到数组最小列的下标 var index = 0;//假设数组第0项就是最小值 var min = arr[0]; //遍历数组 for (var j = 0; j < arr.length; j++) { if (min > arr[j]) { min = arr[j]; index = j; } } //2. 设置left divs[i].style.left = index * (boxWidth + gap) + "px"; //3. 设置top divs[i].style.top = min + gap + "px"; //4. 修改高度 arr[index]:最小列的高度 加上刚刚新增的盒子的高度 arr[index] += divs[i].offsetHeight + gap; } }, // 页面初始化数据获取 fetch_data: function (params, btn) { var loading_dom = ''+cat_name+'来源:' + type_dom + author_info + '
' + '' + ''+cat_name+'来源:' + content.source + '
' + '' + ''+cat_name+'来源:' + content.source + '
' + '' + '' + val.title + '
' + val.title + '
' + val.title.substring(0,14) + '
' + val.title + '