Skip to content

Commit

Permalink
Embed plugin provider url is now empty by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Apr 19, 2017
2 parents 84d3983 + 8fc2ed0 commit 9afd0df
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -3,6 +3,10 @@

## CKEditor 4.7

**Important Notes:**

* [#13793](http://dev.ckeditor.com/ticket/13793): [`embed_provider`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-embed_provider) is no longer preset by default.

New Features:

* [#16971](http://dev.ckeditor.com/ticket/16971): Added a support for color in `background` property containing also other styles for table cells in [Table Tools](http://ckeditor.com/addon/tabletools) plugin.
Expand Down
24 changes: 17 additions & 7 deletions plugins/embed/plugin.js
Expand Up @@ -14,17 +14,18 @@
init: function( editor ) {
var widgetDefinition = CKEDITOR.plugins.embedBase.createWidgetBaseDefinition( editor );

if ( !editor.config.embed_provider ) {
CKEDITOR.error( 'embed-no-provider-url' );
}

// Extend the base definition with additional properties.
CKEDITOR.tools.extend( widgetDefinition, {
// Use a dialog exposed by the embedbase plugin.
dialog: 'embedBase',
button: editor.lang.embedbase.button,
allowedContent: 'div[!data-oembed-url]',
requiredContent: 'div[data-oembed-url]',
providerUrl: new CKEDITOR.template(
editor.config.embed_provider ||
'//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}'
),
providerUrl: new CKEDITOR.template( editor.config.embed_provider || '' ),

// The filter element callback actually allows all divs with data-oembed-url,
// so registering styles to the filter is virtually unnecessary because
Expand Down Expand Up @@ -72,9 +73,8 @@

/**
* A template for the URL of the provider endpoint. This URL will be queried for each resource to be embedded.
* By default CKEditor uses the [Iframely](https://iframely.com/) service.
*
* The template might use the following parameters:
* It uses the following parameters:
*
* * `url` – The URL of the requested media, e.g. `https://twitter.com/ckeditor/status/401373919157821441`.
* * `callback` – The name of the globally available callback used for JSONP requests.
Expand All @@ -83,12 +83,22 @@
*
* config.embed_provider = '//example.com/api/oembed-proxy?resource-url={url}&callback={callback}';
*
* By default CKEditor does not use any provider, although there's a ready to use URL available:
*
* config.embed_provider = '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}'
*
* However, above endpoint contains certain limitations, e.g. can't embed Google Maps content.
* It's recommended to set up an account on the [Iframely](https://iframely.com/) service for
* better control over embedded content.
*
* Read more in the [documentation](#!/guide/dev_media_embed)
* and see the [SDK sample](http://sdk.ckeditor.com/samples/mediaembed.html).
*
* Refer to {@link CKEDITOR.plugins.embedBase.baseDefinition#providerUrl} for more information about content providers.
*
* **Important note:** Prior to version 4.7 this configuration option defaulted to `//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}` string.
*
* @since 4.5
* @cfg {String} [embed_provider=//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}]
* @cfg {String} [embed_provider='']
* @member CKEDITOR.config
*/
19 changes: 19 additions & 0 deletions tests/plugins/embed/manual/embedprovider.html
@@ -0,0 +1,19 @@
<p>Test URLs</p>

<ul>
<li>https://www.youtube.com/watch?v=GUl9_5kK9ts</li>
<li>https://twitter.com/cksource/status/719823128889790464</li>
</ul>

<textarea id="editor1" cols="10" rows="10">
<p>Foo bar</p>
</textarea>
<script>
( function() {
CKEDITOR.replace( 'editor1', {
extraPlugins: 'wysiwygarea,sourcearea,htmlwriter,entities,toolbar,elementspath,undo,clipboard,format,basicstyles,embed,preview',
embed_provider: '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}',
height: 500
} );
} )();
</script>
16 changes: 16 additions & 0 deletions tests/plugins/embed/manual/embedprovider.md
@@ -0,0 +1,16 @@
@bender-tags: 4.7.0, tc, 13793, config
@bender-ui: collapsed

1. Open dev console.
1. Copy any of the links below "Test URLs".
1. Click on "Insert Media Embed" button.
1. Paste URL.
1. Click OK.

## Expected

Content gets embedded into the editor.

## Unexpected

`embed-no-provider-url` error displayed in the dev console.
42 changes: 42 additions & 0 deletions tests/plugins/embed/provider.js
@@ -0,0 +1,42 @@
/* bender-tags: embed */
/* bender-ckeditor-plugins: embed,toolbar */

( function() {
'use strict';

bender.test( {

setUp: function() {
this.errorSpy = sinon.spy( CKEDITOR, 'error' );
},

tearDown: function() {
this.errorSpy && this.errorSpy.restore();
},

'test default embed_provider empty and error thrown': function() {
var spy = this.errorSpy;

bender.editorBot.create( {
name: 'editor1'
}, function( bot ) {
assert.isTrue( spy.calledWith( 'embed-no-provider-url' ) );
assert.areSame( '', bot.editor.widgets.registered.embed.providerUrl.source );
} );
},

'test custom embed_provider used when set and no error thrown': function() {
var spy = this.errorSpy;

bender.editorBot.create( {
name: 'editor2',
config: {
embed_provider: 'testurl?url{url}&callback={callback}'
}
}, function( bot ) {
assert.isTrue( spy.notCalled );
assert.areSame( 'testurl?url{url}&callback={callback}', bot.editor.widgets.registered.embed.providerUrl.source );
} );
}
} );
} )();

0 comments on commit 9afd0df

Please sign in to comment.