-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstickytables.js
More file actions
146 lines (122 loc) · 3.28 KB
/
Copy pathstickytables.js
File metadata and controls
146 lines (122 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(function($){
$.stickytable = function(el, options){
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data("stickytable", base);
base.init = function(){
base.options = $.extend({},$.stickytable.defaultOptions, options);
};
// Run initializer
base.init();
};
$.stickytable.defaultOptions = {
};
$.stickytable.elements = {};
$.stickytable.get_styles = function(obj){
var sheets = document.styleSheets;
var iter;
var rule;
var styles = {};
var rules = window.getComputedStyle(obj.get(0), null);
for(r in rules){
iter= $.stickytable.isNum(r);
if(iter !== false){
styles[rules[r]] = rules.getPropertyValue(rules[r]);
}
}
return styles;
}
$.stickytable.isNum = function(t){
t = parseInt(t);
if(isNaN(t)){
return false;
}else{
return t;
}
}
$.stickytable.css = function(a){
var s = $.stickytable.get_styles(a);
s['background'] = 'none';
s['border'] = 'none';
s['overflow'] = 'visible';
s['overflowX'] = 'visible';
s['overflowY'] = 'visible';
s['padding'] = 0;
return s;
}
$.stickytable.guid = function(){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);});
}
$.stickytable.check_loc = function(tbl){
var sTop = tbl.p.scrollTop();
var min = tbl.startY;
var max = tbl.startY + tbl.t.outerHeight(true);
if(sTop > min && sTop < max){
if(tbl.c.css('display')=='none') tbl.c.css('display', 'inline-table');
}else{
tbl.c.css('display', 'none');
}
}
$.stickytable.updated_p_styles = {
margin:0,
position:'relative',
float:'none'
}
$.fn.stickytable = function(options){
var self; // the table itself
var tbl;
return this.each(function(){
(new $.stickytable(this, options));
// store references
self = $(this);
var parent = self.parent();
parent.scrollTop(0);
var guid = $.stickytable.guid();
// wrap
var wrap, p_styles;
// sometimes they all live in the same element so... lets check for that before wrapping the parent over and over
if(!parent.hasClass('stky-ct-el')){
wrap = $(document.createElement('div'));
wrap.addClass('stky-wrapper');
// get styles and patch them!
p_styles = $.stickytable.css(parent);
wrap.css(p_styles);
parent.css($.stickytable.updated_p_styles);
parent.wrap(wrap);
parent.addClass('stky-ct-el');
wrap = parent.parent();
}else{
wrap = parent.parent();
}
// create our clone.
var clone = self.clone();
// get rid of useless nodes
clone.children('tbody').remove();
clone.css({
display:'none',
position:'absolute',
'z-index':100,
width:parent[0].scrollWidth,
});
clone.addClass('sticky-clone');
wrap.prepend(clone);
//wrap.append(clone);
$.stickytable.elements[guid] = {
t:self,
p:parent,
c:clone,
startY:self.position().top
};
// attach a mouseevent handler to parent
parent.scroll(function(e){
tbl = $.stickytable.elements[guid];
$.stickytable.check_loc(tbl);
});
});
};
})(jQuery);