<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,31 +16,28 @@
 
 var PaginatingTable = new Class({
 
-  initialize: function( tbl, ids, options ) {
-    this.options = $merge({
-      per_page: 10,
-      current_page: 1,
-      offset_el: false,
-      cutoff_el: false,
-      details: false
-    }, options);
+  Implements: Options,
+  
+  options: {
+    per_page: 10,
+    current_page: 1,
+    offset_el: false,
+    cutoff_el: false,
+    details: false
+  },
+  
+  initialize: function( table, ids, options ) {
+    this.table = $(table);
+    this.setOptions(options);
     
-    this.table = $(tbl);
-    this.tbody = this.table.getElementsByTagName( 'tbody' )[0];
+    this.tbody = this.table.getElement('tbody');
     
     if (this.options.offset_el)
       this.options.offset_el = $(this.options.offset_el);
     if (this.options.cutoff_el)
       this.options.cutoff_el = $(this.options.cutoff_el);
 
-    this.paginators = [];
-    if ($type(ids) == 'array'){
-      $each(ids,function(id){
-        this.paginators.push( $(id) );
-      }.bind( this ));
-    } else {
-      this.paginators.push( $(ids) );
-    }
+    this.paginators = ($type(ids) == 'array') ? ids.map($) : [$(ids)];
 
     if (this.options.details) {
       this.options.per_page = this.options.per_page * 2
@@ -50,37 +47,26 @@ var PaginatingTable = new Class({
   },
 
   update_pages: function(){
-    this.pages = Math.ceil( this.tbody.getElementsByTagName('tr').length / this.options.per_page );
+    this.pages = Math.ceil( this.tbody.getChildren().length / this.options.per_page );
     this.create_pagination();
     this.to_page( 1 );
   },
 
   to_page: function( page_num ) {
-    page_num = parseInt( page_num );
+    page_num = page_num.toInt();
     if (page_num &gt; this.pages || page_num &lt; 1) return;
     this.current_page = page_num;
     this.low_limit  = this.options.per_page * ( this.current_page - 1 );
     this.high_limit = this.options.per_page * this.current_page;
-    var trs = this.tbody.getElementsByTagName('tr')
+    var trs = this.tbody.getChildren();
     if (trs.length &lt; this.high_limit) this.high_limit = trs.length;
-    for (var index=0; index &lt; trs.length; index++) {
-      if ( this.low_limit  &lt;= index &amp;&amp;
-           this.high_limit &gt; index    ) {
-        trs[index].style.display = '';
-      } else {
-        trs[index].style.display = 'none';
-      }
+    for (var i = 0, j = trs.length; i &lt; j; i++) {
+      trs[i].style.display = (this.low_limit  &lt;= i &amp;&amp; this.high_limit &gt; i) ? '' : 'none';
     }
     this.paginators.each(function(paginator){
-      var as = paginator.getElementsByTagName( 'a' );
-      for (var index=0;index &lt; as.length;index++){
-        if (index == this.current_page) {
-          as[index].addClass('currentPage');
-        } else {
-          as[index].removeClass('currentPage');
-        }
-      }
-    }.bind( this ));
+      var as = paginator.getElements('a').removeClass('currentPage');
+      as[this.current_page].addClass('currentPage');
+    }, this);
     if (this.options.offset_el)
       this.options.offset_el.set('text', Math.ceil( this.low_limit / ( this.options.details ? 2 : 1 ) + 1 ) );
     if (this.options.cutoff_el)</diff>
      <filename>paginating_table.js</filename>
    </modified>
    <modified>
      <diff>@@ -18,48 +18,52 @@
 
 var SortingTable = new Class({
 
+  Implements: Options,
+  
+  options: {
+    zebra: true,
+    details: false,
+    paginator: false,
+    dont_sort_class: 'nosort',
+    forward_sort_class: 'forward_sort',
+    reverse_sort_class: 'reverse_sort'
+  },
+
   initialize: function( table, options ) {
-    this.options = $merge({
-      zebra: true,
-      details: false,
-      paginator: false,
-      dont_sort_class: 'nosort',
-      forward_sort_class: 'forward_sort',
-      reverse_sort_class: 'reverse_sort'
-    }, options);
-    
     this.table = $(table);
-    this.tbody = $(this.table.getElementsByTagName('tbody')[0]);
+    this.setOptions(options);
+    
+    this.tbody = this.table.getElement('tbody');
     if (this.options.zebra) {
-      SortingTable.stripe_table( this.tbody.getElementsByTagName( 'tr' ) );
+      SortingTable.stripe_table(this.tbody.getChildren());
     }
 
-    this.headers = new Hash;
-    var thead = $(this.table.getElementsByTagName('thead')[0]);
-    this.headers = thead.getElementsByTagName('tr')[0].getElementsByTagName('th');
-    $each(this.headers, function( header, index ) {
-      var header = $(header);
+    this.headers = this.table.getElement('thead').getElements('th');
+    this.headers.each(function( header, index ) {
       if (header.hasClass( this.options.dont_sort_class )) { return }
       header.store( 'column', index )
       header.addEvent( 'mousedown', function(evt){
-        var evt = new Event(evt);
         this.sort_by_header( evt.target );
         if ( this.options.paginator) this.options.paginator.to_page( 1 );
       }.bind( this ) );
-    }.bind( this ) );
+    }, this);
 
     this.load_conversions();
   },
 
   sort_by_header: function( header ){
-    this.rows = new Array;
-    var trs = this.tbody.getElements( 'tr' );
+    var rows = [];
+    
+    var before = this.tbody.getPrevious();
+    this.tbody.dispose();
+    
+    var trs = this.tbody.getChildren();
     while ( row = trs.shift() ) {
       row = { row: row.dispose() };
       if ( this.options.details ) {
         row.detail = trs.shift().dispose();
       }
-      this.rows.unshift( row );
+      rows.unshift( row );
     }
     
     if ( this.sort_column &gt;= 0 &amp;&amp;
@@ -73,19 +77,19 @@ var SortingTable = new Class({
         header.addClass( this.options.reverse_sort_class );
       }
     } else {
-      $each(this.headers, function(h){
+      this.headers.each(function(h){
         h.removeClass( this.options.forward_sort_class );
         h.removeClass( this.options.reverse_sort_class );
-      }.bind( this ));
+      }, this);
       this.sort_column = header.retrieve('column');
       if (header.retrieve('conversion_function')) {
         this.conversion_matcher = header.retrieve('conversion_matcher');
         this.conversion_function = header.retrieve('conversion_function');
       } else {
         this.conversion_function = false;
-        this.rows.some(function(row){
+        rows.some(function(row){
           var to_match = $(row.row.getElementsByTagName('td')[this.sort_column]).get('text');
-          if (to_match == ''){ return false }
+          if (to_match == '') return false;
           this.conversions.some(function(conversion){
             if (conversion.matcher.test( to_match )){
               this.conversion_matcher = conversion.matcher;
@@ -93,38 +97,34 @@ var SortingTable = new Class({
               return true;
             }
             return false;
-          }.bind( this ));
-          if (this.conversion_function){ return true; }
-          return false;
-        }.bind( this ));
-        header.store('conversion_function', this.conversion_function.bind( this ) );
+          }, this);
+          return !!(this.conversion_function);
+        }, this);
+        header.store('conversion_function', this.conversion_function );
         header.store('conversion_matcher', this.conversion_matcher );
       }
       header.addClass( this.options.forward_sort_class );
-      this.rows.each(function(row){
-        row.compare_value = this.conversion_function( row );
-        row.toString = function(){ return this.compare_value }
-      }.bind( this ));
-      this.rows.sort();
+      rows.each(function(row){
+        var compare_value = this.conversion_function( row );
+        row.toString = function(){
+          return compare_value;
+        };
+      }, this);
+      rows.sort();
     }
 
     var index = 0;
-    while ( row = this.rows.shift() ) {
-      row.row.injectInside( this.tbody );
-      if (row.detail){ row.detail.injectInside( this.tbody ) };
+    while ( row = rows.shift() ) {
+      this.tbody.appendChild(row.row);
+      if (row.detail) this.tbody.appendChild(row.detail);
       if ( this.options.zebra ) {
-        row.row.className = row.row.className.replace( this.removeAltClassRe, '$1').clean();
-        if (row.detail){
-          row.detail.className = row.detail.className.replace( this.removeAltClassRe, '$1').clean();
-        }
-        if ( ( index % 2 ) == 0 ) {
-          row.row.addClass( 'alt' );
-          if (row.detail){ row.detail.addClass( 'alt' ); }
-        }
+        var method = (index % 2) ? 'removeClass' : 'addClass';
+      row.row[method]( 'alt' );
+        if (row.detail) row.detail[method]( 'alt' );
       }
       index++;
     }
-    this.rows = false;
+   this.tbody.inject(before, 'after');
   },
 
   load_conversions: function() {
@@ -206,19 +206,11 @@ var SortingTable = new Class({
 
 });
 
-SortingTable.removeAltClassRe = new RegExp('(^|\\s)alt(?:\\s|$)');
-SortingTable.implement({ removeAltClassRe: SortingTable.removeAltClassRe });
-
 SortingTable.stripe_table = function ( tr_elements  ) {
   var counter = 0;
-  $$( tr_elements ).each( function( tr ) {
-    if ( !tr.hasClass('collapsed') ) {
-      counter++;
-    }
-    tr.className = tr.className.replace( this.removeAltClassRe, '$1').clean();
-    if ( !(( counter % 2 ) == 0) ) {
-      tr.addClass( 'alt' );   
-    }
-  }.bind( this ));
+  tr_elements.each( function( tr ) {
+    if ( !tr.hasClass('collapsed') ) counter++;
+  tr[(counter % 2) ? 'addClass' : 'removeClass']( 'alt' );
+  });
 }
 </diff>
      <filename>sorting_table.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0a52fc91cf8df2efbbf6bda03dfa69f416a6c579</id>
    </parent>
  </parents>
  <author>
    <name>digitarald</name>
    <email>mail@digitarald.de</email>
  </author>
  <url>http://github.com/mixonic/tables_on_cows/commit/352dcfe272ee01d73900590fdd869fbc2e6e217b</url>
  <id>352dcfe272ee01d73900590fdd869fbc2e6e217b</id>
  <committed-date>2008-06-21T07:12:32-07:00</committed-date>
  <authored-date>2008-06-21T07:12:32-07:00</authored-date>
  <message>Refactored some loops and cleaned-up element injection. Pluse more mooish style. Needs more clean-up for coherent syntax.</message>
  <tree>a31c043173bfaa0a28a2bbca72cdc5c4fbe5a510</tree>
  <committer>
    <name>digitarald</name>
    <email>mail@digitarald.de</email>
  </committer>
</commit>
