Skip to content
Permalink
Browse files

Merge branch 't/13337b' into major

  • Loading branch information...
Reinmar committed Jun 10, 2015
2 parents ab16bc5 + b8deb7d commit 83e9980b57935a6f95a181d1c9b52bf3d044f929
@@ -7,6 +7,7 @@ New Features:

* [#13304](http://dev.ckeditor.com/ticket/13304): Added support for passing DOM elements to [`config.sharedSpaces`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-sharedSpaces). Thanks to [Undergrounder](https://github.com/Undergrounder)!
* [#13215](http://dev.ckeditor.com/ticket/13215): Added ability to cancel fetching a resource by the Embed plugins.
* [#13337](http://dev.ckeditor.com/ticket/13337): Added the [`repository.onWidget()`](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.repository-method-onWidget) method – a convenient way to listen to [widget](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget) events through the [repository](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.repository).

Fixed Issues:

@@ -540,6 +540,46 @@
return newInstances;
},

/**
* Allows to listen to events on specific types of widgets, even if they are not created yet.
*
* Please note that this method inherits parameters from the {@link CKEDITOR.event#method-on} method with one
* extra parameter at the beginning which is a widget name.
*
* editor.widgets.onWidget( 'image', 'action', function( evt ) {
* // Event `action` occurs on `image` widget.
* } );
*
* @since 4.5
* @param {String} widgetName
* @param {String} eventName
* @param {Function} listenerFunction
* @param {Object} [scopeObj]
* @param {Object} [listenerData]
* @param {Number} [priority=10]
*/
onWidget: function( widgetName ) {
var args = Array.prototype.slice.call( arguments );

args.shift();

for ( var i in this.instances ) {
var instance = this.instances[ i ];

if ( instance.name == widgetName ) {
instance.on.apply( instance, args );
}
}

this.on( 'instanceCreated', function( evt ) {
var widget = evt.data;

if ( widget.name == widgetName ) {
widget.on.apply( widget, args );
}
} );
},

/**
* Parses element classes string and returns an object
* whose keys contain class names. Skips all `cke_*` classes.
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,toolbar,clipboard */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo,basicstyles,clipboard,dialog,link,toolbar,stylescombo,font,colorbutton,language,indentblock */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,contextmenu */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo,clipboard */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools, lineutilsTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,dialog */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,elementspath */
/* bender-include: ../elementspath/_helpers/tools.js */
/* global elementspathTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo,basicstyles,clipboard,dialog */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo,clipboard */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -0,0 +1,3 @@
<textarea id="test_editor">
<p>Hello moto</p>
</textarea>
@@ -0,0 +1,97 @@
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget */

( function() {
'use strict';

var Repository,
Widget,
onSpy,
repo;

function widgetElementFactory() {
var span = new CKEDITOR.dom.element( 'span' );
new CKEDITOR.dom.element( 'p' ).append( span );

return span;
}

bender.editors = {
editor: {
creator: 'inline',
name: 'test_editor'
}
};

bender.test( {
'setUp': function() {
Repository = CKEDITOR.plugins.widget.repository;
Widget = CKEDITOR.plugins.widget;
repo = new Repository( bender.editors.editor );

onSpy = sinon.spy( Widget.prototype, 'on' );
},

'tearDown': function() {
Widget.prototype.on.restore();
},

'test has onWidget function': function() {
assert.isFunction( repo.onWidget );
},

'test event listener added on existing widget': function() {
var cbMock = sinon.mock();

var widget = new Widget( repo, 1, widgetElementFactory(), { name: 'image' }, {} );
repo.instances[ widget.id ] = widget;

repo.onWidget( 'image', 'action', cbMock );

assert.isTrue( onSpy.calledOn( widget ) );
assert.isTrue( onSpy.calledWith( 'action', cbMock ) );
},

'test event listener added for element added to repo after calling "onWidget" method': function() {
var cbMock = sinon.mock();

repo.onWidget( 'image', 'action', cbMock );

// The constructor fires repo#instanceCreated itself.
var widget = new Widget( repo, 1, widgetElementFactory(), { name: 'image' }, {} );
repo.instances[ widget.id ] = widget;

assert.isTrue( onSpy.firstCall.calledOn( widget ) );
assert.isTrue( onSpy.firstCall.calledWithExactly( 'action', cbMock ) );
},

'test event listener not added for different widget type': function() {
repo.onWidget( 'image', 'action', sinon.mock() );

var widget = new Widget( repo, 1, widgetElementFactory(), { name: 'notimage' }, {} );
repo.instances[ widget.id ] = widget;

assert.isTrue( onSpy.neverCalledWith( 'action' ) );
},

'test event listener not added for different widget type 2': function() {
repo.onWidget( 'notimage', 'action', sinon.mock() );

var widget = new Widget( repo, 1, widgetElementFactory(), { name: 'image' }, {} );
repo.instances[ widget.id ] = widget;

assert.isTrue( onSpy.neverCalledWith( 'action' ) );
},

'test event listener called with proper arguments': function() {
var cbMock = sinon.mock();

repo.onWidget( 'image', 'action', cbMock, null, null, 5 );

var widget = new Widget( repo, 1, widgetElementFactory(), { name: 'image' }, {} );
repo.instances[ widget.id ] = widget;

assert.isTrue( onSpy.firstCall.calledWithExactly( 'action', cbMock, null, null, 5 ) );
}
} );
}() );
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo,dialog,basicstyles,clipboard */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget,undo */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-tags: widgetcore */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */

@@ -1,4 +1,4 @@
/* bender-tags: editor,unit,widgetcore,widgetcore */
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */

0 comments on commit 83e9980

Please sign in to comment.
You can’t perform that action at this time.