Skip to content

Commit

Permalink
Merge branch 't/12036' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Jasiun committed Dec 9, 2014
2 parents 0836608 + e672ade commit b709b28
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -14,6 +14,7 @@ New Features:
* [#12143](http://dev.ckeditor.com/ticket/12143): Added [`config.floatSpacePreferRight`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-floatSpacePreferRight) configuration option that switches the alignment of the floating toolbar. Thanks to [InvisibleBacon](http://github.com/InvisibleBacon)!
* [#12416](http://dev.ckeditor.com/ticket/12416): Added [`widget.definition.upcastPriority`](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.definition-property-upcastPriority) property which gives more control over widgets upcasting order to the widget author.
* [#12448](http://dev.ckeditor.com/ticket/12448): Set of new methods, params and events giving the developer more control over HTML insertion. See the [`editable.insertHtml()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editable-method-insertHtml) param `range`, the [`editable.insertHtmlIntoRange()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editable-method-insertHtmlIntoRange) method and the [`editor.afterInsertHtml`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-afterInsertHtml) event.
* [#12036](http://dev.ckeditor.com/ticket/12036): Initialize editor in [`readOnly`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode when `<textarea>` has `readonly` attribute.

Fixed Issues:

Expand Down
33 changes: 19 additions & 14 deletions core/editor.js
Expand Up @@ -329,20 +329,25 @@
* @readonly
* @property {Boolean}
*/
editor.readOnly = !!(
config.readOnly || (
editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ?
editor.element.is( 'textarea' ) ?
editor.element.hasAttribute( 'disabled' )
:
editor.element.isReadOnly()
:
editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ?
editor.element.hasAttribute( 'disabled' )
:
false
)
);
editor.readOnly = isEditorReadOnly();

function isEditorReadOnly() {
if ( config.readOnly ) {
return true;
}

if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ) {
if ( editor.element.is( 'textarea' ) ) {
return editor.element.hasAttribute( 'disabled' ) || editor.element.hasAttribute( 'readonly' );
} else {
return editor.element.isReadOnly();
}
} else if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ) {
return editor.element.hasAttribute( 'disabled' ) || editor.element.hasAttribute( 'readonly' );
}

return false;
}

/**
* Indicates that the editor is running in an environment where
Expand Down
2 changes: 2 additions & 0 deletions tests/core/editor/readonly.html
@@ -1,9 +1,11 @@
<textarea id="inline_textarea">inline_textarea</textarea>
<textarea id="inline_textarea_disabled" disabled>inline_textarea_disabled</textarea>
<textarea id="inline_textarea_readonly" readonly>inline_textarea_readonly</textarea>
<textarea id="inline_textarea_config">inline_textarea_config</textarea>

<textarea id="framed">framed</textarea>
<textarea id="framed_disabled" disabled>framed_disabled</textarea>
<textarea id="framed_readonly" readonly>framed_readonly</textarea>
<textarea id="framed_config">framed_config</textarea>

<div contenteditable="true" id="inline">inline</div>
Expand Down
10 changes: 10 additions & 0 deletions tests/core/editor/readonly.js
Expand Up @@ -17,6 +17,11 @@
creator: 'inline',
readOnly: true
},
inline_textarea_readonly: {
name: 'inline_textarea_readonly',
creator: 'inline',
readOnly: true
},
inline_textarea_config: {
name: 'inline_textarea_config',
creator: 'inline',
Expand All @@ -36,6 +41,11 @@
creator: 'replace',
readOnly: true
},
framed_readonly: {
name: 'framed_readonly',
creator: 'replace',
readOnly: true
},
framed_config: {
name: 'framed_config',
creator: 'replace',
Expand Down

0 comments on commit b709b28

Please sign in to comment.