writer.js 1.23 KB
var $ = require("jquery");
require("../plugin/comment");
require("../plugin/login");
exports.init = function() {
    var cidNum = $(".editor-comment-content").attr("cid");
    $(".comment_button").on("click", function() {
        if ($(".comment-area").find(".comment-textarea").size() > 0) {
            if ($(".editor-comment-content").css("display") == "none") {
                $(".editor-comment-content").show();
            } else {
                $(".editor-comment-content").hide();
            }
        } else {
            $(".comment-area").comment({
                cid: cidNum,
                thirdLogin: true,
                isEdit: true
            });
            $(".editor-comment-content").show();
        }
    });
    exports.updateLogin = function() {
        $(".comment-area").login("updateLoginState");
        $(".comment-area").comment("publishComment");
    }

    var id = {
        id: cidNum
    };
    $.ajax({
        type: 'GET',
        url: YohoConfig.mainUrl + '/writer/default/comment',
        data: id,
        dataType: 'json',
        success: function(response) {
            var data = response.data;
            if (data.total) {
                $(".comment-num").text(data.total);
            }
        }
    })
}