Yahoo! Developer Network Home - Help

YUI Library Examples: Layout Manager (beta): Simple Application

Layout Manager (beta): Simple Application

This example shows an simple application built using the Layout Mananger, Calendar Control, Rich Text Editor and Connection Manager.

Create the Panel

First we must create the panel instance, like this:

Now let's give it some content. Note that we are adding a DIV to the body with an id of layout. This will be the element we anchor the layout to.

Adding the Layout instance

Now we need to listen for the beforeRender event to render our Layout.

Inside of the beforeRender event, we will wait for the element layout to appear in the document, then we will setup our Layout instance.

The layout instance we are creating will have top, left, bottom and center units configured below:

Make the Panel resizable

After we have rendered our panel, we can attach the Resize Utility to it like this:

Now give the resize handle a little CSS to make it look nicer.

This will place a handle at the bottom right corner of the panel. This will only resize the outside portion of the panel, but we want the inside to resize properly.

Now we need to listen for the resize event on the Resize instance and do a little math.

Now we have the Panel resizing the way we want, but the layout is not resizing to match. Inside the resize event from the Resize instance we need to add this at the bottom:

Now we have a resizable panel with a fixed layout inside.

Adding the calendar

Now we listen for the layout's render event and setup our Calendar.

Inside the render event we will call the layout method getUnitByPosition('left') to get the left unit's instance. Then we will create an empty DIV and append it to the body element of the left unit.

Then we will pass that element as the root node for the Calendar Control and render it.

Adding the Rich Text Editor

Using the same technique as above, we will add a Rich Text Editor to the center unit.

Using the layout's getUnitByPosition('center') method, we will set the body of the unit to the textarea that we will convert into an Simple Editor instance. We will also set a custom toolbar to limit the number of buttons.

Make the Editor resize with the Layout and Panel

Now we need to add some code to the resize event to resize the Editor instance when the Layout and Panel are resized.

Making them talk to each other

Now we need to connect the Calendar selectEvent to the Layout Manager.

Now the top unit's header will be updated with the selected date of the Calendar and the Editor will be enabled.

From here, we will set up some pseudo code for saving and storing the data entered on each date selection.

Basically the code below does the following:

  • When a date is selected, set the var dateSelected to the date.
  • Then select that date
  • If the object editorData contains a key matching this date, update the Editor's content with the value.
  • If the var dateSelected was already set, do this:
    • Update the body of the bottom unit with an animated image and status message.
    • Save the Editor HTML to a var html
    • Add a key to editorData for the date and assign its value to the html from the Editor.
    • Fire the Connection Manager request to save the data (this example doesn't do that).
    • Clear the Editor's content.

Full Example Source

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings