| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* global console, window */
- import global from '@ckeditor/ckeditor5-utils/src/dom/global';
- import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
- import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
- import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
- import Font from '@ckeditor/ckeditor5-font/src/font';
- import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
- import Mention from '../../src/mention';
- class CustomMentionAttributeView extends Plugin {
- init() {
- const editor = this.editor;
- editor.conversion.for( 'upcast' ).elementToAttribute( {
- view: {
- name: 'a',
- key: 'data-mention',
- classes: 'mention',
- attributes: {
- href: true
- }
- },
- model: {
- key: 'mention',
- value: viewItem => editor.plugins.get( 'Mention' ).toMentionAttribute( viewItem, {
- link: viewItem.getAttribute( 'href' )
- } )
- },
- converterPriority: 'high'
- } );
- editor.conversion.for( 'downcast' ).attributeToElement( {
- model: 'mention',
- view: ( modelAttributeValue, viewWriter ) => {
- if ( !modelAttributeValue ) {
- return;
- }
- return viewWriter.createAttributeElement( 'a', {
- class: 'mention',
- 'data-mention': modelAttributeValue.id,
- 'href': modelAttributeValue.link
- }, { id: modelAttributeValue._uid } );
- },
- converterPriority: 'high'
- } );
- }
- }
- ClassicEditor
- .create( global.document.querySelector( '#editor' ), {
- plugins: [ ArticlePluginSet, Underline, Font, Mention, CustomMentionAttributeView ],
- toolbar: [
- 'heading',
- '|', 'bulletedList', 'numberedList', 'blockQuote',
- '|', 'bold', 'italic', 'underline', 'link',
- '|', 'fontFamily', 'fontSize', 'fontColor', 'fontBackgroundColor',
- '|', 'insertTable',
- '|', 'undo', 'redo'
- ],
- mention: {
- feeds: [
- { feed: getFeed }
- ]
- }
- } )
- .then( editor => {
- window.editor = editor;
- } )
- .catch( err => {
- console.error( err.stack );
- } );
- function getFeed( feedText ) {
- return [
- { itemId: '1', id: '@Barney Stinson', text: 'Barney Stinson', link: 'https://www.imdb.com/title/tt0460649/characters/nm0000439' },
- { itemId: '2', id: '@Lily Aldrin', text: 'Lily Aldrin', link: 'https://www.imdb.com/title/tt0460649/characters/nm0004989' },
- {
- itemId: '3',
- id: '@Marshall Eriksen',
- text: 'Marshall Eriksen',
- link: 'https://www.imdb.com/title/tt0460649/characters/nm0781981'
- },
- {
- itemId: '4',
- id: '@Robin Scherbatsky',
- text: 'Robin Scherbatsky',
- link: 'https://www.imdb.com/title/tt0460649/characters/nm1130627'
- },
- { itemId: '5', id: '@Ted Mosby', text: 'Ted Mosby', link: 'https://www.imdb.com/title/tt0460649/characters/nm1102140' }
- ].filter( item => {
- const searchString = feedText.toLowerCase();
- return item.id.toLowerCase().includes( searchString );
- } );
- }
|