2015-10-31 16:06:09 +00:00
|
|
|
/*! widget: staticRow - updated 10/31/2015 (v2.24.0) *//*
|
2015-02-09 23:01:27 +00:00
|
|
|
* Version 1.2 mod by Rob Garrison (requires tablesorter v2.16+)
|
2014-04-19 14:34:18 +00:00
|
|
|
* Requires:
|
|
|
|
* jQuery v1.4+
|
|
|
|
* tablesorter plugin, v2.8+, available at http://mottie.github.com/tablesorter/docs/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Nils Luxton
|
|
|
|
* Licensed under the MIT license:
|
|
|
|
* http://www.opensource.org/licenses/mit-license.php
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
|
|
|
/*global jQuery: false */
|
2018-03-17 20:30:25 +00:00
|
|
|
;(function($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
|
|
|
var ts = $.tablesorter,
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// add/refresh row indexes
|
2018-03-17 20:30:25 +00:00
|
|
|
addIndexes = function(table) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var $tr, wo, v, indx, rows,
|
|
|
|
c = table.config;
|
|
|
|
// 'Index' the static rows, saving their current (starting) position in the
|
|
|
|
// table inside a data() param on the <tr> element itself for later use.
|
|
|
|
if (c) {
|
|
|
|
wo = c.widgetOptions;
|
2018-03-17 20:30:25 +00:00
|
|
|
c.$tbodies.each(function() {
|
2015-07-23 04:29:51 +00:00
|
|
|
$tr = $(this).children();
|
|
|
|
rows = $tr.length;
|
|
|
|
$tr.filter(wo.staticRow_class).each(function() {
|
|
|
|
$tr = $(this);
|
|
|
|
indx = $tr.data(wo.staticRow_index);
|
|
|
|
if (typeof indx !== 'undefined') {
|
|
|
|
v = parseFloat(indx);
|
|
|
|
// percentage of total rows
|
|
|
|
indx = (/%/.test(indx)) ? Math.round(v / 100 * rows) : v;
|
|
|
|
} else {
|
|
|
|
indx = $tr.index();
|
|
|
|
}
|
|
|
|
// row indexing starts over within each tbody
|
|
|
|
$tr.data( wo.staticRow_data, indx );
|
|
|
|
});
|
2014-04-19 14:34:18 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
};
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
ts.addWidget({
|
|
|
|
// Give the new Widget an ID to be used in the tablesorter() call, as follows:
|
|
|
|
// $('#myElement').tablesorter({ widgets: ['zebra', 'staticRow'] });
|
|
|
|
id: 'staticRow',
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
options: {
|
|
|
|
staticRow_class : '.static',
|
|
|
|
staticRow_data : 'static-index',
|
|
|
|
staticRow_index : 'row-index',
|
|
|
|
staticRow_event : 'staticRowsRefresh'
|
|
|
|
},
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2018-03-17 20:30:25 +00:00
|
|
|
init: function(table, thisWidget, c, wo) {
|
2015-07-23 04:29:51 +00:00
|
|
|
addIndexes(table);
|
|
|
|
// refresh static rows after updates
|
|
|
|
c.$table
|
|
|
|
.unbind( ('updateComplete.tsstaticrows ' + wo.staticRow_event).replace(/\s+/g, ' ') )
|
2018-03-17 20:30:25 +00:00
|
|
|
.bind('updateComplete.tsstaticrows ' + wo.staticRow_event, function() {
|
2015-07-23 04:29:51 +00:00
|
|
|
addIndexes(table);
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
},
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
format: function(table, c, wo) {
|
|
|
|
// Loop thru static rows, moving them to their original 'indexed' position,
|
|
|
|
// & repeat until no more re-shuffling is needed
|
|
|
|
var targetIndex, $thisRow, indx, numRows, $tbody, hasShuffled, $rows, max;
|
2014-06-22 13:15:49 +00:00
|
|
|
|
2018-03-17 20:30:25 +00:00
|
|
|
c.$tbodies.each(function() {
|
2015-07-23 04:29:51 +00:00
|
|
|
$tbody = $.tablesorter.processTbody(table, $(this), true); // remove tbody
|
|
|
|
hasShuffled = true;
|
|
|
|
indx = 0;
|
|
|
|
$rows = $tbody.children(wo.staticRow_class);
|
|
|
|
numRows = $tbody.children('tr').length - 1;
|
|
|
|
max = $rows.length;
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// don't allow the while loop to cycle more times than the set number of static rows
|
|
|
|
while (hasShuffled && indx < max) {
|
|
|
|
hasShuffled = false;
|
|
|
|
/*jshint loopfunc:true */
|
|
|
|
$rows.each(function() {
|
|
|
|
targetIndex = $(this).data(wo.staticRow_data);
|
|
|
|
// allow setting target index >> num rows to always make a row last
|
|
|
|
targetIndex = targetIndex >= numRows ? numRows : targetIndex < 0 ? 0 : targetIndex;
|
|
|
|
if (targetIndex !== $(this).index()) {
|
|
|
|
hasShuffled = true;
|
|
|
|
$thisRow = $(this).detach();
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
if (targetIndex >= numRows) {
|
|
|
|
// Are we trying to be the last row?
|
|
|
|
$thisRow.appendTo( $tbody );
|
|
|
|
} else if (targetIndex === 0) {
|
2014-04-19 14:34:18 +00:00
|
|
|
// Are we trying to be the first row?
|
|
|
|
$thisRow.prependTo( $tbody );
|
2015-07-23 04:29:51 +00:00
|
|
|
} else {
|
|
|
|
// No, we want to be somewhere in the middle!
|
|
|
|
$thisRow.insertBefore( $tbody.find('tr:eq(' + targetIndex + ')') );
|
|
|
|
}
|
2014-04-19 14:34:18 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
indx++;
|
|
|
|
}
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
$.tablesorter.processTbody(table, $tbody, false); // restore tbody
|
|
|
|
});
|
2014-06-22 13:15:49 +00:00
|
|
|
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler('staticRowsComplete', table);
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2018-03-17 20:30:25 +00:00
|
|
|
remove : function(table, c, wo) {
|
2015-07-23 04:29:51 +00:00
|
|
|
c.$table.unbind( ('updateComplete.tsstaticrows ' + wo.staticRow_event).replace(/\s+/g, ' ') );
|
|
|
|
}
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
2014-04-19 14:34:18 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
})(jQuery);
|