Constrain position of Dojo FloatingPane

故事扮演 提交于 2019-12-05 04:01:28

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!