gpt4 book ai didi

dojo - 限制Dojo FloatingPane的位置

转载 作者:行者123 更新时间:2023-12-04 03:39:50 26 4
gpt4 key购买 nike

我有一个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();
}

});

最佳答案

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

现在进行一些解释;)FloatingPane的DnD功能是通过在 Pane 的dojo.dnd.Moveable方法中实例化的postCreate类实现的。为了限制FloatingPane的移动,您应该使用以下这些可移动项之一:

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

    有关更多详细信息,请参见前面的 jsFiddle

    根据文档,您应该在 destroy()实例上调用 Moveable来将其删除,但是由于 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());
    }
    });
    }

    });

    现在,您可以使用 ConstainedFloatingPane而不是 dojox.layout.FloatingPane:
    var floatingPane = new ConstrainedFloatingPane({
    title: "A Constrained Floating Pane",
    resizable: true
    }, searchboxNode);

    关于dojo - 限制Dojo FloatingPane的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9445868/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com