Przeglądaj źródła

Add js code examples to documentation.

Mateusz Samsel 6 lat temu
rodzic
commit
9cbc27089b
1 zmienionych plików z 90 dodań i 1 usunięć
  1. 90 1
      packages/ckeditor5-link/src/link.js

+ 90 - 1
packages/ckeditor5-link/src/link.js

@@ -38,7 +38,96 @@ export default class Link extends Plugin {
 /**
 /**
  * The configuration of the {@link module:link/link~Link} feature.
  * The configuration of the {@link module:link/link~Link} feature.
  *
  *
- * Read more in {@link module:link/linkt~LinkConfig}.
+ * Read more in {@link module:link/link~LinkConfig}.
  *
  *
  * @member {module:link/link~LinkConfig} module:core/editor/editorconfig~EditorConfig#link
  * @member {module:link/link~LinkConfig} module:core/editor/editorconfig~EditorConfig#link
  */
  */
+
+/**
+ * The configuration of the {@link module:link/link~Link link feature}.
+ *
+ *		ClassicEditor
+ *			.create( editorElement, {
+ * 				link:  ... // Link feature configuration.
+ *			} )
+ *			.then( ... )
+ *			.catch( ... );
+ *
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
+ * @interface LinkConfig
+ */
+
+/**
+ * Configuration of the {@link module:link/link~Link} feature. If set to `true`,
+ * then default 'automatic' decorator is added to the link.
+ *
+ * @member {Boolean} module:link/link~LinkConfig#targetDecorator
+ */
+
+/**
+ * Custom link decorators.
+ *
+ * **Warning** Currently there is no integration between 'automatic' and 'manual' decorators,
+ * which transforms the same attribute. For example, configuring `target` attribute through both
+ * 'automatic' and 'manual' decorator might result with quirk behavior.
+ *
+ * Decorators provides:
+ *   * simple automatic rules based on url address to apply customized and predefined additional attributes.
+ *   * manual rules, which adds UI checkbox, where user can simply trigger predefined attributes for given link.
+ *
+ *
+ * ```js
+ * const link.decorators = [
+ * 	{
+ * 		mode: 'automatic',
+ * 		callback: url => url.startsWith( 'http://' ),
+ * 		attributes: {
+ * 			target: '_blank',
+ * 			rel: 'noopener noreferrer'
+ * 		}
+ * 	},
+ * 	{
+ * 		mode: 'automatic',
+ * 		callback: url => url.includes( 'download' ) && url.endsWith( '.pdf' ),
+ * 		attributes: {
+ * 			download: 'download'
+ * 		}
+ * 	},
+ * 	{
+ * 		mode: 'automatic',
+ * 		callback: url => url.includes( 'image' ) && url.endsWith( '.png' ),
+ * 		attributes: {
+ * 			class: 'light-gallery'
+ * 		}
+ * 	}
+ * ]
+ * ```
+ * @member {Array.<module:link/link~LinkDecoratorAutomaticOption>} module:link/link~LinkConfig#decorators
+ */
+
+/**
+ * This object defining automatic decorator for the links. Based on this option data pipeline will extend links with proper attributes.
+ * For example, you can define rules, when attribute `target="_blank"` will be added to links.
+ * There is a default option which might be activated with {@link module:link/link~LinkConfig#targetDecorator},
+ * which automatically adds attributes:
+ *   * `target="_blank"`
+ *   * `rel="noopener noreferrer"`
+ * for all links started with: `http://`, `https://` or `//`.
+ *
+ * ```js
+ * 	{
+ * 		mode: 'automatic',
+ * 		callback: url => /^(https?:)?\/\//.test( url ),
+ * 		attributes: {
+ * 			target: '_blank',
+ * 			rel: 'noopener noreferrer'
+ * 		}
+ * 	}
+ * ```
+ *
+ * @typedef {Object} module:link/link~LinkDecoratorAutomaticOption
+ * @property {'automatic'} mode it should has always string value 'automatic' for automatic decorators
+ * @property {Function} callback takes `url` as parameter and should return `true`
+ * for urls that be decorate with this decorator.
+ * @property {Object} attributes key-value pairs used as attributes added to anchor during downcasting.
+ */