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) { $.getjson(base + "/flow_statistic.jspx", { page : page, referer : referer }); } /** * 成功返回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.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"); }