From c63493c899de714b05b0521bb38aab60d19030ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 20 Jan 2017 00:55:51 +0100 Subject: Validation initiale --- sources/plugins/widget/dev/console.js | 131 ++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 sources/plugins/widget/dev/console.js (limited to 'sources/plugins/widget/dev/console.js') diff --git a/sources/plugins/widget/dev/console.js b/sources/plugins/widget/dev/console.js new file mode 100644 index 0000000..78db0d0 --- /dev/null +++ b/sources/plugins/widget/dev/console.js @@ -0,0 +1,131 @@ +/** + * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or http://ckeditor.com/license + */ + +/* global CKCONSOLE */ + +'use strict'; + +( function() { + + CKCONSOLE.add( 'widget', { + panels: [ + { + type: 'box', + content: '', + + refresh: function( editor ) { + var instances = obj2Array( editor.widgets.instances ); + + return { + header: 'Instances (' + instances.length + ')', + instances: generateInstancesList( instances ) + }; + }, + + refreshOn: function( editor, refresh ) { + editor.widgets.on( 'instanceCreated', function( evt ) { + refresh(); + + evt.data.on( 'data', refresh ); + } ); + + editor.widgets.on( 'instanceDestroyed', refresh ); + } + }, + + { + type: 'box', + content: + '', + + refresh: function( editor ) { + var focused = editor.widgets.focused, + selected = editor.widgets.selected, + selectedIds = []; + + for ( var i = 0; i < selected.length; ++i ) + selectedIds.push( selected[ i ].id ); + + return { + header: 'Focus & selection', + focused: focused ? 'id: ' + focused.id : '-', + selected: selectedIds.length ? 'id: ' + selectedIds.join( ', id: ' ) : '-' + }; + }, + + refreshOn: function( editor, refresh ) { + editor.on( 'selectionCheck', refresh, null, null, 999 ); + } + }, + + { + type: 'log', + + on: function( editor, log, logFn ) { + // Add all listeners with high priorities to log + // messages in the correct order when one event depends on another. + // E.g. selectionChange triggers widget selection - if this listener + // for selectionChange will be executed later than that one, then order + // will be incorrect. + + editor.on( 'selectionChange', function( evt ) { + var msg = 'selection change', + sel = evt.data.selection, + el = sel.getSelectedElement(), + widget; + + if ( el && ( widget = editor.widgets.getByElement( el, true ) ) ) + msg += ' (id: ' + widget.id + ')'; + + log( msg ); + }, null, null, 1 ); + + editor.widgets.on( 'instanceDestroyed', function( evt ) { + log( 'instance destroyed (id: ' + evt.data.id + ')' ); + }, null, null, 1 ); + + editor.widgets.on( 'instanceCreated', function( evt ) { + log( 'instance created (id: ' + evt.data.id + ')' ); + }, null, null, 1 ); + + editor.widgets.on( 'widgetFocused', function( evt ) { + log( 'widget focused (id: ' + evt.data.widget.id + ')' ); + }, null, null, 1 ); + + editor.widgets.on( 'widgetBlurred', function( evt ) { + log( 'widget blurred (id: ' + evt.data.widget.id + ')' ); + }, null, null, 1 ); + + editor.widgets.on( 'checkWidgets', logFn( 'checking widgets' ), null, null, 1 ); + editor.widgets.on( 'checkSelection', logFn( 'checking selection' ), null, null, 1 ); + } + } + ] + } ); + + function generateInstancesList( instances ) { + var html = '', + instance; + + for ( var i = 0; i < instances.length; ++i ) { + instance = instances[ i ]; + html += itemTpl.output( { id: instance.id, name: instance.name, data: JSON.stringify( instance.data ) } ); + } + return html; + } + + function obj2Array( obj ) { + var arr = []; + for ( var id in obj ) + arr.push( obj[ id ] ); + + return arr; + } + + var itemTpl = new CKEDITOR.template( '
  • id: {id}, name: {name}, data: {data}
  • ' ); +} )(); -- cgit v1.2.3