1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/* bender-tags: editor,unit,insertion */
var doc = CKEDITOR.document,
tools = bender.tools;
bender.editor = { config : {
autoParagraph : false,
allowedContent : true // Disable filter.
} };
bender.test(
{
testInsertElement : function() {
var editor = this.editor;
// When editor has focus.
var ins = CKEDITOR.dom.element.createFromHtml( '<strong>baz</strong>', editor.document );
bender.tools.setHtmlWithSelection( editor, 'foo^bar' );
editor.insertElement( ins );
assert.areSame( 'foo<strong>baz</strong>bar', tools.compatHtml( editor.getData() ), 'insert element with existing selection, editor focused' );
// When editor loose focus.
bender.tools.setHtmlWithSelection( editor, 'foo^bar' );
ins = CKEDITOR.dom.element.createFromHtml( '<strong>baz</strong>', editor.document );
doc.getById( 'text_input' ).focus();
editor.insertElement( ins );
assert.areSame( 'foo<strong>baz</strong>bar', tools.compatHtml( editor.getData() ), 'insert element with existing selection, editor blurred' );
},
testInsertHtml : function() {
var editor = this.editor;
// When editor has focus.
bender.tools.setHtmlWithSelection( editor, 'foo^bar' );
editor.insertHtml( 'baz' );
assert.areSame( 'foobazbar', tools.compatHtml( editor.getData() ), 'insert html with existing selection, editor focused' );
// When editor loose focus.
bender.tools.setHtmlWithSelection( editor, 'foo^bar' );
doc.getById( 'text_input' ).focus();
editor.insertHtml( 'baz' );
assert.areSame( 'foobazbar', tools.compatHtml( editor.getData() ), 'insert html with existing selection, editor blurred' );
},
testInsertText : function() {
var editor = this.editor;
// When editor has focus.
bender.tools.setHtmlWithSelection( editor, 'foo^bar' );
editor.insertText( 'baz' );
assert.areSame( 'foobazbar', tools.compatHtml( editor.getData() ), 'insert text with existing selection, editor focused' );
// When editor loose focus.
bender.tools.setHtmlWithSelection( editor, 'foo^bar' );
doc.getById( 'text_input' ).focus();
editor.insertText( 'baz' );
assert.areSame( 'foobazbar', tools.compatHtml( editor.getData() ), 'insert text with existing selection, editor blurred' );
},
'test insertHtml without filter': function() {
bender.editorBot.create( {
name: 'test_inserthtml_no_acf',
config: {
removePlugins: 'basicstyles'
}
}, function( bot ) {
var editor = bot.editor;
editor.focus();
editor.insertHtml( '<em>A</em>B' );
assert.areSame( '<p>AB</p>', bot.getData(), '<em> has been filtered out' );
editor.insertHtml( '<em>C</em>D', 'unfiltered_html' );
assert.areSame( '<p>AB<em>C</em>D</p>', bot.getData(), '<em> has been inserted' );
} );
},
'test insertHtml uses editor.activeEnterMode': function() {
bender.editorBot.create( {
name: 'test_inserthtml_entermode',
config: {
allowedContent: true
}
}, function( bot ) {
var editor = bot.editor,
toHtml = 0,
mode;
editor.focus();
editor.on( 'toHtml', function( evt ) {
toHtml += 1;
mode = evt.data.enterMode;
} );
editor.setActiveEnterMode( CKEDITOR.ENTER_BR );
editor.insertHtml( 'foo' );
assert.areSame( CKEDITOR.ENTER_BR, mode, 'dynamic enter mode was used - BR' );
editor.setActiveEnterMode( null );
editor.insertHtml( 'foo' );
assert.areSame( CKEDITOR.ENTER_P, mode, 'dynamic enter mode was used - P' );
// Just to be sure that test is correct.
assert.areSame( 2, toHtml, 'toHtml was fired twice' );
} );
}
} );
|