Opened 14 years ago
Closed 12 years ago
#7921 closed enhancement (duplicate)
dojo.attr should handle innerText
Reported by: | Mike Wilcox | Owned by: | Eugene Lazutkin |
---|---|---|---|
Priority: | high | Milestone: | future |
Component: | HTML | Version: | 1.2.0 |
Keywords: | dojo.attr innerText | Cc: | dante |
Blocked By: | Blocking: |
Description
innerText is an important property to handle, as it strips HTML from the contents of a node. It also needs Dojo's assistance to be xbrowser, since FF's version is textContent.
I'm not submitting a patch unless this suggestion is ok'ed. The problem is that this enhancement would add quite a few bites. The _attrProps alone would need the following:
textcontent:dojo.isFF ? "textContent" : "innerText", innertext:dojo.isFF ? "innerText" : "textContent"
and then the setting portion of dojo.attr() would need it's "if" statements restructured a bit.
Change History (15)
comment:1 Changed 14 years ago by
Owner: | changed from phiggins to dante |
---|
comment:2 Changed 13 years ago by
Cc: | dante added |
---|---|
Owner: | changed from dante to Eugene Lazutkin |
comment:3 Changed 13 years ago by
It should be noted from recent tests I've done that textContent on Firefox is hampered by tab spaces and line breaks, and the results are much different from IE. A lot of string parsing would be required for it to work properly.
comment:5 Changed 13 years ago by
Gavin Doughtrie sent this link to dojo.dev, as a reference to how Google handles this: http://code.google.com/p/doctype/wiki/ArticleSetTextContent
I did a little research and went to the source, and found how Mozilla suggests doing it: https://developer.mozilla.org/En/Whitespace_in_the_DOM
A key to the Mozilla article is finding spaces with "\u0020" instead of \s, as the latter will remove spaces that would appear in between words.
What a pita. Why don't they just have innerText??
comment:6 Changed 13 years ago by
Status: | new → assigned |
---|
Typo --- it is Gavin Doughtie. The link he gave is to the code licensed under BSD.
comment:7 Changed 13 years ago by
Component: | Core → HTML |
---|
comment:8 Changed 13 years ago by
I need more information on this as Microsoft's documentation doesn't define the behavior of innerText
(http://msdn.microsoft.com/en-us/library/ms533899(VS.85).aspx):
- What is the use case for
innerText
? - Why stripping whitespaces? Does
innerText
strip whitespaces too? I know that FF creates a bunch of whitespace text nodes between elements. I am asking about other text nodes. - Do we need to strip HTML markup from the text on assignment?
- How to handle IE's read-only
innerText
properties? WithinnerHTML
it was kind of obvious.
comment:9 Changed 13 years ago by
The idea would be to leave innerText to function as normal, since all browsers support it except Firefox. I would imagine trying to set read-onlys should fail naturally.
I don't have a use-case for this. The idea stemmed from a blog I wrote on attr() and this seemed like an obvious omission. I've not actually need this functionality except for some very complex stuff where I should just write the code on my own anyway.
I originally thought it was just an even swap between innerText and textContent, but it appears to be more complicated than that. I would recommend changing this ticket to Won't Fix.
comment:10 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Closing as wontfix for now. Please reopen, if there is a need for such functionality.
comment:11 Changed 13 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
(Reopening because you told me so ;-)
From time to time I need this functionality and I usually put together my own function inline. Would make sense to handle in Dojo IMO. The typical use case is displaying a text string (that may contain HTML-unsafe characters) in an element without having to escape it.
I was actually checking dojo.attr in the Dojo source for this support, but while doing that I came to think that maybe it is not the perfect place for "innerText" handling, as this is not really an attribute and would hide an attribute of the same name? (unlikely, but anyway...)
comment:12 Changed 13 years ago by
Btw, jQuery's text() function is something along these lines. http://docs.jquery.com/Attributes/text
comment:13 Changed 13 years ago by
Note that dojo.NodeList?-traverse offers a text() function that should mimic jQuery's equivalent.
comment:14 Changed 13 years ago by
That's interesting, I hadn't seen that. That makes it even more natural to add this functionality somewhere to the Dojo APIs so I can use it directly on an available DOM element without having to create a NodeList? or query first?
@uhop: does this fall in line with your overall attr() normalization?