Ticket #4409 (closed defect: fixed)

Opened 22 months ago

Last modified 10 months ago

Safari: dijit.Editor dies while creating an unlabelled Button

Reported by: guest Owned by: alex
Priority: normal Milestone: 1.2
Component: Editor Version: 0.9
Severity: normal Keywords:
Cc: hannes.wyss@…, bill

Description (last modified by bill) (diff)

Hi all! I'm working towards getting dijit.Editor usable in Safari.

In dijit.form.Button:postCreate, the following call to dojo.trim fails:

dojo.trim(this.containerNode.innerText || this.containerNode.textContent); 

The reason for this is that in Safari this.containerNode.innerText returns an empty string. Safari then proceeds with this.containerNode.textContent and passes the result of this second call (undefined) to dojo.trim, where no typechecking is done and the call to undefined.replace fails. Unfortunately this transcends my javascript-foo. What's the canonical way to work around that kind of problem? (it seems that Safari treats an empty String as a false-value - is this a bug in Safari?) However, if I explicitly cast the argument, I get a step further:

dojo.trim(String('' || undefined)) 

Possible patch is attached.

Thanks in advance for your feedback, Hannes

Attachments

dojo.button.patch (0.9 kB) - added by guest 22 months ago.

Change History

Changed 22 months ago by guest

  Changed 22 months ago by peller

  • owner deleted
  • component changed from General to Dijit

probably better style-wise to tack on "or empty string"?

dojo.trim(this.containerNode.innerText || this.containerNode.textContent || '');

though this may not be the right thing to do either. You can probably use that as a workaround while you continue to work on Editor. Why doesn't innerText work on Safari?

follow-up: ↓ 3   Changed 22 months ago by peller

  • owner set to liucougar
  • component changed from Dijit to Editor

in reply to: ↑ 2   Changed 22 months ago by guest

Replying to peller:

afics innerText works - it returns an empty string (in my case at least). The problem is that textContent does not.

Meanwhile I've done some research and learned that in Javascript/ECMAScript an empty String is typecast to Boolean False (http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf - 9.2 toBoolean - page 43 (31)).

That leads me to think that the original code does not work as intended, but your suggestion works around that nicely - I'll use that for the time being..

thanks Hannes

  Changed 21 months ago by bill

Looks like two issues here

  • editor is creating buttons with no labels
  • buttons with no labels crash

The second problem should be fixed as you listed or a similar way, perhaps

dojo.trim(this.containerNode[ "innerText" in this.containerNode ? "innerText" : "textContent" ]

but the first problem should also be fixed, for a11y reasons. But where is the unlabeled button being created? Does this happen with standard editor?

  Changed 17 months ago by alex

  • cc bill added
  • status changed from new to assigned
  • owner changed from liucougar to alex
  • milestone set to 1.1

I'm gonna fix the trim issue in core and punt back to bill for fixing the dijit side.

  Changed 16 months ago by doughays

The code in Button.js has already been fixed.

  Changed 16 months ago by dylan

  • milestone changed from 1.1 to 1.2

mass move of editor issues to 1.2.

  Changed 10 months ago by bill

  • status changed from assigned to closed
  • resolution set to fixed
  • description modified (diff)

OK, this seems fixed to me. As Doug said, the Button code is fixed, and probably the buttons don't have labels because they are toolbar buttons and thus just have icons. They do have titles.

Note: See TracTickets for help on using tickets.