-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Prevent nested links #99
base: master
Are you sure you want to change the base?
Conversation
peyerluk
commented
Mar 12, 2015
•
edited by marcbachmann
Loading
edited by marcbachmann
- Editable should not set links if the host or a parent if the host is a link tag
- Consider adding general rules for allowed elements
* should not be possible. | ||
*/ | ||
canLinkBeSet: function() { | ||
var linkParents = content.getParentsAndSelf(this.host, 'a'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peyerluk This iterates throught all parents of the dom up to the html
tag.
I guess we shouldn't go further than the element in which editable.js is initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcbachmann This is on purpose since nesting links should not be allowed in general. Especially in case of teasers the link tag can be outside of the editable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. It's still forbidden in HTML5 :)
It's not allowed to place interactive elements inside an <a>
element:
http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-a-element
http://www.w3.org/html/wg/drafts/html/master/single-page.html#interactive-content-2
getParentsAndSelf: function(node, tagName) { | ||
var parents = []; | ||
while (node) { | ||
if (node.nodeType === nodeType.elementNode) { | ||
if (!tagName || node.nodeName === tagName.toUpperCase()) { | ||
parents.push(node); | ||
} | ||
} | ||
node = node.parentNode; | ||
} | ||
return parents; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peyerluk, would it be possible to merge only this function if you don’t want to merge the patch below? I ask because it comes in handy in other contexts as well, e.g. avoiding <em>
inside of a <strong>
or others.
To address @marcbachmann’s concern perhaps a flag that stops traversal at a given node would be an agreeable compromise?
Lastly, I’d probably rename the function to getAncestorsAndSelf()
to be more in line with the XPath axis ancestor-or-self.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a bit of an odd duck currently as this is the only method that is meant to collect info outside of the host element.
It would need some polishing before we can merge it.
Would this method here help your use case? Or are you more interested in knowing which tags affect a cursor or selection within the host? For that we have the method getTags()
in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.