1 | define(function () { |
||
2 | 'use strict'; |
||
3 | |||
4 | return function (el) { |
||
5 | var self = this; |
||
6 | |||
7 | // Needed to avoid render blocking |
||
8 | var gridBreakpoints = { |
||
9 | lg: [992, 446], |
||
10 | xl: [1200, 560] |
||
11 | }; |
||
12 | |||
13 | var sidebar = document.createElement('div'); |
||
14 | sidebar.classList.add('sidebar'); |
||
15 | el.appendChild(sidebar); |
||
16 | |||
17 | var button = document.createElement('button'); |
||
18 | var visibility = new CustomEvent('visibility'); |
||
19 | sidebar.appendChild(button); |
||
20 | |||
21 | button.classList.add('sidebarhandle'); |
||
22 | button.setAttribute('aria-label', _.t('sidebar.toggle')); |
||
23 | button.onclick = function onclick() { |
||
24 | button.dispatchEvent(visibility); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
25 | sidebar.classList.toggle('hidden'); |
||
26 | }; |
||
27 | |||
28 | var container = document.createElement('div'); |
||
29 | container.classList.add('container'); |
||
30 | sidebar.appendChild(container); |
||
31 | |||
32 | self.getWidth = function getWidth() { |
||
33 | if (gridBreakpoints.lg[0] > window.innerWidth || sidebar.classList.contains('hidden')) { |
||
34 | return 0; |
||
35 | } else if (gridBreakpoints.xl[0] > window.innerWidth) { |
||
36 | return gridBreakpoints.lg[1]; |
||
37 | } |
||
38 | return gridBreakpoints.xl[1]; |
||
39 | }; |
||
40 | |||
41 | self.add = function add(d) { |
||
42 | d.render(container); |
||
43 | }; |
||
44 | |||
45 | self.ensureVisible = function ensureVisible() { |
||
46 | sidebar.classList.remove('hidden'); |
||
47 | }; |
||
48 | |||
49 | self.hide = function hide() { |
||
50 | container.children[1].classList.add('hide'); |
||
51 | container.children[2].classList.add('hide'); |
||
52 | }; |
||
53 | |||
54 | self.reveal = function reveal() { |
||
55 | container.children[1].classList.remove('hide'); |
||
56 | container.children[2].classList.remove('hide'); |
||
57 | }; |
||
58 | |||
59 | self.container = sidebar; |
||
60 | self.button = button; |
||
61 | |||
62 | return self; |
||
63 | }; |
||
64 | }); |
||
65 |