X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fpiedsjaloux-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fplugins%2Fwidget%2Fdev%2Fconsole.js;fp=sources%2Fplugins%2Fwidget%2Fdev%2Fconsole.js;h=78db0d0eb8b8c58bb6f435a5709ad4ff53338f03;hp=0000000000000000000000000000000000000000;hb=317f8f8f0651488f226b5280a8f036c7c135c639;hpb=1096cdefb1c9a3f3c4ca6807e272da6c92e5ed9c
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:
+ '' +
+ '- focused:
' +
+ '- selected:
' +
+ '
',
+
+ 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}
' );
+} )();