diff --git a/bricks/bricks.js b/bricks/bricks.js index bead350..eff0096 100644 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -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||{}); diff --git a/bricks/menu.js b/bricks/menu.js index 92876d9..549d751 100644 --- a/bricks/menu.js +++ b/bricks/menu.js @@ -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", diff --git a/bricks/popup.js b/bricks/popup.js index 3fde4eb..caf909e 100644 --- a/bricks/popup.js +++ b/bricks/popup.js @@ -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){ diff --git a/bricks/utils.js b/bricks/utils.js index edbf7b9..8196266 100644 --- a/bricks/utils.js +++ b/bricks/utils.js @@ -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;