YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Container Family: Simple Panel Example

# Container Family: Simple Panel Example

Use the show/hide buttons below to show and hide two simple panels. The first panel is created based on markup on the page and its `draggable` configuration is set to `true`; it can be dragged around the screen.

View example in new window.

Panel #1 from Markup — This Panel is Draggable
This is a Panel that was marked up in the document.
End of Panel #1

## Creating Two Simple Panels

The Panel Control is an extension of Overlay that is meant to behave similarly to an OS window. Unlike true browser popup windows, Panel Control instances are floating DHTML elements embedded directly within the page context. The Panel Control extends the functionality of Overlay, adding support for modality, drag and drop, and close/dismiss buttons. Panel includes a pre-defined stylesheet to support the default look and feel characteristics that you see on this page.

In this tutorial, we will build two Panels. One of them will be based on existing markup; the other will be created dynamically using script. We'll pass configuration properties via the constructor to specify any non-default settings we want to use in our Panel instances.

// Instantiate a Panel from markup YAHOO.example.container.panel1 = new YAHOO.widget.Panel("panel1", { width:"320px", visible:false, constraintoviewport:true } ); YAHOO.example.container.panel1.render(); // Instantiate a Panel from script YAHOO.example.container.panel2 = new YAHOO.widget.Panel("panel2", { width:"320px", visible:false, draggable:false, close:false } ); YAHOO.example.container.panel2.setHeader("Panel #2 from Script"); YAHOO.example.container.panel2.setBody("This is a dynamically generated Panel."); YAHOO.example.container.panel2.setFooter("End of Panel #2"); YAHOO.example.container.panel2.render("container");

These Panels introduce a few configuration properties. The `constraintoviewport` property, when set to true, will keep the Panel from being positioned outside of the viewport; this defends against the panel being dragged out of the viewport by the user and against the panel being moved outside the viewport by scripted changes to its x/y properties. The `draggable` property determines whether the Panel can be dragged (be sure to include the Drag and Drop Utility if you want your panel to be draggable), and the `close` property determines whether the close icon should be displayed in the header of the Panel.

The markup for `panel1` is in standard module format, as is required by the Module and Overlay classes on which Panel is built. We also provide buttons to allow for easy showing and hiding of both Panels:

<div> <button id="show1">Show panel1</button> <button id="hide1">Hide panel1</button> </div> <div id="panel1"> <div class="hd">Panel #1 from Markup</div> <div class="bd">This is a Panel that was marked up in the document.</div> <div class="ft">End of Panel #1</div> </div> <div> <button id="show2">Show panel2</button> <button id="hide2">Hide panel2</button> </div>

## Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### Container Family Examples:

- The Module Control
- Creating and Positioning an Overlay
- Simple Tooltip Example
- One Tooltip, Many Context Elements
- Simple Panel Example
- Skinning a Panel with Custom CSS: Introduction
- Skinning a Panel with Custom CSS: Advanced
- Creating a Modal "Loading" Panel
- Creating a Resizable Panel
- Dialog Quickstart Example
- SimpleDialog Quickstart Example
- Using ContainerEffect Transitions
- Using the Overlay Manager to Manage Multiple Panels
- Implementing Container Keyboard Shortcuts with KeyListener
- Using the Button ARIA Plugin (included with examples for Button Control)
- Using the Container ARIA Plugin
- Using A Menu Button To Replace A <select> Element (included with examples for Button Control)
- Replacing the content of a Button's Menu (included with examples for Button Control)
- Example of Color Picker Built in a Dialog via JavaScript (included with examples for Color Picker Control)
- Layout inside a resizable Panel (included with examples for Layout Manager)
- Editor in a Dialog Control (included with examples for Rich Text Editor)
- Menu Buttons (included with examples for Button Control)
- Popup Calendar - Advanced (included with examples for Calendar Control)
- Showing, Hiding, and Reordering Columns. (included with examples for DataTable Control)
- Split Buttons (included with examples for Button Control)
- Simple Calendar Menu Button (included with examples for Button Control)
- Calendar Menu Button with Date on Button Face (included with examples for Button Control)
- Color Picker Button (included with examples for Button Control)
- Fixed Width Menu Button (included with examples for Button Control)
- OS-Style Programs Menu (included with examples for Menu Family)
- Application Menubar (included with examples for Menu Family)
- Slider Button (included with examples for Button Control)
- Complex Application (included with examples for Layout Manager)

### More Container Family Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2009 Yahoo! Inc. All rights reserved.

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