rep.jquery 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/.gitignore +25 -0
  2. data/LICENSE +20 -0
  3. data/README +1 -0
  4. data/Rakefile +19 -0
  5. data/TODO +0 -0
  6. data/VERSION +1 -0
  7. data/lib/jquery.rb +1 -0
  8. data/public/images/jquery.tablesorter.blue/asc.gif +0 -0
  9. data/public/images/jquery.tablesorter.blue/bg.gif +0 -0
  10. data/public/images/jquery.tablesorter.blue/desc.gif +0 -0
  11. data/public/images/jquery.tablesorter.blue/style.css +39 -0
  12. data/public/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  13. data/public/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  14. data/public/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  15. data/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  16. data/public/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  17. data/public/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  18. data/public/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  19. data/public/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  20. data/public/images/ui-icons_222222_256x240.png +0 -0
  21. data/public/images/ui-icons_2e83ff_256x240.png +0 -0
  22. data/public/images/ui-icons_454545_256x240.png +0 -0
  23. data/public/images/ui-icons_888888_256x240.png +0 -0
  24. data/public/images/ui-icons_cd0a0a_256x240.png +0 -0
  25. data/public/javascripts/jquery/autogrow.js +134 -0
  26. data/public/javascripts/jquery/easing.js +207 -0
  27. data/public/javascripts/jquery/form.js +639 -0
  28. data/public/javascripts/jquery/jeditable.autogrow.js +41 -0
  29. data/public/javascripts/jquery/jeditable.js +545 -0
  30. data/public/javascripts/jquery/metadata.js +150 -0
  31. data/public/javascripts/jquery/scrollTo.js +217 -0
  32. data/public/javascripts/jquery/suggest.js +314 -0
  33. data/public/javascripts/jquery/tablesorter.patched.js +866 -0
  34. data/public/javascripts/jquery/template.js +93 -0
  35. data/public/javascripts/jquery/tooltip.js +296 -0
  36. data/public/javascripts/jquery/ui.all.js +300 -0
  37. data/public/javascripts/jquery.js +4376 -0
  38. data/public/stylesheets/jquery-ui.css +404 -0
  39. data/public/stylesheets/jquery.suggest.css +29 -0
  40. data/rep.jquery.gemspec +81 -0
  41. metadata +119 -0
