Ticket #3582 (confirmed Bug)

Opened 16 months ago

Last modified 7 weeks ago

Contents of anchors isn't visible

Reported by: alfonsoml Owned by:
Priority: Normal Milestone:
Component: General Version: SVN (CKEditor) - OLD
Keywords: Cc: pomu@…, gilles@…, matthewlefflercomputer@…

Description

Load CKEditor and switch to source mode. Simulate that you are editing any existing page from v2 with anchors that included text:

<p>
	<a name="test">This is</a> some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">CKEditor</a>.</p>

Switch to design view and the contents of anchors isn't visible:

 some sample text. You are using CKEditor.

This worked correctly in V2

Change History

Changed 16 months ago by arczi

  • keywords Confirmed added
  • milestone set to CKEditor 3.x

There is an icon only.

Changed 9 months ago by fredck

#4633 has been marked as DUP.

Changed 6 months ago by pomu0325

  • cc pomu@… added

Changed 6 months ago by Juergen

Ok, the reason seems to be here:

CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
{
	var lang = this.lang.fakeobjects,
		html;

	var writer = new CKEDITOR.htmlParser.basicWriter();
	realElement.writeHtml( writer );
	html = writer.getHtml();

  var attributes =
	{
		'class' : className,
		src : CKEDITOR.getUrl( 'images/spacer.gif' ),
		_cke_realelement : encodeURIComponent( html ),
		_cke_real_node_type : realElement.type,
		alt : lang[ realElementType ] || lang.unknown
	};

  if ( realElementType )
    attributes._cke_real_element_type = realElementType;

  if ( isResizable )
    attributes._cke_resizable = isResizable;

  return new CKEDITOR.htmlParser.element( 'img', attributes );
};

The anchor link is simply getting replaced by an image element. Certainly thats the reason of why no text will be showing up.

I played a litle bit with it but found no way to fix it: If i change the htmlParser.element('img'...) to htmlParser.element('a'...) and also change the attributes (just for cke_anchor), the editor deadloops :( Maybe because it will try to always replace it again and again as long as theres a name tag and no href tag like defined in the datafilter afterInit...

However, i hope this information will give someone else, who is deeper in that editor source code involved than me, some useful tip in that direction.

There seemed to be some others before me trying to change the code for the correct behavior because within the link plugin theres already the correct css definition:

			'a.cke_anchor' +
			'{' +
				'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
				'background-position: 0 center;' +
				'background-repeat: no-repeat;' +
				'border: 1px solid #a9a9a9;' +
				'padding-left: 18px;' +
			'}'

But this class is never being used...

Juergen

Changed 6 months ago by Juergen

Ok, i have some working quick and dirty fix:

	afterInit : function( editor )
	{
		// Register a filter to displaying placeholders after mode change.

		var dataProcessor = editor.dataProcessor,
			dataFilter = dataProcessor && dataProcessor.dataFilter;

		if ( dataFilter )
		{
			dataFilter.addRules(
				{
					elements :
					{
						a : function( element )
						{
							var attributes = element.attributes;
							if ( attributes.name && !attributes.href && !attributes.className )
							{
								attributes.class = 'cke_anchor';
								return element;
							}
//							if ( attributes.name && !attributes.href )
//								return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
						}
					}
				});
		}
	},

I have the changed lines just commented out...

This works for me but i think this could be done some more elegant or more safe (whatever you prefer) ;)

Juergen

Changed 6 months ago by Juergen

Sorry the ckpacker couldn't work with ".class" entry, so i changed this to:

	afterInit : function( editor )
	{
		// Register a filter to displaying placeholders after mode change.

		var dataProcessor = editor.dataProcessor,
			dataFilter = dataProcessor && dataProcessor.dataFilter;

		if ( dataFilter )
		{
			dataFilter.addRules(
				{
					elements :
					{
						a : function( element )
						{
							var attributes = element.attributes;
							if ( attributes.name && !attributes.href && !attributes.className )
							{
								element.attributes['class'] = 'cke_anchor';
								return element;
							}
//							if ( attributes.name && !attributes.href )
//								return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
						}
					}
				});
		}
	},

Now the next step is to change the behavior when adding a new anchor. This quick & dirty fix above is to display the already existing anchors i.e. from fckeditor 2.x.

Changed 5 months ago by Webunity

  • cc gilles@… added

Changed 4 months ago by mattleff

  • cc matthewlefflercomputer@… added

+1

Changed 2 months ago by fredck

#5874 has been marked as DUP.

Changed 7 weeks ago by fredck

  • milestone CKEditor 3.x deleted

Milestone CKEditor 3.x deleted

Note: See TracTickets for help on using tickets.