Is there any way to prevent CKEDITOR to add image dimensions as a style instead of regular attributes?
Instead of
<img src="image.jpg" style="height:100px; width:100px;">
I want this
<img src="image.jpg" height="100px" width="100px">
Instead of
<img src="image.jpg" style="height:100px; width:100px;">
I want this
<img src="image.jpg" height="100px" width="100px">
Re: Image dimensions attributes
When I insert an image, the dimensions get set automatically, as expected. However, if I then set a custom style on the image, the dimensions disappear from the source code. This is probably due to the fact that the style attribute gets overwritten with the custom css from the selected style. This problem could easily be avoided by using the width and height attributes instead of css.
I see no reason why you would use css for setting image dimensions in the first place. The width and height attribute of the img tag were never deprecated. In fact, developers are encouraged to use them, according to most (X)HTML guidelines and best practices.
Re: Image dimensions attributes
There is a bug report about this here:
http://dev.fckeditor.net/ticket/5547
The developer has closed this as "won't fix", stating that putting image dimensions in an inline style is valid behaviour:
However, this isn't the usual way of specifying image dimensions, and I think most developers would expect the height/width attributes to be used. I can't come up with a good explanation as to why though
There is an example here:
http://dev.fckeditor.net/attachment/tic ... 24_5.patch
Showing how to output the image dimensions using attributes but I'm not sure what to do with that (I'm using CKeditor with Drupal).
Edit: As reported on the Drupal CKeditor module, this is breaking functionality with some other Drupal modules:
http://drupal.org/node/731068
Re: Image dimensions attributes
Wrong. Is the user the one that closed his own ticket.
And yes, using styles is valid. It might not be the best option for all the cases, but I didn't refute that. I only said that if an image has specified the dimensions as attributes and styles, then it will be shown according to the styles, not to the attributes as he stated.
Re: Image dimensions attributes
Greetings,
I ended up here when I had the exact same problem (in 3.3.1). I am using CKEditor for HTML Email generation,
so css needs to be kept to a minimum then. In particular the float: attribute is usually not supported,
so images can't be aligned in emails when using CKEditor as is.
I decided to look around myself and 'fix' it myself. This can be done in plugins/image/dialogs/image.js.
This is the minified version though so it's easier to use the one from the _source folder. Go to line 645
for example, and this is where the "width" style is set. Just fiddle with the code and make it set the
attribute instead of the css.
This fix will use width="" height="" align="" instead of style="width:; height:; float:;" for images.
That's all it does. The width and height attributes are XHTML valid, the align one is not.
I tried attaching the file but any extension I tried was not allowed, so here it is in code.
Only the minified version.
Image Attributes fix (images.js)
Mind that you need to make sure that the old image.js is not fetched from cache (otherwise you'll complain
to me and say it doesn't work). Clear your cache, and if your customers need to automatically get it, then
edit ckeditor.js and increment the timestamp which you can find on the first line (such as A5AB4B6 to
A5AB4B7). This should make sure the new version is downloaded.
Hitting control-F5 will not necessarily get the new version!
Re: Image dimensions attributes
Re: Image dimensions attributes
One trick though, and this is a carryover from the old FCKEditor codebase:
Grabbing the image and resizing it via drag regurgitates the code back to everything being under the "style" tag again. After resizing, one can pop the Image Props window up, and then immediately hit "OK" - and the editor will re-regurgitate the code back into seperate width/height/align tags (remainder of tags under "style" remaining).
I wonder if there's a way to get the resize-drag process to go with old-school width/height/align as well...? I fear that's beyond my Javascript-fu.
Re: Image dimensions attributes
Well, apparently the code from that output_html sample that alfonsoml posted about makes the editor generate "legacy html" code. This is excellent for HTML Email generation. I'm not using it yet but probably will.
or mention it in the documentation in some way using the words "HTML Email" or something so people will find it using Google. Just saying, I tried looking for it, but didn't think that those "samples" would actually have extra functionality (which I would call this "legacy html plugin" almost), I thought it would be simple examples.
You can find it under _samples/output_html.html - the code in there. It needs some tiny change since I want "config", while this "replaces" the editor - but it's probably just using the same object into the config. I think. Lots of extra code though, could be worth inserting into another .js file if efficiency is an issue.
Suggestion to CKSource: create a FAQ entry somewhere about HTML Email, that points to this particular sample?
Re: Image dimensions attributes
Re: Image dimensions attributes
Another thing: I found a tiny error in _samples/output_html.html on line 45.
should probably be:
Re: Image dimensions attributes
You should pick up the ones that are interesting to you (even from other samples or the documentation) and adjust them to your site, there isn't a single solution that works OK for everyone.
Re: Image dimensions attributes
Toying with the output_html sample page code to get the old school attributes going with 3.5. Works well.
Only trick is the image border stuff - that's not covered. I'm attempting to add that in now, and hitting one small bump (due to my regex-fu not being up to the task).
Here's what I've got so others can add this in (and hopefully offer up the fix for the last bit) -
Original code below is from the output_html.html sample, lines 158-179:
And here's same batch of code with some additions (marked 'NEW'):
Now this works to pull the border-width value out, and then remove that style and drop in an attribute "border" - but as the border-width style works differently (and can have different values other than a px value), I'm not finding the right regex to replace that style call with *any* possible value. If anyone out there has that fix, by all means, please share.
Re: Image dimensions attributes
I've just implemented JorisDebonnet suggested plugin alteration, it works perfectly as I desire however in doing so the "width", "height" and "align" labels are all displayed as "unspecified". ie. Not the input box values, just the display labels. Is this due to the fact I'm using a newer version of the editor? Any assistance greatly appreciated