Line 222: |
Line 222: |
| | | |
| mw.hook( 'wikipage.content' ).add( createCollapseButtons ); | | mw.hook( 'wikipage.content' ).add( createCollapseButtons ); |
| + | |
| + | // Fix Table Header |
| + | var TableHeadFix = function () { |
| + | var obj, $table, $newtable, $win; |
| + | obj = this; |
| + | |
| + | this.clonehead = function () { |
| + | $newtable = $table.clone(); |
| + | $newtable.find('tr:gt(0)').remove(); |
| + | |
| + | $newtable.css('top', '0'); |
| + | $newtable.css('position', 'fixed'); |
| + | // Fixed by kk @ 2015-04-03 |
| + | $newtable.css('margin-top', '0'); |
| + | $newtable.hide(); |
| + | }; |
| + | |
| + | |
| + | this.check = function () { |
| + | if($table.size() == 0){ |
| + | return; |
| + | } |
| + | var scrollTop = $win.scrollTop(); |
| + | var start_offset = $table.offset(); |
| + | if (scrollTop > start_offset.top && scrollTop <= (start_offset.top + $table.height())) { |
| + | // KK: 调节表格宽度: 原表格宽度+边框宽度 |
| + | $newtable.width($table.width() + 2); |
| + | $newtable.show(); |
| + | } else { |
| + | $newtable.hide(); |
| + | } |
| + | }; |
| + | |
| + | this.event = function () { |
| + | $win.bind('scroll', obj.check); |
| + | }; |
| + | |
| + | this.init = function (obj) { |
| + | $win = $(window); |
| + | $table = $(obj); |
| + | this.clonehead(); |
| + | $table.after($newtable); |
| + | |
| + | this.event(); |
| + | this.check(); |
| + | }; |
| + | } |
| + | |
| + | $(function () { |
| + | //Set table |
| + | $('.fixtable').each(function(){ |
| + | var tableHeadFix = new TableHeadFix(); |
| + | tableHeadFix.init(this); |
| + | }); |
| + | }); |