我有一个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();
}
});
Run Code Online (Sandbox Code Playgroud)
phu*_*ick 11
首先,请参阅jsFiddle的工作示例:http://jsfiddle.net/phusick/3vTXW/
现在有一些解释;)DnD功能FloatingPane是通过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没有分配到任何物体属性,我不破坏它,我只是实例化这三个中的一个moveables子类中的相同DOM节点上:
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());
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
现在您可以使用ConstainedFloatingPane而不是dojox.layout.FloatingPane:
var floatingPane = new ConstrainedFloatingPane({
title: "A Constrained Floating Pane",
resizable: true
}, searchboxNode);
Run Code Online (Sandbox Code Playgroud)