jQuery(document).ready(function($) {
$('.truncate > tbody > tr > td').livequery(function() {
//$(this).css({whiteSpace:'nowrap'});
var c=$('> *',this);
if (c.length==0) {
$(this).css({verticalAlign:'top'});
$(this).html('
');
}
var t=$(this).parents('.truncate:eq(0)').addClass('resize');
});
$('.truncatetxt').livequery(function() {
$(this).hover(function() {
$(this).parent().css({zIndex:2});
$(this).css({position:'absolute',height:'auto',whiteSpace:'normal',top:0,background:'#fff',wordWrap:'break-word','zIndex':2,border:'1px solid #ccc'});
},function() {
$(this).parent().css({zIndex:1});
$(this).css({position:'static',height:'1.2em',whiteSpace:'nowrap',background:'transparent',wordWrap:'normal',border:'none'});
})
});
var truncatewidth=$(window).width();
var truncatecallback=null;
$(window).resize(function() {
if ($(window).width()==truncatewidth)
return;
truncatewidth=$(window).width();
if (truncatecallback!==null) {
window.clearTimeout(truncatecallback);
}
truncatecallback=window.setTimeout(function() {
$('.truncate').addClass('resize');
truncatecallback=null;
},100);
});
$('.truncate.resize').livequery(function() {
$('.truncatetxt',this).width('auto');
$('> tbody > tr > td',this).width('auto');
$(this).width('100%');
$('> tbody',this).hide();
var w=$(this).width();
$('> tbody',this).show();
var nw=$(this).width();
if (nw>w) {
var c=$('> tbody > tr:eq(0)',this).children();
var n=c.length;
// remove the ones which are not as wide as equal widths.
var ow=w/n;
var o=[];
var ws={};
var nr={};
var wss=0;
c.each(function(k) {
var tw=$(this).width();
if (tw<=ow || $('> div > .truncatetxt',this).length==0) {
w-=tw;
n-=1;
} else {
ws[k]=tw;
wss+=tw;
o.push(c);
}
});
if (n>0) {
var pe=(w/wss)*0.9;
for (k in ws) {
if (!ws.hasOwnProperty(k))
continue;
ws[k]=ws[k]*pe;
}
$('> tbody > tr',this).each(function() {
var ch=$(this).children();
for (k in ws) {
if (!ws.hasOwnProperty(k))
continue;
if (typeof(ch[k])=='undefined')
continue;
$(ch[k]).width(ws[k]);
$('> div > .truncatetxt',ch[k]).width(ws[k]);
}
});
}
}
$(this).removeClass('resize');
});
});