Fixed-Header-Table/jquery.fixedheadertable.min.js

21 lines
10 KiB
JavaScript
Raw Normal View History

/*!
* jquery.fixedHeaderTable. The jQuery fixedHeaderTable plugin
*
* Copyright (c) 2013 Mark Malek
* http://fixedheadertable.com
*
* Licensed under MIT
* http://www.opensource.org/licenses/mit-license.php
*
* http://docs.jquery.com/Plugins/Authoring
* jQuery authoring guidelines
*
* Launch : October 2009
* Version : 1.3
* Released: May 9th, 2011
*
*
* all CSS sizing (width,height) is done in pixels (px)
2014-02-27 14:45:57 +04:00
*/(function(c){c.fn.fixedHeaderTable=function(m){var u={width:"100%",height:"100%",themeClass:"fht-default",borderCollapse:!0,fixedColumns:0,fixedColumn:!1,sortable:!1,autoShow:!0,footer:!1,cloneHeadToFoot:!1,autoResize:!1,create:null},b={},n={init:function(a){b=c.extend({},u,a);return this.each(function(){var a=c(this);h._isTable(a)?(n.setup.apply(this,Array.prototype.slice.call(arguments,1)),c.isFunction(b.create)&&b.create.call(this)):c.error("Invalid table mark-up")})},setup:function(){var a=c(this), d=a.find("thead"),e=a.find("tfoot"),g=0,f,k,p;b.originalTable=c(this).clone();b.includePadding=h._isPaddingIncludedWithWidth();b.scrollbarOffset=h._getScrollbarWidth();b.themeClassName=b.themeClass;f=-1<b.width.search("%")?a.parent().width()-b.scrollbarOffset:b.width-b.scrollbarOffset;a.css({width:f});a.closest(".fht-table-wrapper").length||(a.addClass("fht-table"),a.wrap('<div class="fht-table-wrapper"></div>'));f=a.closest(".fht-table-wrapper");!0==b.fixedColumn&&0>=b.fixedColumns&&(b.fixedColumns= 1);0<b.fixedColumns&&0==f.find(".fht-fixed-column").length&&(a.wrap('<div class="fht-fixed-body"></div>'),c('<div class="fht-fixed-column"></div>').prependTo(f),k=f.find(".fht-fixed-body"));f.css({width:b.width,height:b.height}).addClass(b.themeClassName);a.hasClass("fht-table-init")||a.wrap('<div class="fht-tbody"></div>');p=a.closest(".fht-tbody");var l=h._getTableProps(a);h._setupClone(p,l.tbody);a.hasClass("fht-table-init")?k=f.find("div.fht-thead"):(k=0<b.fixedColumns?c('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo(k): c('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo(f),k.find("table.fht-table").addClass(b.originalTable.attr("class")).attr("style",b.originalTable.attr("style")),d.clone().appendTo(k.find("table")));h._setupClone(k,l.thead);a.css({"margin-top":-k.outerHeight(!0)});!0==b.footer&&(h._setupTableFooter(a,this,l),e.length||(e=f.find("div.fht-tfoot table")),g=e.outerHeight(!0));d=f.height()-d.outerHeight(!0)-g-l.border;p.css({height:d});a.addClass("fht-table-init");"undefined"!== typeof b.altClass&&n.altRows.apply(this);0<b.fixedColumns&&h._setupFixedColumn(a,this,l);b.autoShow||f.hide();h._bindScroll(p,l);return this},resize:function(){return this},altRows:function(a){var d=c(this);a="undefined"!==typeof a?a:b.altClass;d.closest(".fht-table-wrapper").find("tbody tr:odd:not(:hidden)").addClass(a)},show:function(a,d,b){var g=c(this),f=g.closest(".fht-table-wrapper");if("undefined"!==typeof a&&"number"===typeof a)return f.show(a,function(){c.isFunction(d)&&d.call(this)}),this; if("undefined"!==typeof a&&"string"===typeof a&&"undefined"!==typeof d&&"number"===typeof d)return f.show(a,d,function(){c.isFunction(b)&&b.call(this)}),this;g.closest(".fht-table-wrapper").show();c.isFunction(a)&&a.call(this);return this},hide:function(a,d,b){var g=c(this),f=g.closest(".fht-table-wrapper");if("undefined"!==typeof a&&"number"===typeof a)return f.hide(a,function(){c.isFunction(b)&&b.call(this)}),this;if("undefined"!==typeof a&&"string"===typeof a&&"undefined"!==typeof d&&"number"=== typeof d)return f.hide(a,d,function(){c.isFunction(b)&&b.call(this)}),this;g.closest(".fht-table-wrapper").hide();c.isFunction(b)&&b.call(this);return this},destroy:function(){var a=c(this),d=a.closest(".fht-table-wrapper");a.insertBefore(d).removeAttr("style").append(d.find("tfoot")).removeClass("fht-table fht-table-init").find(".fht-cell").remove();d.remove();return this}},h={_isTable:function(a){var d=a.is("table"),b=0<a.find("thead").length;a=0<a.find("tbody").length;return d&&b&&a?!0:!1},_bindScroll:function(a){var d= a.closest(".fht-table-wrapper"),c=a.siblings(".fht-thead"),g=a.siblings(".fht-tfoot");a.bind("scroll",function(){0<b.fixedColumns&&d.find(".fht-fixed-column").find(".fht-tbody table").css({"margin-top":-a.scrollTop()});c.find("table").css({"margin-left":-this.scrollLeft});(b.footer||b.cloneHeadToFoot)&&g.find("table").css({"margin-left":-this.scrollLeft})})},_fixHeightWithCss:function(a,d){b.includePadding?a.css({height:a.height()+d.border}):a.css({height:a.parent().h