| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
;(function($) { |
| 15 |
'use strict'; |
| 16 |
var ts = $.tablesorter, |
| 17 |
|
| 18 |
|
| 19 |
addIndexes = function(table) { |
| 20 |
var $tr, wo, v, indx, rows, |
| 21 |
c = table.config; |
| 22 |
|
| 23 |
|
| 24 |
if (c) { |
| 25 |
wo = c.widgetOptions; |
| 26 |
c.$tbodies.each(function() { |
| 27 |
$tr = $(this).children(); |
| 28 |
rows = $tr.length; |
| 29 |
$tr.filter(wo.staticRow_class).each(function() { |
| 30 |
$tr = $(this); |
| 31 |
indx = $tr.data(wo.staticRow_index); |
| 32 |
if (typeof indx !== 'undefined') { |
| 33 |
v = parseFloat(indx); |
| 34 |
|
| 35 |
indx = (/%/.test(indx)) ? Math.round(v / 100 * rows) : v; |
| 36 |
} else { |
| 37 |
indx = $tr.index(); |
| 38 |
} |
| 39 |
|
| 40 |
$tr.data( wo.staticRow_data, indx ); |
| 41 |
}); |
| 42 |
}); |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
ts.addWidget({ |
| 47 |
|
| 48 |
|
| 49 |
id: 'staticRow', |
| 50 |
|
| 51 |
options: { |
| 52 |
staticRow_class : '.static', |
| 53 |
staticRow_data : 'static-index', |
| 54 |
staticRow_index : 'row-index', |
| 55 |
staticRow_event : 'staticRowsRefresh' |
| 56 |
}, |
| 57 |
|
| 58 |
init: function(table, thisWidget, c, wo) { |
| 59 |
addIndexes(table); |
| 60 |
|
| 61 |
c.$table |
| 62 |
.unbind( ('updateComplete.tsstaticrows ' + wo.staticRow_event).replace(/\s+/g, ' ') ) |
| 63 |
.bind('updateComplete.tsstaticrows ' + wo.staticRow_event, function() { |
| 64 |
addIndexes(table); |
| 65 |
ts.applyWidget( table ); |
| 66 |
}); |
| 67 |
}, |
| 68 |
|
| 69 |
format: function(table, c, wo) { |
| 70 |
|
| 71 |
|
| 72 |
var targetIndex, $thisRow, indx, numRows, $tbody, hasShuffled, $rows, max; |
| 73 |
|
| 74 |
c.$tbodies.each(function() { |
| 75 |
$tbody = $.tablesorter.processTbody(table, $(this), true); |
| 76 |
hasShuffled = true; |
| 77 |
indx = 0; |
| 78 |
$rows = $tbody.children(wo.staticRow_class); |
| 79 |
numRows = $tbody.children('tr').length - 1; |
| 80 |
max = $rows.length; |
| 81 |
|
| 82 |
|
| 83 |
while (hasShuffled && indx < max) { |
| 84 |
hasShuffled = false; |
| 85 |
|
| 86 |
$rows.each(function() { |
| 87 |
targetIndex = $(this).data(wo.staticRow_data); |
| 88 |
|
| 89 |
targetIndex = targetIndex >= numRows ? numRows : targetIndex < 0 ? 0 : targetIndex; |
| 90 |
if (targetIndex !== $(this).index()) { |
| 91 |
hasShuffled = true; |
| 92 |
$thisRow = $(this).detach(); |
| 93 |
|
| 94 |
if (targetIndex >= numRows) { |
| 95 |
|
| 96 |
$thisRow.appendTo( $tbody ); |
| 97 |
} else if (targetIndex === 0) { |
| 98 |
|
| 99 |
$thisRow.prependTo( $tbody ); |
| 100 |
} else { |
| 101 |
|
| 102 |
$thisRow.insertBefore( $tbody.find('tr:eq(' + targetIndex + ')') ); |
| 103 |
} |
| 104 |
} |
| 105 |
}); |
| 106 |
indx++; |
| 107 |
} |
| 108 |
|
| 109 |
$.tablesorter.processTbody(table, $tbody, false); |
| 110 |
}); |
| 111 |
|
| 112 |
c.$table.triggerHandler('staticRowsComplete', table); |
| 113 |
}, |
| 114 |
|
| 115 |
remove : function(table, c, wo) { |
| 116 |
c.$table.unbind( ('updateComplete.tsstaticrows ' + wo.staticRow_event).replace(/\s+/g, ' ') ); |
| 117 |
} |
| 118 |
|
| 119 |
}); |
| 120 |
|
| 121 |
})(jQuery); |