YUI Container: ResizePanel: Creating a Resizable Panel

Subclassing Panel to Create ResizePanel

In this tutorial, we will build a subclass for Panel called ResizePanel that will allow the Panel to be resized using a draggable handle in the bottom-right corner of the footer.

The first step to subclassing the Panel is writing the constructor for the new subclass (ResizePanel, in this case) and specifying its inheritance from the Panel class using YAHOO.extend:

Next, we will define a few constants for use by the ResizePanel class: "CSS_PANEL_RESIZE", which defines the CSS class to apply to the Panel, and "CSS_RESIZE_HANDLE", the CSS class to apply to the resize handler.

Next, the initialization method for the ResizePanel is defined. The first step the initialization must perform is to call the superclass's init method so that the superclasses can initialize first. After that, take the following steps:

  1. We fire the beforeInitEvent and add the CSS class to the Panel;
  2. We create the element that will serve as the resize handle in the footer;
  3. We make sure that the footer is set to blank text if no footer is specified by render time, since a footer is required in order for the ResizePanel to function properly.
  4. Finally, we subscribe a function to the Panel's renderEvent wherein we'll configure the resize handle's Drag and Drop instance (instance of YAHOO.util.DragDrop). The resize is achieved by calculating the difference in position between the handle's start point and end point.