cms = {}; /** * 浏览次数 */ cms.viewcount = function(base, contentid, viewid, commentid, downloadid, upid, downid) { viewid = viewid || "views"; commentid = commentid || "comments"; downloadid = downloadid || "downloads"; upid = upid || "ups"; downid = downid || "downs"; $.getjson(base + "/content_view.jspx", { contentid : contentid }, function(data) { if (data.length > 0) { $("#" + viewid).text(data[0]); $("#" + commentid).text(data[1]); $("#" + downloadid).text(data[2]); $("#" + upid).text(data[3]); $("#" + downid).text(data[4]); } }); } /** * 站点流量统计 */ cms.siteflow = function(base, page, referer,flag,pvid, visitorid) { pvid = pvid || "pv"; visitorid = visitorid || "visitor"; flag = flag || 1; $.getjson(base + "/flow_statistic.jspx", { page : page, referer : referer }, function(data) { if(flag==1){ if (data.length > 0) { $("#" + pvid).text(data[0]); $("#" + visitorid).text(data[1]); } } }); } /** * 成功返回true,失败返回false。 */ cms.up = function(base, contentid, origvalue, upid) { upid = upid || "ups"; var updown = $.cookie("_cms_updown_" + contentid); if (updown) { return false; } $.cookie("_cms_updown_" + contentid, "1"); $.get(base + "/content_up.jspx", { "contentid" : contentid }, function(data) { $("#" + upid).text(origvalue + 1); }); return true; } /** * 成功返回true,失败返回false。 */ cms.down = function(base, contentid, origvalue, downid) { downid = downid || "downs"; var updown = $.cookie("_cms_updown_" + contentid); if (updown) { return false; } $.cookie("_cms_updown_" + contentid, "1"); $.get(base + "/content_down.jspx", { contentid : contentid }, function(data) { $("#" + downid).text(origvalue + 1); }); return true; } /** * 获取评分选项投票数 */ cms.scorecount = function(base, contentid,itemprefix) { itemprefix=itemprefix||"score-item-"; $.getjson(base + "/content_score_items.jspx", { contentid : contentid }, function(data) { $("span[id^='"+itemprefix+"']").each(function(){ var itemid=$(this).prop("id").split(itemprefix)[1]; $(this).text(data.result[itemid]); }); }); } /** * 成功返回true,失败返回false。 */ cms.score = function(base, contentid,itemid,itemprefix) { itemprefix=itemprefix||"score-item-"; var score = $.cookie("_cms_score_" + contentid); if (score) { return false; } $.cookie("_cms_score_" + contentid, "1"); $.get(base + "/content_score.jspx", { "contentid" : contentid, "itemid":itemid }, function(data) { if(data.succ){ $("#"+itemprefix + itemid).text(data.count); } }); return true; } /** * 获取附件地址 */ cms.attachment = function(base, contentid, n, prefix) { $.get(base + "/attachment_url.jspx", { "cid" : contentid, "n" : n }, function(data) { var url; for (var i = 0;i < n; i++) { url = base + "/attachment.jspx?cid=" + contentid + "&i=" + i + data[i]; $("#" + prefix + i).attr("href", url); } }, "json"); } /** * 提交评论 */ cms.comment = function(callback, form) { form = form || "commentform"; $("#" + form).validate( { submithandler : function(form) { $(form).ajaxsubmit( { "success" : callback, "datatype" : "json" }); } }); } /** * 获取评论列表 * * @param siteid * @param contentid * @param greatto * @param recommend * @param orderby * @param count */ cms.commentlist = function(base, c, options) { c = c || "commentlistdiv"; $("#" + c).load(base + "/comment_list.jspx", options); } /** * 客户端包含登录 */ cms.logincsi = function(base, c, options) { c = c || "logincsidiv"; $("#" + c).load(base + "/login_csi.jspx", options); } /** * 向上滚动js类 */ cms.uproller = function(rid, speed, issleep, sleeptime, rollrows, rollspan, unithight) { this.speed = speed; this.rid = rid; this.issleep = issleep; this.sleeptime = sleeptime; this.rollrows = rollrows; this.rollspan = rollspan; this.unithight = unithight; this.proll = $('#roll-' + rid); this.prollorig = $('#roll-orig-' + rid); this.prollcopy = $('#roll-copy-' + rid); // this.prollline = $('#p-roll-line-'+rid); this.sleepcount = 0; this.prollcopy[0].innerhtml = this.prollorig[0].innerhtml; var o = this; this.pevent = setinterval(function() { o.roll.call(o) }, this.speed); } cms.uproller.prototype.roll = function() { if (this.proll[0].scrolltop > this.prollcopy[0].offsetheight) { this.proll[0].scrolltop = this.rollspan + 1; } else { if (this.proll[0].scrolltop % (this.unithight * this.rollrows) == 0 && this.sleepcount <= this.sleeptime && this.issleep) { this.sleepcount++; if (this.sleepcount >= this.sleeptime) { this.sleepcount = 0; this.proll[0].scrolltop += this.rollspan; } } else { var modcount = (this.proll[0].scrolltop + this.rollspan) % (this.unithight * this.rollrows); if (modcount < this.rollspan) { this.proll[0].scrolltop += this.rollspan - modcount; } else { this.proll[0].scrolltop += this.rollspan; } } } } cms.leftroller = function(rid, speed, rollspan) { this.rid = rid; this.speed = speed; this.rollspan = rollspan; this.proll = $('#roll-' + rid); this.prollorig = $('#roll-orig-' + rid); this.prollcopy = $('#roll-copy-' + rid); this.prollcopy[0].innerhtml = this.prollorig[0].innerhtml; var o = this; this.pevent = setinterval(function() { o.roll.call(o) }, this.speed); } cms.leftroller.prototype.roll = function() { if (this.proll[0].scrollleft > this.prollcopy[0].offsetwidth) { this.proll[0].scrollleft = this.rollspan + 1; } else { this.proll[0].scrollleft += this.rollspan; } } /** * 收藏信息 */ cms.collect = function(base, cid, operate,showspanid,hidespanid) { $.post(base + "/member/collect.jspx", { "cid" : cid, "operate" : operate }, function(data) { if(data.result){ if(operate==1){ alert("收藏成功!"); $("#"+showspanid).show(); $("#"+hidespanid).hide(); }else{ alert("取消收藏成功!"); $("#"+showspanid).hide(); $("#"+hidespanid).show(); } }else{ alert("请先登录"); } }, "json"); } /** * 列表取消收藏信息 */ cms.cmscollect = function(base, cid, operate) { $.post(base + "/member/collect.jspx", { "cid" : cid, "operate" : operate }, function(data) { if(data.result){ if(operate==1){ alert("收藏成功!"); }else{ alert("取消收藏成功!"); $("#tr_"+cid).remove(); } }else{ alert("请先登录"); } }, "json"); } /** * 检测是否已经收藏信息 */ cms.collectexist = function(base, cid,showspanid,hidespanid) { $.post(base + "/member/collect_exist.jspx", { "cid" : cid }, function(data) { if(data.result){ $("#"+showspanid).show(); $("#"+hidespanid).hide(); }else{ $("#"+showspanid).hide(); $("#"+hidespanid).show(); } }, "json"); } /** * 申请职位信息 */ cms.jobapply = function(base, cid) { $.post(base + "/member/jobapply.jspx", { "cid" : cid }, function(data) { if(data.result==-1){ alert("请先登录"); }else if(data.result==-2){ alert("职位id不能为空"); }else if(data.result==-3){ alert("未找到该职位"); }else if(data.result==-4){ alert("您还没有创建简历,请先完善简历"); }else if(data.result==0){ alert("您今天已经申请了该职位!"); }else if(data.result==1){ alert("成功申请了该职位!"); } }, "json"); }