Yahoo! Developer Network Home - Help

YDN Site Search

# YUI Library Examples: Container Family: Creating a "Loading" Panel

# Container Family: Creating a "Loading" Panel

A common use case for the Panel Control involves using it to display "please wait" text and images to indicate that the application is busy doing something. As this page loads, a "please wait"-style Panel Control instance appears and the remainder of the page dims. When the content for the container is loaded (consisting of lorem ipsum text), the panel and its modaliy mask fade away and the page returns to a normal interactive state.

View example in new window.

## Using Panel as a "Please Wait" or "Loading" Indicator

The Panel can be used to display a temporary message is automatically dismissed when a task has completed. In this tutorial, we will build a Panel that will be displayed while content is being loaded from an external data source, and will be dismissed when the content has finished loading.

We will start by instantiating a Panel and configuring it to display an image and some text in its body. We set it's zindex to be higher than other positioned elements on the page:

// Initialize the temporary Panel to display while waiting for external content to load YAHOO.example.container.wait = new YAHOO.widget.Panel("wait", { width:"240px", fixedcenter:true, close:false, draggable:false, zindex:4, modal:true, visible:false } ); YAHOO.example.container.wait.setHeader("Loading, please wait..."); YAHOO.example.container.wait.setBody('<img src="http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif" />'); YAHOO.example.container.wait.render(document.body);

We will also need to place a container for the content that will be dynamically loaded:

<div id="content"></div>

Finally, we will set up our Connection object and configure its callback to load the content into the container element and close the Panel after the content has finished loading. If the connection is successful, the content will be loaded into the container and the Panel will be hidden. If the connection fails, an error message will be displayed in the container.

// Define the callback object for Connection Manager that will set the body of our content area when the content has loaded var content = document.getElementById("content"); var callback = { success : function(o) { content.innerHTML = o.responseText; content.style.visibility = "visible"; YAHOO.example.container.wait.hide(); }, failure : function(o) { content.innerHTML = o.responseText; content.style.visibility = "visible"; content.innerHTML = "CONNECTION FAILED!"; YAHOO.example.container.wait.hide(); } } // Show the Panel YAHOO.example.container.wait.show(); // Connect to our data source and load the data var conn = YAHOO.util.Connect.asyncRequest("GET", "../assets/somedata.php?r=" + new Date().getTime(), callback);

### YUI Logger Output:

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

### 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 "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
- Example of Color Picker Built in a Dialog via JavaScript (included with examples for Color Picker Control (beta))
- Menu Buttons (included with examples for Button Control (beta))
- Split Buttons (included with examples for Button Control (beta))
- OS-Style Programs Menu (included with examples for Menu Family)
- Application Menubar (included with examples for Menu Family)

### More Container Family Resources:

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

Copyright © 2007 Yahoo! Inc. All rights reserved.

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