检测CK Editor Styles菜单何时打开?

时间:2015-09-18 11:38:07

标签: javascript css ckeditor

当CK编辑器中的样式菜单打开时,有没有办法获取事件?

它在页面中创建一个iFame,我需要在打开时将一个类名注入到该iFrame的body标签中....

2 个答案:

答案 0 :(得分:0)

您无法通过iFrame外部的JavaScript进行此操作。您必须将自定义脚本集成到CK编辑器iFrame中。

这是iFrames的规则,您无法绑定iFrame文档中的事件。同样,在iFrame中无法绑定父文档中的事件

答案 1 :(得分:0)

无法找到一个很好的方法来做到这一点,(事件,回调,CK中的任何类型的API),但找到了一种适合我们需求的方法(使用下划线来包装CK函数)。

它有点hacky,但有效......

    CKEDITOR.on( 'instanceReady', function( event ) {

          //Expose a class on the styles menu so we can scope the styles and target items that are in the menu
          var Styles = event.editor.ui.instances.Styles;
          Styles.onOpen = _.wrap(Styles.onOpen, function(onOpen) { 

            //Trigger the original onOpen method
            _.bind(onOpen, Styles)();

            //Now find the iFrame and inject a class to the body
            var $iframe = $(".cke iframe");

            if($iframe) {
              var addClass=function() {
                $iframe.contents().find('body').addClass('slide styles-menu');
              }

              if ($iframe.contents().find('body').children().length==0) {
                $iframe.one('load', addClass);
              } else {
                addClass();
              }

            }
          });