0

I have a div with id "panelContent", I want to resize the div, my current dojo program can move a div i also want to resize it, can anyone help me out.

Thanks in Advance.

Javascript code :

require(["dojo/dnd/Moveable", "dojo/dom", "dojo/on", "dojo/domReady!"],
  function(Moveable, dom, on){

    var dnd = new Moveable(dom.byId("panelContent"));

});

`

Bourbia Brahim
  • 14,459
  • 4
  • 39
  • 52
Harsha
  • 23
  • 7

2 Answers2

1

In the following example you can see how you can initiate a dijit/layout/ContentPane and resize it programmatically (on button click).

Basically you need to:

  • Retrieve your ContentPane using registry.byId().
  • Change the style property for ContentPane using a dojo setter .set('propertyName', yourValue);

require(["dijit/layout/ContentPane", "dijit/registry", "dijit/form/Button", "dojo/domReady!"], function(ContentPane, registry, Button) {
  new ContentPane({
    content: "<p>Optionally set new content now</p>",
    style: "width: 150px; height:150px; background-color:yellow;"
  }, "panelContent").startup();
  var myButton = new Button({
    label: "Click me to enlarge the panel!",
    onClick: function() {
      registry.byId("panelContent").set('style','width: 350px; background-color:red;')
    }
  }, "button").startup();

});
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" />

<script>
  window.dojoConfig = {
    parseOnLoad: false,
    async: true
  };
</script>

<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.1/dojo/dojo.js">
</script>

<body class="claro">
  <div id="panelContent" data-dojo-type="dijit/layout/ContentPane">
    Hi, pretty boring huh?
  </div>
  <button id="button" type="button"></button>
</body>
Bourbia Brahim
  • 14,459
  • 4
  • 39
  • 52
GibboK
  • 71,848
  • 143
  • 435
  • 658
  • 1
    Interesting , also dojox.layout.ResizeHandle would be for instante resizing , (despite its in experimental version not official package ) – Bourbia Brahim Jun 16 '17 at 00:02
  • 1
    @bRIMOs thanks for sharing. I have tried your snippet for `dojox/layout/ResizeHandle` but unfortunately does not work on Chrome Version 58.0.3029.110 (64-bit) and works on FireFox 54.0 (64-bit). I suppose it is a bug on `ResizeHandle`. Could you reproduce this issue? Once again thanks. – GibboK Jun 16 '17 at 06:47
  • 1
    oh yes thnx didn't notice that ! that's wierd , the problem is ,I just changed to and earlier version (1.9) and that works . could you retry , probably bug in newer version .. – Bourbia Brahim Jun 16 '17 at 10:00
  • yep , Should be reported I think – Bourbia Brahim Jun 16 '17 at 10:44
0

This can be achieved by using the dojo ResizeHandler , so the setps to use it are :

  1. import the dojox/layout/ResizeHandle

  2. Import the resize hander Css Style ( for rendering and resize icon )

  3. set your resizable div poristion to relative

  4. instantiate the rsizeHandler and set target to your div id

so the instantiation would be like :

var handle = new ResizeHandle({
      targetId:"panelContent"
  }).placeAt("panelContent");

you can find bellow a working snippet

require([
  "dojox/layout/ResizeHandle",
  "dojo/dnd/move",
  'dojo/dom',
  'dojo/domReady!'
], function(ResizeHandle, dojoDnd, Dom) {

  new dojoDnd.parentConstrainedMoveable(Dom.byId("panelContent"),                 {
                    handle: this.focusNode,
                    area: "content",
                    within: true
                })

  var handle = new ResizeHandle({
      targetId:"panelContent"
  }).placeAt("panelContent");
  

});
#panelContent {
  background-color:green;
  position:relative;
  width:200px;
  height:100px;
  cursor:pointer;
}

body,html,#container {
  width:100%;
  height:100%;
}
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojox/layout/resources/ResizeHandle.css" rel="stylesheet"/>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" />

<script>
  window.dojoConfig = {
    parseOnLoad: false,
    async: true
  };
</script>


<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script>

<div id="container" class="claro">
  <div id="panelContent">
    <div id="handler"></div>
  </div>
</div>
Bourbia Brahim
  • 14,459
  • 4
  • 39
  • 52