From 5496d7b841a26a8c48e3bcb399f546ab9aa7e57d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 27 Oct 2024 15:48:44 +0800 Subject: [PATCH] bugfix --- bricks/bricks.js | 6 +++++ bricks/message.js | 59 ----------------------------------------------- bricks/popup.js | 34 +++++++++++++++++++++++++++ bricks/widget.js | 3 +++ 4 files changed, 43 insertions(+), 59 deletions(-) create mode 100644 bricks/popup.js diff --git a/bricks/bricks.js b/bricks/bricks.js index a810f32..6eeb33a 100755 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -474,6 +474,7 @@ bricks.App = class extends bricks.Layout { this.lang = navigator.language; } this.lang_x = this.observable('lang', this.lang); + this.zindex = 10000; this.textList = []; this.i18n = new bricks.I18n(objget(opts, 'i18n', {})); this.session_id = null; @@ -483,6 +484,11 @@ bricks.App = class extends bricks.Layout { this._Height = this.dom_element.offsetHeight; document.addEventListener('keydown', this.key_down_action.bind(this)); } + new_zindex(){ + const v = this.zindex; + this.zindex = v + 1; + return v; + } screenHeight(){ return this.dom_element.clientHeight; } diff --git a/bricks/message.js b/bricks/message.js index 4fbb54d..34331fb 100644 --- a/bricks/message.js +++ b/bricks/message.js @@ -1,63 +1,4 @@ var bricks = window.bricks || {}; -bricks.BPopup = class extends bricks.VBox { - /* - { - holder: - title: - auto_open: - auto_dismiss: - archor:cc - timeout: - } - */ - constructor(opts){ - super(opts); - this.task = null; - this.title = opts.title|| 'Title'; - this.archor = opts.archor || 'cc'; - this.timeout = opts.timeout || 0; - this.panel.set_css('message'); - this.build(); - archorize(this.dom_element, this.archor); - } - - build(){ - var tb = new bricks.HBox({height:'40px'}); - tb.set_css('title'); - bricks.VBox.prototype.add_widget.bind(this)(tb); - var tit = new bricks.Text({otext:this.title, i18n:true}); - this.content = new bricks.Filler({}); - bricks.VBox.prototype.add_widget.bind(this)(this.content); - tb.add_widget(tit); - this.holder = bricks.Body; - if (this.opts.holder){ - if (type(this.opts.holder) == 'string'){ - this.holder = getWidgetById(this.opts.holder, bricks.Body); - } else { - this.holder = this.opts.holder; - } - } - } - open(){ - this.holder.add_widget(this); - if (this.timeout > 0){ - this.task = schedule_once(this.dismiss.bind(this), this.timeout); - } - } - add_widget(w, idx){ - this.content.add_widget(w, idx); - if (this.opts.auto_open){ - this.open(); - } - } - dismiss(){ - if (this.task){ - this.task.cancel(); - this.task = null - } - this.target_w.remove_widget(this); - } -} bricks.Message = class extends bricks.Modal { /* diff --git a/bricks/popup.js b/bricks/popup.js new file mode 100644 index 0000000..b75a4e9 --- /dev/null +++ b/bricks/popup.js @@ -0,0 +1,34 @@ +var bricks = window.bricks || {}; + +bricks.Popup = class extends bricks.VBox { + /* + { + timeout:0 + + */ + constructor(opts){ + super(); + this.auto_task = null; + this.set_css('popup'); + const zindex = bricks.app.new_zindex(); + this.set_style('zIndex', zindex); + } + open(){ + var rect = this.parent.showRectage(); + 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.timeout > 0){ + this.auto_task = schedule_once(this.auto_dismiss.bind(this), this.timeout) + } + } + dismiss(){ + if (this.auto_task){ + this.auto_task.cancel(); + this.auto_task = null; + } + this.set_css('display':'none'); + } +} diff --git a/bricks/widget.js b/bricks/widget.js index b20a143..2f2a563 100755 --- a/bricks/widget.js +++ b/bricks/widget.js @@ -41,6 +41,9 @@ bricks.JsWidget = class { } bricks.resize_observer.observe(this.dom_element); } + showRectage(){ + return this.dom_element.getBoundingClientRect(); + } is_in_dom(){ return document.contains(this.dom_element); }