约束 Dojo FloatingPane 的位置

发布于 2025-01-08 18:55:23 字数 1258 浏览 0 评论 0原文

我有一个 dojox.layout.FloatingPane (作为自定义 dijit),它可以放置在其封闭的 div 内的任何位置。我的问题是,用户可能会将 FloatingPane 完全拖到其容器之外,并且无法检索它。有没有什么简单的方法可以强制 FloatingPane 始终保持完全可见?

这是我的代码:

dojo.provide("ne.trim.dijits.SearchDialog");

dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dojox.layout.FloatingPane");

dojo.declare("ne.trim.dijits.SearchDialog", [dijit._Widget, dijit._Templated], {

templateString: dojo.cache("ne.trim.dijits", "templates/SearchDialog.html"),
initialised:false,
floatingPane: null,

postCreate: function() {
    this.init();
},

init: function() {
    console.debug("SearchDialog.init()", "start");
    if ( this.initialised === false ) {
        this.createSearchDialog();
    }
    //ne.trim.AppGlobals.searchDialog = this;
    console.debug("SearchDialog.init()", "end");        
},

createSearchDialog: function() {
    var node = dojo.byId('searchbox');  
    floatingPane = new dojox.layout.FloatingPane({
         title: "A floating pane",
         resizable: true, dockable: true, constrainToContainer: true,
         style:   "position:absolute;top:100;right:100;width:400px;height:300px;z-index:100",
    }, node );

    this.initialised=true;

    floatingPane.startup();
}

});

I have a dojox.layout.FloatingPane (as a custom dijit) which can be positioned anywhere within its enclosing div. My problem is that the user can potentially drag the FloatingPane completely outside of its container and be unable to retrieve it. Is there any easy way to force the FloatingPane to remain entirely visible at all times?

Here's my code:

dojo.provide("ne.trim.dijits.SearchDialog");

dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dojox.layout.FloatingPane");

dojo.declare("ne.trim.dijits.SearchDialog", [dijit._Widget, dijit._Templated], {

templateString: dojo.cache("ne.trim.dijits", "templates/SearchDialog.html"),
initialised:false,
floatingPane: null,

postCreate: function() {
    this.init();
},

init: function() {
    console.debug("SearchDialog.init()", "start");
    if ( this.initialised === false ) {
        this.createSearchDialog();
    }
    //ne.trim.AppGlobals.searchDialog = this;
    console.debug("SearchDialog.init()", "end");        
},

createSearchDialog: function() {
    var node = dojo.byId('searchbox');  
    floatingPane = new dojox.layout.FloatingPane({
         title: "A floating pane",
         resizable: true, dockable: true, constrainToContainer: true,
         style:   "position:absolute;top:100;right:100;width:400px;height:300px;z-index:100",
    }, node );

    this.initialised=true;

    floatingPane.startup();
}

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Hello爱情风 2025-01-15 18:55:23

首先,请参阅 jsFiddle 上的工作示例: http://jsfiddle.net/phusick/3vTXW/

现在进行一些解释;)FloatingPane 的 DnD 功能是通过在窗格中实例化的 dojo.dnd.Moveable 类实现的postCreate 方法。要约束 FloatingPane 的移动,您应该使用以下可移动对象之一:

  • dojo.dnd.parentContainedMoveable - 通过 DOM 节点进行约束
  • dojo.dnd.boxConstrainedMoveable - 通过坐标约束:{l: 10, t: 10, w: 100, h: 100}
  • dojo.dnd.constrainedMoveable - 通过在提供的函数中计算的坐标进行约束

有关更多详细信息,请参阅前述 jsFiddle

根据文档,您应该在 Moveable 实例上调用 destroy() 来删除它,但作为 FloatingPane 的原始 Moveable > 没有分配给任何对象属性,我不会销毁它,我只是在子类中的同一 DOM 节点上实例化这三个 moveables 之一:

var ConstrainedFloatingPane = dojo.declare(dojox.layout.FloatingPane, {

    postCreate: function() {
        this.inherited(arguments);
        this.moveable = new dojo.dnd.move.constrainedMoveable(this.domNode, {
            handle: this.focusNode,
            constraints: function() {
                return dojo.coords(dojo.body());
            }
        });
    }

});

现在您可以使用 ContainFloatingPane > 代替dojox.layout.FloatingPane

var floatingPane = new ConstrainedFloatingPane({
    title: "A Constrained Floating Pane",
    resizable: true
}, searchboxNode);

First of all, see the working example at jsFiddle: http://jsfiddle.net/phusick/3vTXW/

And now some explanation;) The DnD functionality of FloatingPane is achieved via dojo.dnd.Moveable class instantialized in pane's postCreate method. To constrain the movement of the FloatingPane you should use one of these moveables instead:

  • dojo.dnd.parentConstainedMoveable - to constrain by a DOM node
  • dojo.dnd.boxConstrainedMoveable - to constrain by co-ordinates: {l: 10, t: 10, w: 100, h: 100}
  • dojo.dnd.constrainedMoveable - to constrain by co-ordinates calculated in a provided function

For more details see aforementioned jsFiddle.

According to documentation you should call destroy() on Moveable instance to remove it, but as FloatingPane's original Moveable is not assigned to any object property, I do not destroy it, I just instantiate one of those three moveables on the same DOM node in a subclass:

var ConstrainedFloatingPane = dojo.declare(dojox.layout.FloatingPane, {

    postCreate: function() {
        this.inherited(arguments);
        this.moveable = new dojo.dnd.move.constrainedMoveable(this.domNode, {
            handle: this.focusNode,
            constraints: function() {
                return dojo.coords(dojo.body());
            }
        });
    }

});

Now you can use ConstainedFloatingPane instead of dojox.layout.FloatingPane:

var floatingPane = new ConstrainedFloatingPane({
    title: "A Constrained Floating Pane",
    resizable: true
}, searchboxNode);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文