(function( window, undefined ) { var baiduAjax = {}; baiduAjax.extend = function (dest) { sources = Array.prototype.slice.call(arguments, 1); for (var j = 0, len = sources.length, src; j < len; j++) { src = sources[j] || {}; for (var i in src) { if (src.hasOwnProperty(i)) { dest[i] = src[i]; } } } return dest; } baiduAjax.format = function(tpl,obj){ for (var key in obj) { var reg = new RegExp("#{"+key+"}","g"); tpl = tpl.replace(reg,obj[key]); }; return tpl; } baiduAjax.post = function(url, data, onsuccess){ $.ajax({ url:url, data:data, type:'POST', success: onsuccess }); } baiduAjax.get = function(url, onsuccess) { $.ajax({ type:'GET', url:url, success: onsuccess }); } /** * 广告跳转url */ baiduAjax.jumpURL = "http://rp.baidu.com/rpadroute/router"; /** * 解析一个非皮肤类广告(上方:search_ad_ppim) * @function * @grammar baiduAjax.parseRUAd(dataJson) * @param {object} dataJson 返回的数据 * */ baiduAjax.parseRUTopAd = function(dataJson,position,jumpData){ var adTpl = ["
"].join(""); var aLink,aLinkText="",imgSrc="",imgTitle="",imgTitleAll = "",imgAlt="",aList = "",aLinkT=""; if(dataJson.status == 0){ //成功 var adInfos; if(typeof(dataJson.adInfo) == "string"){ adInfos = eval("(" + dataJson.adInfo + ")"); }else{ adInfos = dataJson.adInfo; } //暂时先取广告的第一条数据 jumpData.ad_url = adInfos[position].ads[0].target_url; if(jumpData.ad_url.indexOf("http://") < 0){ jumpData.ad_url = "http://" + jumpData.ad_url; } aLinkT = adInfos[position].ads[0].target_url; jumpData.ad_id = adInfos[position].ads[0].ad_id; aLink = baiduAjax.jumpURL + "?" + $.param(jumpData); if(adInfos[position].ads[0].extend_info && adInfos[position].ads[0].extend_info.title){ aLinkText = adInfos[position].ads[0].extend_info.title; }else{ aLinkText = ""; } if(adInfos[position].ads[0].extend_info.channelLink){ var channels = adInfos[position].ads[0].extend_info.channelLink; for (var i = channels.length - 1; i >= 0; i--) { var link_url = channels[i].link; if(link_url.indexOf("http://") < 0){ link_url = "http://" + link_url; } aList = aList + ""+ channels[i].word + " "; }; } //取img的第一个 if(adInfos[position].ads[0].img_list && adInfos[position].ads[0].extend_info && adInfos[position].ads[0].img_list.length > 0){ if(adInfos[position].ads[0].extend_info.description){ imgTitleAll = adInfos[position].ads[0].extend_info.description; imgTitle = imgTitleAll; if(imgTitle.length > 35){ imgTitle = imgTitle.substring(0,35) + "..."; } }else{ imgTitle = ""; } imgAlt = aLinkText; imgSrc = adInfos[position].ads[0].img_list[0].img_url; }else{ imgAlt = ""; imgSrc = ""; } return baiduAjax.format(adTpl,{ aLink : aLink, aLinkText : aLinkText, imgTitle : imgTitle, imgAlt : imgAlt, aList: aList, imgTitleAll:imgTitleAll, imgSrc : imgSrc, aLinkT:aLinkT, position : position }); }else{ return ""; } return ""; } /** * 解析一个非皮肤类广告(右方:search_ad_im_1 ) * @function * @grammar baiduAjax.parseRUAd(dataJson) * @param {object} dataJson 返回的数据 * */ baiduAjax.parseRUAd = function(dataJson,position,jumpData){ var adTpl = ["