This commit is contained in:
yumoqing 2024-10-28 15:33:18 +08:00
parent c0f2ced739
commit d209adc640
3 changed files with 65 additions and 10 deletions

View File

@ -1,6 +1,6 @@
SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
i18n.js widget.js layout.js bricks.js image.js html.js \
jsoncall.js myoperator.js scroll.js menu.js modal.js running.js \
jsoncall.js myoperator.js scroll.js menu.js popup.js modal.js running.js \
markdown_viewer.js video.js audio.js toolbar.js tab.js \
input.js registerfunction.js button.js accordion.js dataviewer.js \
tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \

View File

@ -4,22 +4,65 @@ bricks.Popup = class extends bricks.VBox {
/*
{
timeout:0
auto_open:
archor:one of ['tl', 'tc', 'tr', 'cl', 'cc', 'cr', 'bl','bc', 'br']
widget:null for bricks.Body, string value for widget's id or a widget object;
auto_dismiss:
*/
constructor(opts){
super();
this.auto_task = null;
this.issub = false;
this.set_css('popup');
const zindex = bricks.app.new_zindex();
this.set_style('zIndex', zindex);
}
add_widget(w, index){
super().add_widget(w, index);
if (this.auto_open){
this.open();
}
}
transform2screen_at(rect, lt){
var screen_rect = bricks.Body.showRectage();
top = rect.top + parseInt(lt.y) / 100 * rect.height;
left = rect.left + parseInt(lt.x) / 100 * rect.width;
return {
top:top + 'px';
left:left + 'px';
}
}
convert_width(){
}
open(){
var rect = this.parent.showRectage();
var rect;
var w;
if (this.widget isinstanceof bricks.Widget){
rect = this.widget.showRectage()
this.issub = true;
} else if (this.widget isinstanceof String){
var w = bricks.getWidgetById(this.widget, bricks.Body);
if (!w){
ithis.issub = true
rect = bricks.Body.showRectage();
}
} else {
rect = bricks.Body.showRectage();
}
var lt = archor_at(this.archor);
this.set_style('display', 'block');
this.set_style('top',`${rect.top + window.scrollY}px`);
thos.set_style('left',`${rect.left + window.scrollX}px`);
this.set_style('width', `${rect.width}px`);
this.set_style('height', `${rect.height}px`);
if (this.issub){
lt = this.transform2screen_at(rect, lt);
if (this.width && this.width.endsWith('%')){
this.set_style('width', parseFloat(rect.width) * parseFloat(this.width) + 'px');
}
if (this.height && this.height.endsWith('%')){
this.set_style('height', parseFloat(rect.height) * parseFloat(this.height) + 'px');
}
}
this.set_style('top',lt.top);
thos.set_style('left',lt.left);
if (this.timeout > 0){
this.auto_task = schedule_once(this.auto_dismiss.bind(this), this.timeout)
}
@ -32,3 +75,5 @@ bricks.Popup = class extends bricks.VBox {
this.set_css('display':'none');
}
}
bricks.Functory.register('Popup', bricks.Popup);

View File

@ -195,7 +195,7 @@ bricks.obj_fmtstr = function(obj, fmt){
return s;
}
var archorize = function(ele,archor){
var archor_at(archor){
/* archor maybe one of the:
"tl", "tc", "tr",
"cl", "cc", "cr",
@ -235,8 +235,18 @@ var archorize = function(ele,archor){
x = '50%';
break;
}
ele.style.top = y;
ele.style.left = x;
return {
x:x,
y:y,
top:y,
left:x
}
}
var archorize = function(ele,archor){
var lt = archorAt(archor);
ele.style.top = lt.top;
ele.style.left = lt.left;
var o = {
'x':x,
'y':y