To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Ticket #505 (closed defect: wontfix)

Opened 19 months ago

Last modified 19 months ago

Double semicolons all over the place in JavaScript output

Reported by: asaphosting Owned by: tboutell
Priority: minor Milestone:
Component: apostrophePlugin Version:
Keywords: Cc: tboutell,
Symfony version: 1.4

Description

If you take a look at any page when logged-in you'll notice that there are double semicolons all over the place in inline JavaScript? handlers like onClick="doSomething();; return false;".

That's because the sfJqueryReloadedPlugin has code like this: $customCode.'; return false;' and the $customCode is the JS code you want to add via jq_* methods. So, I don't know if that's actually a syntax error or if the JS parser sees the semicolon as the line end and so the second semicolon simply marks an empty line. But it sure looks very weird. ;-)

Change History

Changed 19 months ago by agilbert

  • cc tboutell, added
  • owner changed from agilbert to johnnyoffline
  • status changed from new to assigned

John, are you aware of this already? Or is this a Tom thing related to our jQuery plugin.

Changed 19 months ago by johnnyoffline

  • owner changed from johnnyoffline to tboutell

I'm not really sure.

If you use someting like jq_link_to_function and write your inline javascript with an ending semi-colon, it will have two.

That's because the helper appends its own semi-colon to the end of the javascript.

Like so:

    $html_options['onclick'] = $function.'; return false;';

So that means, whatever inline Javascript that gets written in a partial shouldn't end with a semi-colon.

But I think that's crazy.

Using the above as an example, the jQuery helper should probably trim the $function and check the last char for whether or not it's a semi-colon and append one if it's not.

That would fix the problem without having to scrub through a billion projects with semi-colons that aren't necessary.

Maybe Tom can chime in before that happens though.

Changed 19 months ago by tboutell

  • status changed from assigned to closed
  • resolution set to wontfix

Yeah, I've noticed this before. As folks have mentioned this is because the jQuery helpers allow you to pass code in various places, including the output of other jQuery helpers, and trimming everything for semicolons is tricky to do well and do safely in all situations. In particular we can't go breaking code that's following the the examples in the original Symfony book (supporting that sort of thing is the reason the jQuery helper still exists).

This is one of the minor annoyances of life with JavaScript? code that's not being written directly in JavaScript?.

But empty statements are perfectly legal JavaScript? (they are no-operation statements, just as they are in C and everything else that shares the C-style syntax). So the duplicate semicolons are hurting nothing.

The right solution to this problem, and to most other complaints about our JavaScript? code, is to gradually migrate to writing our JavaScript? in JavaScript? rather than trying to write it in PHP. In Apostrophe 2.0 we should not use the jQuery helper, full stop.

In the meantime we shouldn't waste effort trying to make ugly-but-correct autogenerated code slightly less ugly.

Note: See TracTickets for help on using tickets.