-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmylib-sidebar.js
135 lines (121 loc) · 5.11 KB
/
mylib-sidebar.js
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
/* My Library Sidebar Widget
Requires DOM module
Requires Widgets add-on
Optionally uses Class */
var API, global = this;
if (API && API.areFeatures && API.areFeatures('createElement', 'attachDocumentReadyListener')) {
API.attachDocumentReadyListener(function() {
var api = API, getBodyElement = api.getBodyElement, showElement = api.showElement, createElement = api.createElement;
var body = getBodyElement();
var oppositeSides = { left:'right', right:'left', top:'bottom', bottom:'top' };
var attachListener = api.attachListener, getElementParentElement = api.getElementParentElement, callInContext = api.callInContext;
var appendSideBarButton;
if (createElement && attachListener) {
appendSideBarButton = function(elSideBar, v, fn) {
var elButton = createElement('input');
if (elButton) {
elButton.type = 'button';
elButton.className = 'commandbutton';
elButton.value = v;
elSideBar.appendChild(elButton);
attachListener(elButton, 'click', function() {
return fn(getElementParentElement(this), this);
});
elButton = elSideBar = null;
return true;
}
return false;
};
}
if (body && API.isHostMethod(body, 'appendChild') && api.sideBar) {
api.enhanceSideBar = function(el, options, doc) {
var body = getBodyElement(doc);
if (!options) {
options = {};
}
var side = options.side || 'left';
if (body) {
el.style.position = 'absolute';
el.className = options.className || 'sidebar';
if (side == 'left' || side == 'right') {
el.className += ' vertical';
}
el.className += ' ' + side;
body.appendChild(el);
API.sideBar(el, side, options);
return el;
}
return null;
};
if (appendSideBarButton) {
api.createSideBar = function(options, doc) {
if (!options) {
options = {};
}
var el = createElement('div');
if (el) {
API.setControlContent(el, options);
if (options.buttons) {
var onclose = options.onclose;
if (API.showSideBar) {
appendSideBarButton(el, 'Close', function() {
API.showSideBar(el, false, {
effects:options.effects,
side:options.side,
duration:options.duration,
ease:options.ease,
fps:options.fps,
removeOnHide:true
});
API.unSideBar(el);
if (onclose) {
callInContext(onclose, options.callbackContext || API, el);
}
});
}
var onautohidecollision = options.onautohidecollision, onautohide = options.onautohide;
if (API.autoHideSideBar) {
appendSideBarButton(el, 'Auto-hide', function(el, elButton) {
if (API.autoHideSideBar(el, true, { duration:options.duration, ease:options.ease, fps:options.fps })) {
el.className += ' autohide';
elButton.disabled = true;
if (onautohide) {
callInContext(onautohide, options.callbackContext || API, el);
}
} else {
var doAlert = true;
if (onautohidecollision) {
doAlert = callInContext(onautohidecollision, options.callbackContext || API, el) !== false;
}
if (doAlert && API.isHostMethod(global, 'alert')) {
global.alert('Only one sidebar per edge may be hidden.');
}
}
});
}
}
return API.enhanceSideBar(el, options, doc);
}
return null;
};
}
if (showElement) {
var oldShowSideBar = api.showSideBar;
api.showSideBar = function(el, b, options) {
if (options && options.side && options.effects && options.effects == API.effects.slide && !options.effectParams) {
options.effectParams = { side:oppositeSides[options.side] };
}
oldShowSideBar(el, b, options);
};
}
api.destroySideBar = function(el) {
API.unSideBar(el);
var elParent = API.getElementParentElement(el);
if (elParent) {
elParent.removeChild(el);
}
};
}
api = body = null;
});
}