WordPress:在TinyMCE iframe中添加事件

我已经在Wordpress中添加了一些div包装器样式, 但是当我在页面中使用它们时, 无法在页面中的下面添加内容。 CSS:after在div内创建可选区域, 但在div后面创建可选区域无效。

在我的functions.php中, 我有:

  function my_mce_before_init( $settings ) {
    $style_formats = array(
        array(
            'title' => 'Box Two Columns', 'block' => 'div', 'classes' => 'twocolbox', 'wrapper' => true
        ), array(
            'title' => 'Image with Caption', 'block' => 'div', 'classes' => 'img_caption', 'wrapper' => true
        ), array(
            'title' => 'Gallery Horizontal', 'block' => 'div', 'classes' => 'scroller horizontal', 'wrapper' => true
        )
    );

    $settings['style_formats'] = json_encode( $style_formats );
    return $settings;

}
add_filter('tiny_mce_before_init', 'my_mce_before_init');
add_editor_style();

有没有一种方法可以在这里使用execCommand在我定义的div样式后添加一些html?要在之后添加清晰的浮点数等空段落标签?

我试过了:

tinyMCE.execCommand('mceInsertContent', false, 'Hello world!!');" 

然后, MCE编辑器中断。

…尝试了这个, 但是它太小了:在editor-styles.css中:

#tinyMCE:after {
 content: "    ";
 clear:both;
 width: 4em; height:4em;
}

请注意, 你可能需要清除”缓存并按下shift-reload”按钮才能在Wordpress中查看对editor-styles.css的任何更改。

仍在努力。找到一个线程:通过jquery访问tinymce iframe元素

我尝试将此线程中的代码添加到my_mce_before_init中, 但是它刚刚坏了。

….也尝试加载jQuery脚本, 但是目标路径在TinyMCE iframe上不起作用。这些选择器都不起作用:

jQuery(document).ready(function($) {

    $("#tinyMCE").find("div").after('<p style="width:100%; clear:both; height:1em;">&nbsp; 6789</p>');
     $("div").css("color", "red");

    $("#content_ifr").contents().find("div").after('<p style="width:100%; clear:both; height:1em;">&nbsp; 6789</p>');
    $("#content_ifr").contents().find("#tinymce p").css("color", "red");

    $("#wp-content-editor-container").find("textarea").css("color", "red");
    $("iframe").contents().find("p").css("color", "red");

    $('#content_ifr').load(function(){
        $('#content_ifr').contents().find('p').css("color", "red");
    });
 });

#1


你可以使用tinymce配置选项content_css添加html伪元素。在那里你可以定义after元素。试试看!

更新:

初始化tinymce时, 将设置参数设置为以下内容(在tinyMCE.init({…}中)

...
theme: "advanced", // example param
setup : function(ed) {
    ed.onInit.add(function(ed, evt) {
        $("#content_ifr").contents().find("p").css("color", "red");

        // other approach  
        //$(ed.getBody()).find('p').css("color", "red");
    });
}, cleanup: true, // example param
...

来源:

https://www.srcmini02.com/67595.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_36862.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?