forked from vanilla/vanilla
/
jquery.gardencheckcolumn.js
executable file
·55 lines (49 loc) · 1.58 KB
/
jquery.gardencheckcolumn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Garden CheckColumn Plugin (1.1)
* by Mark O'Sullivan (mark@vanillaforums.com)
* by Tim Gunter (tim@vanillaforums.com)
*
* Copyright (c) 2008 Vanilla Forums, Inc
* Licensed under the GPL (GPL-LICENSE.txt) license.
*
* NOTE: This script requires jQuery to work.
* Download jQuery at www.jquery.com
*/
jQuery(document).ready(function($){
$.fn.checkColumn = function(opt) {
opt = $.extend({
noOptionsYet: 0
}, opt);
// Remove the cellpadding on anchor cells
$(this).find('thead td').css('padding', '0px');
// Handle column heading clicks
$(this).find('thead td').each(function(i,el) {
el = $(el);
var columnIndex = el.prop('cellIndex');
var text = el.html();
el.html('');
var anchor = $('<a></a>');
anchor.click(function(event) {
var rows = $(el).parents('table').find('tbody tr');
var checkbox = false;
rows.each(function(j,row){
checkbox = $(row).find('td:eq(' + (columnIndex) + ')').find(":checkbox");
if (checkbox) {
if (checkbox.prop('checked')) {
checkbox.removeAttr('checked');
} else {
checkbox.prop('checked', 'checked');
}
}
})
return false;
});
anchor.html(text);
anchor.prop('href', '#');
el.append(anchor);
});
// Return the object for chaining
return $(this);
}
$('table.CheckColumn').checkColumn();
});