Problem/Motivation
This is a problem in HEAD, with CKEditor 4.4.7, and still is a problem with #2521820: Update CKEditor library to 4.5.3, which updates CKEditor to 4.5.3.
Due to an automatically created <br>, the following CSS is not applying:
/**
* While editing and whenever the caption is empty, show a placeholder.
*
* Based on http://codepen.io/flesler/pen/AEIFc.
*/
.caption > figcaption[contenteditable=true]:empty:before {
content: attr(data-placeholder);
font-style: italic;
}
- Expected

- Note the pesky
<br>! - Actual

- Note that I deleted the
<br>.
Proposed resolution
TBD
Remaining tasks
Find the root cause.
User interface changes
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | interdiff.txt | 1.32 KB | javivf |
| #12 | placeholder-for-empty-caption-2563505-12.patch | 1.16 KB | javivf |
| #8 | After_applying_patch.JPG | 313.69 KB | Trupti Bhosale |
| #8 | before_applying_patch.JPG | 309.91 KB | Trupti Bhosale |
| #4 | placeholder-for-empty-caption-2563505-4.patch | 1.16 KB | adooo |
Comments
Comment #2
quicksketchIn Backdrop we did the following. The starting code should be the same in D8, the Firefox-specific code was added to fix this problem.
See https://github.com/backdrop/backdrop/blob/1.x/core/modules/ckeditor/js/p...
Comment #3
adooo commentedSwapped images in the summary to reflect the problem...
I'll try and fix this one!
Comment #4
adooo commentedComment #5
fmb commentedI followed these steps in Firefox 40.0 and Chromium 45.0:
Before applying the patch, the caption zone is empty. After applying it, it contains "Enter caption here".
I do not provide screenshots, as they would be identical to the ones provided in the description of this issue.
Comment #6
wim leers80 cols violation.
This needs review from at least a JS maintainer, and preferably from the CKEditor team. I've been told by them that the
<br>is necessary for this to function correctly.Comment #7
nod_Oh wow, totally not comfortable reviewing that one. Need CK folks to have a look.
Comment #8
Trupti Bhosale commentedVerified the issue on Chrome and Firefox with the patch "placeholder-for-empty-caption-2563505-4.patch".
'Enter caption here' label is now visible for the image
Steps performed:
1.Create a CT Article
2.Click on Image ckeditor button
3.Select the checkbox 'caption'
4.Click Save to insert the image
5.Verify the label 'Enter caption here' is displayed
Attached snapshots for reference
Comment #9
Trupti Bhosale commentedComment #10
wim leersSee #6.
Comment #11
javivf commentedI'm working on this
Comment #12
javivf commentedFixed issue with the code style
Comment #13
duaelfrI asked @reinmar to come review that issue so I hope he is going to have a moment to do that soon.
Comment #14
wim leers#13: Great, I also pinged him on Skype :)
Comment #15
Reinmar commentedHi guys!
I can't quickly check the patch, so I'm going to improvise and guess :). But first, a brief explanation what that
<br>does there. We call it "br filler" or "bogus br" and it's the way how browsers originally made sure that empty block have non-zero height. If I remember correctly, even today there's no standardised line-height's value that would tell the browser that block should have height of a text. Some browsers (like Chrome iirc) have some non-standard property for that and some other will (FF guys are considering this), so depending on which browser you test it may seem that bogus brs are not needed any more. Nevertheless, those bogus brs are still required and are created either by browsers or by CKEditor.If I can see correctly, the patch that was proposed removes automatically created bogus br upon creation of a caption. Things to consider:
These are the possible annoyances that came to my mind. There may be more cases like this. If that's fine for you, then the patch seems to be ok.
However, I proposed to Wim a more complicated, but complete solution. The idea was to polyfill the :empty selector on a nested editable (and perhaps the main one too). It could work like this:
You could then use such class to add the placeholder.
The tricky part here, as usual, is in the integration with the undo manager. Hard to say in advance how hard it will be. Despite that, I would like to see such plugin for CKEditor one day, so there's a chance that we'll work on it.
Comment #16
wim leersSo would you recommend going forward with the proposed patch for now, as an interim solution, until your "official solution" becomes available?
Comment #17
Reinmar commentedI haven't seen it live, but if you're satisfied with your tests, then yes – I would recommend proceeding.
Comment #18
duaelfrCool! Cool! Cool!
Thank you :)
Comment #20
duaelfrCommited by @webchick on 8.0.x
Thank you all ;)