diff --git a/core/creators/inline.js b/core/creators/inline.js index 717427ec03b..72ee732d90a 100644 --- a/core/creators/inline.js +++ b/core/creators/inline.js @@ -31,8 +31,14 @@ if ( !CKEDITOR.env.isCompatible ) return null; + var elementArg = element; + element = CKEDITOR.dom.element.get( element ); + // Throw error on missing target element. + if ( !element ) + throw 'The provided element, "' + elementArg + '", is missing from the DOM.'; + // Avoid multiple inline editor instances on the same element. if ( element.getEditor() ) throw 'The editor instance "' + element.getEditor().name + '" is already attached to the provided element.'; diff --git a/core/creators/themedui.js b/core/creators/themedui.js index dccb08d1317..e5d08793bb0 100644 --- a/core/creators/themedui.js +++ b/core/creators/themedui.js @@ -323,8 +323,14 @@ CKEDITOR.replaceClass = 'ckeditor'; if ( !CKEDITOR.env.isCompatible ) return null; + var elementArg = element; + element = CKEDITOR.dom.element.get( element ); + // Throw error on missing target element. + if ( !element ) + throw 'The provided element, "' + elementArg + '", is missing from the DOM.'; + // Avoid multiple inline editor instances on the same element. if ( element.getEditor() ) throw 'The editor instance "' + element.getEditor().name + '" is already attached to the provided element.'; diff --git a/tests/core/creators/creators.js b/tests/core/creators/creators.js index 4dc88aaff58..0589baecb61 100644 --- a/tests/core/creators/creators.js +++ b/tests/core/creators/creators.js @@ -162,6 +162,31 @@ bender.test( { wait(); }, + 'test creator replace on bogus DOM element': function() { + try { + CKEDITOR.replace( 'editorBogus', { + on: { + instanceReady: function() { + resume( function() { + assert.fail( 'Creation should fail on bogus DOM elements.' ); + } ); + } + } + } ); + } catch ( e ) { + resume( function() { + if ( e.toString().indexOf( 'The provided element' ) >= 0 ) { + assert.isTrue( true ); + } + else { + assert.fail( 'Error message should be friendly and helpful.' ); + } + } ); + } + + wait(); + }, + 'test creator appendTo': function() { var tc = this, container = CKEDITOR.dom.element.createFromHtml( '
' ); @@ -227,6 +252,31 @@ bender.test( { wait(); }, + 'test creator inline on bogus DOM element': function() { + try { + CKEDITOR.inline( 'editorBogus', { + on: { + instanceReady: function() { + resume( function() { + assert.fail( 'Creation should fail on bogus DOM elements.' ); + } ); + } + } + } ); + } catch ( e ) { + resume( function() { + if ( e.toString().indexOf( 'The provided element' ) >= 0 ) { + assert.isTrue( true ); + } + else { + assert.fail( 'Error message should be friendly and helpful.' ); + } + } ); + } + + wait(); + }, + 'test creator inline-textarea': function() { var tc = this, target = CKEDITOR.document.getBody().append(