This project is archived and is in readonly mode.

#420 ✓invalid

Fx.Sort Method: sortByElements -> seems broken in 1.3?

Reported by bart | October 21st, 2010 @ 09:00 PM | in

This doesn't seem to be sorting if using moo 1.3. It works fine with 1.2.4 and 1.2.5...

Comments and changes to this ticket

  • Arian

    Arian October 21st, 2010 @ 09:18 PM

    • State changed from “new” to “open”
    • Milestone set to
    • Assigned user set to “Aaron Newton”
    • Milestone order changed from “197537” to “0”
  • Yorick Sijsling

    Yorick Sijsling October 22nd, 2010 @ 01:26 PM

    This is not an issue with Fx.Sort.

    The problem you're having is caused by this part:

    vert.sortByElements($$(['#b', '#a', '#c']));

    From the documentation:

    Since MooTools 1.3 this function does not accept multiple collections or multiple strings as arguments.

    Just replace the above with this:

    vert.sortByElements($$('#b, #a, #c'));

    Or as an alternative, use Core 1.3 with compatibility.

  • bart

    bart October 22nd, 2010 @ 02:06 PM

    No that doesn't work either, try playing with the jsFiddle example I posted above. Your solution still only works with 1.2.5.

  • Fabian

    Fabian October 22nd, 2010 @ 06:31 PM

    MooTools 1.2.5

      document.writeln($$('#b', '#a', '#c').get('id'));

    is b,a,c - so sort does work.

    MooTools 1.3.0

      document.writeln($$('#b, #a, #c').get('id'));

    is a,b,c - so nothing to sort (original order).

    So I think the problem is not the sorting, rather than $$ returning the elements in the order of appearance.

  • Arian

    Arian October 23rd, 2010 @ 01:10 PM

    • State changed from “open” to “invalid”

    Of course! Thanks Fabian. $$ is supposed to return the elements in the order they are found in the document.

    If it are just ids, you could do something like:

    var elements = ['a', 'c', 'b'].map(function(el){
  • bart

    bart October 23rd, 2010 @ 01:55 PM

    Just wondering why this worked in the older version? Because of the $$ revisions in 1.3 then?

  • Arian

    Arian October 23rd, 2010 @ 02:35 PM

    First because $$ changed a little bit and don't accept multiple arguments anymore (which simplified the code of $$ a lot) while it is just as easy to just pass a selector where the selectors are separated by a , like $$('#a, #b, #c') instead of $$('#a', '#b', '#c') or other forms like an array, or mixed selector or arrays with elements.
    Secondly because previous versions didn't have such a sophisticated selector engine as Slick, like 1.3 has. Previous versions probably splitted the selectors at the , and appended the resulting elements to the resulting array, without caring about the order of the elements in the document.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket