|
40 | 40 | else if ( !mode )
|
41 | 41 | throw new Error( 'One of the element modes must be specified.' );
|
42 | 42 |
|
43 |
| - if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && mode == CKEDITOR.ELEMENT_MODE_INLINE ) { |
| 43 | + if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && mode == CKEDITOR.ELEMENT_MODE_INLINE ) |
44 | 44 | throw new Error( 'Inline element mode is not supported on IE quirks.' );
|
45 |
| - } |
46 | 45 |
|
47 |
| - // Asserting element DTD depending on mode. |
48 |
| - if ( mode == CKEDITOR.ELEMENT_MODE_INLINE && !element.is( CKEDITOR.dtd.$editable ) || mode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( CKEDITOR.dtd.$nonBodyContent ) ) |
| 46 | + if ( !isSupportedElement( element, mode ) ) |
49 | 47 | throw new Error( 'The specified element mode is not supported on element: "' + element.getName() + '".' );
|
50 | 48 |
|
51 |
| - |
52 | 49 | /**
|
53 | 50 | * The original host page element upon which the editor is created, it's only
|
54 | 51 | * supposed to be provided by the concrete editor creator and is not subjected to
|
|
194 | 191 | return name;
|
195 | 192 | }
|
196 | 193 |
|
| 194 | + // Asserting element DTD depending on mode. |
| 195 | + function isSupportedElement( element, mode ) { |
| 196 | + if ( mode == CKEDITOR.ELEMENT_MODE_INLINE ) |
| 197 | + return element.is( CKEDITOR.dtd.$editable ) || element.is( 'textarea' ); |
| 198 | + else if ( mode == CKEDITOR.ELEMENT_MODE_REPLACE ) |
| 199 | + return !element.is( CKEDITOR.dtd.$nonBodyContent ); |
| 200 | + return 1; |
| 201 | + } |
| 202 | + |
197 | 203 | function updateCommands() {
|
198 | 204 | var commands = this.commands,
|
199 | 205 | name;
|
|
312 | 318 | * @property {Boolean}
|
313 | 319 | * @see CKEDITOR.editor#setReadOnly
|
314 | 320 | */
|
315 |
| - editor.readOnly = !!( editor.config.readOnly || ( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ? editor.element.isReadOnly() : editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ? editor.element.getAttribute( 'disabled' ) : false ) ); |
| 321 | + editor.readOnly = !!( |
| 322 | + editor.config.readOnly || ( |
| 323 | + editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ? |
| 324 | + editor.element.is( 'textarea' ) ? |
| 325 | + editor.element.hasAttribute( 'disabled' ) |
| 326 | + : |
| 327 | + editor.element.isReadOnly() |
| 328 | + : |
| 329 | + editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ? |
| 330 | + editor.element.hasAttribute( 'disabled' ) |
| 331 | + : |
| 332 | + false |
| 333 | + ) |
| 334 | + ); |
316 | 335 |
|
317 | 336 | /**
|
318 | 337 | * Indicates that the editor is running into an environment where
|
|
321 | 340 | * @readonly
|
322 | 341 | * @property {Boolean}
|
323 | 342 | */
|
324 |
| - editor.blockless = editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE && !CKEDITOR.dtd[ editor.element.getName() ][ 'p' ]; |
| 343 | + editor.blockless = editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ? |
| 344 | + !( editor.element.is( 'textarea' ) || CKEDITOR.dtd[ editor.element.getName() ][ 'p' ] ) : |
| 345 | + false; |
325 | 346 |
|
326 | 347 | /**
|
327 | 348 | * The [tabbing navigation](http://en.wikipedia.org/wiki/Tabbing_navigation) order determined for this editor instance.
|
|
636 | 657 | return this.commands[ commandName ] = cmd;
|
637 | 658 | },
|
638 | 659 |
|
| 660 | + /** |
| 661 | + * Attaches editor to form to call {@link #updateElement} before form submit. |
| 662 | + * This method is called by both creators ({@link CKEDITOR#replace replace} and |
| 663 | + * {@link CKEDITOR#inline inline}) so there is no reason to call it manually. |
| 664 | + * |
| 665 | + * @private |
| 666 | + */ |
| 667 | + _attachToForm: function() { |
| 668 | + var editor = this, |
| 669 | + element = editor.element, |
| 670 | + form = new CKEDITOR.dom.element( element.$.form ); |
| 671 | + |
| 672 | + // If are replacing a textarea, we must |
| 673 | + if ( element.is( 'textarea' ) ) { |
| 674 | + if ( form ) { |
| 675 | + function onSubmit( evt ) { |
| 676 | + editor.updateElement(); |
| 677 | + |
| 678 | + // #8031 If textarea had required attribute and editor is empty fire 'required' event and if |
| 679 | + // it was cancelled, prevent submitting the form. |
| 680 | + if ( editor._.required && !element.getValue() && editor.fire( 'required' ) === false ) |
| 681 | + evt.data.preventDefault(); |
| 682 | + } |
| 683 | + form.on( 'submit', onSubmit ); |
| 684 | + |
| 685 | + // Setup the submit function because it doesn't fire the |
| 686 | + // "submit" event. |
| 687 | + if ( !form.$.submit.nodeName && !form.$.submit.length ) { |
| 688 | + form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit ) { |
| 689 | + return function( evt ) { |
| 690 | + onSubmit( new CKEDITOR.dom.event( evt ) ); |
| 691 | + |
| 692 | + // For IE, the DOM submit function is not a |
| 693 | + // function, so we need third check. |
| 694 | + if ( originalSubmit.apply ) |
| 695 | + originalSubmit.apply( this, arguments ); |
| 696 | + else |
| 697 | + originalSubmit(); |
| 698 | + }; |
| 699 | + } ); |
| 700 | + } |
| 701 | + |
| 702 | + // Remove 'submit' events registered on form element before destroying.(#3988) |
| 703 | + editor.on( 'destroy', function() { |
| 704 | + form.removeListener( 'submit', onSubmit ); |
| 705 | + } ); |
| 706 | + } |
| 707 | + } |
| 708 | + }, |
| 709 | + |
639 | 710 | /**
|
640 | 711 | * Destroys the editor instance, releasing all resources used by it.
|
641 | 712 | * If the editor replaced an element, the element will be recovered.
|
|
966 | 1037 | * the current data available in the editor.
|
967 | 1038 | *
|
968 | 1039 | * **Note:** This method will only affect those editor instances created
|
969 |
| - * with {@link CKEDITOR#ELEMENT_MODE_REPLACE} element mode. |
| 1040 | + * with {@link CKEDITOR#ELEMENT_MODE_REPLACE} element mode or inline instances |
| 1041 | + * bound to `<textarea>` elements. |
970 | 1042 | *
|
971 | 1043 | * CKEDITOR.instances.editor1.updateElement();
|
972 | 1044 | * alert( document.getElementById( 'editor1' ).value ); // The current editor data.
|
|
0 commit comments