Why TinyMCE get focus and blur event, when user jump from other input field?

左心房为你撑大大i 提交于 2019-12-01 07:36:22
 <style type="text/css">
   .editor_active { border:#f00 2px solid!important; }
   .editor_inactive { border:#00f 2px dashed!important; }
</style>


<script type="text/javascript">

tinymce.init({
    selector:"textarea",
    setup: function(editor) {
        editor.on('focus', function(e) {
            if(!catching)
            {
                bounceProtect('focus');
            formatMce('focus');
            }
        });
        editor.on('blur', function(e){
            if(!catching){
                bounceProtect('blur');
            formatMce('blur');
            }
        })
    }
});

function formatMce(state)
{
    if (state=='focus') {
       $('#mceControl').addClass('editor_active').removeClass('editor_inactive');
    }
    else {
       $('#mceControl').addClass('editor_inactive').removeClass('editor_active');
    }
}

function bounceProtect(src)
{
    catching = true;
    console.log(src);
    setTimeout(function(){ catching = false;}, 250);
}

var catching = false;

$(document).ready(function(){
$("INPUT,TEXTAREA,BUTTON").focus(function(){ formatMce('blur'); });
});

</script>


</head>
<body style="">

  <input type="text" id="fname" name="fname">
  <div id="mceControl">
    <textarea>Your content here.</textarea>
  </div>

UPDATE: 1 It looks like there are layered controls juggling focus on you - this is a technique we used to use in VB apps to prevent focus wars and avoid key bounces - the 250msec delay should filter out un-intentional focus shifts, but play around with it.

UPDATE: 2 I've wrapped the tinyMCE control in a div and added some code to the editor focus/blur handlers to style that, you won't have any influence over stuff loaded in the IFrame.

UPDATE: 3 Focus/Blur between documents worked, but the focus event wasn't firing when you went from tinyMCE to an input control, a dirty hack is to capture INPUT focus events and emulate a blur on the editor.

It is fixed with the actual Nightly build. I dunno in which version it will be merged.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!