/** 网站js基于:jquery1.9 jquery.plugin */ /*nav*/ function proxy(dom, lei, type) { if (dom) { dom.hover(function () { $(this).addclass(lei); if (type == 1) { if ($(this).find('.sub').length > 0) { $(this).find('.sub').show() } else { $(this).addclass(lei + 'er') } } } , function () { $(this).removeclass(lei); if (type == 1) { if ($(this).find('.sub').length > 0) { $(this).find('.sub').hide() } else { $(this).removeclass(lei + 'er'); } } }) } } $(".navbox li dl").addclass('mycorner').attr({ 'data-corner': 'bottom 9px' }); $("#logo,.navbox ul li a").bind("focus", function () { if (this.blur) this.blur(); }); //ie proxy($(".navbox ul li[class!='line']"), 'hover'); //鼠标经过导航 $(".navbox li[class!='spt']").hover( function () { if ($(this).find('dl').size() > 0) { if ($(this).find('dl p a').size() > 0) { $(this).find('dl').width(990); $(this).find('dl').addclass('nav-pro'); var ddi = $(this).find('dl dd').size(); var pjkd = 990 / ddi; $(this).find('dl dd').width(pjkd); } var lijkd = 0, my = $(this).index(); $('nav li').each(function (j) { if (j >= my) { lijkd += $(this).width(); } return lijkd; }); var dlkd = $(this).find('dl').width(); //var lfw = lijkd - dlkd; var lfw = lijkd - dlkd ; if (lfw < 0) { $(this).find('dl').css("left", lijkd + 'px'); } var lk = $(this).width(); if (dlkd < lk) { $(this).find('dl').width(lk); } $(this).find('dl').slidedown(150); } } , function () { $(this).find('dl').hide(); } ); /*nav end*/ function seturlrefresh(url) { if(url.indexof("?") > 0) return url+"&rnd="+math.random(); else return url+"?rnd="+math.random(); } function refreshvcode(obj, h){ if(!h) $i(obj).src=seturlrefresh("/tools/captcha.ashx"); else $i(obj).src=seturlrefresh("/tools/captcha.ashx?h="+h); } /*表单ajax提交封装(包含验证)*/ function ajaxinitform(formid, btnid, isdialog, urlid){ var formobj = $('#' + formid); var btnobj = $("#" + btnid); var urlobj = $("#" + urlid); formobj.validform({ tiptype:3, callback:function(form){ //ajax提交表单 $(form).ajaxsubmit({ beforesubmit: formrequest, success: formresponse, error: formerror, url: formobj.attr("url"), type: "post", datatype: "json", timeout: 60000 }); return false; } }); //表单提交前 function formrequest(formdata, jqform, options) { btnobj.prop("disabled", true); btnobj.val("提交中..."); } //表单提交后 function formresponse(data, textstatus) { if (data.status == 1) { btnobj.val("提交成功"); //是否提示,默认不提示 if(isdialog == 1){ $.dialog.tips(data.msg, 2, "32x32/succ.png", function(){ if(data.url){ location.href = data.url; }else if(urlobj.length > 0 && urlobj.val() != ""){ location.href = urlobj.val(); }else{ btnobj.prop("disabled", false); location.reload(); } }); }else{ if(data.url){ location.href = data.url; }else if(urlobj){ location.href = urlobj.val(); }else{ btnobj.prop("disabled", false); location.reload(); } } } else { $.dialog.alert(data.msg); btnobj.prop("disabled", false); btnobj.val("再次提交"); } } //表单提交出错 function formerror(xmlhttprequest, textstatus, errorthrown) { $.dialog.alert("状态:" + textstatus + ";出错提示:" + errorthrown); btnobj.prop("disabled", false); btnobj.val("再次提交"); } } /*显示ajax分页列表*/ function ajaxpagelist(listdiv, pagediv, pagesize, pagecount, sendurl, defaultavatar) { //pageindex -页面索引初始值 //pagesize -每页显示条数初始化 //pagecount -取得总页数 initcomment(0);//初始化评论数据 $(pagediv).pagination(pagecount, { callback: pageselectcallback, prev_text: "« 上一页", next_text: "下一页 »", items_per_page:pagesize, num_display_entries:3, current_page:0, num_edge_entries:5, link_to:"javascript:;" }); //分页点击事件 function pageselectcallback(page_id, jq) { initcomment(page_id); } //请求评论数据 function initcomment(page_id) { page_id++; $.ajax({ type: "post", datatype: "json", url: sendurl + "&page_size=" + pagesize + "&page_index=" + page_id, beforesend: function (xmlhttprequest) { $(listdiv).html('

