2016-05-27 21:59:01 +00:00
|
|
|
define(function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2015-03-25 14:33:36 +00:00
|
|
|
return function (el) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2017-02-08 22:32:17 +00:00
|
|
|
// Needed to avoid render blocking
|
|
|
|
var gridBreakpoints = {
|
|
|
|
lg: [992, 446],
|
|
|
|
xl: [1200, 560]
|
|
|
|
};
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var sidebar = document.createElement('div');
|
|
|
|
sidebar.classList.add('sidebar');
|
2016-05-22 11:23:43 +00:00
|
|
|
el.appendChild(sidebar);
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var button = document.createElement('button');
|
2016-05-22 11:23:43 +00:00
|
|
|
sidebar.appendChild(button);
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2017-10-26 19:40:55 +00:00
|
|
|
button.classList.add('sidebarhandle');
|
2017-10-21 00:06:42 +00:00
|
|
|
button.setAttribute('aria-label', _.t('sidebar.toggle'));
|
2017-01-29 23:51:08 +00:00
|
|
|
button.onclick = function onclick() {
|
|
|
|
sidebar.classList.toggle('hidden');
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var container = document.createElement('div');
|
|
|
|
container.classList.add('container');
|
2016-05-22 11:23:43 +00:00
|
|
|
sidebar.appendChild(container);
|
2015-04-04 16:01:57 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.getWidth = function getWidth() {
|
2017-02-09 23:56:23 +00:00
|
|
|
if (gridBreakpoints.lg[0] > window.innerWidth) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return 0;
|
2017-02-09 23:56:23 +00:00
|
|
|
} else if (gridBreakpoints.xl[0] > window.innerWidth) {
|
2017-02-08 22:32:17 +00:00
|
|
|
return gridBreakpoints.lg[1];
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2017-02-08 22:32:17 +00:00
|
|
|
return gridBreakpoints.xl[1];
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.add = function add(d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
d.render(container);
|
|
|
|
};
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.ensureVisible = function ensureVisible() {
|
|
|
|
sidebar.classList.remove('hidden');
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-07-06 20:30:45 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.hide = function hide() {
|
2017-04-14 12:43:46 +00:00
|
|
|
container.children[1].classList.add('hide');
|
|
|
|
container.children[2].classList.add('hide');
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-07-06 20:27:16 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.reveal = function reveal() {
|
2017-04-14 12:43:46 +00:00
|
|
|
container.children[1].classList.remove('hide');
|
|
|
|
container.children[2].classList.remove('hide');
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-07-06 20:27:16 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
self.container = sidebar;
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|