Skip to content

Instantly share code, notes, and snippets.

@caitp
Created August 26, 2014 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caitp/71a97bcb41fdb145b688 to your computer and use it in GitHub Desktop.
Save caitp/71a97bcb41fdb145b688 to your computer and use it in GitHub Desktop.
1. Let table be the table element being sorted.
2. If table's currently-sorting flag is true, then abort these steps.
3. Set table's currently-sorting flag to true.
4. Fire a simple event named sort that is cancelable at table.
5. If the event fired in the previous step was canceled, then jump to the step
labeled end below.
6. If table is not now a sorting-enabled table element, then jump to the
step labeled end below.
7. Let key heading cells be the sorting-enabled th elements of the table
element table.
8. Sort key heading cells in ascending order of the column key ordinality of
their sorted attributes, with those having the same column key ordinality
being sorted in tree order.
9. Let row collection cursor be a pointer to an element, initially pointing at
the first child of table that is after table's first thead, if any, and that
is either a tbody or a tr element, assuming there is one. If there is no such
child, then jump to the step labeled end below.
10. If table has no row group corresponding to a thead element, then set ignore
first group to true. Otherwise, set it to false.
11. Row loop: Let rows be an empty list of tr elements.
12. Repeat while row collection cursor is not null
12.1 If row collection cursor points to a tr element
12.1.1 Collect: Append the element pointed to by row collection cursor
to rows.
12.1.2 If there are no tr or tbody children of table that are later
siblings of the element pointed to by row collection cursor,
or if the next such child is a tbody element, then jump to the
step labeled group below.
12.1.3 Let row collection cursor point to the next tr child of table
that is a later sibling of the element pointed to by row
collection cursor.
12.1.4 Return to the step labeled collect above.
12.2 If row collection cursor points to a tbody element
12.2.1 Place all the tr element children of the element pointed to by
row collection cursor into rows, in tree order.
12.2.2 If rows is empty, jump to the step labeled increment loop below.
12.3 Group: Let groups be an empty list of groups of tr elements.
12.4 Let group be an empty group of tr elements.
12.5 Let group cursor be a pointer to an element, initially pointing at the
first tr element in rows.
12.6 Start group: Let pending rows in group be 1.
12.7 Repeat while group cursor is not null
12.7.1 Repeat while group curosr is not null and pending rows in group
is not zero:
12.7.1.1 Append the tr element pointed to by group cursor to group.
12.7.1.2 If there are any cells whose highest row's element is the
one pointed to by group cursor, then let tallest height be
the number of rows covered by the tallest such cell.
12.7.1.3 If tallest height is greater than pending rows in group
then set pending rows in group to tallest height.
12.7.1.4 Decrement pending rows in group by one.
12.7.1.5 Let group cursor point to the next tr element in rows, if
any; otherwise, let it be null.
12.7.2 Append a new group to groups consisting of the tr elements in group.
12.9 Empty group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment