Skip to content

Commit

Permalink
Merge pull request #2988 from ckeditor/t/2962
Browse files Browse the repository at this point in the history
Introduced Promise support
  • Loading branch information
f1ames authored May 21, 2019
2 parents f9a4b26 + b45cf49 commit 680bdd9
Show file tree
Hide file tree
Showing 15 changed files with 1,353 additions and 2,126 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ API Changes:
* [#2748](https://github.com/ckeditor/ckeditor-dev/issues/2748): Enhance errors thrown while creating editor on a nonexistent element or while trying to instantiate second editor on the same element. Thanks to [Byran Zaugg](https://github.com/blzaugg)!
* [#2698](https://github.com/ckeditor/ckeditor-dev/issues/2698): Added the [`CKEDITOR.htmlParser.element.findOne`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_htmlParser_element.html#method-findOne) method.
* [#2935](https://github.com/ckeditor/ckeditor-dev/issues/2935): Introduced [`CKEDITOR.config.pasteFromWord_keepZeroMargins`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-pasteFromWord_keepZeroMargins) config option, that allows keeping any `margin-*: 0` style that would be otherwise removed when pasting content with [Paste from Word](https://ckeditor.com/cke4/addon/pastefromword) plugin.
* [#2962](https://github.com/ckeditor/ckeditor-dev/issues/2962): Added the [`CKEDITOR.tools.promise`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_tools_promise.html) class.

Other Changes:

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The following libraries are included in CKEditor under the MIT license (see Appe
* CKSource Samples Framework (included in the samples) - Copyright (c) 2014-2019, CKSource - Frederico Knabben.
* PicoModal (included in `samples/js/sf.js`) - Copyright (c) 2012 James Frasca.
* CodeMirror (included in the samples) - Copyright (C) 2014 by Marijn Haverbeke <[email protected]> and others.
* ES6Promise - Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors.

Parts of code taken from the following libraries are included in CKEditor under the MIT license (see Appendix D):

Expand All @@ -61,7 +62,6 @@ The following libraries are included only in the development version of CKEditor
* CKBuilder - Copyright (c) 2012-2019, CKSource - Frederico Knabben.
* CKLangTool - Copyright (c) 2012-2019, CKSource - Frederico Knabben.
* Optimist - Copyright 2010 James Halliday ([email protected]).
* Q - Copyright 2009–2014 Kristopher Michael Kowal.
* Tmp - Copyright (c) 2014 KARASZI István.
* Mkdirp - Copyright 2010 James Halliday ([email protected]).
* Bender.js - Copyright (c) 2014-2019, CKSource - Frederico Knabben.
Expand Down
5 changes: 3 additions & 2 deletions core/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if ( !CKEDITOR.loader ) {
var scripts = {
'_bootstrap': [
'config', 'creators/inline', 'creators/themedui', 'editable', 'ckeditor', 'plugins',
'scriptloader', 'style', 'tools',
'scriptloader', 'style', 'tools', 'promise',
// The following are entries that we want to force loading at the end to avoid dependence recursion.
'dom/comment', 'dom/elementpath', 'dom/text', 'dom/rangelist', 'skin'
],
Expand Down Expand Up @@ -86,7 +86,8 @@ if ( !CKEDITOR.loader ) {
'tools': [ 'env' ],
'ui': [],
'creators/themedui': [],
'creators/inline': []
'creators/inline': [],
'promise': [ 'tools' ]
};

// The production implementation contains a fixed timestamp generated by the releaser.
Expand Down
78 changes: 78 additions & 0 deletions core/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* global Promise, ES6Promise */

( function() {
'use strict';

if ( window.Promise ) {
CKEDITOR.tools.promise = Promise;
} else {
var polyfillURL = CKEDITOR.getUrl( 'vendor/promise.js' );

CKEDITOR.scriptLoader.load( polyfillURL, function( success ) {
if ( success ) {
CKEDITOR.tools.promise = ES6Promise;
} else {
CKEDITOR.error( 'no-vendor-lib', {
path: polyfillURL
} );
}
} );
}

/**
* Alias for [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
* object representing asynchronous operation.
*
* Uses native `Promise` browser implementation if available. For older browsers with lack of `Promise` support, the
* [ES6-Promise](https://github.com/stefanpenner/es6-promise) polyfill is used.
* See [Promise Browser Compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility)
* to learn more.
*
* Refer to [MDN Using Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) guide for
* more details how to work with promises.
*
* **NOTE:** `catch` and `finally` are reserved keywords in IE < 9 browsers. Use bracket notation instead:
*
* ```javascript
* promise[ 'catch' ]( function( err ) {
* // ...
* } );
*
* promise[ 'finally' ]( function() {
* // ...
* } );
* ```
*
* @since 4.12.0
* @class CKEDITOR.tools.promise
*/

/**
* Creates new `Promise` instance.
*
* ```js
* new CKEDITOR.tools.promise( function( resolve, reject ) {
* setTimeout( function() {
* var timestamp;
* try {
* timestamp = ( new Date() ).getTime();
* } catch ( e ) {
* reject( e );
* }
* resolve( timestamp );
* }, 5000 );
* } );
* ```
*
* @param {Function} resolver
* @param {Function} resolver.resolve
* @param {Function} resolver.reject
* @constructor
*/

} )();
4 changes: 2 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ module.exports = function( grunt ) {
// Automatically loaded from .gitignore. Add more if necessary.

'lang/**',
'vendor/**',
'plugins/*/lib/**',
'plugins/**/lang/**',
'plugins/uicolor/yui/**',
'plugins/htmlwriter/samples/assets/outputforflash/**',
'samples/toolbarconfigurator/lib/**',
'tests/adapters/jquery/_assets/**',
'tests/core/dom/_assets/**',
'tests/core/selection/_helpers/rangy.js',
'tests/plugins/pastefromword/generated/_lib/q.js'
'tests/core/selection/_helpers/rangy.js'
];

// Basic configuration which will be overloaded by the tasks.
Expand Down
3 changes: 1 addition & 2 deletions tests/_benderjs/ckeditor/lib/pagebuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ var path = require( 'path' ),
files = [
path.join( __dirname, '..', 'static', 'tools.js' ),
path.join( __dirname, '..', 'static', 'bot.js' ),
path.join( __dirname, '..', 'static', 'extensions.js' ),
path.join( __dirname, 'q.js' )
path.join( __dirname, '..', 'static', 'extensions.js' )
];

module.exports = {
Expand Down
Loading

0 comments on commit 680bdd9

Please sign in to comment.