plugin.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. ( function() {
  6. 'use strict';
  7. CKEDITOR.plugins.add( 'embed', {
  8. icons: 'embed', // %REMOVE_LINE_CORE%
  9. hidpi: true, // %REMOVE_LINE_CORE%
  10. requires: 'embedbase',
  11. init: function( editor ) {
  12. var widgetDefinition = CKEDITOR.plugins.embedBase.createWidgetBaseDefinition( editor );
  13. // Extend the base definition with additional properties.
  14. CKEDITOR.tools.extend( widgetDefinition, {
  15. // Use a dialog exposed by the embedbase plugin.
  16. dialog: 'embedBase',
  17. button: editor.lang.embedbase.button,
  18. allowedContent: 'div[!data-oembed-url]',
  19. requiredContent: 'div[data-oembed-url]',
  20. providerUrl: new CKEDITOR.template(
  21. editor.config.embed_provider ||
  22. '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}'
  23. ),
  24. // The filter element callback actually allows all divs with data-oembed-url,
  25. // so registering styles to the filter is virtually unnecessary because
  26. // classes won't be filtered out. However, registering them will make filter.check() work
  27. // which may be important in some cases.
  28. styleToAllowedContentRules: function( style ) {
  29. // Retrieve classes defined in the style.
  30. var classes = style.getClassesArray();
  31. return {
  32. div: {
  33. propertiesOnly: true,
  34. classes: classes,
  35. attributes: '!data-oembed-url'
  36. }
  37. };
  38. },
  39. upcast: function( el, data ) {
  40. if ( el.name == 'div' && el.attributes[ 'data-oembed-url' ] ) {
  41. data.url = el.attributes[ 'data-oembed-url' ];
  42. return true;
  43. }
  44. },
  45. downcast: function( el ) {
  46. el.attributes[ 'data-oembed-url' ] = this.data.url;
  47. }
  48. }, true );
  49. // Register the definition as 'embed' widget.
  50. editor.widgets.add( 'embed', widgetDefinition );
  51. // Do not filter contents of the div[data-oembed-url] at all.
  52. editor.filter.addElementCallback( function( el ) {
  53. if ( 'data-oembed-url' in el.attributes ) {
  54. return CKEDITOR.FILTER_SKIP_TREE;
  55. }
  56. } );
  57. }
  58. } );
  59. } )();
  60. /**
  61. * A template for the URL of the provider endpoint. This URL will be queried for each resource to be embedded.
  62. * By default CKEditor uses the [Iframely](https://iframely.com/) service.
  63. *
  64. * The template might use the following parameters:
  65. *
  66. * * `url` – The URL of the requested media, e.g. `https://twitter.com/ckeditor/status/401373919157821441`.
  67. * * `callback` – The name of the globally available callback used for JSONP requests.
  68. *
  69. * For example:
  70. *
  71. * config.embed_provider = '//example.com/api/oembed-proxy?resource-url={url}&callback={callback}';
  72. *
  73. * Read more in the [documentation](#!/guide/dev_media_embed)
  74. * and see the [SDK sample](http://sdk.ckeditor.com/samples/mediaembed.html).
  75. *
  76. * Refer to {@link CKEDITOR.plugins.embedBase.baseDefinition#providerUrl} for more information about content providers.
  77. *
  78. * @since 4.5
  79. * @cfg {String} [embed_provider=//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}]
  80. * @member CKEDITOR.config
  81. */