cms = {}; /** * 浏览次数 */ cms.viewcount = function (base, contentid, views, downs, ups, downloads, comments) { views = views || "views"; downs = downs || "downs"; ups = ups || "uplikes"; downloads = downloads || "downloads"; comments = comments || "comment .small"; $.getjson(base + "/content/view", { contentid: contentid }, function (data) { var json = data.data; if (json != null) { //总 $("#" + views).text(json.views); $("#" + downs).text(json.downs); $("#" + ups).text(json.ups); $("#" + downloads).text(json.downloads); $("#" + comments).text(json.comments); // 是否收藏 if (json.iscollection) { $("#heart").attr("name", "1") $("#heart").attr("class", "iconfont iconheart-fill") } else { $("#heart").attr("name", "2") $("#heart").attr("class", "iconfont iconheart hover") } } }); } function getheaders(req) { var headerarr = req.getallresponseheaders().split('\n'); var headers = {}; for (var i = 0; i < headerarr.length; i++) { if (headerarr[i]) { var index = headerarr[i].indexof(':'); var key = headerarr[i].slice(0, index); var value = headerarr[i].slice(index + 1).trim(); headers[key] = value } } return headers } /** * 站点流量统计 */ cms.siteflow = function (base, pvtotal, uvtotal, iptotal, todaypv, todayuv, todayip, yesterdaypv, yesterdayuv, yesterdayip, peakpv, peakuv, peakip) { pvtotal = pvtotal || "pvtotal"; uvtotal = uvtotal || "uvtotal"; iptotal = iptotal || "iptotal"; todaypv = todaypv || "todaypv"; todayuv = todayuv || "todayuv"; todayip = todayip || "todayip"; yesterdaypv = yesterdaypv || "yesterdaypv"; yesterdayuv = yesterdayuv || "yesterdayuv"; yesterdayip = yesterdayip || "yesterdayip"; peakpv = peakpv || "peakpv"; peakuv = peakuv || "peakuv"; peakip = peakip || "peakip"; $.getjson(base + "/index/flow", {}, function (data, status, xhr) { var passtype = getheaders(xhr).needchangepassword window.localstorage.setitem('passtype', passtype) var json = data.data; if (json != null) { //总 $("#" + pvtotal).text(json.pvtotal); $("#" + uvtotal).text(json.uvtotal); $("#" + iptotal).text(json.iptotal); //今 $("#" + todaypv).text(json.todaypv); $("#" + todayuv).text(json.todayuv); $("#" + todayip).text(json.todayip); //昨天 $("#" + yesterdaypv).text(json.yesterdaypv); $("#" + yesterdayuv).text(json.yesterdayuv); $("#" + yesterdayip).text(json.yesterdayip); //峰值 $("#" + peakpv).text(json.peakpv); $("#" + peakuv).text(json.peakuv); $("#" + peakip).text(json.peakip); if (json.isgrey == '1') { $('body').attr('style', '-webkit-filter: grayscale(100%);-moz-filter: grayscale(100%);-ms-filter: grayscale(100%);-o-filter: grayscale(100%);filter: grayscale(100%);filter:progid:dximagetransform.microsoft.basicimage(grayscale=1);filter:gray;') } } }); } /** * 成功返回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.commentlistmore = function (base, c, options) { c = c || "commentlistdiv"; $("#" + c).load(base + "/comment_list.jspx", options); $('#commentdialog').dialog('open'); } /** * 评论顶 */ cms.commentup = function (base, commentid, origvalue, upid) { upid = upid || "commentups"; var updown = $.cookie("_cms_comment_updown_" + commentid); if (updown) { return false; } $.cookie("_cms_comment_updown_" + commentid, "1"); $.get(base + "/comment_up.jspx", { "commentid": commentid }, function (data) { $("#" + upid).text(origvalue + 1); }); return true; } /** * 评论踩 */ cms.commentdown = function (base, commentid, origvalue, downid) { downid = downid || "commentdowns"; var updown = $.cookie("_cms_comment_updown_" + commentid); if (updown) { return false; } $.cookie("_cms_comment_updown_" + commentid, "1"); $.get(base + "/comment_down.jspx", { commentid: commentid }, function (data) { $("#" + downid).text(origvalue + 1); }); return true; } /** * 评论输入框 */ cms.commentinputcsi = function (base, commentinputcsidiv, contentid, commemtid) { commentinputcsidiv = commentinputcsidiv || "commentinputcsidiv"; $("#" + commentinputcsidiv).load(base + "/comment_input_csi.jspx?contentid=" + contentid + "&commemtid=" + commemtid); } cms.commentinputload = function (base, commentinputcsiprefix, commentinputcsidiv, contentid, commemtid) { $("div[id^='" + commentinputcsiprefix + "']").html(""); cms.commentinputcsi(base, commentinputcsidiv, contentid, commemtid); } /** * 是否是微信打开 */ cms.isopeninweixin = function () { var ua = navigator.useragent.tolowercase(); if (ua.match(/micromessenger/i) == "micromessenger") { return true; } else { return false; } } /** * 客户端包含登录 */ 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("请先登录"); location.href = base + "/login.jspx"; } 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"); } cms.checkperm = function (base, contentid) { $.getjson(base + "/page_checkperm.jspx", { contentid: contentid }, function (data) { if (data == 3) { alert("请先登录"); location.href = base + "/user_no_login.jspx"; } else if (data == 4) { location.href = base + "/group_forbidden.jspx"; } else if (data == 5) { location.href = base + "/content/buy.jspx?contentid=" + contentid; } }); } cms.collectcsi = function (base, collectcsidiv, tpl, contentid) { collectcsidiv = collectcsidiv || "collectcsidiv"; $("#" + collectcsidiv).load(base + "/csi_custom.jspx?tpl=" + tpl + "&cid=" + contentid); } cms.getcookie = function getcookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.lastindexof(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexof(";", c_start); if (c_end == -1) { c_end = document.cookie.length; } return unescape(document.cookie.substring(c_start, c_end)); } } return ""; } cms.mobileua = function () { var ua = navigator.useragent.tolowercase(); var mua = { ios: /ipod|iphone|ipad/.test(ua), //ios iphone: /iphone/.test(ua), //iphone ipad: /ipad/.test(ua), //ipad android: /android/.test(ua), //android device windows: /windows/.test(ua), //windows device touch_device: ('ontouchstart' in window) || /touch/.test(ua), //touch device mobile: /mobile/.test(ua), //mobile device (ipad) android_tablet: false, //android tablet windows_tablet: false, //windows tablet tablet: false, //tablet (ipad, android, windows) smart_phone: false //smart phone (iphone, android) }; mua.android_tablet = mua.android && !mua.mobile; mua.windows_tablet = mua.windows && /tablet/.test(ua); mua.tablet = mua.ipad || mua.android_tablet || mua.windows_tablet; mua.smart_phone = mua.mobile && !mua.tablet; return mua; }