2012-08-07 60 views
0

首先出現的是這個已經是一個提問/回答: Constrain position of Dojo FloatingPane http://jsfiddle.net/phusick/3vTXW/在道場約束一個可移動的物體都

我使用上述創建活動窗格,它是第一個工作日。然後我用對象創建了一個模塊,約束不再起作用,我可以將對象移出窗口。

我把下面的代碼放在一個單獨的模塊:

define(["dojo/_base/declare", "dojo/dnd/move", "dojox/layout/FloatingPane"],  function(declare, move, FloatingPane){ 
return declare("dashboardFloatingPane", FloatingPane, { 

constructor: function() { 
     this.inherited(arguments); 
     this.moveable = new dojo.dnd.move.boxConstrainedMoveable(
      this.domNode, { 
       handle: this.focusNode, 
       constraints: { 
         l: 0, 
         t: 20, 
         w: 500, 
         h: 500        
        }, 
       within: true 
      } 
     );        
    } 
}); 
}); 

然後,我在這裏創建對象:再次

 require(["dojo/dnd/move", "dojox/layout/FloatingPane", "dashboardFloatingPane", "dojo/domReady!"], 
     function(move, FloatingPane, dashboardFloatingPane) { 

      var widgetNode1 = dojo.byId("widget1"); 

      var floatingPane = new dashboardFloatingPane({ 
       title: "A floating pane", 
       resizable: true, 
       dockable: false, 
       style: "position:absolute;top:40px;left:40px;width:160px;height:100px;"  
       }, widgetNode1); 

      floatingPane.startup(); 
     }); 

但是,我可以移動窗格的地方我想,連外被設置的框。請有任何想法嗎?

回答

1

您需要覆蓋postCreate方法,而不是dojox/layout/FloatingPane類中的contructor

原因是原始類將this.moveable設置爲它自己的可移動類型,因此要覆蓋它,必須將其重新分配給您的受約束的可移動類型。

試試這個:

define(["dojo/_base/declare", "dojo/dnd/move", "dojox/layout/FloatingPane"], function(declare, move, FloatingPane){ 
    return declare("dashboardFloatingPane", FloatingPane, { 

    postCreate: function() { 
     this.inherited(arguments); 
     this.moveable = new dojo.dnd.move.boxConstrainedMoveable(
     // snip... 
    ); 
    } 
    }); 
}); 
+0

謝謝,這是非常合情合理的,它的工作現在:)。 – L4zl0w 2012-08-10 08:41:18