123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- (function($) {
- $.chromatable = {
- defaults : {
- width : "900px",
- height : "300px",
- scrolling : "yes"
- }
- };
- $.fn.chromatable = function(options) {
-
- var options = $.extend({}, $.chromatable.defaults, options);
- return this
- .each(function() {
- var $this = $(this);
- var $uniqueID = $(this).attr("ID") + ("wrapper");
- $(this).css('width', options.width).addClass("_scrolling");
- $(this).wrap(
- '<div class="scrolling_outer"><div id="'
- + $uniqueID
- + '" class="scrolling_inner"></div></div>');
- $(".scrolling_outer").css({
- 'position' : 'relative'
- });
- $("#" + $uniqueID).css({
- 'border' : '1px solid #CCCCCC',
- 'overflow-x' : 'hidden',
- 'overflow-y' : 'auto',
- 'padding-right' : '17px'
- });
- $("#" + $uniqueID).css('height', options.height);
- $("#" + $uniqueID).css('width', options.width);
- $(this).before(
- $(this).clone().attr("id", "").addClass("_thead")
- .css({
- 'width' : 'auto',
- 'display' : 'block',
- 'position' : 'absolute',
- 'border' : 'none',
- 'border-bottom' : '1px solid #CCC',
- 'top' : '1px'
- }));
- $('._thead').children('tbody').remove();
- $(this)
- .each(
- function($this) {
- if (options.width == "100%"
- || options.width == "auto") {
- $("#" + $uniqueID).css({
- 'padding-right' : '0px'
- });
- }
- if (options.scrolling == "no") {
- $("#" + $uniqueID)
- .before(
- '<a href="javascript:;" class="expander" style="width:100%;">Expand table</a>');
- $("#" + $uniqueID).css({
- 'padding-right' : '0px'
- });
- $(".expander")
- .each(
- function(int) {
- $(this).attr(
- "ID",
- int);
- $(this)
- .bind(
- "click",
- function() {
- $("#"+ $uniqueID).css(
- {
- 'height' : 'auto'
- });
- $("#"+ $uniqueID+ " ._thead").remove();
- $(this).remove();
- });
- });
- $("#" + $uniqueID).resizable({
- handles : 's'
- }).css("overflow-y", "hidden");
- }
- });
- $curr = $this.prev();
- $("thead:eq(0)>tr th", this).each(
- function(i) {
- $("thead:eq(0)>tr th:eq(" + i + ")", $curr)
- .width($(this).width());
- });
- if (options.width == "100%" || "auto") {
- $(window).resize(function() {
- resizer($this);
- });
- }
- });
- };
- function resizer($this) {
- $curr = $this.prev();
- $("thead:eq(0)>tr th", $this).each(function(i) {
- $("thead:eq(0)>tr th:eq(" + i + ")", $curr).width($(this).width());
- });
- }
- ;
- })(jQuery);
|