/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ /* globals window, document, setTimeout */ // Show clipboard input notification when user tries to paste a content from MS Word or Google Docs. setTimeout( () => { // Don't show the warning notification in "Paste from Office" and "Paste from Google Docs" demos. if ( window.preventPasteFromOfficeNotification ) { return; } const editables = document.querySelectorAll( '.ck-content' ); const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i; const msWordMatch1 = //i; const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i; // A global variable indication if clipboard notification is visible. // We use the variable for displaying only one instance of the clipboard notification. window.isClipboardInputNotificationVisible = false; editables.forEach( editable => { const editor = editable.ckeditorInstance; if ( !editor ) { return; } editor.plugins.get( 'Clipboard' ).listenTo( editor.editing.view.document, 'clipboardInput', ( evt, data ) => { const htmlString = data.dataTransfer.getData( 'text/html' ); const match = msWordMatch1.test( htmlString ) || msWordMatch2.test( htmlString ) || googleDocsMatch.test( htmlString ); if ( match && !window.isClipboardInputNotificationVisible ) { createClipboardInputNotification(); } } ); } ); }, 3000 ); // The notification should contain the links to the demos where user can test rich formatting from. function createClipboardInputNotification() { const title = 'Hello!'; const message = `
We detected that you tried to paste content from Microsoft Word or Google Docs.
Please bear in mind that the editor demo to which you try to paste does not have all the features enabled. Due to that, unsupported formatting is being stripped.
Check out the Paste from Word or Paste from Google Docs demos for the best experience.
`; window.createNotification( title, message, () => { window.isClipboardInputNotificationVisible = false; } ); window.isClipboardInputNotificationVisible = true; } /** * Creates a notification and appends it to the `.main__content` element. * * @param {String} title A title of the notification. * @param {String} message A message to display in the notification. * @param {Function} [onClose] A callback function that executes on closing the notification. * * @returns {Object} A notification element. */ window.createNotification = function( title, message, onClose ) { const notificationTemplate = `