Opened 13 years ago

Closed 12 years ago

#6435 closed Bug (invalid)

Modifications to the document aren't reflected in the preview window

Reported by: Tobi Reif Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:

Description

Some snipped example lines:

var selected = editor.getSelection().getSelectedElement(); if (selected.getName() == 'foo') {

selected.setAttribute('some_attribute',bar); ...

This works, but the change is not reflected in CKEditor's preview window. getData() might also not have the modified HTML code.

I had asked in the forum: "How to (using JS) modify the HTML code of the document in the proper way - so that it will really be changed: so that I can expect the preview window (and the data from getData() ) to reflect these changes."

But didn't get a general solution.

Thus far I consider this a bug.

How to modify the HTML code of the document in a way that causes the preview window (and the data from getData() ) to reflect these changes?

Change History (1)

comment:1 Changed 12 years ago by Jakub Ś

Resolution: invalid
Status: newclosed

Perhaps this link will be helpfull http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.range.html

Selection should be rather made with:

var selection = new CKEDITOR.dom.range( editor.document );
var element = editor.document.getById( 'someElemId' );
selection.selectNodeContents( element );
editor.getSelection().selectRanges( selection );
var selected =  new CKEDITOR.dom.selection( editor.document );
if (selected.getStartElement().getName() == 'p') {
selected.getStartElement().setAttribute('some_attribute','testValue');
console.log(editor.getData());		
}

The above works fine (checked under latest CKEditor 3.6.2).

You have said that editor.getData() doesn't return updated values. If for some reason the above will not work you can try firing saveSnapshot event manually before getting the data.

editor.fire( 'saveSnapshot' );

Anyway I'm closing the ticket as invalid.

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy