Optimize stars by not emitting inline javascript and loading info out of data attributes.

Review Request #1900 — Created Nov. 9, 2010 and submitted

Review Board
This change reworks the "star" functionality (shown on reviews and the dashboard) to be lighter weight in terms of HTML page weight and JavaScript execution, by following an "unobtrusive JavaScript" pattern. The stars plugin is changed to load the parameters for stars from data attributes on the star itself instead of a script tag emitted for each star, and then they are all set up at once by class name. The jQuery code to handle stars is also cleaned up and made a bit more efficient partially by moving things out of the loops and closures and partially by caching things using jQuery.data(). This does change the contract for the toggleStar plugin, but as far as I can tell it is only used here.
This change is in use on our ReviewBoard install.
  2. reviewboard/htdocs/media/rb/js/common.js (Diff revision 1)
    Can be combined to one statement.
  3. May want to use live(), in case stars are dynamically added later. As an example, I'd like to eventually make the dashboard not reload the whole page, but rather the list of review requests. If we need to initiate a toggleStar() for all stars, it'll be important to plan that.
Review request changed

Change Summary:

Changed based on Christian's comments to use live().


Revision 2 (+36 -35)

Show changes

  1. Pushed to release-1.5.x as cf33eb2. Thanks!