|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Panel</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Panel</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p> |
|
|
32 |
Panel is a Widget that mimics the functionality of a regular OS window. It is similar to Overlay, with added functionality to support modality, event listeners on which to auto-hide and auto-focus, header/footer button support and skins. Panel does not have any implementation code of it's own. It implements a set of extensions that provide certain sets of functionality. The <a href="../widget/widget-build.html">"Creating Custom Widget Classes"</a> example shows how you can use these extensions to build classes which mix and match some of the above features. |
|
|
33 |
</p> |
|
|
34 |
</div> |
|
|
35 |
|
|
|
36 |
<h2 id="getting-started">Getting Started</h2> |
|
|
37 |
|
|
|
38 |
<p> |
|
|
39 |
To include the source files for Panel and its dependencies, first load |
|
|
40 |
the YUI seed file if you haven't already loaded it. |
|
|
41 |
</p> |
|
|
42 |
|
|
|
43 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre> |
|
|
44 |
|
|
|
45 |
|
|
|
46 |
<p> |
|
|
47 |
Next, create a new YUI instance for your application and populate it with the |
|
|
48 |
modules you need by specifying them as arguments to the <code>YUI().use()</code> method. |
|
|
49 |
YUI will automatically load any dependencies required by the modules you |
|
|
50 |
specify. |
|
|
51 |
</p> |
|
|
52 |
|
|
|
53 |
<pre class="code prettyprint"><script> |
|
|
54 |
// Create a new YUI instance and populate it with the required modules. |
|
|
55 |
YUI().use('panel', function (Y) { |
|
|
56 |
// Panel is available and ready for use. Add implementation |
|
|
57 |
// code here. |
|
|
58 |
}); |
|
|
59 |
</script></pre> |
|
|
60 |
|
|
|
61 |
|
|
|
62 |
<p> |
|
|
63 |
For more information on creating YUI instances and on the |
|
|
64 |
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the |
|
|
65 |
documentation for the <a href="../yui/index.html">YUI Global Object</a>. |
|
|
66 |
</p> |
|
|
67 |
|
|
|
68 |
|
|
|
69 |
<p> |
|
|
70 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
71 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
72 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
73 |
</p> |
|
|
74 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
75 |
|
|
|
76 |
|
|
|
77 |
<h2 id="creating-a-panel">Creating a Panel</h2> |
|
|
78 |
|
|
|
79 |
<p> |
|
|
80 |
This simple example will create a Panel with default functionality. By default, a Panel is rendered with a "close" button added to the header, with modality disabled, and will be hidden if the <code>esc</code> key or "close" button is pressed. |
|
|
81 |
</p> |
|
|
82 |
|
|
|
83 |
<pre class="code prettyprint lang-javascript">YUI().use('panel', function (Y) { |
|
|
84 |
|
|
|
85 |
var panel = new Y.Panel({ |
|
|
86 |
srcNode : '#myPanelContent', |
|
|
87 |
width : 400, |
|
|
88 |
centered: true, |
|
|
89 |
render : true |
|
|
90 |
}); |
|
|
91 |
|
|
|
92 |
});</pre> |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
<h2 id="modal-panel">Modal Panel</h2> |
|
|
96 |
|
|
|
97 |
<p> |
|
|
98 |
A Panel is not modal by default. This functionality can be changed through the <code>modal</code> attribute, either during instantiation or later through the <code>set()</code> method. |
|
|
99 |
</p> |
|
|
100 |
|
|
|
101 |
<pre class="code prettyprint lang-javascript">YUI().use('panel', function (Y) { |
|
|
102 |
|
|
|
103 |
var panel = new Y.Panel({ |
|
|
104 |
srcNode: '#myPanelContent', |
|
|
105 |
width : 400, |
|
|
106 |
modal : true // Make the Panel modal |
|
|
107 |
}); |
|
|
108 |
|
|
|
109 |
panel.render(); |
|
|
110 |
// Optionally, we could have written: |
|
|
111 |
// panel.set('modal', true); |
|
|
112 |
|
|
|
113 |
});</pre> |
|
|
114 |
|
|
|
115 |
|
|
|
116 |
<p> |
|
|
117 |
Panels can be nested in one another, and have different modal behavior. For instance, a modal Panel may launch a non-modal Panel on top of it. The <a href="http://yuilibrary.com/yui/docs/api/classes/WidgetModality.html"><code>WidgetModality</code></a> extension takes care of nesting behavior so no extra code is required for the implementer. Refer to the examples for more information. |
|
|
118 |
</p> |
|
|
119 |
|
|
|
120 |
<h2 id="choosing-when-to-focus-and-hide">Choosing When to Focus and Hide</h2> |
|
|
121 |
|
|
|
122 |
<p> |
|
|
123 |
By default, a modal Panel will return focus to itself if anything else on the page receives focus or is clicked. On the other hand, clicking the "close" button, or pressing the <code>esc</code> key will hide it. Both of these options can be configured as needed through the <code>hideOn</code> and <code>focusOn</code> attributes. |
|
|
124 |
</p> |
|
|
125 |
|
|
|
126 |
<p> |
|
|
127 |
The following code snippet shows how to change the default "hide" behavior. Instead of hiding when the <code>esc</code> key is pressed, the Panel hides whenever something outside its <code>boundingBox</code> is pressed, or when a certain element on the page (with an id of <code>anotherNode</code>) is clicked. |
|
|
128 |
</p> |
|
|
129 |
|
|
|
130 |
<pre class="code prettyprint lang-javascript">YUI().use('panel', function (Y) { |
|
|
131 |
|
|
|
132 |
var panel = new Y.Panel({ |
|
|
133 |
srcNode : '#myPanelContent', |
|
|
134 |
width : 400, |
|
|
135 |
centered: true, |
|
|
136 |
modal : false, |
|
|
137 |
render : true, |
|
|
138 |
|
|
|
139 |
// The `hideOn` Attribute takes an array of objects with a required |
|
|
140 |
// `eventName` property, and two optional properties: |
|
|
141 |
// `node` and `keyCode`. |
|
|
142 |
hideOn: [ |
|
|
143 |
{ |
|
|
144 |
// When we don't specify a `node`, |
|
|
145 |
// it defaults to the `boundingBox` of this Panel instance. |
|
|
146 |
eventName: 'clickoutside' |
|
|
147 |
}, |
|
|
148 |
{ |
|
|
149 |
// Listen to click events on the `node` that was specified. |
|
|
150 |
node : Y.one('#anotherNode'), |
|
|
151 |
eventName: 'click' |
|
|
152 |
} |
|
|
153 |
] |
|
|
154 |
}); |
|
|
155 |
|
|
|
156 |
});</pre> |
|
|
157 |
|
|
|
158 |
|
|
|
159 |
<p> |
|
|
160 |
Similarly, the <code>focusOn</code> attribute can be changed to configure the default focus behavior. |
|
|
161 |
</p> |
|
|
162 |
|
|
|
163 |
<pre class="code prettyprint lang-javascript">var panel = new Y.Panel({ |
|
|
164 |
srcNode : '#myPanelContent', |
|
|
165 |
width : 400, |
|
|
166 |
centered: true, |
|
|
167 |
modal : false, |
|
|
168 |
render : true, |
|
|
169 |
|
|
|
170 |
// The `focusOn` Attribute takes an array of objects with a required |
|
|
171 |
// `eventName` property, and optionally the `node` property. |
|
|
172 |
focusOn: [ |
|
|
173 |
{ |
|
|
174 |
// When we don't specify a `node`, |
|
|
175 |
// it defaults to the `boundingBox` of this Panel instance. |
|
|
176 |
eventName: 'clickoutside' |
|
|
177 |
}, |
|
|
178 |
{ |
|
|
179 |
// Listen to click events on the `node` that was specified. |
|
|
180 |
node : Y.one('#anotherNode'), |
|
|
181 |
eventName: 'click' |
|
|
182 |
} |
|
|
183 |
] |
|
|
184 |
}); |
|
|
185 |
|
|
|
186 |
});</pre> |
|
|
187 |
|
|
|
188 |
|
|
|
189 |
<p> |
|
|
190 |
To simply get rid of the default behavior, we could just set the <code>focusOn</code> and <code>hideOn</code> attributes to empty Arrays. |
|
|
191 |
</p> |
|
|
192 |
|
|
|
193 |
<h2 id="headerfooter-button-support">Header/Footer Button Support</h2> |
|
|
194 |
|
|
|
195 |
<p> |
|
|
196 |
Panel supports header/footer buttons through the <a href="http://yuilibrary.com/yui/docs/api/classes/WidgetButtons.html"><code>WidgetButtons</code></a> and <a href="http://yuilibrary.com/yui/docs/api/classes/WidgetStdMod.html"><code>WidgetStdMod</code></a> extensions. By default, it comes with a "close" button represented by the "x" in the top-right corner of the header. As a developer, you can easily add/remove buttons to the header or the footer, change the style of existing buttons, or change the markup that is used to render the buttons. |
|
|
197 |
</p> |
|
|
198 |
|
|
|
199 |
<pre class="code prettyprint lang-javascript">YUI().use('panel', function (Y) { |
|
|
200 |
|
|
|
201 |
function doSomethingElse() { |
|
|
202 |
// ... |
|
|
203 |
} |
|
|
204 |
|
|
|
205 |
var panel = new Y.Panel({ |
|
|
206 |
srcNode : '#myPanelContent', |
|
|
207 |
width : 400, |
|
|
208 |
centered: true, |
|
|
209 |
|
|
|
210 |
// Make changes to the buttons through the `buttons` attribute, |
|
|
211 |
// which takes an Array of Objects. |
|
|
212 |
buttons: [ |
|
|
213 |
{ |
|
|
214 |
// Each object has a `value` property, |
|
|
215 |
// which can be text or an HTML string. |
|
|
216 |
value: "Okay", |
|
|
217 |
|
|
|
218 |
// The `action` property takes the Function that should be |
|
|
219 |
// executed on a click event. |
|
|
220 |
action: function(e) { |
|
|
221 |
e.preventDefault(); |
|
|
222 |
panel.hide(); |
|
|
223 |
doSomethingElse(); |
|
|
224 |
}, |
|
|
225 |
|
|
|
226 |
// The `section` property tells where to render the button and |
|
|
227 |
// should be `Y.WidgetStdMod.HEADER` or `Y.WidgetStdMod.FOOTER`. |
|
|
228 |
section: Y.WidgetStdMod.FOOTER |
|
|
229 |
|
|
|
230 |
// Optional `classNames` property to add CSS classes to the |
|
|
231 |
// button Node. |
|
|
232 |
|
|
|
233 |
// optional `href` property if you are linking to an URL. |
|
|
234 |
} |
|
|
235 |
] |
|
|
236 |
}); |
|
|
237 |
|
|
|
238 |
panel.render(); |
|
|
239 |
|
|
|
240 |
});</pre> |
|
|
241 |
|
|
|
242 |
|
|
|
243 |
<p> |
|
|
244 |
If you want to append buttons to the ones that are already present within the Panel, you can use the <code>addButton()</code> method. |
|
|
245 |
</p> |
|
|
246 |
|
|
|
247 |
<pre class="code prettyprint lang-javascript">var cancelButton = { |
|
|
248 |
value : 'Cancel', |
|
|
249 |
action: function(e) { |
|
|
250 |
e.preventDefault(); |
|
|
251 |
// ... |
|
|
252 |
}, |
|
|
253 |
|
|
|
254 |
// 'header', 'footer' or Y.WidgetStdMod.HEADER also work here. |
|
|
255 |
section: Y.WidgetStdMod.FOOTER |
|
|
256 |
}; |
|
|
257 |
|
|
|
258 |
panel.addButton(cancelButton);</pre> |
|
|
259 |
|
|
|
260 |
|
|
|
261 |
<h2 id="notes-regarding-older-browsers">Notes Regarding Older Browsers</h2> |
|
|
262 |
|
|
|
263 |
<p> |
|
|
264 |
Panel is tested across the A-grade browser set according to the <a href="http://yuilibrary.com/yui/docs/tutorials/gbs/" alt="Graded Browser Support">GBS Browser Test Baseline</a> as of July 2011. |
|
|
265 |
</p> |
|
|
266 |
|
|
|
267 |
<p> |
|
|
268 |
However, developers implementing Panel and other components which rely on <code>z-index</code> support in IE6 and IE7 should be aware of the concept of <a href="https://developer.mozilla.org/en/Understanding_CSS_z-index/Stacking_context_example_2" alt="Stacking Context in IE">stacking context</a>. Essentially, when setting the <code>z-index</code> of the widget, you should ensure that the Widget's parent does not have a lower <code>z-index</code>. |
|
|
269 |
</p> |
|
|
270 |
</div> |
|
|
271 |
</div> |
|
|
272 |
</div> |
|
|
273 |
|
|
|
274 |
<div class="yui3-u-1-4"> |
|
|
275 |
<div class="sidebar"> |
|
|
276 |
|
|
|
277 |
<div id="toc" class="sidebox"> |
|
|
278 |
<div class="hd"> |
|
|
279 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
280 |
</div> |
|
|
281 |
|
|
|
282 |
<div class="bd"> |
|
|
283 |
<ul class="toc"> |
|
|
284 |
<li> |
|
|
285 |
<a href="#getting-started">Getting Started</a> |
|
|
286 |
</li> |
|
|
287 |
<li> |
|
|
288 |
<a href="#creating-a-panel">Creating a Panel</a> |
|
|
289 |
</li> |
|
|
290 |
<li> |
|
|
291 |
<a href="#modal-panel">Modal Panel</a> |
|
|
292 |
</li> |
|
|
293 |
<li> |
|
|
294 |
<a href="#choosing-when-to-focus-and-hide">Choosing When to Focus and Hide</a> |
|
|
295 |
</li> |
|
|
296 |
<li> |
|
|
297 |
<a href="#headerfooter-button-support">Header/Footer Button Support</a> |
|
|
298 |
</li> |
|
|
299 |
<li> |
|
|
300 |
<a href="#notes-regarding-older-browsers">Notes Regarding Older Browsers</a> |
|
|
301 |
</li> |
|
|
302 |
</ul> |
|
|
303 |
</div> |
|
|
304 |
</div> |
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
<div class="sidebox"> |
|
|
309 |
<div class="hd"> |
|
|
310 |
<h2 class="no-toc">Examples</h2> |
|
|
311 |
</div> |
|
|
312 |
|
|
|
313 |
<div class="bd"> |
|
|
314 |
<ul class="examples"> |
|
|
315 |
|
|
|
316 |
|
|
|
317 |
<li data-description="Shows how to instantiate multiple Panel instances, and use nested modality to interact with a Datatable."> |
|
|
318 |
<a href="panel-form.html">Creating a Modal Form</a> |
|
|
319 |
</li> |
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
<li data-description="Shows how to create a panel that animates as it is shown and hidden"> |
|
|
324 |
<a href="panel-animate.html">Creating an Animated Panel</a> |
|
|
325 |
</li> |
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
<li data-description="Shows how to create a dialog instance that can be reused for multiple messages and confirmations."> |
|
|
330 |
<a href="dialog.html">Creating a Reusable Dialog</a> |
|
|
331 |
</li> |
|
|
332 |
|
|
|
333 |
|
|
|
334 |
</ul> |
|
|
335 |
</div> |
|
|
336 |
</div> |
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
</div> |
|
|
341 |
</div> |
|
|
342 |
</div> |
|
|
343 |
</div> |
|
|
344 |
|
|
|
345 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
346 |
<script>prettyPrint();</script> |
|
|
347 |
|
|
|
348 |
<script> |
|
|
349 |
YUI.Env.Tests = { |
|
|
350 |
examples: [], |
|
|
351 |
project: '../assets', |
|
|
352 |
assets: '../assets/panel', |
|
|
353 |
name: 'panel', |
|
|
354 |
title: 'Panel', |
|
|
355 |
newWindow: '', |
|
|
356 |
auto: false |
|
|
357 |
}; |
|
|
358 |
YUI.Env.Tests.examples.push('panel-form'); |
|
|
359 |
YUI.Env.Tests.examples.push('panel-animate'); |
|
|
360 |
YUI.Env.Tests.examples.push('dialog'); |
|
|
361 |
|
|
|
362 |
</script> |
|
|
363 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
|
367 |
</body> |
|
|
368 |
</html> |