forked from DGNum/gestioCOF
Commit gore : premier push vers git.eleves
This commit is contained in:
parent
e2e3bcd2b8
commit
392be324f6
2961 changed files with 295287 additions and 20 deletions
19
media/js/joequery-Stupid-Table-Plugin/LICENSE
Normal file
19
media/js/joequery-Stupid-Table-Plugin/LICENSE
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2012 Joseph McCullough
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
166
media/js/joequery-Stupid-Table-Plugin/README.md
Normal file
166
media/js/joequery-Stupid-Table-Plugin/README.md
Normal file
|
@ -0,0 +1,166 @@
|
|||
Stupid jQuery Table Sort
|
||||
========================
|
||||
|
||||
This is a stupid jQuery table sorting plugin. Nothing fancy, nothing really
|
||||
impressive. Overall, stupidly simple.
|
||||
|
||||
[View the demo here][0]
|
||||
|
||||
See the example.html document to see how to implement it.
|
||||
|
||||
|
||||
Example Usage
|
||||
-------------
|
||||
|
||||
The JS:
|
||||
|
||||
$("table").stupidtable();
|
||||
|
||||
The HTML:
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="int">int</th>
|
||||
<th data-sort="float">float</th>
|
||||
<th data-sort="string">string</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td>-.18</td>
|
||||
<td>banana</td>
|
||||
</tr>
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
The thead and tbody tags must be used.
|
||||
|
||||
Add a `data-sort` attribute of "DATATYPE" to the th elements to make them sortable
|
||||
by that data type. If you don't want that column to be sortable, just omit the
|
||||
`data-sort` attribute.
|
||||
|
||||
|
||||
Predefined data types
|
||||
---------------------
|
||||
|
||||
Our aim is to keep this plugin as lightweight as possible. Consequently, the
|
||||
only predefined datatypes that you can pass to the th elements are
|
||||
|
||||
* `int`
|
||||
* `float`
|
||||
* `string` (case-sensitive)
|
||||
* `string-ins` (case-insensitive)
|
||||
|
||||
These data types will be sufficient for many simple tables. However, if you need
|
||||
different data types for sorting, you can easily create your own!
|
||||
|
||||
|
||||
Creating your own data types
|
||||
----------------------------
|
||||
|
||||
Creating your own data type for sorting purposes is easy as long as you are
|
||||
comfortable using custom functions for sorting. Consult [Mozilla's Docs][1]
|
||||
if you're not.
|
||||
|
||||
Let's create an alphanum datatype for a User ID that takes strings in the
|
||||
form "D10", "A40", and sorts them based on the number.
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="string">Name</th>
|
||||
<th data-sort="int">Age</th>
|
||||
<th data-sort="alphanum">UserID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Joseph McCullough</td>
|
||||
<td>20</td>
|
||||
<td>D10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Justin Edwards</td>
|
||||
<td>29</td>
|
||||
<td>A40</td>
|
||||
</tr>
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
Now we need to specify how the **alphanum** type will be sorted. To do that,
|
||||
we do the following:
|
||||
|
||||
$("table").stupidtable({
|
||||
"alphanum":function(a,b){
|
||||
|
||||
var pattern = "^[A-Z](\\d+)$";
|
||||
var re = new RegExp(pattern);
|
||||
|
||||
var aNum = re.exec(a).slice(1);
|
||||
var bNum = re.exec(b).slice(1);
|
||||
|
||||
return parseInt(aNum,10) - parseInt(bNum,10);
|
||||
}
|
||||
});
|
||||
|
||||
This extracts the integers from the cell and compares them in the style
|
||||
that sort functions use.
|
||||
|
||||
|
||||
Callbacks
|
||||
---------
|
||||
|
||||
To execute a callback function after a table column has been sorted, you can
|
||||
bind on `aftertablesort`.
|
||||
|
||||
var table = $("table").stupidtable();
|
||||
table.bind('aftertablesort', function (event, data) {
|
||||
// data.column - the index of the column sorted after a click
|
||||
// data.direction - the sorting direction (either asc or desc)
|
||||
// $(this) - this table object
|
||||
|
||||
console.log("The sorting direction: " + data.direction);
|
||||
console.log("The column index: " + data.column);
|
||||
});
|
||||
|
||||
Similarly, to execute a callback before a table column has been sorted, you can
|
||||
bind on `beforetablesort`.
|
||||
|
||||
See the complex_example.html file.
|
||||
|
||||
|
||||
Data with multiple representations/predefined order
|
||||
---------------------------------------------------
|
||||
|
||||
Often we find two distinct ways of offering data: In a machine friendly way,
|
||||
and a Human-friendly way. A clear example is a Timestamp. Additionally,
|
||||
arbitrary data values may already have a predefined sort order. In either case,
|
||||
it's to our advantage to have a way to store the "sortable data" while letting
|
||||
the viewer see the Human-friendly representation of that data. While the
|
||||
purpose of the custom sort methods is to take data and make it sortable
|
||||
(machine friendly), sometimes this is too hard or too expensive, computationally
|
||||
speaking.
|
||||
|
||||
To solve this problem, you can specify a `data-sort-value` attribute to
|
||||
table cells, and the attribute value will be the basis of the sort as opposed
|
||||
to the text value of the table cell. See the complex_example.html file, where
|
||||
we sort a column of letters based not on their alphabetical order, but by their
|
||||
frequency in the English language. You'll still need to specify a sort type
|
||||
or come up with your own custom sort function, but the presence of the
|
||||
`data-sort-value` attribute tells the plugin to use the value of the
|
||||
attribute as the basis of the sort.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
The Stupid jQuery Plugin is licensed under the MIT license. See the LICENSE
|
||||
file for full details.
|
||||
|
||||
|
||||
|
||||
[0]: http://joequery.github.com/Stupid-Table-Plugin/
|
||||
[1]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort
|
77
media/js/joequery-Stupid-Table-Plugin/examples/basic.html
Normal file
77
media/js/joequery-Stupid-Table-Plugin/examples/basic.html
Normal file
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Stupid jQuery table sort</title>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="../stupidtable.js?dev"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
$("table").stupidtable();
|
||||
});
|
||||
</script>
|
||||
<style type="text/css">
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
th {
|
||||
background-color: #eee;
|
||||
}
|
||||
th[data-sort]{
|
||||
cursor:pointer;
|
||||
}
|
||||
tr.awesome{
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Stupid jQuery table sort!</h1>
|
||||
|
||||
<p>This example shows how a sortable table can be implemented with very little configuration. Simply specify the data type on a <code><th></code> element using the <code>data-sort</code> attribute, and the plugin handles the rest.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="int">int</th>
|
||||
<th data-sort="float">float</th>
|
||||
<th data-sort="string">string</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td>-.18</td>
|
||||
<td>banana</td>
|
||||
</tr>
|
||||
<tr class="awesome">
|
||||
<td>95</td>
|
||||
<td>36</td>
|
||||
<td>coke</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>-152.5</td>
|
||||
<td>apple</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>-53</td>
|
||||
<td>88.5</td>
|
||||
<td>zebra</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>195</td>
|
||||
<td>-858</td>
|
||||
<td>orange</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
70
media/js/joequery-Stupid-Table-Plugin/examples/colspan.html
Normal file
70
media/js/joequery-Stupid-Table-Plugin/examples/colspan.html
Normal file
|
@ -0,0 +1,70 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Stupid jQuery table sort (colspan test)</title>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="../stupidtable.js?dev"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
$("table").stupidtable();
|
||||
});
|
||||
</script>
|
||||
<style type="text/css">
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
th {
|
||||
background-color: #eee;
|
||||
}
|
||||
th[data-sort]{
|
||||
cursor:pointer;
|
||||
}
|
||||
tr.awesome{
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Stupid jQuery table sort! (colspan test)</h1>
|
||||
|
||||
<p>Tables using colspans are handled just fine.</p>
|
||||
|
||||
<table id="stupid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="string">Letter</td>
|
||||
<th colspan="2" data-sort="string">colspan=2</th>
|
||||
<th data-sort="int">Number</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>def</td>
|
||||
<td>X</td>
|
||||
<td>9</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>abc</td>
|
||||
<td>Z</td>
|
||||
<td>8</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>bcd</td>
|
||||
<td>Y</td>
|
||||
<td>7</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
183
media/js/joequery-Stupid-Table-Plugin/examples/complex.html
Normal file
183
media/js/joequery-Stupid-Table-Plugin/examples/complex.html
Normal file
|
@ -0,0 +1,183 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Stupid jQuery table sort (complex example)</title>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="../stupidtable.js?dev"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
// Helper function to convert a string of the form "Mar 15, 1987" into
|
||||
// a Date object.
|
||||
var date_from_string = function(str){
|
||||
var months = ["jan","feb","mar","apr","may","jun","jul",
|
||||
"aug","sep","oct","nov","dec"];
|
||||
var pattern = "^([a-zA-Z]{3})\\s*(\\d{2}),\\s*(\\d{4})$";
|
||||
var re = new RegExp(pattern);
|
||||
var DateParts = re.exec(str).slice(1);
|
||||
|
||||
var Year = DateParts[2];
|
||||
var Month = $.inArray(DateParts[0].toLowerCase(), months);
|
||||
var Day = DateParts[1];
|
||||
return new Date(Year, Month, Day);
|
||||
}
|
||||
|
||||
var moveBlanks = function(a, b) {
|
||||
if ( a < b ){
|
||||
if (a == "")
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
if ( a > b ){
|
||||
if (b == "")
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
var moveBlanksDesc = function(a, b) {
|
||||
// Blanks are by definition the smallest value, so we don't have to
|
||||
// worry about them here
|
||||
if ( a < b )
|
||||
return 1;
|
||||
if ( a > b )
|
||||
return -1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
var table = $("table").stupidtable({
|
||||
"date":function(a,b){
|
||||
// Get these into date objects for comparison.
|
||||
|
||||
aDate = date_from_string(a);
|
||||
bDate = date_from_string(b);
|
||||
|
||||
return aDate - bDate;
|
||||
},
|
||||
"moveBlanks": moveBlanks,
|
||||
"moveBlanksDesc": moveBlanksDesc,
|
||||
});
|
||||
|
||||
table.on("beforetablesort", function (event, data) {
|
||||
// data.column - the index of the column sorted after a click
|
||||
// data.direction - the sorting direction (either asc or desc)
|
||||
$("#msg").text("Sorting index " + data.column)
|
||||
});
|
||||
|
||||
table.on("aftertablesort", function (event, data) {
|
||||
var th = $(this).find("th");
|
||||
th.find(".arrow").remove();
|
||||
var dir = $.fn.stupidtable.dir;
|
||||
|
||||
var arrow = data.direction === dir.ASC ? "↑" : "↓";
|
||||
th.eq(data.column).append('<span class="arrow">' + arrow +'</span>');
|
||||
});
|
||||
|
||||
$("tr").slice(1).click(function(){
|
||||
$(".awesome").removeClass("awesome");
|
||||
$(this).addClass("awesome");
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<style type="text/css">
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
th {
|
||||
background-color: #eee;
|
||||
}
|
||||
th[data-sort]{
|
||||
cursor:pointer;
|
||||
}
|
||||
tr.awesome{
|
||||
color: red;
|
||||
}
|
||||
#msg {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Stupid jQuery table sort! (complex example)</h1>
|
||||
|
||||
<p>This example showcases several of the more advanced features, including specifying sort values, custom data types and callbacks. View the source of this file or see the <a href="http://joequery.github.com/Stupid-Table-Plugin/">documentation</a> for more details on how to implement them.</p>
|
||||
|
||||
<p id="msg"> </p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="int">int</th>
|
||||
<th data-sort="int">int</th>
|
||||
<th data-sort="float">float</th>
|
||||
<th data-sort="moveBlanks" data-sort-desc="moveBlanksDesc">string</th>
|
||||
<th data-sort="string-ins">case</th>
|
||||
<th>Can't sort me!</th>
|
||||
<th data-sort="date">date</th>
|
||||
<th data-sort="int">Letter frequency</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td>15</td>
|
||||
<td>-.18</td>
|
||||
<td>banana</td>
|
||||
<td>Homer</td>
|
||||
<td>arbitrary</td>
|
||||
<td>Sep 15, 2002</td>
|
||||
<td data-sort-value="0">E</td>
|
||||
</tr>
|
||||
<tr class="awesome">
|
||||
<td>95</td>
|
||||
<td>95</td>
|
||||
<td>36</td>
|
||||
<td></td>
|
||||
<td>purple</td>
|
||||
<td>pointless</td>
|
||||
<td>Aug 07, 2004</td>
|
||||
<td data-sort-value="1">T</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>2</td>
|
||||
<td>-152.5</td>
|
||||
<td></td>
|
||||
<td>is</td>
|
||||
<td>silly</td>
|
||||
<td>Mar 15, 1986</td>
|
||||
<td data-sort-value="2">A</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>-53</td>
|
||||
<td>-53</td>
|
||||
<td>88.5</td>
|
||||
<td>hello</td>
|
||||
<td>a</td>
|
||||
<td>eccentric</td>
|
||||
<td>Feb 27, 2086</td>
|
||||
<td data-sort-value="3">O</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>195</td>
|
||||
<td>195</td>
|
||||
<td>-858</td>
|
||||
<td>orange</td>
|
||||
<td>fruit</td>
|
||||
<td>garbage</td>
|
||||
<td>Mar 15, 1986</td>
|
||||
<td data-sort-value="4">I</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
5524
media/js/joequery-Stupid-Table-Plugin/examples/large-table.html
Normal file
5524
media/js/joequery-Stupid-Table-Plugin/examples/large-table.html
Normal file
File diff suppressed because it is too large
Load diff
158
media/js/joequery-Stupid-Table-Plugin/stupidtable.js
Normal file
158
media/js/joequery-Stupid-Table-Plugin/stupidtable.js
Normal file
|
@ -0,0 +1,158 @@
|
|||
// Stupid jQuery table plugin.
|
||||
|
||||
// Call on a table
|
||||
// sortFns: Sort functions for your datatypes.
|
||||
(function($) {
|
||||
|
||||
$.fn.stupidtable = function(sortFns) {
|
||||
return this.each(function() {
|
||||
var $table = $(this);
|
||||
sortFns = sortFns || {};
|
||||
|
||||
// ==================================================== //
|
||||
// Utility functions //
|
||||
// ==================================================== //
|
||||
|
||||
// Merge sort functions with some default sort functions.
|
||||
sortFns = $.extend({}, $.fn.stupidtable.default_sort_fns, sortFns);
|
||||
|
||||
// Return the resulting indexes of a sort so we can apply
|
||||
// this result elsewhere. This returns an array of index numbers.
|
||||
// return[0] = x means "arr's 0th element is now at x"
|
||||
var sort_map = function(arr, sort_function, reverse_column) {
|
||||
var map = [];
|
||||
var index = 0;
|
||||
if (reverse_column) {
|
||||
for (var i = arr.length-1; i >= 0; i--) {
|
||||
map.push(i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var sorted = arr.slice(0).sort(sort_function);
|
||||
for (var i=0; i<arr.length; i++) {
|
||||
index = $.inArray(arr[i], sorted);
|
||||
|
||||
// If this index is already in the map, look for the next index.
|
||||
// This handles the case of duplicate entries.
|
||||
while ($.inArray(index, map) != -1) {
|
||||
index++;
|
||||
}
|
||||
map.push(index);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
};
|
||||
|
||||
// Apply a sort map to the array.
|
||||
var apply_sort_map = function(arr, map) {
|
||||
var clone = arr.slice(0),
|
||||
newIndex = 0;
|
||||
for (var i=0; i<map.length; i++) {
|
||||
newIndex = map[i];
|
||||
clone[newIndex] = arr[i];
|
||||
}
|
||||
return clone;
|
||||
};
|
||||
|
||||
// ==================================================== //
|
||||
// Begin execution! //
|
||||
// ==================================================== //
|
||||
|
||||
// Do sorting when THs are clicked
|
||||
$table.on("click", "th", function() {
|
||||
var trs = $table.children("tbody").children("tr");
|
||||
var $this = $(this);
|
||||
var th_index = 0;
|
||||
var dir = $.fn.stupidtable.dir;
|
||||
|
||||
$table.find("th").slice(0, $this.index()).each(function() {
|
||||
var cols = $(this).attr("colspan") || 1;
|
||||
th_index += parseInt(cols,10);
|
||||
});
|
||||
|
||||
// Determine (and/or reverse) sorting direction, default `asc`
|
||||
var sort_dir = $this.data("sort-dir") === dir.ASC ? dir.DESC : dir.ASC;
|
||||
|
||||
// Choose appropriate sorting function. If we're sorting descending, check
|
||||
// for a `data-sort-desc` attribute.
|
||||
if ( sort_dir == dir.DESC )
|
||||
var type = $this.data("sort-desc") || $this.data("sort") || null;
|
||||
else
|
||||
var type = $this.data("sort") || null;
|
||||
|
||||
// Prevent sorting if no type defined
|
||||
if (type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger `beforetablesort` event that calling scripts can hook into;
|
||||
// pass parameters for sorted column index and sorting direction
|
||||
$table.trigger("beforetablesort", {column: th_index, direction: sort_dir});
|
||||
// More reliable method of forcing a redraw
|
||||
$table.css("display");
|
||||
|
||||
// Run sorting asynchronously on a timout to force browser redraw after
|
||||
// `beforetablesort` callback. Also avoids locking up the browser too much.
|
||||
setTimeout(function() {
|
||||
// Gather the elements for this column
|
||||
var column = [];
|
||||
var sortMethod = sortFns[type];
|
||||
|
||||
// Push either the value of the `data-order-by` attribute if specified
|
||||
// or just the text() value in this column to column[] for comparison.
|
||||
trs.each(function(index,tr) {
|
||||
var $e = $(tr).children().eq(th_index);
|
||||
var sort_val = $e.data("sort-value");
|
||||
var order_by = typeof(sort_val) !== "undefined" ? sort_val : $e.text();
|
||||
column.push(order_by);
|
||||
});
|
||||
|
||||
// Create the sort map. This column having a sort-dir implies it was
|
||||
// the last column sorted. As long as no data-sort-desc is specified,
|
||||
// we're free to just reverse the column.
|
||||
var reverse_column = !!$this.data("sort-dir") && !$this.data("sort-desc");
|
||||
var theMap = sort_map(column, sortMethod, reverse_column);
|
||||
|
||||
// Reset siblings
|
||||
$table.find("th").data("sort-dir", null).removeClass("sorting-desc sorting-asc");
|
||||
$this.data("sort-dir", sort_dir).addClass("sorting-"+sort_dir);
|
||||
|
||||
// Replace the content of tbody with the sortedTRs. Strangely (and
|
||||
// conveniently!) enough, .append accomplishes this for us.
|
||||
var sortedTRs = $(apply_sort_map(trs, theMap));
|
||||
$table.children("tbody").append(sortedTRs);
|
||||
|
||||
// Trigger `aftertablesort` event. Similar to `beforetablesort`
|
||||
$table.trigger("aftertablesort", {column: th_index, direction: sort_dir});
|
||||
// More reliable method of forcing a redraw
|
||||
$table.css("display");
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Enum containing sorting directions
|
||||
$.fn.stupidtable.dir = {ASC: "asc", DESC: "desc"};
|
||||
|
||||
$.fn.stupidtable.default_sort_fns = {
|
||||
"int": function(a, b) {
|
||||
return parseInt(a, 10) - parseInt(b, 10);
|
||||
},
|
||||
"float": function(a, b) {
|
||||
return parseFloat(a) - parseFloat(b);
|
||||
},
|
||||
"string": function(a, b) {
|
||||
if (a < b) return -1;
|
||||
if (a > b) return +1;
|
||||
return 0;
|
||||
},
|
||||
"string-ins": function(a, b) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
if (a < b) return -1;
|
||||
if (a > b) return +1;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
3
media/js/joequery-Stupid-Table-Plugin/stupidtable.min.js
vendored
Normal file
3
media/js/joequery-Stupid-Table-Plugin/stupidtable.min.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
(function(d){d.fn.stupidtable=function(b){return this.each(function(){var a=d(this);b=b||{};b=d.extend({},d.fn.stupidtable.default_sort_fns,b);a.on("click","th",function(){var n=a.children("tbody").children("tr"),e=d(this),j=0,m=d.fn.stupidtable.dir;a.find("th").slice(0,e.index()).each(function(){var a=d(this).attr("colspan")||1;j+=parseInt(a,10)});var l=e.data("sort-dir")===m.ASC?m.DESC:m.ASC,p=l==m.DESC?e.data("sort-desc")||e.data("sort")||null:e.data("sort")||null;null!==p&&(a.trigger("beforetablesort",
|
||||
{column:j,direction:l}),a.css("display"),setTimeout(function(){var k=[],c=b[p];n.each(function(a,b){var c=d(b).children().eq(j),e=c.data("sort-value"),c="undefined"!==typeof e?e:c.text();k.push(c)});var f=[],g=0;if(e.data("sort-dir")&&!e.data("sort-desc"))for(c=k.length-1;0<=c;c--)f.push(c);else for(var h=k.slice(0).sort(c),c=0;c<k.length;c++){for(g=d.inArray(k[c],h);-1!=d.inArray(g,f);)g++;f.push(g)}a.find("th").data("sort-dir",null).removeClass("sorting-desc sorting-asc");e.data("sort-dir",l).addClass("sorting-"+
|
||||
l);g=n.slice(0);for(h=c=0;h<f.length;h++)c=f[h],g[c]=n[h];f=d(g);a.children("tbody").append(f);a.trigger("aftertablesort",{column:j,direction:l});a.css("display")},10))})})};d.fn.stupidtable.dir={ASC:"asc",DESC:"desc"};d.fn.stupidtable.default_sort_fns={"int":function(b,a){return parseInt(b,10)-parseInt(a,10)},"float":function(b,a){return parseFloat(b)-parseFloat(a)},string:function(b,a){return b<a?-1:b>a?1:0},"string-ins":function(b,a){b=b.toLowerCase();a=a.toLowerCase();return b<a?-1:b>a?1:0}}})(jQuery);
|
4
media/js/jquery.min.js
vendored
Normal file
4
media/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue