-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack.js
135 lines (96 loc) · 3.46 KB
/
slack.js
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
window.onload = function () {
addRules();
}
document.addEventListener( "DOMNodeInserted", addRules );
function addRules() {
var baseLeft = (getCookie('baseLeft') === undefined ) ? 'calc(30% - 15px)': 'calc(' + getCookie('baseLeft') + '% - 15px)' ,
baseRight = (getCookie('baseRight') === undefined ) ? '70%': getCookie('baseRight') + '%',
client_body = document.getElementById('client_body'),
col_messages = document.getElementById('col_messages'),
col_flex = document.getElementById('col_flex');
if (client_body !== undefined){
}
if (col_messages !== undefined){
}
if (col_flex !== undefined){
}
if (col_messages !== undefined && document.getElementsByClassName('slider')[0] === undefined){
col_messages.insertAdjacentHTML("afterEnd", "<div class='slider' style='height: 100%; width: 15px; cursor: col-resize;'></div>");
}
if (document.getElementsByClassName('slider')[0] !== undefined){
resize();
}
}
function resize(){
var sliderElem = document.getElementById('client_body'),
thumbElem = document.getElementsByClassName('slider')[0],
col_messages = document.getElementById('col_messages'),
col_flex = document.getElementById('col_flex');
thumbElem.onmousedown = function(e) {
var thumbCoords = getCoords(thumbElem),
shiftX = e.pageX - thumbCoords.left,
sliderCoords = getCoords(sliderElem);
document.onmousemove = function(e) {
var newLeft = e.pageX - shiftX - sliderCoords.left;
if (newLeft < 0) {
newLeft = 0;
}
var rightEdge = sliderElem.offsetWidth - thumbElem.offsetWidth;
if (newLeft > rightEdge) {
newLeft = rightEdge;
}
var baseLeft = (newLeft/(sliderElem.offsetWidth/100)),
baseRight = 100-(newLeft/(sliderElem.offsetWidth/100));
if (col_messages !== undefined){
// col_messages.style.flexBasis = 'calc(' + baseLeft + '% - 15px)';
}
if (col_flex !== undefined){
col_flex.style.flexBasis = baseRight + '%';
}
setCookie('baseLeft', baseLeft, {expires: 3600 * 24 * 31 * 12, path: '/'});
setCookie('baseRight', baseRight, {expires: 3600 * 24 * 31 * 12, path: '/'});
}
document.onmouseup = function() {
document.onmousemove = document.onmouseup = null;
};
return false;
};
thumbElem.ondragstart = function() {
return false;
};
function getCoords(elem) {
var box = elem.getBoundingClientRect();
return {
top: box.top + pageYOffset,
left: box.left + pageXOffset
};
}
}
function setCookie(name, value, options) {
options = options || {};
var expires = options.expires;
if (typeof expires == "number" && expires) {
var d = new Date();
d.setTime(d.getTime() + expires * 1000);
expires = options.expires = d;
}
if (expires && expires.toUTCString) {
options.expires = expires.toUTCString();
}
value = encodeURIComponent(value);
var updatedCookie = name + "=" + value;
for (var propName in options) {
updatedCookie += "; " + propName;
var propValue = options[propName];
if (propValue !== true) {
updatedCookie += "=" + propValue;
}
}
document.cookie = updatedCookie;
}
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}