I have a situation where I need users to be able to select and act on, elements like lists so that it's possible to detect if a child/descendant like <li> is selected or if the parent like <ul> is selected. Users would switch to the parent using the elementspath plugin / bottom bar tag breadcrumbs.
For example on a document like this:
Users must be able to target the ul element. I tried the following, but GetSelectedElement() always returns null!
This is how I can get the first child of the selection, but I need to retrieve the parent!
How would I gain access to the parent element?
For example on a document like this:
<ul> <li>Something</li> <li>Something</li> </ul>
Users must be able to target the ul element. I tried the following, but GetSelectedElement() always returns null!
var selection = editor.getSelection(); var test = selection.GetSelectedElement(); debug(test); // This is null, I expected it to be ul
This is how I can get the first child of the selection, but I need to retrieve the parent!
var selection = editor.getSelection(); var element = selection.getStartElement(); debug(element); // This returns the first LI element
How would I gain access to the parent element?
Re: GetSelectedElement returns null, can I get selected pare
Is there a workaround? This is a critical function.
Re: GetSelectedElement returns null in IE and Chrome, BUG?
I do believe it's a confirmed bug. No proposed workarounds yet.
Customer and Community Manager, CKSource
Follow us on: Facebook, Twitter, LinkedIn
If you think you found a bug in CKEditor, read this!
Re: GetSelectedElement returns null in IE and Chrome, BUG?
Also, is there a way to I could "vote up" the bug to bump it's priority?
Re: GetSelectedElement returns null in IE and Chrome, BUG?
Given a node, you can easily get its parent: http://docs.cksource.com/ckeditor_api/s ... #getParent
now you can check if it's the node that you want, or if you want to keep on searching or anything else.
Re: GetSelectedElement returns null in IE and Chrome, BUG?
Re: GetSelectedElement returns null in IE and Chrome, BUG?
You'll have to dig a little into the code to understand it better unless you can find someone else explaining better how to handle the selection and your current problems.
Re: GetSelectedElement returns null in IE and Chrome, BUG?
Re: GetSelectedElement returns null in IE and Chrome, BUG?
You can ask the browser to select a node and it might react in different ways, it can select just that node correctly, or move the boundaries to some other node, it depends on each browser and the type of selection that you want to perform (it's not the same to select a <p> than a <tr>, also empty nodes are problematic for Opera and Webkit IIRC)
In a general way when you have a selection marked by the pipes as this
Which is the "selected element"?
is not the p because it's not fully selected, and it's not the span because there's also text selected beyond its boundaries.
So the correct statement is that there's a range selected with two boundary points, and you can use them to check the selection according to your needs.
Re: GetSelectedElement returns null in IE and Chrome, BUG?
I think I get it now, thank you for taking the time to explain it to me and sorry for being so slow! My problem in thinking was that I wasn't really thinking about it as a selection, rather that I had just clicked on an element so I should gain access to that targeted element. I think I'll try my "hack" approach to get to my goal, at least until issue 7928 is closed.