2

私はこれを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コンテンツをクリアする効果がない場合は、プレースホルダー値とともに保存される値を変更しないでください。

4

0 に答える 0