Skip to content

Commit

Permalink
this.th => this.$th
Browse files Browse the repository at this point in the history
  • Loading branch information
kylefox committed Mar 7, 2012
1 parent bff0094 commit ce989cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions index.html
Expand Up @@ -22,7 +22,10 @@
}
th {
background: #f4f4f4;
cursor: pointer;
}

th:hover,
th.sorted {
background: #d4d4d4;
}
Expand Down
20 changes: 10 additions & 10 deletions jquery.tablesort.js
Expand Up @@ -14,15 +14,15 @@ $(function() {
}
}

$.tablesort = function ($el, settings) {
$.tablesort = function ($table, settings) {
var self = this;
this.$el = $el;
this.$table = $table;
this.settings = $.extend({}, $.tablesort.defaults, settings);
this.$el.find('thead th').bind('click.tablesort', function() {
this.$table.find('thead th').bind('click.tablesort', function() {
self.sort($(this));
});
this.index = null;
this.th = null;
this.$th = null;
this.direction = null;
};

Expand All @@ -31,7 +31,7 @@ $(function() {
sort: function(th) {
var start = new Date(),
self = this,
table = this.$el,
table = this.$table,
rows = table.find('tbody tr'),
direction,
aRow,
Expand All @@ -43,14 +43,14 @@ $(function() {
if(rows.length === 0)
return;

self.$el.find('thead th').removeClass(self.settings.asc + ' ' + self.settings.desc);
self.$table.find('thead th').removeClass(self.settings.asc + ' ' + self.settings.desc);

this.index = th.index();
this.th = th;
this.$th = th;
this.direction = this.direction === 'asc' ? 'desc' : 'asc';
direction = this.direction == 'asc' ? 1 : -1;

self.$el.trigger('tablesort:start', [self]);
self.$table.trigger('tablesort:start', [self]);
self.log("Sorting by " + this.index + ' ' + this.direction);

rows.sort(function(a, b) {
Expand Down Expand Up @@ -91,7 +91,7 @@ $(function() {
th.addClass(self.settings[self.direction]);

self.log('Sort finished in ' + ((new Date()).getTime() - start.getTime()) + 'ms');
self.$el.trigger('tablesort:complete', [self]);
self.$table.trigger('tablesort:complete', [self]);

},

Expand All @@ -107,7 +107,7 @@ $(function() {
},

destroy: function() {
this.$el.find('thead th').unbind('click.tablesort');
this.$table.find('thead th').unbind('click.tablesort');
return null;
}

Expand Down

0 comments on commit ce989cf

Please sign in to comment.