Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isSupportedEnvironment virtual member #2693

Merged
merged 39 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bdfed0a
Added isSupportedEnvironment docs.
jacekbogdanski Dec 19, 2018
ec02fca
Fixed docs indent.
jacekbogdanski Dec 19, 2018
06f627a
Docs refactoring.
jacekbogdanski Apr 9, 2019
0c46d42
Added default supported environment method.
jacekbogdanski Apr 9, 2019
97fec76
Added plugin support env tests.
jacekbogdanski Apr 9, 2019
00aa51c
Added testing method to ignore unsupported env.
jacekbogdanski Apr 9, 2019
fd84a59
Tableselection env support change.
jacekbogdanski Apr 9, 2019
8502dcf
Fixed issue with not fully loaded CKEDITOR instance.
jacekbogdanski Apr 9, 2019
a096ea9
Moved tableselection env support method, refactored unit tests.
jacekbogdanski Apr 9, 2019
471e849
Refactored tableselection manual tests.
jacekbogdanski Apr 9, 2019
b4531a8
Moved env support method.
jacekbogdanski Apr 9, 2019
d877a0f
Refactored easyimage manual tests.
jacekbogdanski Apr 9, 2019
180f9ad
Refactored easyimage unit tests.
jacekbogdanski Apr 9, 2019
e22ca61
Restored tools for imagebase.
jacekbogdanski Apr 9, 2019
a081e91
Balloon toolbar env support and test refactoring.
jacekbogdanski Apr 9, 2019
1522e9d
Refactored balloon toolbar manual tests.
jacekbogdanski Apr 10, 2019
496e818
Docs rewording.
jacekbogdanski May 23, 2019
c32f2d1
Moved default method.
jacekbogdanski May 23, 2019
36ec9d1
isSupportedEnvironment for autocomplete.
jacekbogdanski May 27, 2019
a7c4834
Cleanup.
jacekbogdanski May 27, 2019
d9f4945
Updated mentions tests.
jacekbogdanski May 27, 2019
7eb5c78
Updated emoji.
jacekbogdanski May 27, 2019
bb93f65
Uploadwidget isSupportedEnvironment support.
jacekbogdanski May 27, 2019
66556f4
Uploadfile isSupportedEnvironment support.
jacekbogdanski May 27, 2019
5f75919
uploadimage isSupportedEnvironment support.
jacekbogdanski May 27, 2019
a69345a
codesnippet isSupportedEnvironment support.
jacekbogdanski May 27, 2019
9d72a21
Additional spacing in test.
f1ames Jun 10, 2019
d1b83ba
Refactored tests.
jacekbogdanski Jun 13, 2019
cfcb6cd
Removed redundant tools path.
jacekbogdanski Jun 13, 2019
874f531
isSupportedEnvironment for mathjax.
jacekbogdanski Jun 13, 2019
2b7031c
Updated cloudservice tests.
jacekbogdanski Jun 13, 2019
fadd495
Updated imagebase tests.
jacekbogdanski Jun 13, 2019
c26ce5d
Removed dead code.
jacekbogdanski Jun 13, 2019
1bebe77
Removed unused references.
jacekbogdanski Jun 13, 2019
e1caeeb
Restored test.
jacekbogdanski Jun 13, 2019
c42958d
Rebase fixes.
jacekbogdanski Jun 15, 2019
0aa5846
Removed leftover file reference.
jacekbogdanski Jun 15, 2019
4b0f677
Changelog entry.
jacekbogdanski Jun 17, 2019
48b29cd
Changelog entry rewording.
f1ames Jun 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ API Changes:
* [#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.
* [#2924](https://github.com/ckeditor/ckeditor-dev/issues/2924): Added the [`CKEDITOR.tools.style.border`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_tools_style_border.html) object wrapping CSS border style helpers under single type.
* [#2495](https://github.com/ckeditor/ckeditor-dev/issues/2495): [Table Selection](https://ckeditor.com/cke4/addon/tableselection) plugin can be now disabled for the given table by the `data-cke-tableselection-ignored` attribute.
* [#2692](https://github.com/ckeditor/ckeditor-dev/issues/2692): Plugins can now expose information about supported environment by implementing [`pluginDefinition.isSupportedEnvironment`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_pluginDefinition.html#method-isSupportedEnvironment) method.

Other Changes:

Expand Down
26 changes: 26 additions & 0 deletions core/plugindefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,29 @@
*
* @property {String} [icons]
*/

/**
* A function which should be implemented if a plugin is not supported on every
* available environment according to
* [Browser Compatibility](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_browsers.html)
* or specific editor configuration.
*
* This function won't be called by the plugin loader itself and it's not required for a proper
* plugin initialization. However, it's recommended to implement the function if a plugin
* has environment requirements. This information may be important for related features
* and testing environment.
*
* ```javascript
* CKEDITOR.plugins.add( 'sample', {
* isSupportedEnvironment: function( editor ) {
* // Plugin supported only on modern browsers.
* return !CKEDITOR.env.ie || CKEDITOR.env.edge;
* }
* } );
* ```
*
* @since 4.12.0
* @method isSupportedEnvironment
* @param {CKEDITOR.editor} editor
* @returns {Boolean} Information if the plugin is supported in the current environment.
*/
6 changes: 6 additions & 0 deletions core/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ CKEDITOR.plugins.load = CKEDITOR.tools.override( CKEDITOR.plugins.load, function
'.png' );
}
}

// Plugin is supported by default (#2692).
plugin.isSupportedEnvironment = plugin.isSupportedEnvironment || function() {
return true;
};

initialized[ pluginName ] = 1;
}

Expand Down
5 changes: 2 additions & 3 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2020,9 +2020,8 @@

// Handle special case - fake selection of table cells.
if ( editor && editor.plugins.tableselection &&
CKEDITOR.plugins.tableselection.isSupportedEnvironment &&
isTableSelection( ranges ) &&
!isSelectingTable &&
editor.plugins.tableselection.isSupportedEnvironment() &&
isTableSelection( ranges ) && !isSelectingTable &&
!ranges[ 0 ]._getTableElement( { table: 1 } ).hasAttribute( 'data-cke-tableselection-ignored' )
) {
performFakeTableSelection.call( this, ranges );
Expand Down
3 changes: 3 additions & 0 deletions plugins/autocomplete/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
requires: 'textwatcher',
onLoad: function() {
CKEDITOR.document.appendStyleSheet( this.path + 'skins/default.css' );
},
isSupportedEnvironment: function() {
return !CKEDITOR.env.ie || CKEDITOR.env.version > 8;
}
} );

