mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
119 lines
2.8 KiB
JavaScript
119 lines
2.8 KiB
JavaScript
$(function(){
|
|
|
|
$("a.external").each(function(){this.target = '_new';});
|
|
|
|
var cleanupCode = function(code){
|
|
return code.replace(/[<>\"\'\t\n]/g, function(m) { return {
|
|
'<' : '<',
|
|
'>' : '>',
|
|
"'" : ''',
|
|
'"' : '"',
|
|
'\t': ' ',
|
|
'\n': '<br/>' // needed for IE
|
|
}[m]});
|
|
};
|
|
|
|
// get javascript source
|
|
if ($("#js").length) {
|
|
$("#javascript pre").addClass('mod').html( cleanupCode( $("#js").html() ) );
|
|
}
|
|
if ($("#css").length) {
|
|
$("pre.lang-css").addClass('mod').html( cleanupCode( $("#css").html() ) );
|
|
}
|
|
if ($("#demo").length) {
|
|
$("#html pre").addClass('mod').html( cleanupCode( $("#demo").html() ) );
|
|
}
|
|
|
|
// apply to already pre-formatted blocks to add <br> for IE
|
|
$('pre:not(.mod)').each(function(){
|
|
var $t = $(this);
|
|
$t.html( cleanupCode( $t.html() ) );
|
|
});
|
|
|
|
if (typeof prettyPrint !== 'undefined') { prettyPrint(); }
|
|
|
|
// hide child rows
|
|
$('#root .tablesorter-childRow').hide();
|
|
// toggle child row content, not hiding the row since we are using rowspan
|
|
$('#root .toggle').click(function(){
|
|
$(this).closest('tr').nextUntil('tr:not(.tablesorter-childRow)').toggle();
|
|
return false;
|
|
});
|
|
|
|
var animating = false;
|
|
|
|
$('.collapsible').hide();
|
|
$('.toggle2')
|
|
.click(function(e){
|
|
if (!animating) {
|
|
animating = true;
|
|
$(this).closest('tr').find('.collapsible').slideToggle();
|
|
setTimeout(function(){ animating = false; }, 200);
|
|
}
|
|
return false;
|
|
});
|
|
$('.toggle2, span.permalink')
|
|
.dblclick(function(){
|
|
window.location.hash = '#' + $(this).closest('tr')[0].id;
|
|
return false;
|
|
});
|
|
|
|
$('.toggleAll, .showAll, .hideAll').click(function(){
|
|
var t = $.trim($(this).text());
|
|
$(this).parent().next('table').find('.collapsible')[t]();
|
|
return false;
|
|
});
|
|
|
|
// update version number
|
|
var t = $('.current-version');
|
|
if (t.length) {
|
|
t.html($.tablesorter.version);
|
|
}
|
|
|
|
});
|
|
|
|
function showProperty(){
|
|
var prop, h = window.location.hash;
|
|
if (h) {
|
|
prop = $(h);
|
|
if (prop.length && prop[0].tagName !== "TABLE") {
|
|
prop.find('.collapsible').show();
|
|
if (h === '#csschildrow') {
|
|
$('#root .tablesorter-childRow').show();
|
|
}
|
|
// move below sticky header
|
|
if (/options/.test(prop.closest('table').attr('id') || '')) {
|
|
$(window).scrollTop( prop.position().top - 30 );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$(window).load(function(){
|
|
|
|
$(window).bind('hashchange', function(){
|
|
showProperty();
|
|
});
|
|
showProperty();
|
|
|
|
});
|
|
|
|
// append hidden parsed value to cell
|
|
var addParsedValues = function($t, cols, format){
|
|
var i, j, r,
|
|
$r = $t.find('tbody tr'),
|
|
c = $t[0].config.cache[0].normalized,
|
|
l = c.length - 1;
|
|
$r.each(function(i){
|
|
r = this;
|
|
$.each(cols, function(v,j){
|
|
r.cells[j].innerHTML += ' <span class="val hidden">(<span class="results">' + (format ? format(c[i][j]) : c[i][j]) + '</span>)</span>';
|
|
});
|
|
});
|
|
|
|
$('.toggleparsedvalue').on('click', function(){
|
|
$('.val').toggleClass('hidden');
|
|
});
|
|
|
|
};
|