| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
;(function($) { |
| 8 |
'use strict'; |
| 9 |
var ts = $.tablesorter; |
| 10 |
|
| 11 |
ts.formatter = { |
| 12 |
init : function( c ) { |
| 13 |
var events = c.widgetOptions.formatter_event + |
| 14 |
' pagerComplete updateComplete '.split(' ').join('.tsformatter '); |
| 15 |
c.$table |
| 16 |
.off( events.replace(/\s+/g, ' ') ) |
| 17 |
.on( events, function() { |
| 18 |
ts.formatter.setup( c ); |
| 19 |
}); |
| 20 |
ts.formatter.setup( c ); |
| 21 |
}, |
| 22 |
setup : function( c ) { |
| 23 |
|
| 24 |
if ( $.isEmptyObject( c.cache ) ) { return; } |
| 25 |
var $tbody, tbodyIndex, rowIndex, rows, cell, len, column, |
| 26 |
wo = c.widgetOptions, |
| 27 |
data = { config: c, wo: wo }, |
| 28 |
formatter = [], |
| 29 |
$headers = []; |
| 30 |
|
| 31 |
for ( column = 0; column < c.columns; column++ ) { |
| 32 |
$headers[ column ] = c.$headerIndexed[ column ]; |
| 33 |
formatter[ column ] = ts.getColumnData( c.table, wo.formatter_column, column ) || false; |
| 34 |
} |
| 35 |
|
| 36 |
for ( tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) { |
| 37 |
$tbody = ts.processTbody( c.table, c.$tbodies.eq( tbodyIndex ), true ); |
| 38 |
rows = c.cache[ tbodyIndex ]; |
| 39 |
len = rows.normalized.length; |
| 40 |
for ( rowIndex = 0; rowIndex < len; rowIndex++ ) { |
| 41 |
data.$row = rows.normalized[ rowIndex ][ c.columns ].$row; |
| 42 |
data.$cells = data.$row.children( 'th, td' ); |
| 43 |
for ( column = 0; column < c.columns; column++ ) { |
| 44 |
if ( formatter[ column ] ) { |
| 45 |
data.columnIndex = column; |
| 46 |
data.$header = $headers[ column ]; |
| 47 |
data.$cell = data.$cells.eq( column ); |
| 48 |
cell = data.$cell[0]; |
| 49 |
|
| 50 |
data.text = cell.getAttribute( c.textAttribute ) || cell.textContent || data.$cell.text(); |
| 51 |
cell.innerHTML = formatter[ column ]( data.text, data ); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
ts.processTbody( c.table, $tbody, false); |
| 56 |
} |
| 57 |
} |
| 58 |
}; |
| 59 |
|
| 60 |
ts.addWidget({ |
| 61 |
id: 'formatter', |
| 62 |
priority: 100, |
| 63 |
options: { |
| 64 |
formatter_column : {}, |
| 65 |
formatter_event : 'applyFormatter' |
| 66 |
}, |
| 67 |
init: function( table ) { |
| 68 |
ts.formatter.init( table.config ); |
| 69 |
} |
| 70 |
}); |
| 71 |
|
| 72 |
})( jQuery ); |