Navigation Menu

Skip to content

Commit

Permalink
Merge branch 't/10925c' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Apr 7, 2015
2 parents 3263734 + 61f53fb commit aba11da
Show file tree
Hide file tree
Showing 27 changed files with 2,210 additions and 2 deletions.
Binary file added plugins/embed/icons/embed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/embed/icons/hidpi/embed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions plugins/embed/plugin.js
@@ -0,0 +1,70 @@
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/

( function() {
'use strict';

CKEDITOR.plugins.add( 'embed', {
icons: 'embed', // %REMOVE_LINE_CORE%
hidpi: true, // %REMOVE_LINE_CORE%
requires: 'embedbase',

init: function( editor ) {
var widgetDefinition = CKEDITOR.plugins.embedBase.createWidgetBaseDefinition( editor );

// 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}'
),

upcast: function( el, data ) {
if ( el.name == 'div' && el.attributes[ 'data-oembed-url' ] ) {
data.url = el.attributes[ 'data-oembed-url' ];

return true;
}
},

downcast: function( el ) {
el.attributes[ 'data-oembed-url' ] = this.data.url;
}
}, true );

// Register the definition as 'embed' widget.
editor.widgets.add( 'embed', widgetDefinition );

// Do not filter contents of the div[data-oembed-url] at all.
editor.filter.addElementCallback( function( el ) {
if ( 'data-oembed-url' in el.attributes ) {
return CKEDITOR.FILTER_SKIP_TREE;
}
} );
}
} );

} )();

/**
* A template for URL to the provider endpoint. This URL will be queried for each resource to be embedded.
* By default CKEditor uses [Iframely](https://iframely.com/) service.
*
* The template might use the following parameters:
*
* * `url` - The URL of requested media, e.g. `https://twitter.com/ckeditor/status/401373919157821441`.
* * `callback` - A name of globally available callback, used for JSONP requests.
*
* You can read more about content providers in {@link CKEDITOR.plugins.embedBase.baseDefinition#providerUrl}.
*
* @since 4.5.0
* @cfg {String} [embed_provider=//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}]
* @member CKEDITOR.config
*/
86 changes: 86 additions & 0 deletions plugins/embedbase/dialogs/embedbase.js
@@ -0,0 +1,86 @@
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/

/* global alert */

CKEDITOR.dialog.add( 'embedBase', function( editor ) {
'use strict';

var lang = editor.lang.embedbase;

return {
title: lang.title,
minWidth: 350,
minHeight: 50,

onLoad: function() {
var that = this,
okButton = that.getButton( 'ok' );

this.on( 'ok', function( evt ) {
// We're going to hide it manually, after remote response is fetched.
evt.data.hide = false;

// Disable the OK button for the time of loading, so user can't trigger multiple inserts.
okButton.disable();

// We don't want the widget system to finalize widget insertion (it happens with priority 20).
evt.stop();

var url = that.getValueOf( 'info', 'url' );

that.widget.loadContent( url, {
noNotifications: true,

callback: function() {
if ( !that.widget.isReady() ) {
editor.widgets.finalizeCreation( that.widget.wrapper.getParent( true ) );
}

editor.fire( 'saveSnapshot' );

okButton.enable();
that.hide();
},

errorCallback: function( messageTypeOrMessage ) {
that.getContentElement( 'info', 'url' ).select();

// We need to enable the OK button so user can fix the URL.
okButton.enable();

alert( that.widget.getErrorMessage( messageTypeOrMessage, url, 'Given' ) );
}
} );
}, null, null, 15 );
},

contents: [
{
id: 'info',

elements: [
{
type: 'text',
id: 'url',
label: lang.url,

setup: function( widget ) {
this.setValue( widget.data.url );
},

validate: function() {
if ( !this.getDialog().widget.isUrlValid( this.getValue() ) ) {
return lang.unsupportedUrlGiven;
}

return true;
}
}
]
}
]
};
} );
16 changes: 16 additions & 0 deletions plugins/embedbase/lang/en.js
@@ -0,0 +1,16 @@
/*
Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'embedbase', 'en', {
pathName: 'media object',
title: 'Media Embed',
url: 'URL',
button: 'Insert Media Embed',
unsupportedUrlGiven: 'The given URL is not supported.',
unsupportedUrl: 'The URL {url} is not supported by Media Embed.',
fetchingFailedGiven: 'Failed to fetch content for the given URL.',
fetchingFailed: 'Failed to fetch content for {url}.',
fetchingOne: 'Fetching oEmbed response...',
fetchingMany: 'Fetching oEmbed responses, {current} of {max} done...'
} );

0 comments on commit aba11da

Please sign in to comment.