@@ -0,0 +1,866 @@
1
+ //= require "../jquery"
2
+
3
+ /*
4
+ *
5
+ * TableSorter 2.0 - Client-side table sorting with ease!
6
+ * Version 2.0.3
7
+ * @requires jQuery v1.2.3
8
+ *
9
+ * Copyright (c) 2007 Christian Bach
10
+ * Examples and docs at: http://tablesorter.com
11
+ * Dual licensed under the MIT and GPL licenses:
12
+ * http://www.opensource.org/licenses/mit-license.php
13
+ * http://www.gnu.org/licenses/gpl.html
14
+ *
15
+ */
16
+ /**
17
+ *
18
+ * @description Create a sortable table with multi-column sorting capabilitys
19
+ *
20
+ * @example $('table').tablesorter();
21
+ * @desc Create a simple tablesorter interface.
22
+ *
23
+ * @example $('table').tablesorter({ sortList:[[0,0],[1,0]] });
24
+ * @desc Create a tablesorter interface and sort on the first and secound column in ascending order.
25
+ *
26
+ * @example $('table').tablesorter({ headers: { 0: { sorter: false}, 1: {sorter: false} } });
27
+ * @desc Create a tablesorter interface and disableing the first and secound column headers.
28
+ *
29
+ * @example $('table').tablesorter({ 0: {sorter:"integer"}, 1: {sorter:"currency"} });
30
+ * @desc Create a tablesorter interface and set a column parser for the first and secound column.
31
+ *
32
+ *
33
+ * @param Object settings An object literal containing key/value pairs to provide optional settings.
34
+ *
35
+ * @option String cssHeader (optional) A string of the class name to be appended to sortable tr elements in the thead of the table.
36
+ * Default value: "header"
37
+ *
38
+ * @option String cssAsc (optional) A string of the class name to be appended to sortable tr elements in the thead on a ascending sort.
39
+ * Default value: "headerSortUp"
40
+ *
41
+ * @option String cssDesc (optional) A string of the class name to be appended to sortable tr elements in the thead on a descending sort.
42
+ * Default value: "headerSortDown"
43
+ *
44
+ * @option String sortInitialOrder (optional) A string of the inital sorting order can be asc or desc.
45
+ * Default value: "asc"
46
+ *
47
+ * @option String sortMultisortKey (optional) A string of the multi-column sort key.
48
+ * Default value: "shiftKey"
49
+ *
50
+ * @option String textExtraction (optional) A string of the text-extraction method to use.
51
+ * For complex html structures inside td cell set this option to "complex",
52
+ * on large tables the complex option can be slow.
53
+ * Default value: "simple"
54
+ *
55
+ * @option Object headers (optional) An array containing the forces sorting rules.
56
+ * This option let's you specify a default sorting rule.
57
+ * Default value: null
58
+ *
59
+ * @option Array sortList (optional) An array containing the forces sorting rules.
60
+ * This option let's you specify a default sorting rule.
61
+ * Default value: null
62
+ *
63
+ * @option Array sortForce (optional) An array containing forced sorting rules.
64
+ * This option let's you specify a default sorting rule, which is prepended to user-selected rules.
65
+ * Default value: null
66
+ *
67
+ * @option Array sortAppend (optional) An array containing forced sorting rules.
68
+ * This option let's you specify a default sorting rule, which is appended to user-selected rules.
69
+ * Default value: null
70
+ *
71
+ * @option Boolean widthFixed (optional) Boolean flag indicating if tablesorter should apply fixed widths to the table columns.
72
+ * This is usefull when using the pager companion plugin.
73
+ * This options requires the dimension jquery plugin.
74
+ * Default value: false
75
+ *
76
+ * @option Boolean cancelSelection (optional) Boolean flag indicating if tablesorter should cancel selection of the table headers text.
77
+ * Default value: true
78
+ *
79
+ * @option Boolean debug (optional) Boolean flag indicating if tablesorter should display debuging information usefull for development.
80
+ *
81
+ * @type jQuery
82
+ *
83
+ * @name tablesorter
84
+ *
85
+ * @cat Plugins/Tablesorter
86
+ *
87
+ * @author Christian Bach/christian.bach@polyester.se
88
+ */
89
+
90
+ (function($) {
91
+ $.extend({
92
+ tablesorter: new function() {
93
+
94
+ var parsers = [], widgets = [];
95
+
96
+ this.defaults = {
97
+ cssHeader: "header",
98
+ cssAsc: "headerSortUp",
99
+ cssDesc: "headerSortDown",
100
+ sortInitialOrder: "asc",
101
+ sortMultiSortKey: "shiftKey",
102
+ sortForce: null,
103
+ sortAppend: null,
104
+ textExtraction: "simple",
105
+ parsers: {},
106
+ widgets: [],
107
+ widgetZebra: {css: ["even","odd"]},
108
+ headers: {},
109
+ widthFixed: false,
110
+ cancelSelection: true,
111
+ sortList: [],
112
+ headerList: [],
113
+ dateFormat: "us",
114
+ decimal: '.',
115
+ debug: false
116
+ };
117
+
118
+ /* debuging utils */
119
+ function benchmark(s,d) {
120
+ log(s + "," + (new Date().getTime() - d.getTime()) + "ms");
121
+ }
122
+
123
+ this.benchmark = benchmark;
124
+
125
+ function log(s) {
126
+ if (typeof console != "undefined" && typeof console.debug != "undefined") {
127
+ console.log(s);
128
+ } else {
129
+ alert(s);
130
+ }
131
+ }
132
+
133
+ /* parsers utils */
134
+ function buildParserCache(table,$headers) {
135
+
136
+ if(table.config.debug) { var parsersDebug = ""; }
137
+
138
+ var rows = table.tBodies[0].rows;
139
+
140
+ if(table.tBodies[0].rows[0]) {
141
+
142
+ var list = [], cells = rows[0].cells, l = cells.length;
143
+
144
+ for (var i=0;i < l; i++) {
145
+ var p = false;
146
+
147
+ if($.metadata && ($($headers[i]).metadata() && $($headers[i]).metadata().sorter) ) {
148
+
149
+ p = getParserById($($headers[i]).metadata().sorter);
150
+
151
+ } else if((table.config.headers[i] && table.config.headers[i].sorter)) {
152
+
153
+ p = getParserById(table.config.headers[i].sorter);
154
+ }
155
+ if(!p) {
156
+ p = detectParserForColumn(table,cells[i]);
157
+ }
158
+
159
+ if(table.config.debug) { parsersDebug += "column:" + i + " parser:" +p.id + "\n"; }
160
+
161
+ list.push(p);
162
+ }
163
+ }
164
+
165
+ if(table.config.debug) { log(parsersDebug); }
166
+
167
+ return list;
168
+ };
169
+
170
+ function detectParserForColumn(table,node) {
171
+ var l = parsers.length;
172
+ for(var i=1; i < l; i++) {
173
+ if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)) {
174
+ return parsers[i];
175
+ }
176
+ }
177
+ // 0 is always the generic parser (text)
178
+ return parsers[0];
179
+ }
180
+
181
+ function getParserById(name) {
182
+ var l = parsers.length;
183
+ for(var i=0; i < l; i++) {
184
+ if(parsers[i].id.toLowerCase() == name.toLowerCase()) {
185
+ return parsers[i];
186
+ }
187
+ }
188
+ return false;
189
+ }
190
+
191
+ /* utils */
192
+ function buildCache(table) {
193
+
194
+ if(table.config.debug) { var cacheTime = new Date(); }
195
+
196
+
197
+ var totalRows = (table.tBodies[0] && table.tBodies[0].rows.length) || 0,
198
+ totalCells = (table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length) || 0,
199
+ parsers = table.config.parsers,
200
+ cache = {row: [], normalized: []};
201
+
202
+ for (var i=0;i < totalRows; ++i) {
203
+
204
+ /** Add the table data to main data array */
205
+ var c = table.tBodies[0].rows[i], cols = [];
206
+
207
+ cache.row.push($(c));
208
+
209
+ for(var j=0; j < totalCells; ++j) {
210
+ cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));
211
+ }
212
+
213
+ cols.push(i); // add position for rowCache
214
+ cache.normalized.push(cols);
215
+ cols = null;
216
+ };
217
+
218
+ if(table.config.debug) { benchmark("Building cache for " + totalRows + " rows:", cacheTime); }
219
+
220
+ return cache;
221
+ };
222
+
223
+ function getElementText(config,node) {
224
+
225
+ if(!node) return "";
226
+
227
+ var t = "";
228
+
229
+ if(config.textExtraction == "simple") {
230
+ if(node.childNodes[0] && node.childNodes[0].hasChildNodes()) {
231
+ t = node.childNodes[0].innerHTML;
232
+ } else {
233
+ t = node.innerHTML;
234
+ }
235
+ } else {
236
+ if(typeof(config.textExtraction) == "function") {
237
+ t = config.textExtraction(node);
238
+ } else {
239
+ t = $(node).text();
240
+ }
241
+ }
242
+ return t;
243
+ }
244
+
245
+ function appendToTable(table,cache) {
246
+
247
+ if(table.config.debug) {var appendTime = new Date()}
248
+
249
+ var c = cache,
250
+ r = c.row,
251
+ n= c.normalized,
252
+ totalRows = n.length,
253
+ checkCell = (n[0].length-1),
254
+ tableBody = $(table.tBodies[0]),
255
+ rows = [];
256
+
257
+ for (var i=0;i < totalRows; i++) {
258
+ rows.push(r[n[i][checkCell]]);
259
+ if(!table.config.appender) {
260
+
261
+ var o = r[n[i][checkCell]];
262
+ var l = o.length;
263
+ for(var j=0; j < l; j++) {
264
+
265
+ tableBody[0].appendChild(o[j]);
266
+
267
+ }
268
+
269
+ //tableBody.append(r[n[i][checkCell]]);
270
+ }
271
+ }
272
+
273
+ if(table.config.appender) {
274
+
275
+ table.config.appender(table,rows);
276
+ }
277
+
278
+ rows = null;
279
+
280
+ if(table.config.debug) { benchmark("Rebuilt table:", appendTime); }
281
+
282
+ //apply table widgets
283
+ applyWidget(table);
284
+
285
+ // trigger sortend
286
+ setTimeout(function() {
287
+ $(table).trigger("sortEnd");
288
+ },0);
289
+
290
+ };
291
+
292
+ function buildHeaders(table) {
293
+
294
+ if(table.config.debug) { var time = new Date(); }
295
+
296
+ var meta = ($.metadata) ? true : false, tableHeadersRows = [];
297
+
298
+ for(var i = 0; i < table.tHead.rows.length; i++) { tableHeadersRows[i]=0; };
299
+
300
+ $tableHeaders = $("thead th",table);
301
+
302
+ $tableHeaders.each(function(index) {
303
+
304
+ this.count = 0;
305
+ this.column = index;
306
+ this.order = formatSortingOrder(table.config.sortInitialOrder);
307
+
308
+ if(checkHeaderMetadata(this) || checkHeaderOptions(table,index)) this.sortDisabled = true;
309
+
310
+ if(!this.sortDisabled) {
311
+ $(this).addClass(table.config.cssHeader);
312
+ }
313
+
314
+ // add cell to headerList
315
+ table.config.headerList[index]= this;
316
+ });
317
+
318
+ if(table.config.debug) { benchmark("Built headers:", time); log($tableHeaders); }
319
+
320
+ return $tableHeaders;
321
+
322
+ };
323
+
324
+ function checkCellColSpan(table, rows, row) {
325
+ var arr = [], r = table.tHead.rows, c = r[row].cells;
326
+
327
+ for(var i=0; i < c.length; i++) {
328
+ var cell = c[i];
329
+
330
+ if ( cell.colSpan > 1) {
331
+ arr = arr.concat(checkCellColSpan(table, headerArr,row++));
332
+ } else {
333
+ if(table.tHead.length == 1 || (cell.rowSpan > 1 || !r[row+1])) {
334
+ arr.push(cell);
335
+ }
336
+ //headerArr[row] = (i+row);
337
+ }
338
+ }
339
+ return arr;
340
+ };
341
+
342
+ function checkHeaderMetadata(cell) {
343
+ if(($.metadata) && ($(cell).metadata().sorter === false)) { return true; };
344
+ return false;
345
+ }
346
+
347
+ function checkHeaderOptions(table,i) {
348
+ if((table.config.headers[i]) && (table.config.headers[i].sorter === false)) { return true; };
349
+ return false;
350
+ }
351
+
352
+ function applyWidget(table) {
353
+ var c = table.config.widgets;
354
+ var l = c.length;
355
+ for(var i=0; i < l; i++) {
356
+
357
+ getWidgetById(c[i]).format(table);
358
+ }
359
+
360
+ }
361
+
362
+ function getWidgetById(name) {
363
+ var l = widgets.length;
364
+ for(var i=0; i < l; i++) {
365
+ if(widgets[i].id.toLowerCase() == name.toLowerCase() ) {
366
+ return widgets[i];
367
+ }
368
+ }
369
+ };
370
+
371
+ function formatSortingOrder(v) {
372
+
373
+ if(typeof(v) != "Number") {
374
+ i = (v.toLowerCase() == "desc") ? 1 : 0;
375
+ } else {
376
+ i = (v == (0 || 1)) ? v : 0;
377
+ }
378
+ return i;
379
+ }
380
+
381
+ function isValueInArray(v, a) {
382
+ var l = a.length;
383
+ for(var i=0; i < l; i++) {
384
+ if(a[i][0] == v) {
385
+ return true;
386
+ }
387
+ }
388
+ return false;
389
+ }
390
+
391
+ function setHeadersCss(table,$headers, list, css) {
392
+ // remove all header information
393
+ $headers.removeClass(css[0]).removeClass(css[1]);
394
+
395
+ var h = [];
396
+ $headers.each(function(offset) {
397
+ if(!this.sortDisabled) {
398
+ h[this.column] = $(this);
399
+ }
400
+ });
401
+
402
+ var l = list.length;
403
+ for(var i=0; i < l; i++) {
404
+ h[list[i][0]].addClass(css[list[i][1]]);
405
+ }
406
+ }
407
+
408
+ function fixColumnWidth(table,$headers) {
409
+ var c = table.config;
410
+ if(c.widthFixed) {
411
+ var colgroup = $('<colgroup>');
412
+ $("tr:first td",table.tBodies[0]).each(function() {
413
+ colgroup.append($('<col>').css('width',$(this).width()));
414
+ });
415
+ $(table).prepend(colgroup);
416
+ };
417
+ }
418
+
419
+ function updateHeaderSortCount(table,sortList) {
420
+ var c = table.config, l = sortList.length;
421
+ for(var i=0; i < l; i++) {
422
+ var s = sortList[i], o = c.headerList[s[0]];
423
+ o.count = s[1];
424
+ o.count++;
425
+ }
426
+ }
427
+
428
+ /* sorting methods */
429
+ function multisort(table,sortList,cache) {
430
+
431
+ if(table.config.debug) { var sortTime = new Date(); }
432
+
433
+ var dynamicExp = "var sortWrapper = function(a,b) {", l = sortList.length;
434
+
435
+ for(var i=0; i < l; i++) {
436
+
437
+ var c = sortList[i][0];
438
+ var order = sortList[i][1];
439
+ var s = (getCachedSortType(table.config.parsers,c) == "text") ? ((order == 0) ? "sortText" : "sortTextDesc") : ((order == 0) ? "sortNumeric" : "sortNumericDesc");
440
+
441
+ var e = "e" + i;
442
+
443
+ dynamicExp += "var " + e + " = " + s + "(a[" + c + "],b[" + c + "]); ";
444
+ dynamicExp += "if(" + e + ") { return " + e + "; } ";
445
+ dynamicExp += "else { ";
446
+ }
447
+
448
+ // if value is the same keep orignal order
449
+ var orgOrderCol = cache.normalized[0].length - 1;
450
+ dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";
451
+
452
+ for(var i=0; i < l; i++) {
453
+ dynamicExp += "}; ";
454
+ }
455
+
456
+ dynamicExp += "return 0; ";
457
+ dynamicExp += "}; ";
458
+
459
+ eval(dynamicExp);
460
+
461
+ cache.normalized.sort(sortWrapper);
462
+
463
+ if(table.config.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order+ " time:", sortTime); }
464
+
465
+ return cache;
466
+ };
467
+
468
+ function sortText(a,b) {
469
+ return ((a < b) ? -1 : ((a > b) ? 1 : 0));
470
+ };
471
+
472
+ function sortTextDesc(a,b) {
473
+ return ((b < a) ? -1 : ((b > a) ? 1 : 0));
474
+ };
475
+
476
+ function sortNumeric(a,b) {
477
+ return a-b;
478
+ };
479
+
480
+ function sortNumericDesc(a,b) {
481
+ return b-a;
482
+ };
483
+
484
+ function getCachedSortType(parsers,i) {
485
+ return parsers[i].type;
486
+ };
487
+
488
+ /* public methods */
489
+ this.construct = function(settings) {
490
+
491
+ return this.each(function() {
492
+
493
+ if(!this.tHead || !this.tBodies) return;
494
+
495
+ var $this, $document,$headers, cache, config, shiftDown = 0, sortOrder;
496
+
497
+ this.config = {};
498
+
499
+ config = $.extend(this.config, $.tablesorter.defaults, settings);
500
+
501
+ // store common expression for speed
502
+ $this = $(this);
503
+
504
+ // build headers
505
+ $headers = buildHeaders(this);
506
+
507
+ // try to auto detect column type, and store in tables config
508
+ this.config.parsers = buildParserCache(this,$headers);
509
+
510
+
511
+ // build the cache for the tbody cells
512
+ cache = buildCache(this);
513
+
514
+ // get the css class names, could be done else where.
515
+ var sortCSS = [config.cssDesc,config.cssAsc];
516
+
517
+ // fixate columns if the users supplies the fixedWidth option
518
+ fixColumnWidth(this);
519
+
520
+ // apply event handling to headers
521
+ // this is to big, perhaps break it out?
522
+ $headers.click(function(e) {
523
+
524
+ $this.trigger("sortStart");
525
+
526
+ var totalRows = ($this[0].tBodies[0] && $this[0].tBodies[0].rows.length) || 0;
527
+
528
+ if(!this.sortDisabled && totalRows > 0) {
529
+
530
+
531
+ // store exp, for speed
532
+ var $cell = $(this);
533
+
534
+ // get current column index
535
+ var i = this.column;
536
+
537
+ // get current column sort order
538
+ this.order = this.count++ % 2;
539
+
540
+ // user only whants to sort on one column
541
+ if(!e[config.sortMultiSortKey]) {
542
+
543
+ // flush the sort list
544
+ config.sortList = [];
545
+
546
+ if(config.sortForce != null) {
547
+ var a = config.sortForce;
548
+ for(var j=0; j < a.length; j++) {
549
+ if(a[j][0] != i) {
550
+ config.sortList.push(a[j]);
551
+ }
552
+ }
553
+ }
554
+
555
+ // add column to sort list
556
+ config.sortList.push([i,this.order]);
557
+
558
+ // multi column sorting
559
+ } else {
560
+ // the user has clicked on an all ready sortet column.
561
+ if(isValueInArray(i,config.sortList)) {
562
+
563
+ // revers the sorting direction for all tables.
564
+ for(var j=0; j < config.sortList.length; j++) {
565
+ var s = config.sortList[j], o = config.headerList[s[0]];
566
+ if(s[0] == i) {
567
+ o.count = s[1];
568
+ o.count++;
569
+ s[1] = o.count % 2;
570
+ }
571
+ }
572
+ } else {
573
+ // add column to sort list array
574
+ config.sortList.push([i,this.order]);
575
+ }
576
+ };
577
+ setTimeout(function() {
578
+ //set css for headers
579
+ setHeadersCss($this[0],$headers,config.sortList,sortCSS);
580
+ appendToTable($this[0],multisort($this[0],config.sortList,cache));
581
+ },1);
582
+ // stop normal event by returning false
583
+ return false;
584
+ }
585
+ // cancel selection
586
+ }).mousedown(function() {
587
+ if(config.cancelSelection) {
588
+ this.onselectstart = function() {return false};
589
+ return false;
590
+ }
591
+ });
592
+
593
+ // apply easy methods that trigger binded events
594
+ $this.bind("update",function() {
595
+
596
+ // rebuild parsers.
597
+ this.config.parsers = buildParserCache(this,$headers);
598
+
599
+ // rebuild the cache map
600
+ cache = buildCache(this);
601
+
602
+ }).bind("sorton",function(e,list) {
603
+
604
+ $(this).trigger("sortStart");
605
+
606
+ config.sortList = list;
607
+
608
+ // update and store the sortlist
609
+ var sortList = config.sortList;
610
+
611
+ // update header count index
612
+ updateHeaderSortCount(this,sortList);
613
+
614
+ //set css for headers
615
+ setHeadersCss(this,$headers,sortList,sortCSS);
616
+
617
+
618
+ // sort the table and append it to the dom
619
+ appendToTable(this,multisort(this,sortList,cache));
620
+
621
+ }).bind("appendCache",function() {
622
+
623
+ appendToTable(this,cache);
624
+
625
+ }).bind("applyWidgetId",function(e,id) {
626
+
627
+ getWidgetById(id).format(this);
628
+
629
+ }).bind("applyWidgets",function() {
630
+ // apply widgets
631
+ applyWidget(this);
632
+ });
633
+
634
+ if($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
635
+ config.sortList = $(this).metadata().sortlist;
636
+ }
637
+ // if user has supplied a sort list to constructor.
638
+ if(config.sortList.length > 0) {
639
+ $this.trigger("sorton",[config.sortList]);
640
+ }
641
+
642
+ // apply widgets
643
+ applyWidget(this);
644
+ });
645
+ };
646
+
647
+ this.addParser = function(parser) {
648
+ var l = parsers.length, a = true;
649
+ for(var i=0; i < l; i++) {
650
+ if(parsers[i].id.toLowerCase() == parser.id.toLowerCase()) {
651
+ a = false;
652
+ }
653
+ }
654
+ if(a) { parsers.push(parser); };
655
+ };
656
+
657
+ this.addWidget = function(widget) {
658
+ widgets.push(widget);
659
+ };
660
+
661
+ this.formatFloat = function(s) {
662
+ var i = parseFloat(s);
663
+ return (isNaN(i)) ? 0 : i;
664
+ };
665
+ this.formatInt = function(s) {
666
+ var i = parseInt(s);
667
+ return (isNaN(i)) ? 0 : i;
668
+ };
669
+
670
+ this.isDigit = function(s,config) {
671
+ var DECIMAL = '\\' + config.decimal;
672
+ var exp = '/(^[+]?0(' + DECIMAL +'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)' + DECIMAL +'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*' + DECIMAL +'0+$)/';
673
+ return RegExp(exp).test($.trim(s));
674
+ };
675
+
676
+ this.clearTableBody = function(table) {
677
+ if($.browser.msie) {
678
+ function empty() {
679
+ while ( this.firstChild ) this.removeChild( this.firstChild );
680
+ }
681
+ empty.apply(table.tBodies[0]);
682
+ } else {
683
+ table.tBodies[0].innerHTML = "";
684
+ }
685
+ };
686
+ }
687
+ });
688
+
689
+ // extend plugin scope
690
+ $.fn.extend({
691
+ tablesorter: $.tablesorter.construct
692
+ });
693
+
694
+ var ts = $.tablesorter;
695
+
696
+ // add default parsers
697
+ ts.addParser({
698
+ id: "text",
699
+ is: function(s) {
700
+ return true;
701
+ },
702
+ format: function(s) {
703
+ return $.trim(s.toLowerCase());
704
+ },
705
+ type: "text"
706
+ });
707
+
708
+ ts.addParser({
709
+ id: "digit",
710
+ is: function(s,table) {
711
+ var c = table.config;
712
+ return $.tablesorter.isDigit(s,c);
713
+ },
714
+ format: function(s) {
715
+ return $.tablesorter.formatFloat(s);
716
+ },
717
+ type: "numeric"
718
+ });
719
+
720
+ ts.addParser({
721
+ id: "currency",
722
+ is: function(s) {
723
+ return /^[£$€?.]/.test(s);
724
+ },
725
+ format: function(s) {
726
+ return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));
727
+ },
728
+ type: "numeric"
729
+ });
730
+
731
+ ts.addParser({
732
+ id: "ipAddress",
733
+ is: function(s) {
734
+ return /^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);
735
+ },
736
+ format: function(s) {
737
+ var a = s.split("."), r = "", l = a.length;
738
+ for(var i = 0; i < l; i++) {
739
+ var item = a[i];
740
+ if(item.length == 2) {
741
+ r += "0" + item;
742
+ } else {
743
+ r += item;
744
+ }
745
+ }
746
+ return $.tablesorter.formatFloat(r);
747
+ },
748
+ type: "numeric"
749
+ });
750
+
751
+ ts.addParser({
752
+ id: "url",
753
+ is: function(s) {
754
+ return /^(https?|ftp|file):\/\/$/.test(s);
755
+ },
756
+ format: function(s) {
757
+ return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));
758
+ },
759
+ type: "text"
760
+ });
761
+
762
+ ts.addParser({
763
+ id: "isoDate",
764
+ is: function(s) {
765
+ return /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);
766
+ },
767
+ format: function(s) {
768
+ return $.tablesorter.formatFloat((s != "") ? new Date(s.replace(new RegExp(/-/g),"/")).getTime() : "0");
769
+ },
770
+ type: "numeric"
771
+ });
772
+
773
+ ts.addParser({
774
+ id: "percent",
775
+ is: function(s) {
776
+ return /\%$/.test($.trim(s));
777
+ },
778
+ format: function(s) {
779
+ return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));
780
+ },
781
+ type: "numeric"
782
+ });
783
+
784
+ ts.addParser({
785
+ id: "usLongDate",
786
+ is: function(s) {
787
+ return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));
788
+ },
789
+ format: function(s) {
790
+ return $.tablesorter.formatFloat(new Date(s).getTime());
791
+ },
792
+ type: "numeric"
793
+ });
794
+
795
+ ts.addParser({
796
+ id: "shortDate",
797
+ is: function(s) {
798
+ return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
799
+ },
800
+ format: function(s,table) {
801
+ var c = table.config;
802
+ s = s.replace(/\-/g,"/");
803
+ if(c.dateFormat == "us") {
804
+ // reformat the string in ISO format
805
+ s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
806
+ } else if(c.dateFormat == "uk") {
807
+ //reformat the string in ISO format
808
+ s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
809
+ } else if(c.dateFormat == "dd/mm/yy" || c.dateFormat == "dd-mm-yy") {
810
+ s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$1/$2/$3");
811
+ }
812
+ return $.tablesorter.formatFloat(new Date(s).getTime());
813
+ },
814
+ type: "numeric"
815
+ });
816
+
817
+ ts.addParser({
818
+ id: "time",
819
+ is: function(s) {
820
+ return /^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);
821
+ },
822
+ format: function(s) {
823
+ return $.tablesorter.formatFloat(new Date("2000/01/01 " + s).getTime());
824
+ },
825
+ type: "numeric"
826
+ });
827
+
828
+
829
+ ts.addParser({
830
+ id: "metadata",
831
+ is: function(s) {
832
+ return false;
833
+ },
834
+ format: function(s,table,cell) {
835
+ var c = table.config, p = (!c.parserMetadataName) ? 'sortValue' : c.parserMetadataName;
836
+ return $(cell).metadata()[p];
837
+ },
838
+ type: "numeric"
839
+ });
840
+
841
+ // add default widgets
842
+ ts.addWidget({
843
+ id: "zebra",
844
+ format: function(table) {
845
+ if(table.config.debug) { var time = new Date(); }
846
+ //$("tr:visible",table.tBodies[0])
847
+ // .filter(':even')
848
+ // .removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0])
849
+ // .end().filter(':odd')
850
+ // .removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);
851
+ //if(table.config.debug) { $.tablesorter.benchmark("Applying Zebra widget", time); }
852
+
853
+ // CWY 03/2009 patched for jquery 1.3.2 according to http://groups.google.com/group/jquery-en/browse_thread/thread/ecd890538837818b
854
+
855
+ var tbodyfix = $("tr", table.tBodies[0]);
856
+ if ($(tbodyfix).css("display") !== "none" && $(tbodyfix).css("visibility") !== "hidden") {
857
+ $(tbodyfix)
858
+ .filter(':even')
859
+ .removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0])
860
+ .end().filter(':odd')
861
+ .removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);
862
+ if(table.config.debug) { $.tablesorter.benchmark("Applying Zebra widget", time); }
863
+ }
864
+ }
865
+ });
866
+ })(jQuery);