forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtnc.js
More file actions
170 lines (140 loc) · 6.17 KB
/
tnc.js
File metadata and controls
170 lines (140 loc) · 6.17 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const tabListener = require('@binary-com/binary-style').tabListener;
const getElementById = require('../../_common/common_functions').getElementById;
const localize = require('../../_common/localize').localize;
const TNCApproval = require('../../app/pages/user/tnc_approval');
const State = require('../../_common/storage').State;
const Client = require('../../app/base/client');
const BinarySocket = require('../../app/base/socket');
const TermsAndConditions = (() => {
let sidebar_width;
const onLoad = () => {
const container = document.getElementsByClassName('sidebar-collapsible-container')[0];
if (container) sidebar_width = container.offsetWidth;
handleActiveTab(); // adds active class
TNCApproval.requiresTNCApproval(
$('#btn_accept'),
() => { $('.tnc_accept').setVisibility(1); },
() => { $('#tnc_accept').html(localize('Your settings have been updated successfully.')); });
tabListener();
initSidebar();
checkWidth();
window.onresize = checkWidth;
$('.currentYear').text(new Date().getFullYear());
BinarySocket.wait('authorize', 'website_status', 'landing_company').then(() => {
const landing_company_shortcode = Client.get('landing_company_shortcode') || State.getResponse('landing_company.gaming_company.shortcode');
const client_country = Client.get('residence') || State.getResponse('website_status.clients_country');
const is_uk_client = client_country === 'gb';
if (is_uk_client && landing_company_shortcode === 'maltainvest') {
getElementById('mf_uk').setVisibility(1);
}
});
};
const handleActiveTab = () => {
const params = window.location.hash.split('&');
const hash = params[0] || '#legal';
const menu = '.tab-menu-wrap';
const content = '.tab-content-wrapper';
const parent_active = 'active';
const child_active = 'a-active';
$(menu)
.find('li')
.removeClass(parent_active)
.find('span')
.removeClass(child_active);
let $tab_to_show = $(hash);
// if hash is a subtab or has subtabs
if ($tab_to_show.find('.tm-li-2').length > 0 || /tm-li-2/.test($(hash).attr('class'))) {
$tab_to_show =
$tab_to_show
.find('.tm-a-2')
.first()
.addClass(child_active)
.closest('.tm-li');
}
$tab_to_show.addClass(parent_active);
let content_to_show = `div${hash}-content`;
if ($(content_to_show).length === 0) {
content_to_show = `div#${$(hash).find('.tm-li-2').first().attr('id')}-content`;
}
$(content)
.find('> div')
.setVisibility(0)
.end()
.find(content_to_show)
.setVisibility(1);
};
const initSidebar = () => {
const { hash, pathname } = window.location;
if (!hash) {
window.history.replaceState({}, '', `${pathname}#legal-binary`);
} else if ($(`${hash}-link`).is('.has-submenu')) {
window.history.replaceState({}, '', `${pathname}${hash}-binary`);
}
$('.sidebar-collapsible').on('click', sidebarClickHandler);
updateSidebarDOM();
};
const updateSidebarDOM = () => {
const id = window.location.hash;
const $li = $(`${id}-link`);
const $parent_li = $li.closest('.has-submenu');
if ($parent_li.length) {
$parent_li.addClass('active').children('a').addClass('selected no-transition');
}
$li.addClass('active').find('a').addClass('selected');
$(`${id}-content`).removeClass('invisible');
};
const sidebarClickHandler = (e) => {
const $target = $(e.target);
if (!$target.is('a')) return;
const $submenu = $target.siblings('ul');
if ($submenu.length) {
// parent link is clicked
e.preventDefault();
if ($submenu.find('.selected').length) {
// has selected sublink
$target.removeClass('no-transition').parent('li').toggleClass('active');
} else {
window.location.hash = $submenu.find('a')[0].hash;
}
}
};
const checkWidth = () => {
const mq = window.matchMedia('(max-width: 1023px)').matches;
if (mq) {
$('.sidebar-collapsible').css({ position: 'relative' });
$(window).off('scroll', stickySidebar);
} else {
$(window).on('scroll', stickySidebar);
}
return mq;
};
const stickySidebar = () => {
const $sidebar = $('.sidebar-collapsible');
if (!$sidebar.is(':visible')) return;
const $content = $('.sidebar-collapsible-content');
const $container = $('.sidebar-collapsible-container');
const $content_height = $('.toggle-content:not(.invisible)')[0].offsetHeight;
// if scroll has not passed end of the sidebar yet or if text content is too short
// scrollbar should remain relative otherwise it will break the page
if (window.scrollY < $content.offset().top || $content_height < $sidebar[0].offsetHeight) {
$sidebar.css({ position: 'relative' });
} else if (window.scrollY + $sidebar[0].offsetHeight + 20 >=
$container[0].offsetHeight + $container.offset().top) { // 20 is the padding for content from bottom, to avoid menu snapping back up
$sidebar.css({ position: 'absolute', bottom: '20px', top: '', width: sidebar_width });
} else {
let position_style = 'fixed';
if (!!window.MSInputMethodContext && !!document.documentMode) { // fix styling for IE11
position_style = 'static';
}
$sidebar.css({ position: position_style, top: '0px', bottom: '', width: sidebar_width });
}
};
const onUnload = () => {
$('.sidebar-collapsible').off('click');
};
return {
onLoad,
onUnload,
};
})();
module.exports = TermsAndConditions;