function setCookie(c_name, value, expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); } function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return (arr[2]); else return null; } function subComment(that) { var dataId = $("#data_id").val(); var commContent =$(that).parent().siblings(".comment-textarea").html(); var commContentTxt =$(that).parent().siblings(".comment-textarea").text(); var commentId = $(that).parent(".publish").parent(".reply-commert").parent(".re-reply-lists").siblings(".replay-head").attr('netid'); commentId = typeof(commentId) === 'undefined' ? 0 : commentId; var url = $("#data_id").parent().attr('action'); if(commContentTxt=="" && commContent!=""){ alert("纯表情会让人误以为您是表情帝,还是说点实在的吧!"); return; } if(commContentTxt==""||commContentTxt.length<5||commContentTxt.length>500){ alert("评论内容长度为5~500个字!"); return; } if($("#data_time").val()=="1"){ setTimeout(function(){ $("#data_time").val("0"); },60000) alert("水也不是这么灌的,请您休息一分钟再发表评论!"); return; } if(getCookie("timeC"+dataId)=="succ"){ alert("不好意思,您已经评价了!"); return; } $.post(url, {data_id: dataId, commcontent: commContent, comment_id:commentId}, function(data){ if( data.code == 0 ) { alert("评论添加成功,请等待审核"); $("#data_time").val("1") setCookie("timeC"+dataId,"succ"); $(that).parent().siblings(".comment-textarea").html(''); } else { alert(data.msg); return false; } },'json'); } /* * 教程点赞 * @param {int} type 1:点赞;2:不好 * @returns {undefined} */ function doGrade(type) { var dataId = $("#data_id").val(); var url = 'http://duote.runjiapp.com/tech/AddPingjia/'; $.post(url, {data_id: dataId,st:type}, function(data){ if( data.code == 0 ) { if(type == 1) { var goodNum = $(".detail-footer a em")[0].innerHTML; goodNum = parseInt(goodNum) + 1; $(".detail-footer a em")[0].innerHTML=goodNum; $(".detail-footer a").each(function(){ $(this).attr('onclick',''); $(this).attr('disabled',true); }); } else if(type == 2) { var badNum = $(".detail-footer a em")[1].innerHTML; badNum = parseInt(badNum) + 1; $(".detail-footer a em")[1].innerHTML=badNum; } } else { alert(data.msg); return false; } },'json'); } /* * 上传图片验证 * * @param {obj} fileobj 上传按钮 * @param {obj} imgobj 预览图片对象 */ function checkImg(fileObj,imgObj, width, height, size) { var url; if (fileObj.files) { if (window.navigator.userAgent.indexOf("MSIE") >= 1) { fileObj.select(); url = document.selection.createRange().text; } url = window.URL.createObjectURL(fileObj.files[0]); } else { url = fileObj.value; url = "file:///" + url; } image = new Image(); image.src = url; if(size) { var fileSize = fileObj.files[0].size/1024; if(parseInt(fileSize) > size) { alert("图片大小不能超过"+size+"k"); $(fileObj).val(''); imgObj.attr('src', ''); return false; } } image.onload = function() { // image.src = url; if (image.width != width || image.height != height) { alert("请上传尺寸为"+width+"*"+height+"的图片!"); $(fileObj).val(''); return false; }else{ imgObj.attr('src', url); $(imgObj).show(); return true; } }; /* if(width) { if(nWidth!=width) { alert("图片要求宽为:"+width+"px"); $(fileObj).val(''); imgObj.attr('src', ''); return false; } } if(height) { if(nHeight!=height) { alert("图片要求高为:"+height+"px"); $(fileObj).val(''); imgObj.attr('src', ''); return false; } } */ } /* * 评论点赞 */ function DoGood(that) { var comment_id = $(that).parent(".rt-reply").parent(".replay-head").attr('netid'); var url = $("#add_good_url").val(); $.post(url, {comment_id: comment_id}, function(data){ if( data.code == 0 ) { var goodNum = that.innerHTML; goodNum = parseInt(goodNum) + 1; that.innerHTML=goodNum; $(that).addClass('cur'); $(that).attr('onclick',''); $(that).attr('disabled',true); } else { alert(data.msg); return false; } },'json'); } /* * * 加入收藏 */ function addBookmark() { /*tj('g392', '');*/ var title = document.title; var url = window.location.href; if (window.sidebar) { try { window.sidebar.addPanel(title, url, ''); } catch (e) { alert("您的浏览器不支持该功能,请使用Ctrl+D收藏本页"); } } else { try { window.external.AddFavorite(url, title); } catch (e) { alert("您的浏览器不支持该功能,请使用Ctrl+D收藏本页"); } } }