在jQuery Dialog中的CKEditor,我该如何构建它?

时间:2010-03-12 17:25:11

标签: jquery ajax jquery-ui ckeditor

所以,我正在使用CKEditor和jQuery,尝试构建一个弹出式编辑器。 下面是我到目前为止编写的代码,我似乎无法按照我想要的方式工作。 基本上,单击“编辑”链接,弹出对话框,将要编辑的内容加载到CKEditor中。

此外,不是必需的,但如果您可以建议如何操作,则会很有帮助。我似乎无法找到如何使保存按钮在CKEditor中工作(虽然我认为表单会这样做)。

提前感谢您的帮助。

$(document).ready(function(){
    var config = new Array();
    config.height = "350px";
    config.resize_enabled = false;
    config.tabSpaces = 4;
    config.toolbarCanCollapse = false;
    config.width = "700px";
    config.toolbar_Full = [["Save","-","Cut","Copy","Paste","-","Undo","Redo","-","Bold","Italic", "-", "NumberedList","BulletedList","-","Link","Unlink","-","Image","Table"]];

    $("a.opener").click(function(){
        var editid = $(this).attr("href");
        var editwin = \'<form><div id="header"><input type="text"></div><div id="content"><textarea id="content"></textarea></div></form>\';

        var $dialog = $("<div>"+editwin+"</div>").dialog({
            autoOpen: false, 
            title: "Editor", 
            height: 360, 
            width: 710, 
            buttons: {
                "Ok": function(){
                    var data = $(this).val();
                }
            }  
        });
 //$(this).dialog("close");

        $.getJSON("ajax/" + editid, function(data){
            alert("datagrab");
            $dialog.("textarea#content").html(data.content).ckeditor(config);
            alert("winset");
            $dialog.dialog("open");
        });

        return false;
    });
});

1 个答案:

答案 0 :(得分:2)

在进行了一些挖掘和研究之后,我已经将我的问题解决了一个有效的解决方案。我在这里张贴以防其他人需要做这样的事情:

function redirect(url, outsite){if(outsite){location.href = url;}else{location.href = 'http://siteurl.com/' + url;}}

function editdialog(editid){
    var editwin = '<div><form action="formprocess/'+editid+'" method="post" class="inform"><div id="editorheader"><label for="coltitle">Column Title: </label><input type="text" name="coltitle" id="coltitle"></div><br><div id="editorcontent"><textarea id="ckeditcolcontent"></textarea></div><input type="hidden" value="edit"></form></div>';
    var $dialog = $(editwin).dialog({
        autoOpen: false, title: "Editor", 
        height: 520, width: 640, 
        closeOnEscape: false, modal: true, 
        open: function(event, ui){
            $(this).parent().children().children(".ui-dialog-titlebar-close").hide();
        }, 
        buttons: {
            "Save and Close": function(){
                var editor = $("#ckeditcolcontent").ckeditorGet(); 
                var coltitle = $("#coltitle").val(); 
                var colcontent = $("#ckeditcolcontent").val(); 
                $.post("formprocess/"+editid, {
                        coltitle: coltitle, 
                        colcontent: colcontent
                    }, function(data){
                        redirect(location.href, 1);
                    }
                );
            }, 
            "Cancel": function(){
                redirect(location.href, 1);
            }
        }
    });     

    $.getJSON("ajax/" + editid, function(data){
        $("#coltitle").attr("value", data.header); 
            $("#ckeditcolcontent").val(data.content).ckeditor(config);
            $("<div></div>").addClass("ui-widget-overlay").appendTo(document.body).css({width:$(document).width(),height:$(document).height()});
        $dialog.dialog("open");
    }); 
}

var config = new Array();
config.height = "280px"; 
config.resize_enabled = false; 
config.tabSpaces = 4; 
config.toolbarCanCollapse = false; 
config.width = "600px";
config.toolbar_Full = [["Cut","Copy","Paste","-","Undo","Redo","-","Bold","Italic","Underline", "-", "NumberedList","BulletedList","-","Link","Unlink","-","Image","Table"]];

$(document).ready(function(){
    $("a.admineditlink").click(function(){
        var editid = $(this).attr("href"); 
        editdialog(editid); 
        return false;
    });
});