正在很努力加载,请稍候...

'); }, success: function(data) { var strhtml = ''; for(var i in data){ strhtml += '
  • ' + '
    #' + (parseint(parseint(i) + 1) + parseint(pagesize) * parseint(page_id-1)) + '
    ' + '
    '; if(typeof(data[i].avatar) != "undefined"){ strhtml += ''; }else{ strhtml += ''; } strhtml += '
    ' + '
    ' + '
    ' + '' + data[i].user_name + '\n' + '' + data[i].add_time + '' + '
    ' + '

    ' + unescape(data[i].content) + '

    ' + '
    '; if(data[i].is_reply == 1){ strhtml += '
    ' + '
    ' + '' + data[i].reply_time + '' + ' 管理员回复:' + '
    ' + '

    ' + unescape(data[i].reply_content) + '

    ' + '
    '; } strhtml += '
  • '; } $(listdiv).html(strhtml); }, error: function (xmlhttprequest, textstatus, errorthrown) { $(listdiv).html('

    暂无评论,快来抢沙发吧!

    '); } }); } } //单击执行ajax请求操作 function clicksubmit(sendurl){ $.ajax({ type: "post", url: sendurl, datatype: "json", timeout: 20000, success: function(data, textstatus) { if (data.status == 1){ $.dialog.tips(data.msg, 2, "32x32/succ.png", function(){ location.reload(); }); } else { $.dialog.alert(data.msg); } }, error: function (xmlhttprequest, textstatus, errorthrown) { $.dialog.alert("状态:" + textstatus + ";出错提示:" + errorthrown); } }); } /*发送验证*/ function sendemail(username, sendurl) { if(username == ""){ $.dialog.alert('对不起,用户名不允许为空!'); return false; } //提交 $.ajax({ url: sendurl, type: "post", timeout: 60000, data: { username: function () { return username; } }, datatype: "json", success: function (data, type) { if (data.status == 1) { $.dialog.tips(data.msg, 2, "32x32/succ.png", function(){}); } else { $.dialog.alert(data.msg); } }, error: function(xmlhttprequest, textstatus, errorthrown){ $.dialog.alert("状态:" + textstatus + ";出错提示:" + errorthrown); } }); } /*绑定顶踩事件*/ function initvotes(){ $(".voteup, .votedown").bind("click",function(){ var pid = $(this).data("postid"); if($(this).hasclass("voteup")){ voteup(pid); }else if($(this).hasclass("votedown")){ votedown(pid); } //$(this).closest(".interactive").find(".voteup").unbind("click"); //$(this).closest(".interactive").find(".votedown").unbind("click"); }) } //顶功能 function voteup(tid) { this.onclick = function(){}; var href = '/tools/submit_ajax.ashx?action=voteup&appid=200&id=' + tid; var havedo = check_vote(tid); var voteitem=jquery('#voteup-' + tid).parent(); if (!havedo) { havedo = check_vote(tid); } if (!havedo) { jquery.getjson(href + '&callback=?', function (result) { if (!isnan(result) && result > 0) { jquery('#voteup-' + tid).text(result); //jquery('#voteup-' + tid).parent().removeclass('voteup'); jquery('#voteup-' + tid).parent().addclass('voted'); cookie_add(tid); voteitem.find("i").show(); settimeout(function () {voteitem.find("i").fadeout()},1000); } else { voteitem.append("投票失败").show().fadein(); settimeout(function () { voteitem.find(".votetips").fadeout().remove(); }, 1000); } }); }else { voteitem.append("已投票").show().fadein(); settimeout(function () { voteitem.find(".votetips").fadeout().remove(); }, 1000); } } //踩功能 function votedown(tid) { this.onclick = function(){}; var href = '/tools/submit_ajax.ashx?action=votedown&appid=200&id=' + tid; var havedo = check_vote(tid); var voteitem=jquery('#votedown-' + tid).parent(); if (!havedo) { havedo = check_vote(tid); } if (!havedo) { jquery.getjson(href + '&callback=?', function (result) { //alert(result); if (!isnan(result) && result > 0) { jquery('#votedown-' + tid).text(result); jquery('#votedown-' + tid).parent().removeclass('votedown'); jquery('#votedown-' + tid).parent().addclass('voted'); cookie_add(tid); voteitem.find("i").show(); settimeout(function () {voteitem.find("i").fadeout()},1000); } else { voteitem.append("投票失败").show().fadein(); } }) }else{ voteitem.append("已投票").show().fadein(); settimeout(function () {voteitem.find(".votetips").fadeout().remove(); }, 1000); } } //检查是否操作过 function check_vote(tid) { var handle = $.cookie("vote"); var havedo = false; if (handle!=null) { var arr = handle.split(","); for (var i = 0; i < arr.length; i++) { if (arr[i] == tid) havedo = true; } } else { $.cookie("vote",""); } return havedo; } //添加tid到cookie function cookie_add(tid) { var handle = $.cookie("vote"); handle += tid + ','; var exdate = new date(); exdate.setdate(exdate.getdate() + 3); $.cookie("vote",handle,{expires:exdate.toutcstring()}); } //图片浏览 function previewimage(file, id, width, height) { width = width || 0; height = height || 0; var maxwidth = width; var maxheight = height; var div = document.getelementbyid(id); if (file.files && file.files[0]) { div.innerhtml = ''; var img = document.getelementbyid('imghead_' + id); img.onload = function () { var rect = clacimgzoomparam(maxwidth, maxheight, img.offsetwidth, img.offsetheight); img.width = rect.width; img.height = rect.height; } var reader = new filereader(); reader.onload = function (evt) { img.src = evt.target.result; } reader.readasdataurl(file.files[0]); } else { file.select(); file.blur(); var src = document.selection.createrange().text; var sfilter = "width:" + maxwidth + "px;height:" + maxheight + "px;"; sfilter += "filter:progid:dximagetransform.microsoft.alphaimageloader(src='" + src + "',sizingmethod='scale');"; div.innerhtml = "
    "; } } function clacimgzoomparam(maxwidth, maxheight, width, height) { var param = { top: 0, left: 0, width: width, height: height }; if (width > maxwidth || height > maxheight) { ratewidth = width / maxwidth; rateheight = height / maxheight; if (ratewidth > rateheight) { param.width = maxwidth; param.height = math.round(height / ratewidth); } else { param.width = math.round(width / rateheight); param.height = maxheight; } } param.left = math.round((maxwidth - param.width) / 2); param.top = math.round((maxheight - param.height) / 2); return param; } function gethits(_appid,tid) { var url='/tools/submit_ajax.ashx?action=view_article_click&appid='+ _appid +'&id=' + tid; jquery.getjson(url + '&callback=?', function (result) { jquery('#views-' + tid).text(result.views); jquery('#voteup-' + tid).text(result.voteups); jquery('#votedown-' + tid).text(result.votedowns); $.cookie('hits', tid); }); } $(document).ready(function () { });