?/getId function G$(element){return typeof(element)=="object" ? element : document.getElementById(element);}; //supportHover function supportHover(elem,tag){var obj = elem.getElementsByTagName(tag);for(var i = 0; i< obj.length; i++) {obj[i].onmouseover = function() {this.className = "active"}; obj[i].onmouseout = function() {this.className= ""};};}; //getElementsByClassName function getElementsByClassName(className, tag, parent){// 获取class命名的节? parent = parent || document; tag = tag || "*"; var allTags = (tag === "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag); var classElems = []; className = className.replace(/\-/g, "\\-"); var regex = new RegExp("(^|\\s)" + className + "(\\s|$)"); var elenemt; for(var i=0; i 0 ) { elem.style.fontSize = (parseInt(defaultSize) + 2) + "px"; }; if ( size < 0 ) { elem.style.fontSize = (parseInt(defaultSize) - 2) + "px"; }; }; /* detail pic fixer 20141104添加判断图库入口 */ function picSizeFixer(){ var doc = document.getElementById("chan_newsDetail").getElementsByTagName("img"), tukuEntrance = document.getElementById("tukuEntrance"); for (i=0; i 800){ doc[i].width = 800; }; }; }; // function epSearchCheck(id) { var elem = typeof(id)=="object" ? id : document.getElementById(id); elem.onsubmit = function() { if ( !elem.keyword.value ) { alert("请输入关键字..."); elem.keyword.focus(); return false; }; elem.setAttribute("method", "get"); elem.setAttribute("action", "http://www.google.com.u94j4lt.top/#newwindow=1&q=" + elem.keyword.value + "+site:china.com" +"&safe=strict"); }; }; // var load = load || {}; load.hash = load.hash || {}; load.createScript = function(url, data, callback, scriptCharset){ var head, script; if(data){ url += '?' + encodeURI(data); }; if(!load.hash.createScript){ load.hash.createScript = {} }; if(load.hash.createScript[url]){ if(callback){ callback.call(window) }; return false; }else{ load.hash.createScript[url] = true; }; head = document.getElementsByTagName("head")[0] || document.documentElement; script = document.createElement("script"); if(scriptCharset){ script.charset = scriptCharset; }; script.src = url; var done = false; script.onload = script.onreadystatechange = function() { if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) { done = true; if(callback){ callback.call(window) }; script.onload = script.onreadystatechange = null; if ( head && script.parentNode ) { head.removeChild( script ); } } }; head.insertBefore( script, head.firstChild ); }; function getCommentUrl(id){ var newsid = 'cms'+id; var str = getPath(newsid); var src = 'http://club.china.com.u94j4lt.top' + str + 'num.js?t='+(Math.random()*10000000000000000); load.createScript(src, "", function(){ if(typeof(commentnum)!="undefined"){ (commentnum.news.threadurl); } }); } function getPath(newsid) { var path = newsid.substring(3, newsid.length); var syspath = newsid.substring(0, 3); var l = path.length; for (var i = 8; i > l; i--) { path = "0" + path; } var path5 = path.substring(path.length - 1, path.length); var path4 = path.substring(path.length - 3, path.length - 1); var path3 = path.substring(path.length - 5, path.length - 3); var path2 = path.substring(0, path.length - 5); var path1 = "/data/"; return path1 + syspath + "/" + path2 + "/" + path3 + "/" + path4 + "/" + path5; } /* auther:f7 date:2011.11 */ var ClubClearPhotoShow = (function(){ var g = function(id) { if(typeof id == "string" || id instanceof String) { return document.getElementById(id); } else if (id && id.nodeName && (id.nodeType == 1 || id.nodeType == 9)) { return id; } return null; }; // 获取class命名的节? function getElementsByClassName(className, tag, parent){ parent = parent || document; tag = tag || "*"; var allTags = (tag === "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag); var classElems = []; className = className.replace(/\-/g, "\\-"); var regex = new RegExp("(^|\\s)" + className + "(\\s|$)"); var elenemt; for(var i=0; i= 0) { result = trim(result.replace(re, "")); } } elem.className = result; return elem; }; /** * 重置图片大小 * @method resetPhotoSize * @static * @param {HTMLElement} elem 需要处理的图片节点 * @param {Number} width 重置宽度 * @param {Number} height 重置高度 * @return */ var resetPhotoSize = function (img, maxWidth, maxHeight) { var widthbe, heightbe, that=this, myimg = new Image(); myimg.src = img.getAttribute("src"); photoElementLoad(myimg, function(){ widthbe = img.width; heightbe = img.height; if ( widthbe > maxWidth ) { setImgType(img, maxWidth, heightbe*(maxWidth/widthbe)); heightbe = heightbe*(maxWidth/widthbe); } if ( heightbe > maxHeight ) { setImgType(img, widthbe*(maxHeight/heightbe), maxHeight); heightbe = maxHeight; } img.style.display = "block"; img.style.marginTop = (92-heightbe)/2 +"px"; }); }; var setImgType = function (img, imgWidth, imgHeight) { //img.setAttribute("width", imgWidth); img.style.width = imgWidth + "px"; img.style.height = imgHeight + "px"; //img.setAttribute("height", imgHeight); }; /** * 监听图片元素加载完成 * @method photoElementLoad * @static * @param {HTMLElement} elem 目标图片元素 * @param {Function} callback 回调方法 * @return * @remark 内部执行方法,外部请引用 cn.photoLoad 方法 */ var photoElementLoad = function(elem, callback){ var done = false; if(elem.width > 0){// 针对IE6??缓存加载不能正确处理的临时解决方? if(callback){ callback(elem) }; return false; } // 处理浏览器兼? elem.onload = elem.onreadystatechange = function() { if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) { done = true; if(callback){ callback(elem) }; // 处理IE内存泄漏 elem.onload = elem.onreadystatechange = null; } }; }; // 滚动所需代码 function cpu(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;}; // 减速运? function slowdown(element,plan,start,space,speed,_f){ var count = 0;// 定义变量初始? var speed = speed || 50; function place(){ element[plan] = cpu(count,start,space,speed);// 通过CPU()函数计算出当前应该出现的位置 count++;// 变量递增 if(count === speed){// 当变量与速度相等时表示达到终? clearTimeout(command);// 停止运动 count = 0;// 变量初始? element[plan] = space + start;// 精确终点位置 if(_f)_f();// 回调函数 return false; } var command = setTimeout(place,15);// 定时启动 } place();// 初始执行 } // 点击滚动 function lieScroll(ID,clickLeft,clickRight,c){ // ID 滚动体的ID或节点对? // clickLeft 左点击的ID或节点对? // clickRight 右点击的ID或节点对? // c 滚动的宽? var element = g(ID); var clickLeft = g(clickLeft); var clickRight = g(clickRight); var CHE,addDiv,factWidth=0; var changeWidth; var classLeft = clickLeft.className; var classRight = clickRight.className; var flag = true; element.innerHTML = "
"+ element.innerHTML +"
"; addDiv = element.getElementsByTagName("div")[0]; CHE = addDiv.childNodes; for(var i=0; i factWidth){// 处理本身尺寸小于显示尺寸 clickLeft.className=classLeft; clickRight.className=classRight; } } clickLeft.onclick = function(){ if(flag){ flag = false; slowdown(element,"scrollLeft", element.scrollLeft, -c*4, 30, function(){flag = true; resetJT();}); } }; clickRight.onclick = function(){ if(flag){ flag = false; slowdown(element,"scrollLeft", element.scrollLeft, c*4, 30, function(){flag = true; resetJT();}); } }; setTimeout(resetJT, 500); }; // ******************************** /** * 高清图片展示 * @method ClearPhoto * @remark 数据来源是页面的图片列表数据 */ var ClearPhoto = function(){ this.minPhoto = "";// 存储高清图库中小图的模块节点 this.init(); }; // 初始? ClearPhoto.prototype.init = function(){ this.minPhoto = g("smallPicList").getElementsByTagName("img"); lieScroll("smallPicList", "clickLeft", "clickRight", 120); this.setElement(); this.saveBigPic(); /** * 修正IE系标题变为锚点的BUG【IE7、IE8受BUG侵害? * @return */ function repairTitle() { var originalTitle = document.getElementsByTagName("title")[0].innerHTML; if (/msie (\d+\.\d+)/i.test(navigator.userAgent) ? (document.documentMode || + RegExp['\x241']) : undefined) { document.title = originalTitle; document.attachEvent('onpropertychange', function (e) { e = e || window.event; if (e.propertyName === 'title' && document.title !== originalTitle) { setTimeout(function () { document.title = originalTitle; }, 1); }; }); }; }; repairTitle(); }; // 设置页面元素 ClearPhoto.prototype.setElement = function(){ var that = this; //[#14358] 研发&网页制作5.12新闻频道大图模式新开广告?注掉使后台对图片总数做假生效 侯丽? 2014/05/15 start //g("allPhotoCount").innerHTML = this.minPhoto.length; //[#14358] 研发&网页制作5.12新闻频道大图模式新开广告? 侯丽? 2014/05/15 end each(this.minPhoto, function(i, v){ resetPhotoSize(v, 100, 94); }); }; // 显示指定大图 ClearPhoto.prototype.show = function(c){ //var url, info, preUrl, currentHeight, currentWidth, currentImg, preIndex, preImg, that = this; var currentHeight, currentWidth, currentImg = this, url = g("bigPic").getElementsByTagName("img")[0].getAttribute("src"); //if(!this.flag) return false;// 条件不足不执? // 处理上一页下一页到头的问题 if(c < 0){ alert("这是第一张了?); return false; }else if(c >= this.minPhoto.length){ alert("后面再没有了?); return false; }; // 打开loading g("bigPhotoLoading").style.display = "block"; // 隐藏上下页箭? g("webPre").style.display = "none"; g("webNext").style.display = "none"; // 清楚图片设置的历史宽? g("bigPic").getElementsByTagName("img")[0].style.width = ""; this.synchroCurrentPhoto(c);// 同步当前缩略图的位置 // 创建当前图片节点 currentImg = new Image(); currentImg.src = url; // 当前大图加载完成的操? photoElementLoad(currentImg, function(){ var photo = g("bigPic").getElementsByTagName("img")[0]; // 设置相关元素的高? currentHeight = currentImg.height; currentWidth = currentImg.width; // 处理超宽图片 if(currentImg.width > 998){ photo.style.width = "998px"; currentHeight = parseInt((currentHeight*998)/currentWidth); } //alert(currentHeight); g("bigPhotoLoading").style.height = currentHeight +"px"; g("photoLoadingImg").style.top = (currentHeight-16)/2 +"px"; g("webPre").style.height = currentHeight +"px"; g("webNext").style.height = currentHeight +"px"; // 关闭loading g("bigPhotoLoading").style.display = "none"; //g("bigPic").style.display = "block"; // 显示上下页箭? g("webPre").style.display = "block"; g("webNext").style.display = "block"; g("webPre").href += "#photos"; g("webNext").href += "#photos"; }); }; // 同步当前缩略图的位置 ClearPhoto.prototype.synchroCurrentPhoto = function(count){ var elem = g("smallPicList"); var items = g("smallPicList").getElementsByTagName("a"); var base = 120; var a = count*base; var b = elem.scrollLeft; var c = 240; var d = a-b-c; slowdown(elem,"scrollLeft", elem.scrollLeft, d, 30); document.getElementById("smallPicList").getElementsByTagName("li")[count].className = "curPic"; for (var i = 0, l = items.length; i < l; i++) { items[i].href += "#photos";// 添加小图锚链? }; }; /* 查看大图 */ ClearPhoto.prototype.saveBigPic = function(){ if(document.getElementById("bigPic")){ var bigimgsrc=document.getElementById("bigPic").getElementsByTagName("img"); var picbut = document.getElementById("chan_gHD_url"); picbut.href = bigimgsrc[0].src; } }; return { g:g, getElementsByClassName:getElementsByClassName, ClearPhoto:ClearPhoto } })(); //#12780 /** * Suggest 实现,需要MiniAjax支持 * @param ajax_url Ajax请求地址 * @param self_name 当前Suggest对象名称 * @param obj_name 输入的input的ID * @param param_name 参数名称,可不填,默认为keyword */ function show_news_list(id, news_array, n) { var obj=document.getElementById(id); if(!obj || !news_array || typeof(obj) == 'undefined' || typeof(news_array) == 'undefined') { return false; } var arr_length = news_array.length; if(arr_length == 21) { //去掉和此文章相同的链? var now_url = document.location; now_url = now_url.toString(); var patt = new RegExp("\d{8,10}\.html", "i"); var file_name = now_url.match(/\d{8,10}(_\d{1,3})?\.html/ig); file_name = file_name.toString(); file_name = file_name.replace(/_\d{1,3}/, ""); var match = 0; for(j=0;j<21;j++) { if(news_array[j]['location'].match(file_name)) { news_array.remove(j); match = 1; break; } } if(match == 0) { news_array.remove(21); } } var list_length = Math.ceil(arr_length/5); var news_list = new Array(); for(i=0;i"+unescape(data[i]['short_title'])+"\n"; } obj.innerHTML = li_html; } var head_num = 0, like_num = 0; function headline_play(id, news_array) { show_news_list(id, news_array, head_num); head_num++; //show_news_list('head_news_ul', head_news) } function like_play(id, news_array) { show_news_list(id, news_array, like_num); like_num++; //show_news_list('head_news_ul', head_news) } Array.prototype.remove=function(dx) { if(isNaN(dx)||dx>this.length){return false;} for(var i=0,n=0;iٶ