DCSIMG
Ajax ToolKit:Fix ResizableControl handler position problem - Pini Dayan

Pini Dayan

The best thing about a boolean is even if you are wrong, you are only off by a bit.

Ajax ToolKit:Fix ResizableControl handler position problem

One of the controls available in the Ajax ToolKit is the ResizableControlExtender which makes a panel (div) resizable. One of the major bugs this control has his the ability to set the location for the handler (The place holder for the mouse with the resize cursor) to the left bottom corner of the ResizableControl target. There are many solutions out there , but as I tried them most of them simply do not solve the problem. After downloading the ResizableControlBehavior.js file and learning how it works , here is a simple solution to the problem:

1. Set the HandleOffsetY and HandleOffsetX properties of the ResizableControlExtender control to 3.

2. During this point the handler will be set in the top right corner as the following code from the ResizableControlBehavior.js  indicates: 

  // The this._handleHolder provedes a wrapper with absolute positioning

  // so that this._handle can be absolutely positioned relative to the

  // this._frame instead of the page

  this._handleHolder = document.createElement('DIV');

  this._handleHolder.style.width = '0px';

  this._handleHolder.style.height = '0px';

  this._handleHolder.style.position = ((Sys.Browser.agent === Sys.Browser.Opera) ?

    'relative' : 'absolute');

  this._frame.insertBefore(this._handleHolder, this._frame.firstChild);

 

  // The this._handle represents the UI handle for the user to grab with

  // the mouse

  this._handle = document.createElement('DIV');

  this._handle.className = this._HandleCssClass;

  this._handle.style.position = 'absolute';

  this._handleHolder.appendChild(this._handle);

 

3. So all we need to do is fix the _handler position:

 

  //Get control using the behaviour id

  var resizeControl = $find("ResizableControlExtenderBehavior1");

 

  //Get initial left and top of the handler

  var handlerInitialLeft = resizeControl._handle.style.left;

  var handlerInitialTop = resizeControl._handle.style.top;

 

 //Get the width and height of the resizable control

 var myPanel = $get(GetdivParticipantsID());

 var myPanelWidth = parseInt(myPanel .style.width.replace("px", "")) - 10;

var myPanelHeight = parseInt(myPanel .style.height.replace("px", "")) - 10;

 

//Change the handlers location

resizeControl._handle.style.left = (parseInt(handlerInitialLeft.replace("px", ""), 10) 

                                                 myPanelWidth ) + "px";

resizeControl._handle.style.top = (parseInt(handlerInitialTop.replace("px", ""), 10) +

                                                myPanelHeight ) + "px";

 

Enjoy.

Comments

Veselin said:

Hi!

What is this?

GetdivParticipantsID()???????????

# February 23, 2010 5:33 PM

Pini Dayan said:

This is the Id of my resizable panel that I inject from the server...

# February 25, 2010 11:26 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: