cloudservices.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module cloudservices/cloudservices
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import Token from '@ckeditor/ckeditor-cloudservices-core/src/token/token';
  10. /**
  11. * Plugin introducing CKEditor 5's Cloud Services integration.
  12. * It takes care of the {@link module:cloudservices/cloudservices~CloudServicesConfig `config.cloudService`}
  13. * configuration options and initializes the token provider.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class CloudServices extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. init() {
  22. const editor = this.editor;
  23. const config = editor.config;
  24. const options = config.get( 'cloudServices' ) || {};
  25. for ( const optionName in options ) {
  26. this[ optionName ] = options[ optionName ];
  27. }
  28. /**
  29. * The authentication token URL for CKEditor Cloud Services.
  30. *
  31. * @readonly
  32. * @member {String|undefined} #tokenUrl
  33. */
  34. /**
  35. * The URL to which the files should be uploaded.
  36. *
  37. * @readonly
  38. * @default 'https://files.cke-cs.com/upload/'
  39. * @member {String} #uploadUrl
  40. */
  41. if ( !this.uploadUrl ) {
  42. this.uploadUrl = 'https://files.cke-cs.com/upload/';
  43. }
  44. /**
  45. * Other plugins use this token for the authorization process. It handles token requesting and refreshing.
  46. * Its value is `null` when {@link module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl} is not provided.
  47. *
  48. * @readonly
  49. * @member {Object|null} #token
  50. */
  51. if ( !this.tokenUrl ) {
  52. this.token = null;
  53. return;
  54. }
  55. this.token = new CloudServices.Token( this.tokenUrl );
  56. return this.token.init();
  57. }
  58. }
  59. CloudServices.Token = Token;
  60. /**
  61. * The configuration of CKEditor Cloud Services. Introduced by the {@link module:cloudservices/cloudservices~CloudServices} plugin.
  62. *
  63. * Read more in {@link module:cloudservices/cloudservices~CloudServicesConfig}.
  64. *
  65. * @member {module:cloudservices/cloudservices~CloudServicesConfig} module:core/editor/editorconfig~EditorConfig#cloudServices
  66. */
  67. /**
  68. * The configuration for all plugins using CKEditor Cloud Services.
  69. *
  70. * ClassicEditor
  71. * .create( document.querySelector( '#editor' ), {
  72. * cloudServices: ... // CloudServices config.
  73. * } )
  74. * .then( ... )
  75. * .catch( ... );
  76. *
  77. * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
  78. *
  79. * @interface CloudServicesConfig
  80. */
  81. /**
  82. * The authentication token URL for CKEditor Cloud Services. The token is used to authenticate all plugins using Cloud Services,
  83. * for instance Easy Image. The token URL has to point to the service where the token is generated.
  84. *
  85. * ClassicEditor
  86. * .create( document.querySelector( '#editor' ), {
  87. * cloudServices: {
  88. * tokenUrl: TOKEN_URL
  89. * },
  90. * plugins: [ ArticlePluginSet, EasyImage ],
  91. * toolbar: [ 'headings', 'undo', 'redo', 'insertImage' ],
  92. * image: {
  93. * toolbar: [ 'imageStyleFull', 'imageStyleSide', '|', 'imageTextAlternative' ]
  94. * }
  95. * } );
  96. *
  97. * @member {String} module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl
  98. */
  99. /**
  100. * The URL to which the files should be uploaded.
  101. *
  102. * @member {String} [module:cloudservices/cloudservices~CloudServicesConfig#uploadUrl='https://files.cke-cs.com/upload/']
  103. */