Skip to content
Permalink
Browse files

Merge branch 't/12168' into major

  • Loading branch information...
pjasiun committed Jul 28, 2014
2 parents 291fb3d + 026a13e commit cb28e9cf363923d204f40617827a76b9b6ee5712
Showing with 529 additions and 167 deletions.
  1. +3 −0 CHANGES.md
  2. +16 −40 core/editable.js
  3. +64 −0 core/tools.js
  4. +118 −49 plugins/clipboard/plugin.js
  5. +22 −0 tests/core/tools.js
  6. +206 −46 tests/plugins/clipboard/datatransfer.js
  7. +100 −32 tests/plugins/clipboard/drop.js
@@ -6,6 +6,9 @@ CKEditor 4 Changelog
New Features:

* [#10931](http://dev.ckeditor.com/ticket/10931): Introduce ability to insert widgets into another widget's nested editables. Note that unless nested editable's [allowed content](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.nestedEditable.definition-property-allowedContent) is defined precisely since CKEditor 4.5 some widget buttons may become enabled.
* [#11437](http://dev.ckeditor.com/ticket/11437): Drag and Drop support.
* [#11460](http://dev.ckeditor.com/ticket/11460): Custom handling for dropped content in the editor.
* [#12168](http://dev.ckeditor.com/ticket/12168): `dataTransfer` facade.

Fixed Issues:

@@ -245,50 +245,26 @@
insertText: function( text ) {
beforeInsert( this );

var editor = this.editor,
mode = editor.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : editor.activeEnterMode,
isEnterBrMode = mode == CKEDITOR.ENTER_BR,
tools = CKEDITOR.tools;

// CRLF -> LF
var html = tools.htmlEncode( text.replace( /\r\n/g, '\n' ) );

// Tab -> &nbsp x 4;
html = html.replace( /\t/g, '    ' );

var paragraphTag = mode == CKEDITOR.ENTER_P ? 'p' : 'div';

// Two line-breaks create one paragraphing block.
if ( !isEnterBrMode ) {
var duoLF = /\n{2}/g;
if ( duoLF.test( html ) )
{
var openTag = '<' + paragraphTag + '>', endTag = '</' + paragraphTag + '>';
html = openTag + html.replace( duoLF, function() { return endTag + openTag; } ) + endTag;
}
}

// One <br> per line-break.
html = html.replace( /\n/g, '<br>' );

// Compensate padding <br> at the end of block, avoid loosing them during insertion.
if ( !isEnterBrMode ) {
html = html.replace( new RegExp( '<br>(?=</' + paragraphTag + '>)' ), function( match ) {
return tools.repeat( match, 2 );
} );
}

// Preserve spaces at the ends, so they won't be lost after insertion (merged with adjacent ones).
html = html.replace( /^ | $/g, '&nbsp;' );
insert( this, 'text', this.transformPlainTextToHtml( text ) );
},

// Finally, preserve whitespaces that are to be lost.
html = html.replace( /(>|\s) /g, function( match, before ) {
return before + '&nbsp;';
} ).replace( / (?=<)/g, '&nbsp;' );
/**
* Set enterMode based on current selection and {@link CKEDITOR.editor#activeEnterMode}
* and call {@link CKEDITOR.tools#transformPlainTextToHtml}.
*
* @since 4.5
* @param {String} text Text to transform.
* @returns {String} HTML generated from the text.
*/
transformPlainTextToHtml: function( text ) {
var enterMode = this.editor.getSelection().getStartElement().hasAscendant( 'pre', true ) ?
CKEDITOR.ENTER_BR :
this.editor.activeEnterMode;

insert( this, 'text', html );
return CKEDITOR.tools.transformPlainTextToHtml( text, enterMode );
},


/**
* @see CKEDITOR.editor#insertElement
*/
@@ -375,6 +375,55 @@
return text.replace( quoteEscRegex, '"' ).replace( ltEscRegex, '<' ).replace( gtEscRegex, '>' );
},

/**
* Transforms text to the valid HTML: creates paragraphs, replaces tabs with no breaking spaces etc..
*
* @since 4.5
* @param {String} text Text to transform.
* @param {Number} enterMode Editors {@link CKEDITOR.config#enterMode enter mode}.
* @returns {String} HTML generated from the text.
*/
transformPlainTextToHtml: function( text, enterMode ) {
var isEnterBrMode = enterMode == CKEDITOR.ENTER_BR,
// CRLF -> LF
html = this.htmlEncode( text.replace( /\r\n/g, '\n' ) );

// Tab -> &nbsp x 4;
html = html.replace( /\t/g, '&nbsp;&nbsp; &nbsp;' );

var paragraphTag = enterMode == CKEDITOR.ENTER_P ? 'p' : 'div';

// Two line-breaks create one paragraphing block.
if ( !isEnterBrMode ) {
var duoLF = /\n{2}/g;
if ( duoLF.test( html ) )
{
var openTag = '<' + paragraphTag + '>', endTag = '</' + paragraphTag + '>';
html = openTag + html.replace( duoLF, function() { return endTag + openTag; } ) + endTag;
}
}

// One <br> per line-break.
html = html.replace( /\n/g, '<br>' );

// Compensate padding <br> at the end of block, avoid loosing them during insertion.
if ( !isEnterBrMode ) {
html = html.replace( new RegExp( '<br>(?=</' + paragraphTag + '>)' ), function( match ) {
return CKEDITOR.tools.repeat( match, 2 );
} );
}

// Preserve spaces at the ends, so they won't be lost after insertion (merged with adjacent ones).
html = html.replace( /^ | $/g, '&nbsp;' );

// Finally, preserve whitespaces that are to be lost.
html = html.replace( /(>|\s) /g, function( match, before ) {
return before + '&nbsp;';
} ).replace( / (?=<)/g, '&nbsp;' );

return html;
},

/**
* Gets a unique number for this CKEDITOR execution session. It returns
* consecutive numbers starting from 1.
@@ -405,6 +454,21 @@
return 'cke_' + this.getNextNumber();
},

/**
* Gets a universally unique ID. It returns a random string
* up to ISO/IEC 11578:1996, without dashes, with the "e" prefix to
* make sure that ID does not starts with number.
*
* @returns {String} A global unique ID.
*/
getUniqueId: function() {
var uuid = 'e'; // Make sure that id does not start with number.
for ( var i = 0; i < 8; i++ ) {
uuid += Math.floor( ( 1 + Math.random() ) * 0x10000 ).toString( 16 ).substring( 1 );
}
return uuid;
},

/**
* Creates a function override.
*

0 comments on commit cb28e9c

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