$().ready(function() {

	$('.summernote').summernote({
		height : '220px',
		lang : 'zh-CN',
		callbacks: {
            onImageUpload: function(files, editor, $editable) {
                sendFile(files);
            }
        }
	});
	validateRule();
});


$.validator.setDefaults({
	submitHandler : function() {
		save(1);
	}
});
function save(status) {
    $("#status").val(status);
    var content_sn = $("#content_sn").summernote('code');
    $("#content").val(content_sn);
    let valid = $("#signupForm").valid()
    if (valid) {
        $.ajax({
            cache: true,
            type: "POST",
            url: "/blog/bContent/save",
            data: $('#signupForm').serialize(),// 你的formid
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (r) {
                if (r.code == 0) {
                    parent.layer.msg(r.msg);
                    parent.reLoad();
                    $("#cid").val(r.cid);

                } else {
                    parent.layer.alert(r.msg)
                }
            }
        });
    }
}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
        rules: {
            title: "required",
            author: "required",
            content: "required",
            tags: "required"
        },
        messages: {
            title: "请填写文章标题",
            author: "请填写文章作者",
            content: "请填写文章内容",
            tags: "请选择位置",
        }
    });
}

function returnList() {
	var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
	parent.layer.close(index);
}