保存/发布时的清晰内容

时间:2012-10-11 21:02:42

标签: javascript jquery

我已将此作为textarea[placeholder]和tinymce的基本占位符。

//set up a new editor functionality
setup: function(ed) {

    // Set placeholder
    var $editorMce = $('#'+ed.id);
    var editorMce_placeholder = $editorMce.attr("placeholder");
    if(editorMce_placeholder.length){
        var is_placeholder = false;

        ed.onInit.add(function(ed) {                            
            // get the current content
            var cont = ed.getContent();

            // If its empty and we have a placeholder set the value
            if(cont.length == 0){
                ed.setContent(editorMce_placeholder);

                // Get updated content
                cont = editorMce_placeholder;
            }

            // convert to plain text and compare strings
            is_placeholder = (cont == editorMce_placeholder);                   

            // nothing to do
            if (!is_placeholder){
                return;
            }
        });

        ed.onMouseDown.add(function(ed,e) {
            // replace the default content on focus if the same as original placeholder
            if (is_placeholder){
                ed.setContent('');
            }
        });

        ed.onSaveContent.add(function(ed, o) {
            // replace the content back to empty if the same as placeholder
            if(editorMce_placeholder == o.content){
                ed.setContent('');
            }
       });
    }

直到// clear content

为止

我试过onSubmit

ed.onSubmit.add(function(ed, e) {
    // replace the content back to empty if the same as placeholder
    if(editorMce_placeholder == $(ed.getContent()).text()){
        ed.setContent("");
        // just to be sure:
        $editorMce.val("");
    }
});

还有onPostProcess

ed.onPostProcess.add(function(ed, e) {
    // replace the content back to empty if the same as placeholder
    if(editorMce_placeholder == $(ed.getContent()).text()){
        o.content = '';
    }
});

在提交它时,如果没有清除textarea值/ iframe内容的效果,则不会更改使用占位符值保存的值。

0 个答案:

没有答案