Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
195 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* bender-tags: htmldataprocessor,htmlwriter */ | ||
/* bender-ckeditor-plugins: htmlwriter */ | ||
|
||
'use strict'; | ||
|
||
var attrValue = '<p x="1"2">\'"& <a y="3">&</a></p>', | ||
encodedAttrValue = '<p x="1&quot;2">\'"& &lt;a y="3"&gt;&amp;&lt;/a&gt;</p>'; | ||
|
||
bender.editors = { | ||
htmlWriter: { | ||
name: 'editor_htmlwriter', | ||
creator: 'inline', | ||
config: { | ||
allowedContent: true, | ||
extraPlugins: 'htmlwriter', | ||
enterMode: CKEDITOR.ENTER_P | ||
} | ||
}, | ||
|
||
basicWriter: { | ||
name: 'editor_basicwriter', | ||
creator: 'inline', | ||
config: { | ||
allowedContent: true, | ||
removePlugins: 'htmlwriter', | ||
enterMode: CKEDITOR.ENTER_P | ||
} | ||
} | ||
}; | ||
|
||
function doTestProcessorAttributeIsPreserved( bot ) { | ||
var editor = bot.editor, | ||
enabled = false; | ||
|
||
editor.editable().setHtml( '<p><span>foo</span></p>' ); | ||
|
||
editor.dataProcessor.htmlFilter.addRules( { | ||
elements: { | ||
span: function( el ) { | ||
// Affect only this test. | ||
if ( enabled ) { | ||
el.attributes[ 'data-foo' ] = attrValue; | ||
} | ||
} | ||
} | ||
} ); | ||
|
||
enabled = true; | ||
|
||
var data = editor.getData(); | ||
assert.areSame( '<p><span data-foo="' + encodedAttrValue + '">foo</span></p>', data, 'attribute was properly encoded when getting data' ); | ||
|
||
bot.setData( data, function() { | ||
enabled = false; | ||
var span = editor.editable().findOne( 'span' ); | ||
|
||
assert.areSame( attrValue, span.data( 'foo' ), 'attribute was properly preserved when loading data' ); | ||
} ); | ||
} | ||
|
||
bender.test( { | ||
'test inline editor with htmlwriter preserves attribute set in htmlFilter': function() { | ||
doTestProcessorAttributeIsPreserved( bender.editorBots.htmlWriter ); | ||
}, | ||
|
||
'test inline editor with basicwriter preserves attribute set in htmlFilter': function() { | ||
doTestProcessorAttributeIsPreserved( bender.editorBots.basicWriter ); | ||
}, | ||
|
||
'test editor preserves attribute set in DOM': function() { | ||
var bot = bender.editorBots.basicWriter, | ||
editor = bot.editor; | ||
|
||
editor.editable().setHtml( '<p><span>x</span></p>' ); | ||
editor.editable().findOne( 'span' ).setAttribute( 'data-bar', attrValue ); | ||
|
||
bot.setData( editor.getData(), function() { | ||
var span = editor.editable().findOne( 'span' ); | ||
|
||
assert.areSame( attrValue, span.data( 'bar' ) ); | ||
} ); | ||
}, | ||
|
||
'test browser preserves attribute': function() { | ||
var el = CKEDITOR.document.createElement( 'span' ); | ||
el.data( 'foo', attrValue ); | ||
|
||
var el2 = CKEDITOR.document.createElement( 'span' ); | ||
el2.setHtml( el.getOuterHtml() ); | ||
assert.areSame( attrValue, el2.getFirst().data( 'foo' ) ); | ||
} | ||
} ); |