Line 0
Link Here
|
|
|
1 |
// Set expiration date for cookies |
2 |
var date = new Date(); |
3 |
date.setTime(date.getTime()+(365*24*60*60*1000)); |
4 |
var expiration = date.toGMTString(); |
5 |
|
6 |
|
7 |
function hideColumns(){ |
8 |
valCookie = YAHOO.util.Cookie.get("showColumns", function(stringValue){ |
9 |
return stringValue.split("/"); |
10 |
}); |
11 |
if(valCookie){ |
12 |
$("#showall").attr("checked","").parent().removeClass("selected"); |
13 |
for( i=0; i<valCookie.length; i++ ){ |
14 |
if(valCookie[i] != ''){ |
15 |
index = valCookie[i] - 2; |
16 |
$("#itemst td:nth-child("+valCookie[i]+"),#itemst th:nth-child("+valCookie[i]+")").toggle(); |
17 |
$("#checkheader"+index).attr("checked","").parent().removeClass("selected"); |
18 |
} |
19 |
} |
20 |
} |
21 |
} |
22 |
|
23 |
function hideColumn(num) { |
24 |
$("#hideall,#showall").attr("checked","").parent().removeClass("selected"); |
25 |
valCookie = YAHOO.util.Cookie.get("showColumns", function(stringValue){ |
26 |
return stringValue.split("/"); |
27 |
}); |
28 |
// set the index of the table column to hide |
29 |
$("#"+num).parent().removeClass("selected"); |
30 |
var hide = Number(num.replace("checkheader","")) + 2; |
31 |
// hide header and cells matching the index |
32 |
$("#itemst td:nth-child("+hide+"),#itemst th:nth-child("+hide+")").toggle(); |
33 |
// set or modify cookie with the hidden column's index |
34 |
if(valCookie){ |
35 |
var found = false; |
36 |
for( $i=0; $i<valCookie.length; $i++ ){ |
37 |
if (hide == valCookie[i]) { |
38 |
found = true; |
39 |
break; |
40 |
} |
41 |
} |
42 |
if( !found ){ |
43 |
valCookie.push(hide); |
44 |
var cookieString = valCookie.join("/"); |
45 |
YAHOO.util.Cookie.set("showColumns", cookieString, { |
46 |
expires: date |
47 |
}); |
48 |
} |
49 |
} else { |
50 |
YAHOO.util.Cookie.set("showColumns", hide, { |
51 |
expires: date |
52 |
}); |
53 |
} |
54 |
} |
55 |
|
56 |
// Array Remove - By John Resig (MIT Licensed) |
57 |
// http://ejohn.org/blog/javascript-array-remove/ |
58 |
Array.prototype.remove = function(from, to) { |
59 |
var rest = this.slice((to || from) + 1 || this.length); |
60 |
this.length = from < 0 ? this.length + from : from; |
61 |
return this.push.apply(this, rest); |
62 |
}; |
63 |
|
64 |
function showColumn(num){ |
65 |
$("#hideall").attr("checked","").parent().removeClass("selected"); |
66 |
$("#"+num).parent().addClass("selected"); |
67 |
valCookie = YAHOO.util.Cookie.get("showColumns", function(stringValue){ |
68 |
return stringValue.split("/"); |
69 |
}); |
70 |
// set the index of the table column to hide |
71 |
show = Number(num.replace("checkheader","")) + 2; |
72 |
// hide header and cells matching the index |
73 |
$("#itemst td:nth-child("+show+"),#itemst th:nth-child("+show+")").toggle(); |
74 |
// set or modify cookie with the hidden column's index |
75 |
if(valCookie){ |
76 |
var found = false; |
77 |
for( i=0; i<valCookie.length; i++ ){ |
78 |
if (show == valCookie[i]) { |
79 |
valCookie.remove(i); |
80 |
found = true; |
81 |
} |
82 |
} |
83 |
if( found ){ |
84 |
var cookieString = valCookie.join("/"); |
85 |
YAHOO.util.Cookie.set("showColumns", cookieString, { |
86 |
expires: date |
87 |
}); |
88 |
} |
89 |
} |
90 |
} |
91 |
function showAllColumns(){ |
92 |
$("#selections").checkCheckboxes(); |
93 |
$("#selections span").addClass("selected"); |
94 |
$("#itemst td:nth-child(2),#itemst tr th:nth-child(2)").nextAll().show(); |
95 |
YAHOO.util.Cookie.remove("showColumns"); |
96 |
$("#hideall").attr("checked","").parent().removeClass("selected"); |
97 |
} |
98 |
function hideAllColumns(){ |
99 |
$("#selections").unCheckCheckboxes(); |
100 |
$("#selections span").removeClass("selected"); |
101 |
$("#itemst td:nth-child(2),#itemst th:nth-child(2)").nextAll().hide(); |
102 |
$("#hideall").attr("checked","checked").parent().addClass("selected"); |
103 |
var cookieString = allColumns.join("/"); |
104 |
YAHOO.util.Cookie.set("showColumns", cookieString, { |
105 |
expires: date |
106 |
}); |
107 |
} |
108 |
|
109 |
$(document).ready(function() { |
110 |
hideColumns(); |
111 |
$("#itemst").tablesorter({ |
112 |
widgets : ['zebra'], |
113 |
headers: {0:{sorter: false}} |
114 |
}); |
115 |
$("#selectallbutton").click(function(){ |
116 |
$("#itemst").checkCheckboxes(); |
117 |
return false; |
118 |
}); |
119 |
$("#clearallbutton").click(function(){ |
120 |
$("#itemst").unCheckCheckboxes(); |
121 |
return false; |
122 |
}); |
123 |
$("#selections input").change(function(e){ |
124 |
var num = $(this).attr("id"); |
125 |
if(num == 'showall'){ |
126 |
showAllColumns(); |
127 |
e.stopPropagation(); |
128 |
} else if(num == 'hideall'){ |
129 |
hideAllColumns(); |
130 |
e.stopPropagation(); |
131 |
} else { |
132 |
if($(this).attr("checked")){ |
133 |
showColumn(num); |
134 |
} else { |
135 |
hideColumn(num); |
136 |
} |
137 |
} |
138 |
}); |
139 |
}); |