PageSourceSearch

https://snasu.org/wp-content/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.tableHeader.js

js snasu.org collected 2026-10-05 09:48:46 UTC 3,358 bytes, 130 lines download raw bytes

1// https://civicrm.org/licensing
2(function($) {
3
4// Keep track of all header cells.
5var cells = [];
6
7// Attach to all headers.
8$(document).ready(function() {
9  $('table thead.sticky').each(function () {
10    // Make all absolute positioned elements relative to the table.
11    var height = $(this).parent('table').css('position', 'relative').height();
12    
13    // Find all header cells.
14    $('th', this).each(function () {
15      
16      // Ensure each cell has an element in it.
17      var html = $(this).html();
18      if (html == ' ') {
19	html = ' ';
20      }
21      if ($(this).children().length == 0) {
22	html = '<span>'+ html +'</span>';
23      }
24      
25      // Clone and wrap cell contents in sticky wrapper that overlaps the cell's padding.
26      $('<div class="sticky-header" style="position: fixed; display: none; top: 0px;">'+ html +'</div>').prependTo(this);
27      var div = $('div.sticky-header', this).css({
28	  'marginLeft': '-'+ $(this).css('paddingLeft'),
29          'marginRight': '-'+ $(this).css('paddingRight'),
30          'paddingLeft': $(this).css('paddingLeft'),
31          'paddingTop': $(this).css('paddingTop'),
32          'paddingRight': $(this).css('paddingRight'),
33          'paddingBottom': $(this).css('paddingBottom')
34	})[0];
35      // Adjust width to fit cell and hide.
36      
37      //CRM-6467
38      var length = $(this).width() - $(div).width();
39      if ( length < 0 ) length = $(div).width() - $(this).width();
40      $(div).css('paddingRight', parseInt($(div).css('paddingRight')) + length +'px');
41
42      cells.push(div);
43      
44      // Get position.
45      div.cell = this;
46      div.table = $(this).parent('table')[0];
47      div.stickyMax = height;
48      div.stickyPosition = $(this).y();
49    });
50  });
51});
52
53// Track scrolling.
54var scroll = function() {
55  $(cells).each(function () {
56    // Fetch scrolling position.
57    var scroll = document.documentElement.scrollTop || document.body.scrollTop;
58    var offset = scroll - this.stickyPosition - 4;
59    if (offset > 0 && offset < this.stickyMax - 100) {
60      $(this).css({display:'block'});
61    }
62    else {
63      $(this).css('display', 'none');
64    }
65  });
66};
67$(window).scroll(scroll);
68$(document.documentElement).scroll(scroll);
69
70// Track resizing.
71var resize = function () {
72  $(cells).each(function () {
73    // Get position.
74    $(this).css({ 'position': 'relative', 'top': '0'});
75    this.stickyPosition = $(this.cell).y();
76    this.stickyMax = $(this.table).height();
77  });
78};
79$(window).resize(resize);
80
81// Track the element positions
82$.fn.x = function(n) {
83  var result = null;
84  this.each(function() {
85    var o = this;
86    if (n === undefined) {
87      var x = 0;
88      if (o.offsetParent) {
89	while (o.offsetParent) {
90	  x += o.offsetLeft;
91	  o = o.offsetParent;
92	}
93      }
94      if (result === null) {
95	result = x;
96      } else {
97	result = Math.min(result, x);
98      }
99    } else {
100      o.style.left = n + 'px';
101    }
102  });
103  return result;
104};
105
106$.fn.y = function(n) {
107  var result = null;
108  this.each(function() {
109    var o = this;
110    if (n === undefined) {
111      var y = 0;
112      if (o.offsetParent) {
113	while (o.offsetParent) {
114	  y += o.offsetTop;
115	  o = o.offsetParent;
116	}
117      }
118      if (result === null) {
119	result = y;
120      } else {
121	result = Math.min(result, y);
122      }
123    } else {
124      o.style.top = n + 'px';
125    }
126  });
127  return result;
128};
129
130})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.