Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1974 (closed enhancement: fixed)

Opened 11 years ago

Last modified 11 years ago

[PATCH] Ordering of JS and CSS widgets at render time

Reported by: rejoc Owned by: rejoc
Priority: normal Milestone: 1.1b2
Component: TurboGears Version: 1.0.6
Severity: normal Keywords: needs review
Cc: remi.jolin@…

Description

Here is a patch (tg controllers.py and widgets/base.py) + tests to allow to fix the order the JS scripts and CSS will be rendered on the page. The patch is built on top of the 1.0 branch.

Just add an 'order' parameter to your JSLink/JSSource/CSSLink/CSSSource definition like this

JSLink(my_static, 'javascript/myscript.js', order=5)

or you can also modify an existing JSLink :

mochikit.order=10

default value for order is 0.

scripts with same order value stay in the same order as defined in the javascript or css list (just as before).

Attachments

widgets_base.py.diff Download (408 bytes) - added by rejoc 11 years ago.
tests_test_form_controllers.py.diff Download (2.1 KB) - added by rejoc 11 years ago.
controllers.py.diff Download (625 bytes) - added by rejoc 11 years ago.

Change History

Changed 11 years ago by rejoc

Changed 11 years ago by rejoc

Changed 11 years ago by rejoc

comment:1 Changed 11 years ago by Chris Arndt

I don't understand the need for this feature. What can you do without it, what you couldn't do before? Can you provide a use case?

comment:2 Changed 11 years ago by Chris Arndt

  • Keywords needs feedback added
  • Summary changed from ordering JS and CSS at render time to [PATCH] Ordering of JS and CSS widgets at render time

comment:3 Changed 11 years ago by rejoc

I had a case with a page that was simultaneously using "google maps", "mochikit" and "lightbox" which is based on "scriptaculous/prototype".

Everythings worked great before I added the need for mochikit. When I added a widget using mochikit to the page, lightbox did not work anymore, raising an JS error about an unavailable function (looked like prototype did not load all its components).

I first checked the mochikit script and used the "long naming" for mochikit functions ("MochiKit?.xxx.function" instead of simply "function"). This had solved a similar issue I have had before. But here, it was not enough.

Then, I wondered if the order of the definitions of the JS scripts within the page could have some importance (a reply on the list from Jorge Godoy on 2007/04/23 "Re: TurboGears Mochikit Scriptaculous noob questions" alerted me about potential compatibility issues) and tried to change this order. I tried to do this without patching TG but I did not find a way. So I wrote this patch. And I used it to have mochikit.js to load after lightbox related scripts and everything went OK.

I know it would be better not to use widgets that use different JS libraries but you don't always have the choice these widgets come from everywhere...

It's quite difficult to provide a simple test case for that because it deals with a quite complex page.

comment:4 Changed 11 years ago by Chris Arndt

  • Keywords review added; feedback removed

comment:5 Changed 11 years ago by faide

Remi,

could this feature be implemented only in 1.1 ? I am reluctant to include new functionnalities in 1.0 now that it has gone in bugfix only.

I understand the need for this patch but I feel pushing 1.1 forward is now more important than diluting our efforts by maintaining multiple branches at the same time.

Florent.

comment:6 Changed 11 years ago by faide

  • Milestone changed from 1.1 to 1.1 beta 2

comment:7 Changed 11 years ago by rejoc

Florent,

No problem of course. This will give me a good reason to switch to 1.1 ;-) (idem for ticket #1988 if you find the feature interesting)

comment:8 Changed 11 years ago by rejoc

  • Status changed from new to assigned
  • Owner changed from anonymous to rejoc

comment:9 Changed 11 years ago by rejoc

  • Status changed from assigned to closed
  • Resolution set to fixed

comment:10 Changed 11 years ago by Chris Arndt

Was this applied? If not, please don't close this ticket as fixed! If yes, please put the revision number in a ticket comment.

comment:11 Changed 11 years ago by rejoc

fixed in rev 5667

Note: See TracTickets for help on using tickets.