Expand Down
4 changes: 4 additions & 0 deletions plugins/balloontoolbar/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@
CKEDITOR.plugins.add( 'balloontoolbar', {
requires: 'balloonpanel',

isSupportedEnvironment: function() {
return !CKEDITOR.env.ie || CKEDITOR.env.version > 8;
f1ames marked this conversation as resolved.
Show resolved Hide resolved
},

beforeInit: function( editor ) {
if ( !cssLoaded ) {
// Load fallback styles.
Expand Down
10 changes: 6 additions & 4 deletions plugins/codesnippet/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
'use strict';

( function() {
var isBrowserSupported = !CKEDITOR.env.ie || CKEDITOR.env.version > 8;

CKEDITOR.plugins.add( 'codesnippet', {
requires: 'widget,dialog',
lang: 'ar,az,bg,ca,cs,da,de,de-ch,el,en,en-au,en-gb,eo,es,es-mx,et,eu,fa,fi,fr,fr-ca,gl,he,hr,hu,id,it,ja,km,ko,ku,lt,lv,nb,nl,no,oc,pl,pt,pt-br,ro,ru,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
icons: 'codesnippet', // %REMOVE_LINE_CORE%
hidpi: true, // %REMOVE_LINE_CORE%

isSupportedEnvironment: function() {
return !CKEDITOR.env.ie || CKEDITOR.env.version > 8;
},

beforeInit: function( editor ) {
editor._.codesnippet = {};

Expand Down Expand Up @@ -105,7 +107,7 @@
init: function( callback ) {
var that = this;

if ( isBrowserSupported ) {
if ( editor.plugins.codesnippet.isSupportedEnvironment() ) {
CKEDITOR.scriptLoader.load( path + 'lib/highlight/highlight.pack.js', function() {
that.hljs = window.hljs;
callback();
Expand Down Expand Up @@ -313,7 +315,7 @@
callback = function( formatted ) {
// IE8 (not supported browser) have issue with new line chars, when using innerHTML.
// It will simply strip it.
that.parts.code.setHtml( isBrowserSupported ?
that.parts.code.setHtml( editor.plugins.codesnippet.isSupportedEnvironment() ?
formatted : formatted.replace( newLineRegex, '<br>' ) );
};

Expand Down
12 changes: 6 additions & 6 deletions plugins/easyimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,6 @@
}
};

function isSupportedBrowser() {
return !CKEDITOR.env.ie || CKEDITOR.env.version >= 11;
}

function addUploadButtonToToolbar( editor ) {
editor.ui.addButton( BUTTON_PREFIX + 'Upload', {
label: editor.lang.easyimage.commands.upload,
Expand Down Expand Up @@ -535,8 +531,12 @@
CKEDITOR.dialog.add( 'easyimageAlt', this.path + 'dialogs/easyimagealt.js' );
},

isSupportedEnvironment: function() {
return !CKEDITOR.env.ie || CKEDITOR.env.version >= 11;
},

init: function( editor ) {
if ( !isSupportedBrowser() ) {
if ( !this.isSupportedEnvironment() ) {
return;
}
loadStyles( editor, this );
Expand All @@ -545,7 +545,7 @@
// Widget must be registered after init in case that link plugin is dynamically loaded e.g. via
// `config.extraPlugins`.
afterInit: function( editor ) {
if ( !isSupportedBrowser() ) {
if ( !this.isSupportedEnvironment() ) {
return;
}
var styles = getStylesForEditor( editor );
Expand Down
8 changes: 6 additions & 2 deletions plugins/emoji/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,12 @@
icons: 'emojipanel',
hidpi: true,

isSupportedEnvironment: function() {
return !CKEDITOR.env.ie || CKEDITOR.env.version >= 11;
},

beforeInit: function() {
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 11 ) {
if ( !this.isSupportedEnvironment() ) {
return;
}
if ( !stylesLoaded ) {
Expand All @@ -560,7 +564,7 @@
},

init: function( editor ) {
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 11 ) {
if ( !this.isSupportedEnvironment() ) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions plugins/mathjax/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
icons: 'mathjax',
hidpi: true, // %REMOVE_LINE_CORE%

isSupportedEnvironment: function() {
return !CKEDITOR.env.ie || CKEDITOR.env.version > 8;
},

init: function( editor ) {
var cls = editor.config.mathJaxClass || 'math-tex';

Expand Down
3 changes: 3 additions & 0 deletions plugins/mentions/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
self.instances.push( new Mentions( editor, config ) );
} );
} );
},
isSupportedEnvironment: function( editor ) {
return editor.plugins.autocomplete.isSupportedEnvironment( editor );
}
} );

Expand Down
16 changes: 6 additions & 10 deletions plugins/tableselection/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,20 +1149,16 @@
var editable = editor.editable();
editable.attachListener( editable, 'keydown', getTableOnKeyDownListener( editor ), null, null, -1 );
editable.attachListener( editable, 'keypress', tableKeyPressListener, null, null, -1 );
},

/**
* Determines whether table selection is supported in the current environment.
*
* @property {Boolean}
* @private
*/
isSupportedEnvironment: !( CKEDITOR.env.ie && CKEDITOR.env.version < 11 )
}
};

CKEDITOR.plugins.add( 'tableselection', {
requires: 'clipboard,tabletools',

isSupportedEnvironment: function() {
return !( CKEDITOR.env.ie && CKEDITOR.env.version < 11 );
},

onLoad: function() {
// We can't alias these features earlier, as they could be still not loaded.
tabletools = CKEDITOR.plugins.tabletools;
Expand All @@ -1176,7 +1172,7 @@

init: function( editor ) {
// Disable unsupported browsers.
if ( !CKEDITOR.plugins.tableselection.isSupportedEnvironment ) {
if ( !this.isSupportedEnvironment() ) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion plugins/uploadfile/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
requires: 'uploadwidget,link',
init: function( editor ) {
// Do not execute this paste listener if it will not be possible to upload file.
if ( !CKEDITOR.plugins.clipboard.isFileApiSupported ) {
if ( !this.isSupportedEnvironment() ) {
return;
}

Expand All @@ -37,6 +37,10 @@
this.replaceWith( '<a href="' + upload.url + '" target="_blank">' + upload.fileName + '</a>' );
}
} );
},

isSupportedEnvironment: function() {
return CKEDITOR.plugins.clipboard.isFileApiSupported;
}
} );
} )();
6 changes: 5 additions & 1 deletion plugins/uploadimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@
);
},

isSupportedEnvironment: function() {
return CKEDITOR.plugins.clipboard.isFileApiSupported;
},

init: function( editor ) {
// Do not execute this paste listener if it will not be possible to upload file.
if ( !CKEDITOR.plugins.clipboard.isFileApiSupported ) {
if ( !this.isSupportedEnvironment() ) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions plugins/uploadwidget/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// because otherwise wrong widget may handle upload placeholder element (e.g. image2 plugin would handle image).
// `data-widget` attribute is allowed only in the elements which has also `data-cke-upload-id` attribute.
editor.filter.allow( '*[!data-widget,!data-cke-upload-id]' );
},

isSupportedEnvironment: function() {
return CKEDITOR.plugins.clipboard.isFileApiSupported;
}
} );

Expand Down
40 changes: 40 additions & 0 deletions tests/_benderjs/ckeditor/static/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,46 @@
} );

bender.tools = {
/**
* Ignores test case when the given plugin is not supported on the testing
* environment. Uses {@link CKEDITOR.pluginDefinition#isSupportedEnvironment} to
* verify if plugin is supported.
*
* Works for both manual and unit tests.
*
* @param pluginName pluginName Plugin name to check.
* @param CKEDITOR.editor [editor] Editor instance passsed as an argument
* to the {@link CKEDITOR.pluginDefinition#isSupportedEnvironment} method.
*/
ignoreUnsupportedEnvironment: function( pluginName, editor ) {
f1ames marked this conversation as resolved.
Show resolved Hide resolved
if ( editor ) {
if ( editor.status === 'ready' ) {
ignoreUnsupportedEnvironment();
} else {
editor.once( 'instanceReady', ignoreUnsupportedEnvironment );
}
return;
}

if ( CKEDITOR.plugins.registered[ pluginName ] ) {
ignoreUnsupportedEnvironment();
} else {
CKEDITOR.once( pluginName + 'PluginReady', ignoreUnsupportedEnvironment );
}

function ignoreUnsupportedEnvironment() {
var plugin = editor ? editor.plugins[ pluginName ] : CKEDITOR.plugins.registered[ pluginName ];

if ( !plugin.isSupportedEnvironment( editor ) ) {
if ( bender.testData.manual ) {
bender.ignore();
} else {
assert.ignore();
}
}
}
},

/**
* Creates an array from an object.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/core/plugins/plugins.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<textarea id="errortest">test</textarea>
<textarea id="errortest">test</textarea>
<textarea id="env"></textarea>
27 changes: 27 additions & 0 deletions tests/core/plugins/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,32 @@ bender.test(

assert.isFalse( result, 'Conflicts not detected.' );
assert.isFalse( spy.called );
},

// (#2692)
'test supported environment': function() {
CKEDITOR.plugins.add( 'envdefault', {} );
CKEDITOR.plugins.add( 'envcustom', {
isSupportedEnvironment: function() {
return false;
}
} );

var editor = CKEDITOR.replace( 'env', {
plugins: 'wysiwygarea,envdefault,envcustom',
on: {
instanceReady: function() {
resume( function() {
assert.isTrue( editor.plugins.envdefault.isSupportedEnvironment(),
'Plugin should be supported by default' );

assert.isFalse( editor.plugins.envcustom.isSupportedEnvironment(),
'Plugin should allow for custom isSupportedEnvironment implementation' );
} );
}
}
} );

wait();
}
} );
4 changes: 1 addition & 3 deletions tests/plugins/autocomplete/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
bender.test( {

setUp: function() {
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
assert.ignore();
}
bender.tools.ignoreUnsupportedEnvironment( 'autocomplete' );
},

'test API exists': function() {
Expand Down
4 changes: 1 addition & 3 deletions tests/plugins/autocomplete/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

bender.test( {
setUp: function() {
if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) {
assert.ignore();
}
bender.tools.ignoreUnsupportedEnvironment( 'autocomplete' );
},

'test preventDefault is called on mousedown': function() {
Expand Down
4 changes: 1 addition & 3 deletions tests/plugins/autocomplete/manual/__template__.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

<script>

if ( autocompleteUtils.isUnsupportedEnvironment() ) {
bender.ignore();
}
bender.tools.ignoreUnsupportedEnvironment( 'autocomplete' );

CKEDITOR.replace( 'editor1', {
width: 600,
Expand Down
Loading