8
0
Просмотр исходного кода

Add utils for checking if provided element is a textarea.

Mateusz Samsel 6 лет назад
Родитель
Сommit
0d3844a2cf
1 измененных файлов с 27 добавлено и 0 удалено
  1. 27 0
      packages/ckeditor5-core/src/editor/utils/preventrunintextarea.js

+ 27 - 0
packages/ckeditor5-core/src/editor/utils/preventrunintextarea.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+/**
+ * @module core/editor/utils/preventrunintextarea
+ */
+
+import { isElement } from 'lodash-es';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
+/**
+ * Function returns rejected promise, when passed argument is a textarea element.
+ * In any other case is returned empty resolved promise.
+ *
+ * @param {HTMLElement|String} sourceElementOrData The DOM element that will be the source for the created editor
+ * or the editor's initial data.
+ * @returns {Promise}
+ */
+export default function preventRunInTextarea( someElementOrData ) {
+	if ( isElement( someElementOrData ) && someElementOrData.tagName.toLowerCase() === 'textarea' ) {
+		return Promise.reject(
+			new CKEditorError( 'editor-wrong-element: This type of editor cannot be initialised inside <textarea> element.' )
+		);
+	}
+	return Promise.resolve();
+}