Difference between revisions of "MediaWiki:Common.js"

Jump to: navigation, search

Difference between revisions of "MediaWiki:Common.js"

Line 1: Line 1:
table.scroll {
+
// Change the selector if needed
     width: 100%; /* Optional */
+
var $table = $('table.scroll'),
    /* border-collapse: collapse; */
+
     $bodyCells = $table.find('tbody tr:first').children(),
     border-spacing: 0;
+
     colWidth;
    border: 2px solid black;
 
}
 
  
table.scroll tbody,
+
// Adjust the width of thead cells when window resizes
table.scroll thead { display: block; }
+
$(window).resize(function() {
 
+
     // Get the tbody columns width array
thead tr th {  
+
    colWidth = $bodyCells.map(function() {
    height: 30px;
+
        return $(this).width();
    line-height: 30px;
+
     }).get();
     /*text-align: left;*/
+
      
}
+
    // Set the width of thead columns
 
+
    $table.find('thead tr').children().each(function(i, v) {
table.scroll tbody {
+
        $(v).width(colWidth[i]);
    height: 100px;
+
     });  
     overflow-y: auto;
+
}).resize(); // Trigger resize handler
     overflow-x: hidden;
 
}
 
 
 
tbody { border-top: 2px solid black; }
 
 
 
tbody td, thead th {
 
    width: 20%; /* Optional */
 
     border-right: 1px solid black;
 
}
 
 
 
tbody td:last-child, thead th:last-child {
 
    border-right: none;
 
}
 

Revision as of 22:36, 4 November 2020

// Change the selector if needed
var $table = $('table.scroll'),
    $bodyCells = $table.find('tbody tr:first').children(),
    colWidth;

// Adjust the width of thead cells when window resizes
$(window).resize(function() {
    // Get the tbody columns width array
    colWidth = $bodyCells.map(function() {
        return $(this).width();
    }).get();
    
    // Set the width of thead columns
    $table.find('thead tr').children().each(function(i, v) {
        $(v).width(colWidth[i]);
    });    
}).resize(); // Trigger resize handler