Skip to content
Permalink
Browse files

Merge branch 't/12416' into major

  • Loading branch information...
Reinmar committed Sep 16, 2014
2 parents 0dfdca2 + eb4ce93 commit 35f64d7718b98b41ad1e04cf3da50f7112000b70
Showing with 105 additions and 5 deletions.
  1. +1 −0 CHANGES.md
  2. +20 −0 core/tools.js
  3. +29 −5 plugins/widget/plugin.js
  4. +12 −0 tests/core/tools.js
  5. +43 −0 tests/plugins/widget/widgetsrepoapi.js
@@ -12,6 +12,7 @@ New Features:
* [#12169](http://dev.ckeditor.com/ticket/12169): Introduce [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop), [`editor.dragstart`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-dragstart) and [`editor.dragend`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-dragend) events.
* [#11583](http://dev.ckeditor.com/ticket/11583): Added support for HTML5 `required` attribute in various form elements. Thanks to [Steven Busse](https://github.com/sbusse)!
* [#12143](http://dev.ckeditor.com/ticket/12143): Added [`config.floatSpacePreferRight`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-floatSpacePreferRight) configuration option that switches the alignment of the floating toolbar. Thanks to [InvisibleBacon](http://github.com/InvisibleBacon)!
* [#12416](http://dev.ckeditor.com/ticket/12416): Added [`widgetDefinition.upcastPriority`](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.definition-property-upcastPriority) property which gives more control over widgets upcasting order to the widget author.

Fixed Issues:

@@ -68,6 +68,26 @@
return true;
},

/**
* Finds index of the first element in array for which the `compareFunction` returns `true`.
*
* CKEDITOR.tools.getIndex( [ 1, 2, 4, 3, 5 ], function( el ) {
* return el >= 3;
* } ); // 2
*
* @since 4.5
* @param {Array} array Array to search in.
* @param {Function} compareFunction Compare function.
* @returns {Number} The index of the first matching element or `-1` if none matches.
*/
getIndex: function( arr, compareFunction ) {
for ( var i = 0; i < arr.length; ++i ) {
if ( compareFunction( arr[ i ] ) )
return i;
}
return -1;
},

/**
* Creates a deep copy of an object.
*
@@ -1736,20 +1736,36 @@

function addWidgetProcessors( widgetsRepo, widgetDef ) {
var upcast = widgetDef.upcast,
upcasts;
upcasts,
priority = widgetDef.upcastPriority || 10;

if ( !upcast )
return;

// Multiple upcasts defined in string.
if ( typeof upcast == 'string' ) {
upcasts = upcast.split( ',' );
while ( upcasts.length )
widgetsRepo._.upcasts.push( [ widgetDef.upcasts[ upcasts.pop() ], widgetDef.name ] );
while ( upcasts.length ) {
addUpcast( widgetDef.upcasts[ upcasts.pop() ], widgetDef.name, priority );
}
}
// Single rule which is automatically activated.
else
widgetsRepo._.upcasts.push( [ upcast, widgetDef.name ] );
else {
addUpcast( upcast, widgetDef.name, priority );
}

function addUpcast( upcast, name, priority ) {
// Find index of the first higher (in terms of value) priority upcast.
var index = CKEDITOR.tools.getIndex( widgetsRepo._.upcasts, function( element ) {
return element[ 2 ] > priority;
} );
// Add at the end if it is the highest priority so far.
if ( index < 0 ) {
index = widgetsRepo._.upcasts.length;
}

widgetsRepo._.upcasts.splice( index, 0, [ upcast, name, priority ] );
}
}

function blurWidget( widgetsRepo, widget ) {
@@ -3453,6 +3469,14 @@
* @property {Object} upcasts
*/

/**
* The {@link #upcast} method(s) priority. The upcast with lower priority number will be called before
* the one with higher number. The default priority is `10`.
*
* @since 4.5
* @property {Number} [upcastPriority=10]
*/

/**
* The function to be used to downcast this widget or
* a name of the downcast option from the {@link #downcasts} object.
@@ -58,6 +58,18 @@ bender.test(
assert.isFalse( CKEDITOR.tools.isArray( window.x ) );
},

'test getIndex - not found': function() {
assert.areSame( -1, CKEDITOR.tools.getIndex( [ 1, 2, 3 ], function( el ) { return el == 4; } ) );
},

'test getIndex - found first': function() {
assert.areSame( 2, CKEDITOR.tools.getIndex( [ 0, 1, 2, 2, 2, 3, 2, 2 ], function( el ) { return el == 2; } ) );
},

'test getIndex - found on last position': function() {
assert.areSame( 2, CKEDITOR.tools.getIndex( [ 0, 1, 2 ], function( el ) { return el == 2; } ) );
},

test_htmlEncode1: function() {
assert.areSame( '&lt;b&gt;Test&lt;/b&gt;', CKEDITOR.tools.htmlEncode( '<b>Test</b>' ) );
},
@@ -157,6 +157,49 @@
assert.isTrue( true );
},

'test widgets.add - upcast priorities': function() {
var editor = this.editor,
bot = this.editorBot,
upcastCalled = '';

editor.widgets.add( 'prioritiesTest1', {
upcast: function() {
upcastCalled += '1';
}
} );

editor.widgets.add( 'prioritiesTest2', {
upcastPriority: 5,
upcast: function() {
upcastCalled += '2';
}
} );

editor.widgets.add( 'prioritiesTest3', {
upcastPriority: 5,
upcast: function() {
upcastCalled += '3';
}
} );

editor.widgets.add( 'prioritiesTest4', {
upcastPriority: 15,
upcast: function() {
upcastCalled += '4';
}
} );

editor.widgets.add( 'prioritiesTest5', {
upcast: function() {
upcastCalled += '5';
}
} );

bot.setData( '<p>foo</p>', function() {
assert.areSame( '23154', upcastCalled );
} );
},

'test widgets.wrapElement - inline': function() {
var editor = this.editor;

0 comments on commit 35f64d7

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