forked from zombieFox/nightTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.js
More file actions
114 lines (104 loc) · 2.67 KB
/
Copy pathcontrol.js
File metadata and controls
114 lines (104 loc) · 2.67 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
var control = (function() {
var state = {
edit: false,
style: {
block: true,
list: false
}
};
var get = function() {
return state;
};
var bind = function() {
var controlAdd = helper.e(".control-add");
var controlEdit = helper.e(".control-edit");
var controlLinkBlock = helper.e(".control-link-blocks");
var controlLinkList = helper.e(".control-link-list");
controlAdd.addEventListener("click", function() {
links.add();
}, false);
controlEdit.addEventListener("click", function() {
_toggleEdit();
render();
links.tabIndex();
data.save();
}, false);
controlLinkBlock.addEventListener("click", function() {
_toggleListStyle("block");
render();
data.save();
}, false);
controlLinkList.addEventListener("click", function() {
_toggleListStyle("list");
render();
data.save();
}, false);
};
var _toggleEdit = function() {
if (state.edit) {
state.edit = false;
} else {
state.edit = true;
};
};
var _toggleListStyle = function(style) {
var action = {
block: function() {
state.style.block = true;
state.style.list = false;
},
list: function() {
state.style.block = false;
state.style.list = true;
}
};
action[style]();
};
var render = function() {
var html = helper.e("html");
var controlEdit = helper.e(".control-edit");
var controlLinkBlock = helper.e(".control-link-blocks");
var controlLinkList = helper.e(".control-link-list");
var _renderEdit = function() {
if (state.edit) {
helper.addClass(html, "is-edit");
helper.addClass(controlEdit, "active");
} else {
helper.removeClass(html, "is-edit");
helper.removeClass(controlEdit, "active");
};
};
var _renderStyle = function() {
if (state.style.block) {
helper.addClass(html, "is-link-block");
helper.removeClass(html, "is-link-list");
helper.addClass(controlLinkBlock, "active");
helper.removeClass(controlLinkList, "active");
} else if (state.style.list) {
helper.removeClass(html, "is-link-block");
helper.addClass(html, "is-link-list");
helper.removeClass(controlLinkBlock, "active");
helper.addClass(controlLinkList, "active");
};
};
_renderEdit();
_renderStyle();
};
var restore = function(object) {
if (object) {
state = object;
render();
};
};
var init = function() {
bind();
render();
};
// exposed methods
return {
init: init,
get: get,
restore: restore,
render: render
};
})();