Event delayer gets upset if there's a " in it

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Event delayer gets upset if there's a " in it
« on April 7th, 2013, 04:55 PM »
I don't know if this should even be fixed, but I do want to make record of it.

I have a select, it has a simple onchange, which is to alter the disabled property of another input. Specifically,
Code: [Select]
onchange="$(\'input[name=\"infraction_duration_number\"]\').dostuff();"

The nested quote mark causes issues, but as I said, I'm not sure this necessarily needs a fix - doing something like this is not what you would necessarily call common.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Event delayer gets upset if there's a " in it
« Reply #1, on April 7th, 2013, 06:47 PM »
You can remove the double quotes entirely. That solves your problem. Or use chr(24) or something like that. I don't remember the number exactly. This will stand for a double quote in one of my upcoming commits which precisely aims to fix that. ;)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Event delayer gets upset if there's a " in it
« Reply #2, on April 7th, 2013, 06:50 PM »
As it turns out I changed the code to use an id rather than reusing the name but yeah I can now fully understand the need for the workaround as proposed ;)

* Arantor is not really a jQuery / JS guru, not the way he is with PHP

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Event delayer gets upset if there's a " in it
« Reply #3, on April 7th, 2013, 06:57 PM »
It's not that a workaround was needed for this... I've always suppressed double quotes in these situations when embedding in an inline event. It's just that when you include some JSE string in these, sometimes you'll get a double quote, whether you want it to not. Originally it was handled differently (i.e. would convert it to a quot entity), but I recently figured (and documented it) that I could get away with a chr() call, like I'm doing in other situations.

I really need to get started committing stuff...!

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Event delayer gets upset if there's a " in it
« Reply #4, on April 7th, 2013, 07:01 PM »
Quote
It's not that a workaround was needed for this...
You mean
Code: [Select]
onchange="$(\'input[name=infraction_duration_number]\').dostuff();"

would have been legal?
Quote
I really need to get started committing stuff...!
You wait until the commit I'm working on lands. I can't do it in bits because it all absolutely has to work together >_< So far, 25 modified, 3 added (will be 4 added by the time I'm finished, I'm not doing Eng-UK until I'm done)

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Event delayer gets upset if there's a " in it
« Reply #5, on April 7th, 2013, 08:49 PM »
Quote from Arantor on April 7th, 2013, 07:01 PM
You mean
Code: [Select]
onchange="$(\'input[name=infraction_duration_number]\').dostuff();"

would have been legal?
In XHTML, no, but guess what is legal in HTML5..? Mostly everything, notably removing double quotes from parameters as long as they don't have a space in them ;) So, I'm guessing there's no reason for CSS3 to complain against this. And jQuery understands this perfectly, too.
And even if it didn't validate, it's JavaScript, so it's not processed by validators anyway... :P
Quote
You wait until the commit I'm working on lands. I can't do it in bits because it all absolutely has to work together >_< So far, 25 modified, 3 added (will be 4 added by the time I'm finished, I'm not doing Eng-UK until I'm done)
Yay...

Oh, speaking about Eng-UK, I stumbled upon the Google dev blog, which mentioned that hreflang="..." must use a string like "en-GB", while we're using "en_UK". We don't have "en-GB" in our language strings, but we do have "GB", so it might be possible to build the complete string from scratch by taking the paypal one and adding it to the generic language string, I don't know... What's your say?

Let's see... My uncommitted stuff... 26 modified files, 1 removed file. I'm in the same waters as you are..!
I'll post them in another topic for you to see, if you're curious!

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Event delayer gets upset if there's a " in it
« Reply #6, on April 7th, 2013, 09:03 PM »
Quote
And jQuery understands this perfectly, too.
This is more what I meant, I didn't realise it did.
Quote
We don't have "en-GB" in our language strings, but we do have "GB", so it might be possible to build the complete string from scratch by taking the paypal one and adding it to the generic language string, I don't know... What's your say?
English UK should have en_GB rather than en_UK, my bad. I've fixed that locally.

If only there were some fecking consistency between these fecking things. The locale string is for setlocale, the PayPal one for PayPal, why can't Google accept either of these without having to make its own standard on top? For hreflang, we should supply str_replace('_', '-', $txt['lang_locale'])

On the other hand, the <html> tag also expects a language identifier following ISO 630-1, which is two characters (which is currently provided by $txt['lang_dictionary'], although originally set up for pspell, and no, enchant doesn't use that, enchant uses the locale setting)

Why can't everyone just adopt the locale format and be bloody done with it? >_<