12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
-
-
+
+
+
|
Creates a new tooltip-like widget using the given options object.
Options:
.refresh: callback which is called just before the tooltip is
revealed or moved. It must refresh the contents of the tooltip,
if needed, by applying the content to/within this.e, which is the
base DOM element for the tooltip. If the contents are static and
set up via the .init option then this callback is not needed.
base DOM element for the tooltip (and is a child of
document.body). If the contents are static and set up via the
.init option then this callback is not needed.
.adjustX: an optional callback which is called when the tooltip
is to be displayed at a given position and passed the X
viewport-relative coordinate. This routine must either return its
argument as-is or return an adjusted value. The intent is to
allow a given tooltip may be positioned more appropriately for a
given context, if needed (noting that the desired position can,
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
-
+
|
Returns this object.
Sidebar: showing/hiding the widget is, as is conventional for
this framework, done by removing/adding the 'hidden' CSS class
to it, so that class must be defined appropriately.
*/
show: function(){
var x = 0, y = 0, showIt;
var x = undefined, y = undefined, showIt;
if(2===arguments.length){
x = arguments[0];
y = arguments[1];
showIt = true;
}else if(1===arguments.length){
if(arguments[0] instanceof HTMLElement){
const p = arguments[0];
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if(showIt){
this.refresh();
x = this.options.adjustX.call(this,x);
y = this.options.adjustY.call(this,y);
x += window.pageXOffset;
y += window.pageYOffset;
}
D[showIt ? 'removeClass' : 'addClass'](this.e, 'hidden');
if(x || y){
this.e.style.left = x+"px";
this.e.style.top = y+"px";
}
console.debug("showIt?",showIt,x,y);
if(showIt){
if('number'===typeof x && 'number'===typeof y){
this.e.style.left = x+"px";
this.e.style.top = y+"px";
}
D.removeClass(this.e, 'hidden');
}else{
D.addClass(this.e, 'hidden');
delete this.e.style.removeProperty('left');
delete this.e.style.removeProperty('top');
}
return this;
},
}
hide: function(){return this.show(false)}
}/*F.PopupWidget.prototype*/;
/**
Convenience wrapper around a PopupWidget which pops up a shared
PopupWidget instance to show toast-style messages (commonly seen
on Android). Its arguments may be anything suitable for passing
to fossil.dom.append(), and each argument is first append()ed to
the toast widget, then the widget is shown for
F.toast.config.displayTimeMs milliseconds. This is called while
a toast is currently being displayed, the first will be overwritten
and the time until the message is hidden will be reset.
The toast is always shown at the viewport-relative coordinates
defined by the F.toast.config.position.
The toaster's DOM element has the CSS classes fossil-tooltip
and fossil-toast, so can be style via those.
*/
F.toast = function f(/*...*/){
if(!f.toast){
f.toast = function ff(argsObject){
if(!ff.toaster) ff.toaster = new F.PopupWidget({
cssClass: ['fossil-tooltip', 'fossil-toast']
});
if(f._timer) clearTimeout(f._timer);
D.clearElement(ff.toaster.e);
var i = 0;
for( ; i < argsObject.length; ++i ){
D.append(ff.toaster.e, argsObject[i]);
};
ff.toaster.show(f.config.position.x, f.config.position.y);
f._timer = setTimeout(()=>ff.toaster.hide(), f.config.displayTimeMs);
};
}
f.toast(arguments);
};
F.toast.config = {
position: { x: 5, y: 5 /*viewport-relative, pixels*/ },
displayTimeMs: 2500
};
})(window.fossil);
|