forked from ReDEnergy/SessionSync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-sorting.js
More file actions
118 lines (95 loc) · 3.23 KB
/
Copy pathsession-sorting.js
File metadata and controls
118 lines (95 loc) · 3.23 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
define(function(require, exports) {
'use strict';
// *****************************************************************************
// Custom Modules
// Utils
const { AppConfig } = require('../config');
const { HTMLCreator } = require('../utils/dom');
const { WindowEvents, GlobalEvents } = require('../utils/global-events');
// *****************************************************************************
// API
function SessionSorting()
{
// Create DomHealper
var DomElem = HTMLCreator();
// ------------------------------------------------------------------------
// UI
// Session ordering
var sortControl = DomElem('div', {class: 'sorting-method', tooltip: 'Sort sessions'});
// Sorting dropdown
var optionList = DomElem('div', {class: 'option-list'});
var options = {
'name-asc' : { description: 'name ↑', index: 0 },
'name-desc' : { description: 'name ↓', index: 1 },
'position-asc' : { description: 'position ↑', index: 2 },
'position-desc' : { description: 'position ↓', index: 3 },
'date-asc' : { description: 'date ↑', index: 4 },
'date-desc' : { description: 'date ↓', index: 5 }
};
for (var key in options)
{
var option = DomElem('div', {class: 'option', value: key});
option.textContent = options[key].description;
optionList.appendChild(option);
}
var dropdown = DomElem('div', {class: 'dropdown'});
dropdown.appendChild(optionList);
sortControl.appendChild(dropdown);
var activeButton = optionList.children[0];
// ------------------------------------------------------------------------
// Events
AppConfig.onChange('session.sorting', function (value) {
if (options[value]) {
activeButton = optionList.children[options[value].index];
activeButton.setAttribute('active', '');
}
});
optionList.addEventListener('click', function(e) {
if (e.target.className == 'option') {
if (e.target != activeButton) {
activeButton.removeAttribute('active');
activeButton = e.target;
var value = activeButton.getAttribute('value');
activeButton.setAttribute('active', '');
}
WindowEvents.emit(document, 'SortSessionsBy', value);
}
});
var state = false;
var toggleState = function toggleState() {
state = !state;
sortControl.setAttribute('active', state);
WindowEvents.emit(document, 'OverlaySystem', { state: state, zIndex: 1 });
};
document.addEventListener('click', function(e) {
if (e.target.className == 'sorting-method') {
toggleState();
}
else {
if (state == true)
toggleState();
}
});
// Tooltip events
sortControl.addEventListener('mouseover', function(e) {
var tooltipMsg = e.target.getAttribute('tooltip');
if (tooltipMsg) {
WindowEvents.emit(document, 'ShowTooltip', {
node: e.target,
message: tooltipMsg
});
} else {
WindowEvents.emit(document, 'HideTooltip');
}
});
sortControl.addEventListener('mouseleave', function() {
WindowEvents.emit(document, 'HideTooltip');
});
// ------------------------------------------------------------------------
// Data
this.DOMRoot = sortControl;
}
// *****************************************************************************
// Public API
exports.SessionSorting = SessionSorting;
});