This commit is contained in:
yumoqing 2025-01-21 18:20:24 +08:00
parent f1842722b4
commit 0a7c9fca0f
4 changed files with 40 additions and 18 deletions

View File

@ -303,7 +303,21 @@ var _buildWidget = async function(from_widget, target, mode, options, desc){
return;
}
if (w.parent) return;
if (w.parent) {
if (target instanceof bricks.Popup || target instanceof bricks.PopupWindow){
target.destroy();
}
return;
}
if (target instanceof bricks.Popup || target instanceof bricks.PopupWindow) {
if (! target.parent){
bricks.app.add_widget(target);
}
console.log('target=', target);
if (desc.popup_options.eventpos){
target.bind('opened', bricks.relocate_by_eventpos.bind(null, desc.event, target));
}
}
if (mode == 'replace'){
target.clear_widgets();
@ -313,9 +327,8 @@ var _buildWidget = async function(from_widget, target, mode, options, desc){
} else {
target.add_widget(w);
}
if ((target instanceof bricks.Popup || target instanceof bricks.PopupWindow) \
&& desc.popup_options.eventpos){
target.bind('opened', bricks.relocate_by_eventpos.bind(None, desc.event, target));
if (target instanceof bricks.Popup || target instanceof bricks.PopupWindow) {
target.open();
}
}
@ -343,7 +356,7 @@ bricks.buildUrlwidgetHandler = function(w, target, rtdata, desc){
"widgettype":"urlwidget",
"options":options
}
return _buildWidget.bind(None, w, target, desc.mode || 'replace', opts, desc);
return _buildWidget.bind(null, w, target, desc.mode || 'replace', opts, desc);
}
bricks.buildBricksHandler = function(w, target, rtdata, desc){
var options = objcopy(desc.options||{});

View File

@ -24,7 +24,19 @@ bricks.Menu = class extends bricks.VBox {
console.log(event);
let e = event.target;
let opts = event.params;
var t = bricks.getWidgetById(this.target);
var t;
var popts;
if (this.target == 'PopupWindow'){
popts = bricks.get_popupwindow_default_options();
bricks.extend(popts, this.popup_options || {});
t = new bricks.PopupWindow(popts);
} else if (this.target == 'Popup'){
popts = bricks.get_popup_default_options();
bricks.extend(popts, this.popup_options || {});
t = new bricks.Popup(popts);
} else {
t = bricks.getWidgetById(this.target);
}
if (t){
var desc = {
"widgettype":"urlwidget",

View File

@ -72,7 +72,7 @@ bricks.Popup = class extends bricks.VBox {
set_dismiss_events(w){
if (!this.dismiss_events) return;
this.dismiss_events.forEach(ename => {
w.bind(ename, this.distroy.bind(this));
w.bind(ename, this.destroy.bind(this));
});
}
bring_to_top(){
@ -284,6 +284,9 @@ bricks.Popup = class extends bricks.VBox {
}
}
open(){
if (!this.parent){
bricks.app.add_widget(this);
}
var rect, w, h;
if (this.opened) {
return;
@ -341,7 +344,10 @@ bricks.Popup = class extends bricks.VBox {
}
add_widget(w, i){
this.set_dismiss_events(w);
return this.content_w.add_widget(w, i);
this.content_w.add_widget(w, i);
if (this.auto_open){
this.open();
}
}
remove_widget(w){
return this.content_w.remove_widget(w);
@ -455,15 +461,6 @@ bricks.PopupWindow = class extends bricks.Popup {
}
super.dismiss()
}
add_widget(w, i){
return this.content_w.add_widget(w, i);
}
remove_widget(w){
return this.content_w.remove_widget(w);
}
clear_widgets(){
return this.content_w.clear_widgets();
}
}
bricks.Dock = class extends bricks.HBox {
constructor(opts){

View File

@ -1,7 +1,7 @@
var bricks = window.bricks || {};
bricks.bug = false;
var bricks.relocate_by_eventpos = function(event, widget){
bricks.relocate_by_eventpos = function(event, widget){
var ex,ey;
var x,y;
var xsize = bricks.Body.dom_element.clientWidth;