1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/**
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/* global CKCONSOLE */
'use strict';
( function() {
CKCONSOLE.add( 'focus', {
panels: [
{
type: 'box',
content:
'<ul class="ckconsole_list">' +
'<li>active by fM: <span class="ckconsole_value" data-value="activeFM"></span></li>' +
'<li>active inner: <span class="ckconsole_value" data-value="activeInner"></span></li>' +
'<li>active host: <span class="ckconsole_value" data-value="activeHost"></span></li>' +
'</ul>',
refresh: function( editor ) {
var focusManager = editor.focusManager;
return {
header: 'Focus (' + ( focusManager.hasFocus ? 'focused' : 'blurred' ) + ')',
activeFM: focusManager.hasFocus ? active2Str( focusManager.currentActive ) : '-',
activeInner: editor.document ? active2Str( editor.document.getActive() ) : '-',
activeHost: active2Str( CKEDITOR.document.getActive() )
};
},
refreshOn: function( editor, refresh ) {
editor.on( 'focus', refresh );
editor.on( 'blur', refresh );
editor.on( 'contentDom', function() {
editor.editable().attachListener( editor.document, 'mouseup', function() {
// Some changes (e.g. iframe creation) need time.
setTimeout( refresh, 100 );
} );
} );
CKEDITOR.document.on( 'mouseup', function() {
// Some changes (e.g. iframe creation) need time.
setTimeout( refresh, 100 );
} );
editor.on( 'instanceReady', refresh );
}
},
{
type: 'log',
on: function( editor, log, logFn ) {
editor.on( 'focus', logFn( '--- editor#focus ---' ) );
editor.on( 'blur', logFn( '--- editor#blur ---' ) );
editor.on( 'contentDom', function() {
var editable = editor.editable();
editable.attachListener( editor.document, 'focus', logFn( 'document#focus' ) );
editable.attachListener( editor.document, 'blur', logFn( 'document#blur' ) );
editable.attachListener( editor.document.getWindow(), 'focus', logFn( 'window#focus' ) );
editable.attachListener( editor.document.getWindow(), 'blur', logFn( 'window#blur' ) );
editable.attachListener( editable, 'focus', logFn( 'editable#focus' ) );
editable.attachListener( editable, 'blur', logFn( 'editable#blur' ) );
} );
}
}
]
} );
// Get <name ...>.
function element2Str( element ) {
var str = element.getOuterHtml().split( '>' )[ 0 ] + '>';
if ( str.length > 40 )
str = str.slice( 0, 35 ) + '...>';
return str.replace( '<', '<' );
}
function active2Str( active ) {
if ( active instanceof CKEDITOR.dom.window )
return 'window (' + element2Str( new CKEDITOR.dom.element( active.$.document.body ) ) + ')';
else
return element2Str( active );
}
} )();
|