forked from wingmeng/fixedThead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixedThead.min.js
1 lines (1 loc) · 4.14 KB
/
fixedThead.min.js
1
(function(t){function e(t,e){var r=e,d=function(e){(0==t[e]||t[e])&&!isNaN(t[e])&&t[e]>=0&&(r[e]=t[e])};for(var i in r)d(i);return r}function r(t,e){if(t.parent().parent("div.fixed-thead").length){var r={table:t,bodyWrap:t.parent(),wrapper:t.parent().parent(),scrollBarWt:f(),opts:e};a(r,!0)}}function d(t){var e=t.parent().parent("div.fixed-thead"),r=t.data("style");r?t.attr("style",r).removeAttr("data-style"):t.removeAttr("style"),e.before(t),e.empty().remove()}function i(t,e){var r=t.clone(),d=t.attr("id");return d&&r.attr("id","clone_"+d+"_"+e),r.removeAttr("style"),r}function a(e,r){var d=e.opts,i={};d.row>0&&d.col>0?(i.head=n(e),i.side=p(e),i.corner=s(e)):(d.row>0&&(i.head=n(e)),d.col>0&&(i.side=p(e))),l(e,i),r||(e.bodyWrap.scroll(function(){i.side&&i.side.scrollTop(t(this).scrollTop()),i.head&&i.head.scrollLeft(t(this).scrollLeft())}),t(window).resize(function(){l(e,i)}))}function o(e,r){var d=t('<div class="fixed-thead"></div>'),i=t('<div class="fixed-thead-body"></div>');e.wrap(d).wrap(i);var a={table:e,bodyWrap:e.parent(),wrapper:e.parent().parent(),scrollBarWt:f(),opts:r};return r.top&&a.wrapper.css("margin-top",r.top),r.bottom&&a.wrapper.css("margin-bottom",r.bottom),a}function n(e){var r=e.wrapper.find("div.fixed-thead-head"),d=i(e.table,"head");return 0==r.length?(r=t('<div class="fixed-thead-head"></div>'),e.bodyWrap.before(r.append(d))):r.empty().append(d),r=u(r,e,"head")}function p(e){var r=e.wrapper.find("div.fixed-thead-side"),d=i(e.table,"side");return 0==r.length?(r=t('<div class="fixed-thead-side"></div>'),e.bodyWrap.before(r.append(d))):r.empty().append(d),r=u(r,e,"side")}function s(e){var r=e.wrapper.find("div.fixed-thead-corner"),d=i(e.table,"corner");return 0==r.length?(r=t('<div class="fixed-thead-corner"></div>'),e.bodyWrap.before(r.append(d))):r.empty().append(d),r=u(r,e,"corner")}function l(t,e){var r=0,d=0,i=0;if(e.head){for(var a=0;a<t.opts.row;a++)d+=t.table.find("tr").eq(a).outerHeight();++d,t.table.css("margin-top",-d+"px"),e.head.height(d),r=h(t,e.head,d)}if(e.side){for(var a=0;a<t.opts.col;a++)i+=t.table.find("tr:eq(0)").children().eq(a).outerWidth();++i,t.table.width()<=t.bodyWrap.width()&&(i=0),t.table.css("margin-left",-i+"px"),t.bodyWrap.css("margin-left",i+"px"),e.head&&e.head.css("margin-left",i+"px").children("table").css("margin-left",-i+"px"),e.side.css({top:d-1+"px",width:i+"px",maxHeight:r-t.scrollBarWt+1+"px"}).children("table").css("margin-top",-(d-1)+"px")}e.corner&&e.corner.css({width:i+"px",height:d+"px"})}function h(e,r,d){var i=0;i="auto"==e.opts.height?t(window).height()-e.opts.vspace-d-e.opts.top-e.opts.bottom:e.opts.height-d,e.bodyWrap.css("max-height",i+"px");var a=r.children("table"),o=a.find(".fixed-thead-rowfix");return e.bodyWrap.height()<e.table.height()-d?o.length||c(e,r,a):o.remove(),i}function c(e,r,d){for(var i=e.scrollBarWt-1+"px",a=0;a<e.opts.row;a++){var o=d.find("tr").eq(a),n=o.children().last().clone();if(n.empty().addClass("fixed-thead-rowfix"),d.width()>r.width()){var p=t('<div style="width:'+i+'"></div>');n.css({width:0,padding:0}).append(p)}else n.css({width:i,padding:0});o.append(n)}}function f(){var e,r,d=document.createElement("div"),i=t(d);return i.css({position:"absolute",top:"-50px",zIndex:"-1",width:"50px",height:"50px",overflow:"hidden"}),document.body.appendChild(d),e=d.clientWidth,d.style.overflowY="scroll",r=d.clientWidth,i.remove(),e-r}function v(){return Math.random().toString(36).substr(2,8)}function u(t,e,r){return __salt=v(),1==e.opts.distorted&&("head"==r||"corner"==r?t.find("input, button").prop("disabled",!0):"side"==r?t.find("tbody tr td:nth-child(n+"+(e.opts.col+1)+")").find("input, button").prop("disabled",!0):t.find("tbody tr td:nth-child(-n+"+e.opts.col+")").find("input, button").prop("disabled",!0)),t}t.fn.fixedThead=function(i){var n={height:"auto",vspace:0,top:0,bottom:0,row:1,col:0,distorted:0},p=t.extend(n,t.fn.fixedThead.option,i);return this.each(function(){var s=t(this);if(p=e(p,n),"string"==typeof i)return void("refresh"===i?r(s,p):"destroy"===i&&d(s));if(s.parent().parent("div.fixed-thead").length)return void r(s,p);s.attr("style")&&(s.attr("data-style",s.attr("style")),s.removeAttr("style"));var l=o(s,p);a(l),l=null})},t.fn.fixedThead.option={}})(jQuery);