[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[EP-tech] Re: sort order of contributors.Contribution for other languages



> @Gilles: Your idea sounds nice. What static part should I change in
> order to make it work? (eg default.xml?)

I think it's better to add a javascript file in 
.../archives/YOURID/cfg/static/javascript/auto/

We use jQuery, so I am not very comfortable with plain javascript and 
even less with prototype.
But with jQuery, you could use something like the following and adapt it 
to your content.

    // To prevent problems between Prototype and jQuery
    jQuery.noConflict();

    // To run the code after the browser has finished loaded the DOM
    jQuery(document).ready(function($){

         // Code from
    http://stackoverflow.com/questions/12073270/sorting-options-elements-alphabetically-using-jquery
         // ***NOT FULLY TESTED***|

    |    var options = $('select[id$="pays_publication"] option');
         var arr = options.map(function(_, o) {
             return {
                 t: $(o).text(),
                 v: o.value,
                 s: $(o).attr('selected')
             };
         }).get();

         arr.sort(function(o1, o2) {
             return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0;
         });

         options.each(function(i, o) {
             o.value = arr[i].v;
             $(o).text(arr[i].t);
             $(o).attr('selected', arr[i].s);
         });

    });

Of course you'll also need to load the jQuery library.

If you don't use jQuery, it would be better to find the corresponding 
code for Prototype so you will not have to load another library just for 
this functionality.

Regards
GF