Opened 13 years ago

Last modified 12 years ago

#7921 confirmed Bug

editor.mode always returns empty string

Reported by: daveVW Owned by:
Priority: Normal Milestone:
Component: General Version: 3.0
Keywords: HasPatch Cc:

Description

To solve the problem, I have to modify the file plugins/editingblock/plugin.js. Is this OK ?

New code : (1 line disabled, 1 line added)

CKEDITOR.editor.prototype.setMode = function( mode ) {

this.fire( 'beforeSetMode', { newMode : mode } );

var data, holderElement = this.getThemeSpace( 'contents' ), isDirty = this.checkDirty();

Unload the previous mode. if ( this.mode ) {

if ( mode == this.mode )

return;

this.fire( 'beforeModeUnload' );

var currentMode = getMode( this ); data = currentMode.getData(); currentMode.unload( holderElement ); this.mode = ; LINE HAS BEEN DISABLED

}

holderElement.setHtml( );

Load required mode. var modeEditor = getMode( this, mode ); if ( !modeEditor )

throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';

if ( !isDirty ) {

this.on( 'mode', function() {

this.resetDirty(); this.removeListener( 'mode', arguments.callee );

});

}

modeEditor.load( holderElement, ( typeof data ) != 'string' ? this.getData() : data);

FOLLOWING LINE HAS BEEN ADDED this.mode = (this.mode == 'wysiwyg') ? 'source' : 'wysiwyg';

};

Attachments (1)

7921.patch (558 bytes) - added by Jakub Ś 13 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 13 years ago by daveVW

To solve the problem, I have to modify the file plugins/editingblock/plugin.js. Is this OK ?

New code : (1 line disabled, 1 line added)

	CKEDITOR.editor.prototype.setMode = function( mode )
	{
		this.fire( 'beforeSetMode', { newMode : mode } );

		var data,
			holderElement = this.getThemeSpace( 'contents' ),
			isDirty = this.checkDirty();

		// Unload the previous mode.
		if ( this.mode )
		{
			if ( mode == this.mode )
				return;

			this.fire( 'beforeModeUnload' );

			var currentMode = getMode( this );
			data = currentMode.getData();
			currentMode.unload( holderElement );
			//this.mode = '';     // DISABLED LINE
		}

		holderElement.setHtml( '' );

		// Load required mode.
		var modeEditor = getMode( this, mode );
		if ( !modeEditor )
			throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';

		if ( !isDirty )
		{
			this.on( 'mode', function()
				{
					this.resetDirty();
					this.removeListener( 'mode', arguments.callee );
				});
		}

		modeEditor.load( holderElement, ( typeof data ) != 'string'  ? this.getData() : data);
this.mode = (this.mode == 'wysiwyg') ? 'source' : 'wysiwyg';    // NEW LINE


	};

comment:2 Changed 13 years ago by Jakub Ś

Status: newpending

Editor needs some time to load its scripts. When you ask CKEditor "to quickly" it may return an empty string or 'undefined'.

I have used sample code in clean release of CKEditor:

setTimeout(function(){
	alert(CKEDITOR.instances.editor2.mode); 
},4000); //have also tried 2000 and 1000

I have tried on version 3.6, trunk and the one you specified - 3.5.3. The result was always the same - text 'wysiwyg' or 'source' was returned.

Could this be the source of your problem or you are getting the same error using the above code and a clean version of CKEditor?

comment:3 Changed 13 years ago by daveVW

I try to add a new comment, but the comment is always rejected as spam ! Any alternative way to reach you ?

comment:4 Changed 13 years ago by Wiktor Walc

@daveVW - try again

comment:5 Changed 13 years ago by daveVW

Not possible to add my code example. I always receive following message : "Submission rejected as potential spam (Akismet says content is spam)"

comment:6 Changed 13 years ago by Wiktor Walc

(added by daveVW):

I added following line to the function CKEDITOR.editor.prototype.setMode :

CKEDITOR.editor.prototype.setMode = function( mode )
{
...
this.fire( 'afterSetMode' );
}

Then, I added following javascript code :

oEditor.on('afterSetMode', doAlert);

function doAlert() {
   alert(oEditor.mode);
   setTimeout(function(){alert(oEditor.mode);},4000);
}

Each time when changing the mode, the first alert returns an empty string, the second alert is OK. This means that it takes some time to fill the mode property.

However, I think it would be OK to modify the function CKEDITOR.editor.prototype.setMode by replacing the line

this.mode = '';

with

this.mode = (this.mode == 'wysiwyg') ? 'source' : 'wysiwyg';

Do you agree ?

comment:7 Changed 13 years ago by Wiktor Walc

@daveVW - I hope it's the correct version of the comment you have tried to add. Dunno why Akismet is rejecting you, I've marked your comments as "Ham" a couple of times.

In case of similar problems in the future please (hopefully it will not happen) just add a comment that you're being rejected.

comment:8 Changed 13 years ago by daveVW

Thanks! That's the right comment. Do you agree with the replacement I proposed ?

Changed 13 years ago by Jakub Ś

Attachment: 7921.patch added

comment:9 Changed 13 years ago by Jakub Ś

Keywords: HasPatch? added
Status: pendingconfirmed
Version: 3.5.33.0

Looks like it improves the described problem. The only question is whether it will not break anything else.

I'm attaching a patch based on your solution and let the senior developers decide.

comment:10 Changed 13 years ago by daveVW

Maybe following solution is cleaner: Replace the line

this.mode = '';

with

this.mode = mode;

comment:11 Changed 13 years ago by Johannes Fischer

Hi,

I am working on an event driven application which creates a new editor instance when a specific event occurs and it uses setData() to set the content of the particular instance. I should add that the app is a single page application.

Now, when the first event occurs the editor content renders fine. In every following case the content of the editor does not render in Firefox (version 7) or Chrome (version 14). Ironically, only IE browsers (tested version 8 and 9) worked fine.

The editor is configured to only use the maximize plugin and sometimes, for testing purposes, I have the source plugin enabled as well. In the instances were the content is not rendered, I can get it to show up when switching between 'wysiwyg' and 'source' mode.

When debugging the issue in the browser I noticed that when I create the first editor instance, there isn't a listener registered for the 'afterSetData' event and the content is rendered fine. In the following instantiations, the 'editingblock' plugin has a listener registered for this event and the fact that editor.mode is an empty string prevents the data from ever being set.

When I came saw this ticket and tried the suggested change:

this.mode = mode;

my problem was solved.

However, I am sure if I got to the real bottom of this but I would appreciate a comment on the matter.

Thanks a lot, Johannes

PS: I am using CKEdtior v3.6.2

comment:12 Changed 12 years ago by Jakub Ś

Keywords: HasPatch added; HasPatch? removed
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