src/cm/media/js/lib/yui/yui_3.10.3/docs/overlay/overlay-anim-plugin.html
changeset 525 89ef5ed3c48b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/overlay/overlay-anim-plugin.html	Tue Jul 16 14:29:46 2013 +0200
@@ -0,0 +1,938 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Example: Animation Plugin</title>
+    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
+    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
+    <link rel="stylesheet" href="../assets/css/main.css">
+    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
+    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
+    <script src="../../build/yui/yui-min.js"></script>
+    
+</head>
+<body>
+<!--
+<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>
+-->
+<div id="doc">
+    <div id="hd">
+        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
+    </div>
+    
+
+            <h1>Example: Animation Plugin</h1>
+    <div class="yui3-g">
+        <div class="yui3-u-3-4">
+            <div id="main">
+                <div class="content"><style type="text/css" scoped>
+    /* If js is enabled, hide overlay markup off screen while the overlay is being instantiated */
+    .yui3-js-enabled .yui3-overlay-loading {
+        top:-1000em;
+        left:-1000em;
+        position:absolute;
+    }
+
+/* Overlay Look/Feel */
+.yui3-overlay-content {
+    background-color: #ECEFFB;  
+    border: 1px solid #9EA8C6;
+    border-radius: 3px;
+    box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
+}
+
+.yui3-overlay-content .yui3-widget-hd {
+    background-color: #B6BFDA;  
+    color: #30418C;
+    font-size: 120%;
+    font-weight: bold;
+    padding: 0.2em 0.5em 0.3em;
+    border-radius: 2px 2px 0 0;
+}
+
+.yui3-overlay-content .yui3-widget-bd {
+    padding: 0.4em 0.6em 0.5em;
+}
+
+.yui3-overlay-content .yui3-widget-ft {
+    background-color:#DFE3F5;
+    padding: 0.4em 0.6em 0.5em;
+    border-radius: 0 0 2px 2px;
+}
+
+</style>
+
+<div class="intro">
+    <p>This example shows how you can use Widget's plugin infrastructure to customize the existing behavior of a widget.</p>
+    
+    <p>We create an Animation plugin class for Overlay called <code>AnimPlugin</code> which changes the way Overlay instances are shown/hidden, by fading them in and out. The Overlay is initially constructed with the <code>AnimPlugin</code> plugged in <em>(with the duration set to 2 seconds)</em>.
+    Clicking the "Unplug AnimPlugin" button, will restore the original non-Animated Overlay show/hide behavior. Clicking on the "Plug AnimPlugin" button will plug in the <code>AnimPlugin</code> again, but with a shorter duration.</p>
+    
+    <p>NOTE: This example serves as a tutorial for how to build your own plugins. A packaged animation plugin based on this example is available by using the <code>widget-anim</code> module, which sets up a <a href="http://yuilibrary.com/yui/docs/api/WidgetAnim.js.html"><code>Y.Plugin.WidgetAnim</code></a> class, similar to the one discussed in this example.</p>
+</div>
+
+<div class="example">
+    <div id="overlay" class="yui3-overlay-loading">
+    <div class="yui3-widget-hd">Overlay Header</div>
+    <div class="yui3-widget-bd">Overlay Body</div>
+    <div class="yui3-widget-ft">Overlay Footer</div>
+</div>
+
+<button type="button" id="show">Show</button>
+<button type="button" id="hide">Hide</button>
+<button type="button" id="unplug">Unplug AnimPlugin</button>
+<button type="button" id="plug">Plug AnimPlugin (duration:0.5)</button>
+
+<script type="text/javascript">
+YUI().use("overlay", "anim", "plugin", function(Y) {
+
+    /* Animation Plugin Constructor */
+    function AnimPlugin(config) {
+        AnimPlugin.superclass.constructor.apply(this, arguments);
+    }
+
+    /* 
+     * The namespace for the plugin. This will be the property on the widget, which will 
+     * reference the plugin instance, when it's plugged in
+     */
+    AnimPlugin.NS = "fx";
+
+    /*
+     * The NAME of the AnimPlugin class. Used to prefix events generated
+     * by the plugin class.
+     */
+    AnimPlugin.NAME = "animPlugin";
+
+    /*
+     * The default set of attributes for the AnimPlugin class.
+     */
+    AnimPlugin.ATTRS = {
+
+        /*
+         * Default duration. Used by the default animation implementations
+         */
+        duration : {
+            value: 0.2
+        },
+
+        /*
+         * Default animation instance used for showing the widget (opacity fade-in)
+         */
+        animVisible : {
+            valueFn : function() {
+
+                var host = this.get("host"),
+                    boundingBox = host.get("boundingBox");
+
+                var anim = new Y.Anim({
+                    node: boundingBox,
+                    to: { opacity: 1 },
+                    duration: this.get("duration")
+                });
+
+                // Set initial opacity, to avoid initial flicker
+                if (!host.get("visible")) {
+                    boundingBox.setStyle("opacity", 0);
+                }
+
+                // Clean up, on destroy. Where supported, remove
+                // opacity set using style. Else make 100% opaque
+                anim.on("destroy", function() {
+                    if (Y.UA.ie) {
+                        this.get("node").setStyle("opacity", 1);
+                    } else {
+                        this.get("node").setStyle("opacity", "");
+                    }
+                });
+
+                return anim;
+            }
+        },
+
+        /*
+         * Default animation instance used for hiding the widget (opacity fade-out)
+         */
+        animHidden : {
+            valueFn : function() {
+                return new Y.Anim({
+                    node: this.get("host").get("boundingBox"),
+                    to: { opacity: 0 },
+                    duration: this.get("duration")
+                });
+            }
+        }
+    }
+
+    /*
+     * Extend the base plugin class
+     */
+    Y.extend(AnimPlugin, Y.Plugin.Base, {
+
+        /*
+         * Initialization code. Called when the 
+         * plugin is instantiated (whenever it's 
+         * plugged into the host)
+         */
+        initializer : function(config) {
+            this._bindAnimVisible();
+            this._bindAnimHidden();
+
+            this.after("animVisibleChange", this._bindAnimVisible);
+            this.after("animHiddenChange", this._bindAnimHidden);
+
+            // Override default _uiSetVisible method, with custom animated method
+            this.doBefore("_uiSetVisible", this._uiAnimSetVisible);
+        },
+
+        /*
+         * Destruction code. Invokes destroy in the individual animation instances,
+         * and lets them take care of cleaning up any state.
+         */
+        destructor : function() {
+            this.get("animVisible").stop().destroy();
+            this.get("animHidden").stop().destroy();
+        },
+
+        /*
+         * The custom animation method, added by the plugin.
+         *
+         * This method replaces the default _uiSetVisible handler
+         * Widget provides, by injecting itself before _uiSetVisible,
+         * (using Plugins before method) and preventing the default
+         * behavior.
+         */
+        _uiAnimSetVisible : function(val) {
+            if (this.get("host").get("rendered")) {
+                if (val) {
+                    this.get("animHidden").stop();
+                    this.get("animVisible").run();
+                } else {
+                    this.get("animVisible").stop();
+                    this.get("animHidden").run();
+                }
+                return new Y.Do.Prevent("AnimPlugin prevented default show/hide");
+            }
+        },
+
+        /*
+         * The original Widget _uiSetVisible implementation
+         */
+        _uiSetVisible : function(val) {
+            var host = this.get("host");
+            var hiddenClass = host.getClassName("hidden");
+            if (!val) {
+                host.get("boundingBox").addClass(hiddenClass);
+            } else {
+                host.get("boundingBox").removeClass(hiddenClass);
+            }
+        },
+
+        /* Sets up call to invoke original visibility handling when the animVisible animation is started */
+        _bindAnimVisible : function() {
+            var animVisible = this.get("animVisible");
+
+            // Setup original visibility handling (for show) before starting to animate
+            animVisible.on("start", Y.bind(function() {
+                this._uiSetVisible(true);
+            }, this));
+        },
+
+        /* Sets up call to invoke original visibility handling when the animHidden animation is complete */
+        _bindAnimHidden : function() {
+            var animHidden = this.get("animHidden");
+
+            // Setup original visibility handling (for hide) after completing animation
+            animHidden.after("end", Y.bind(function() {
+                this._uiSetVisible(false);
+            }, this));
+        }
+    });
+
+    // Create a new Overlay instance, and add AnimPlugin with a default duration of 2 seconds
+    var overlay = new Y.Overlay({
+        srcNode: "#overlay",
+        width:"13em",
+        height:"10em",
+        visible:false,
+        shim:false,
+        align: {
+            node: "#show", 
+            points: ["tl", "bl"]
+        },
+        plugins : [{fn:AnimPlugin, cfg:{duration:2}}]
+    });
+    overlay.render();
+
+    Y.on("click", function() {
+        overlay.show();
+    }, "#show");
+
+    Y.on("click", function() {
+        overlay.hide();
+    }, "#hide");
+
+    Y.on("click", function() {
+        overlay.unplug("fx");
+    }, "#unplug");
+
+    Y.on("click", function() {
+        overlay.unplug("fx");
+        overlay.plug(AnimPlugin, {duration:0.5});
+    }, "#plug");
+
+});
+</script>
+
+</div>
+
+<h2>Creating an Animation Plugin For Overlay</h2>
+
+<h3>Setting Up The YUI Instance</h3>
+
+<p>For this example, we'll pull in the <code>overlay</code> module, along with the <code>anim</code> and <code>plugin</code> modules. The <code>anim</code> module provides the animation utility, and <code>plugin</code> will provide
+the <code>Plugin</code> base class which we'll extend to create our <code>AnimPlugin</code>. The code to set up our sandbox instance is shown below:</p>
+ 
+<pre class="code prettyprint">YUI({...}).use(&quot;overlay&quot;, &quot;anim&quot;, &quot;plugin&quot;, function(Y) {
+    &#x2F;&#x2F; We&#x27;ll write our code here, after pulling in the default 
+    &#x2F;&#x2F; Overlay widget, the Animation utility and the 
+    &#x2F;&#x2F; Plugin base class
+});</pre>
+
+
+<p>Using the <code>overlay</code> module will also pull down the default CSS required for overlay, on top of which we only need to add our required look/feel CSS for the example.</p>
+
+<p>
+<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
+page's <code>&lt;body&gt;</code> element or to a parent element of the widget in order to apply
+the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
+</p>
+<pre class="code prettyprint">&lt;body class=&quot;yui3-skin-sam&quot;&gt; &lt;!-- You need this skin class --&gt;</pre>
+
+
+<h3>AnimPlugin Class Structure</h3>
+
+<p>The <code>AnimPlugin</code> class will extend the <code>Plugin</code> base class. Since <code>Plugin</code> derives from <code>Base</code>, we follow the same pattern we use for widgets and other utilities which extend Base to setup our new class.</p>
+
+<p>Namely:</p>
+
+<ul>
+    <li>Setting up the constructor to invoke the superclass constructor</li>
+    <li>Setting up a <code>NAME</code> property, to identify the class</li>
+    <li>Setting up the default attributes, using the <code>ATTRS</code> property</li>
+    <li>Providing prototype implementations for anything we want executed during initialization and destruction using the <code>initializer</code> and <code>destructor</code> lifecycle methods</li>
+</ul>
+    
+<p>Additionally, since this is a plugin, we provide a <code>NS</code> property for the class, which defines the property which will refer to the <code>AnimPlugin</code> instance on the host class (e.g. <code>overlay.fx</code> will be an instance of <code>AnimPlugin</code>)</p>.
+
+<p>This basic structure is shown below:</p>
+
+<pre class="code prettyprint">&#x2F;* Animation Plugin Constructor *&#x2F;
+function AnimPlugin(config) {
+    AnimPlugin.superclass.constructor.apply(this, arguments);
+}
+
+&#x2F;* 
+ * The namespace for the plugin. This will be the property on the widget, which will 
+ * reference the plugin instance, when it&#x27;s plugged in
+ *&#x2F;
+AnimPlugin.NS = &quot;fx&quot;;
+
+&#x2F;*
+ * The NAME of the AnimPlugin class. Used to prefix events generated
+ * by the plugin class.
+ *&#x2F;
+AnimPlugin.NAME = &quot;animPlugin&quot;;
+
+&#x2F;*
+ * The default set of attributes for the AnimPlugin class.
+ *&#x2F;
+AnimPlugin.ATTRS = {
+
+    &#x2F;*
+     * Default duration. Used by the default animation implementations
+     *&#x2F;
+    duration : {
+        value: 0.2
+    },
+
+    &#x2F;*
+     * Default animation instance used for showing the widget (opacity fade-in)
+     *&#x2F;
+    animVisible : {
+        valueFn : function() {
+            ...
+        }
+    },
+
+    &#x2F;*
+     * Default animation instance used for hiding the widget (opacity fade-out)
+     *&#x2F;
+    animHidden : {
+        valueFn : function() {
+            ...
+        }
+    }
+}
+
+&#x2F;*
+ * Extend the base plugin class
+ *&#x2F;
+Y.extend(AnimPlugin, Y.Plugin.Base, {
+
+    &#x2F;&#x2F; Lifecycle methods
+    initializer : function(config) { ... },
+    destructor : function() { ... },
+
+    &#x2F;&#x2F; Other plugin specific methods
+    _uiAnimSetVisible : function(val) { ... },
+    _uiSetVisible : function(val) { ... },
+    ...
+});</pre>
+
+
+<h3>Attributes: animVisible, animHidden</h3>
+
+<p>The <code>animVisible</code> and <code>animHidden</code> attributes use Attribute's <code>valueFn</code> support to set up instance based default values for the attributes.</p>
+
+<p>The <code>animHidden</code> attribute is pretty straight forward and simply returns the Animation instance bound to the bounding box of the Overlay to provide a fade-out animation:</p>
+
+<pre class="code prettyprint">animHidden : {
+    valueFn : function() {
+        return new Y.Anim({
+            node: this.get(&quot;host&quot;).get(&quot;boundingBox&quot;),
+            to: { opacity: 0 },
+            duration: this.get(&quot;duration&quot;)
+        });
+    }
+}</pre>
+
+
+<p>The <code>animVisible</code> attribute is a little more interesting:</p>
+
+<pre class="code prettyprint">animVisible : {
+    valueFn : function() {
+
+        var host = this.get(&quot;host&quot;),
+            boundingBox = host.get(&quot;boundingBox&quot;);
+
+        var anim = new Y.Anim({
+            node: boundingBox,
+            to: { opacity: 1 },
+            duration: this.get(&quot;duration&quot;)
+        });
+
+        &#x2F;&#x2F; Set initial opacity, to avoid initial flicker
+        if (!host.get(&quot;visible&quot;)) {
+            boundingBox.setStyle(&quot;opacity&quot;, 0);
+        }
+
+        &#x2F;&#x2F; Clean up, on destroy. Where supported, remove
+        &#x2F;&#x2F; opacity set using style. Else make 100% opaque
+        anim.on(&quot;destroy&quot;, function() {
+            if (Y.UA.ie) {
+                this.get(&quot;node&quot;).setStyle(&quot;opacity&quot;, 1);
+            } else {
+                this.get(&quot;node&quot;).setStyle(&quot;opacity&quot;, &quot;&quot;);
+            }
+        });
+
+        return anim;
+    }
+}</pre>
+
+
+<p>It essentially does the same thing as <code>animHidden</code>; setting up an Animation instance to provide an opacity based fade-in. However it also sets up a listener which will attempt to cleanup the opacity state of the Overlay when the plugin is unplugged from the Overlay. When a plugin is unplugged, it is destroyed.</p>
+
+<h3>Lifecycle Methods: initializer, destructor</h3>
+
+<p>In the <code>initializer</code>, we set up listeners on the animation instances (using <code>_bindAnimVisible, _bindAnimHidden</code>), which invoke the original visibility handling to make the Overlay visible before starting the <code>animVisible</code> animation and hide it after the <code>animHidden</code> animation is complete.</p>
+
+<pre class="code prettyprint">initializer : function(config) {
+    this._bindAnimVisible();
+    this._bindAnimHidden();
+
+    this.after(&quot;animVisibleChange&quot;, this._bindAnimVisible);
+    this.after(&quot;animHiddenChange&quot;, this._bindAnimHidden);
+
+    &#x2F;&#x2F; Override default _uiSetVisible method, with custom animated method
+    this.doBefore(&quot;_uiSetVisible&quot;, this._uiAnimSetVisible);
+}
+
+...
+
+_bindAnimVisible : function() {
+    var animVisible = this.get(&quot;animVisible&quot;);
+
+    animVisible.on(&quot;start&quot;, Y.bind(function() {
+        &#x2F;&#x2F; Setup original visibility handling (for show) before starting to animate
+        this._uiSetVisible(true);
+    }, this));
+},
+
+_bindAnimHidden : function() {
+    var animHidden = this.get(&quot;animHidden&quot;);
+
+    animHidden.after(&quot;end&quot;, Y.bind(function() {
+        &#x2F;&#x2F; Setup original visibility handling (for hide) after completing animation
+        this._uiSetVisible(false);
+    }, this));
+}</pre>
+
+
+<p>
+However the key part of the <code>initializer</code> method is the call to <code>this.doBefore(&quot;_uiSetVisible&quot;, this._uiAnimSetVisible)</code> <em>(line 9)</em>. <code>Plugin</code>'s <code>doBefore</code> and <code>doAfter</code> methods, will let you set up both before/after event listeners, as well as inject code to be executed before or after a given method on the host object (in this case the Overlay) is invoked.
+</p>
+<p>
+For the animation plugin, we want to change how the Overlay updates its UI in response to changes to the <code>visible</code> attribute. Instead of simply flipping visibility (through the application of the <code>yui-overlay-hidden</code> class), we want to fade the Overlay in and out. Therefore, we inject our custom animation method, <code>_uiSetAnimVisible</code>, before the Overlay's <code>_uiSetVisible</code>.
+</p>
+
+<p>Using <code>Plugin</code>'s <code>doBefore&#x2F;doAfter</code> methods to setup any event listeners and method injection code on the host object (Overlay), ensures that the custom behavior is removed when the plugin is unplugged from the host, restoring it's original behavior.</p>
+
+<p>The <code>destructor</code> simply calls <code>destroy</code> on the animation instances used, and lets them perform their own cleanup (as defined in the discussion on attributes):</p>
+
+<pre class="code prettyprint">destructor : function() {
+    this.get(&quot;animVisible&quot;).stop().destroy();
+    this.get(&quot;animHidden&quot;).stop().destroy();
+},</pre>
+
+
+<h3>The Animated Visibility Method</h3>
+
+<p>The <code>_uiAnimSetVisible</code> method is the method we use to over-ride the default visibility handling for the Overlay. Instead of simply adding or removing the <code>yui-overlay-hidden</code> class, it starts the appropriate animation depending on whether or not visible is being set to true or false:</p>
+
+<pre class="code prettyprint">_uiAnimSetVisible : function(val) {
+    if (this.get(&quot;host&quot;).get(&quot;rendered&quot;)) {
+        if (val) {
+            this.get(&quot;animHidden&quot;).stop();
+            this.get(&quot;animVisible&quot;).run();
+        } else {
+            this.get(&quot;animVisible&quot;).stop();
+            this.get(&quot;animHidden&quot;).run();
+        }
+        return new Y.Do.Halt();
+    }
+}</pre>
+
+
+<p>Since this method is injected before the default method which handles visibility changes for Overlay (<code>_uiSetVisibility</code>), we invoke <code>Y.Do.Halt()</code> to prevent the original method from being invoked, since we'd like to invoke it in response to the animation starting or completing. 
+<code>Y.Do</code> is YUI's aop infrastructure and is used under the hood by Plugin's <code>doBefore</code> and <code>doAfter</code> methods when injecting code</p>.
+
+<h3>The Original Visibility Method</h3>
+
+<p>The original visiblity handling for Overlay is replicated in the <code>AnimPlugin</code>'s <code>_uiSetVisible</code> method and is invoked before starting the <code>animVisible</code> animation and after completing the <code>animHidden</code> animation as described above.</p>
+
+<pre class="code prettyprint">_uiSetVisible : function(val) {
+    var host = this.get(&quot;host&quot;);
+    if (!val) {
+        host.get(&quot;boundingBox&quot;).addClass(host.getClassName(&quot;hidden&quot;));
+    } else {
+        host.get(&quot;boundingBox&quot;).removeClass(host.getClassName(&quot;hidden&quot;));
+    }
+}</pre>
+
+
+<p><strong>NOTE:</strong> We're evaluating whether or not <code>Y.Do</code> may provide access to the original method for a future release, which would make this replicated code unnecessary.</p>
+
+<h3>Using The Plugin</h3>
+
+<p>All objects which derive from <a href="http://yuilibrary.com/yui/docs/api/Base.html">Base</a> are <a href="http://yuilibrary.com/yui/docs/api/Plugin.Host.html">Plugin Hosts</a>. They provide <code>plug</code> and <code>unplug</code> methods to allow users to add/remove plugins to/from existing instances. They also allow the user to specify the set of plugins to be applied to a new instance, along with their configurations, as part of the constructor arguments:</p>
+
+<pre class="code prettyprint">var overlay = new Y.Overlay({
+    contentBox: &quot;#overlay&quot;,
+    width:&quot;10em&quot;,
+    height:&quot;10em&quot;,
+    visible:false,
+    shim:false,
+    align: {
+        node: &quot;#show&quot;, 
+        points: [&quot;tl&quot;, &quot;bl&quot;]
+    },
+    plugins : [{fn:AnimPlugin, cfg:{duration:2}}]
+});
+overlay.render();</pre>
+
+
+<p>We use the constructor support to setup the <code>AnimPlugin</code> for the instance with a custom value for its <code>duration</code> attribute as shown on line 11 above.</p>
+
+<p><strong>NOTE:</strong> In the interests of keeping the example focused on the plugin infrastructure, we turn off shimming for the overlay. If we needed to enable shimming, In IE6, we'd need to remove the alpha opacity filter set on the shim while animating, to have IE animate the contents of the Overlay correctly.</p>
+
+<p>The example also uses the <code>plug</code> and <code>unplug</code> methods, to add and remove the custom animation behavior after the instance is created:</p>
+
+<pre class="code prettyprint">&#x2F;&#x2F; Listener for the &quot;Unplug AnimPlugin&quot; button, 
+&#x2F;&#x2F; removes the AnimPlugin from the overlay instance
+Y.on(&quot;click&quot;, function() {
+    overlay.unplug(&quot;fx&quot;);
+}, &quot;#unplug&quot;);
+
+&#x2F;&#x2F; Listener for the &quot;Plug AnimPlugin&quot; button, 
+&#x2F;&#x2F; removes the AnimPlugin from the overlay instance, 
+&#x2F;&#x2F; and re-adds it with a new, shorter duration value.
+Y.on(&quot;click&quot;, function() {
+    overlay.unplug(&quot;fx&quot;);
+    overlay.plug(AnimPlugin, {duration:0.5});
+}, &quot;#plug&quot;);</pre>
+
+
+<h2>Complete Example Source</h2>
+<pre class="code prettyprint">&lt;div id=&quot;overlay&quot; class=&quot;yui3-overlay-loading&quot;&gt;
+    &lt;div class=&quot;yui3-widget-hd&quot;&gt;Overlay Header&lt;&#x2F;div&gt;
+    &lt;div class=&quot;yui3-widget-bd&quot;&gt;Overlay Body&lt;&#x2F;div&gt;
+    &lt;div class=&quot;yui3-widget-ft&quot;&gt;Overlay Footer&lt;&#x2F;div&gt;
+&lt;&#x2F;div&gt;
+
+&lt;button type=&quot;button&quot; id=&quot;show&quot;&gt;Show&lt;&#x2F;button&gt;
+&lt;button type=&quot;button&quot; id=&quot;hide&quot;&gt;Hide&lt;&#x2F;button&gt;
+&lt;button type=&quot;button&quot; id=&quot;unplug&quot;&gt;Unplug AnimPlugin&lt;&#x2F;button&gt;
+&lt;button type=&quot;button&quot; id=&quot;plug&quot;&gt;Plug AnimPlugin (duration:0.5)&lt;&#x2F;button&gt;
+
+&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
+YUI().use(&quot;overlay&quot;, &quot;anim&quot;, &quot;plugin&quot;, function(Y) {
+
+    &#x2F;* Animation Plugin Constructor *&#x2F;
+    function AnimPlugin(config) {
+        AnimPlugin.superclass.constructor.apply(this, arguments);
+    }
+
+    &#x2F;* 
+     * The namespace for the plugin. This will be the property on the widget, which will 
+     * reference the plugin instance, when it&#x27;s plugged in
+     *&#x2F;
+    AnimPlugin.NS = &quot;fx&quot;;
+
+    &#x2F;*
+     * The NAME of the AnimPlugin class. Used to prefix events generated
+     * by the plugin class.
+     *&#x2F;
+    AnimPlugin.NAME = &quot;animPlugin&quot;;
+
+    &#x2F;*
+     * The default set of attributes for the AnimPlugin class.
+     *&#x2F;
+    AnimPlugin.ATTRS = {
+
+        &#x2F;*
+         * Default duration. Used by the default animation implementations
+         *&#x2F;
+        duration : {
+            value: 0.2
+        },
+
+        &#x2F;*
+         * Default animation instance used for showing the widget (opacity fade-in)
+         *&#x2F;
+        animVisible : {
+            valueFn : function() {
+
+                var host = this.get(&quot;host&quot;),
+                    boundingBox = host.get(&quot;boundingBox&quot;);
+
+                var anim = new Y.Anim({
+                    node: boundingBox,
+                    to: { opacity: 1 },
+                    duration: this.get(&quot;duration&quot;)
+                });
+
+                &#x2F;&#x2F; Set initial opacity, to avoid initial flicker
+                if (!host.get(&quot;visible&quot;)) {
+                    boundingBox.setStyle(&quot;opacity&quot;, 0);
+                }
+
+                &#x2F;&#x2F; Clean up, on destroy. Where supported, remove
+                &#x2F;&#x2F; opacity set using style. Else make 100% opaque
+                anim.on(&quot;destroy&quot;, function() {
+                    if (Y.UA.ie) {
+                        this.get(&quot;node&quot;).setStyle(&quot;opacity&quot;, 1);
+                    } else {
+                        this.get(&quot;node&quot;).setStyle(&quot;opacity&quot;, &quot;&quot;);
+                    }
+                });
+
+                return anim;
+            }
+        },
+
+        &#x2F;*
+         * Default animation instance used for hiding the widget (opacity fade-out)
+         *&#x2F;
+        animHidden : {
+            valueFn : function() {
+                return new Y.Anim({
+                    node: this.get(&quot;host&quot;).get(&quot;boundingBox&quot;),
+                    to: { opacity: 0 },
+                    duration: this.get(&quot;duration&quot;)
+                });
+            }
+        }
+    }
+
+    &#x2F;*
+     * Extend the base plugin class
+     *&#x2F;
+    Y.extend(AnimPlugin, Y.Plugin.Base, {
+
+        &#x2F;*
+         * Initialization code. Called when the 
+         * plugin is instantiated (whenever it&#x27;s 
+         * plugged into the host)
+         *&#x2F;
+        initializer : function(config) {
+            this._bindAnimVisible();
+            this._bindAnimHidden();
+
+            this.after(&quot;animVisibleChange&quot;, this._bindAnimVisible);
+            this.after(&quot;animHiddenChange&quot;, this._bindAnimHidden);
+
+            &#x2F;&#x2F; Override default _uiSetVisible method, with custom animated method
+            this.doBefore(&quot;_uiSetVisible&quot;, this._uiAnimSetVisible);
+        },
+
+        &#x2F;*
+         * Destruction code. Invokes destroy in the individual animation instances,
+         * and lets them take care of cleaning up any state.
+         *&#x2F;
+        destructor : function() {
+            this.get(&quot;animVisible&quot;).stop().destroy();
+            this.get(&quot;animHidden&quot;).stop().destroy();
+        },
+
+        &#x2F;*
+         * The custom animation method, added by the plugin.
+         *
+         * This method replaces the default _uiSetVisible handler
+         * Widget provides, by injecting itself before _uiSetVisible,
+         * (using Plugins before method) and preventing the default
+         * behavior.
+         *&#x2F;
+        _uiAnimSetVisible : function(val) {
+            if (this.get(&quot;host&quot;).get(&quot;rendered&quot;)) {
+                if (val) {
+                    this.get(&quot;animHidden&quot;).stop();
+                    this.get(&quot;animVisible&quot;).run();
+                } else {
+                    this.get(&quot;animVisible&quot;).stop();
+                    this.get(&quot;animHidden&quot;).run();
+                }
+                return new Y.Do.Prevent(&quot;AnimPlugin prevented default show&#x2F;hide&quot;);
+            }
+        },
+
+        &#x2F;*
+         * The original Widget _uiSetVisible implementation
+         *&#x2F;
+        _uiSetVisible : function(val) {
+            var host = this.get(&quot;host&quot;);
+            var hiddenClass = host.getClassName(&quot;hidden&quot;);
+            if (!val) {
+                host.get(&quot;boundingBox&quot;).addClass(hiddenClass);
+            } else {
+                host.get(&quot;boundingBox&quot;).removeClass(hiddenClass);
+            }
+        },
+
+        &#x2F;* Sets up call to invoke original visibility handling when the animVisible animation is started *&#x2F;
+        _bindAnimVisible : function() {
+            var animVisible = this.get(&quot;animVisible&quot;);
+
+            &#x2F;&#x2F; Setup original visibility handling (for show) before starting to animate
+            animVisible.on(&quot;start&quot;, Y.bind(function() {
+                this._uiSetVisible(true);
+            }, this));
+        },
+
+        &#x2F;* Sets up call to invoke original visibility handling when the animHidden animation is complete *&#x2F;
+        _bindAnimHidden : function() {
+            var animHidden = this.get(&quot;animHidden&quot;);
+
+            &#x2F;&#x2F; Setup original visibility handling (for hide) after completing animation
+            animHidden.after(&quot;end&quot;, Y.bind(function() {
+                this._uiSetVisible(false);
+            }, this));
+        }
+    });
+
+    &#x2F;&#x2F; Create a new Overlay instance, and add AnimPlugin with a default duration of 2 seconds
+    var overlay = new Y.Overlay({
+        srcNode: &quot;#overlay&quot;,
+        width:&quot;13em&quot;,
+        height:&quot;10em&quot;,
+        visible:false,
+        shim:false,
+        align: {
+            node: &quot;#show&quot;, 
+            points: [&quot;tl&quot;, &quot;bl&quot;]
+        },
+        plugins : [{fn:AnimPlugin, cfg:{duration:2}}]
+    });
+    overlay.render();
+
+    Y.on(&quot;click&quot;, function() {
+        overlay.show();
+    }, &quot;#show&quot;);
+
+    Y.on(&quot;click&quot;, function() {
+        overlay.hide();
+    }, &quot;#hide&quot;);
+
+    Y.on(&quot;click&quot;, function() {
+        overlay.unplug(&quot;fx&quot;);
+    }, &quot;#unplug&quot;);
+
+    Y.on(&quot;click&quot;, function() {
+        overlay.unplug(&quot;fx&quot;);
+        overlay.plug(AnimPlugin, {duration:0.5});
+    }, &quot;#plug&quot;);
+
+});
+&lt;&#x2F;script&gt;</pre>
+
+</div>
+            </div>
+        </div>
+
+        <div class="yui3-u-1-4">
+            <div class="sidebar">
+                
+
+                
+                    <div class="sidebox">
+                        <div class="hd">
+                            <h2 class="no-toc">Examples</h2>
+                        </div>
+
+                        <div class="bd">
+                            <ul class="examples">
+                                
+                                    
+                                        <li data-description="Shows how to instantiate a basic Overlay instance, and use the Overlay&#x27;s basic XY positioning support.">
+                                            <a href="overlay-xy.html">Basic XY Positioning</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to create a simple tooltip incorporating the overlay shim feature.">
+                                            <a href="overlay-tooltip.html">Simple Tooltip</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to use the Overlay&#x27;s XY alignment support, to align the Overlay relative to another element, or to the viewport.">
+                                            <a href="overlay-align.html">Alignment Support</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to use the Overlay&#x27;s zindex and shim support when positioning Overlays above other elements on the page.">
+                                            <a href="overlay-stack.html">Stack Support</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to modify content in the Overlay&#x27;s header, body and footer sections.">
+                                            <a href="overlay-stdmod.html">Standard Module Support</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to use Overlay&#x27;s constrainment support, to limit the XY value which can be set for an Overlay.">
+                                            <a href="overlay-constrain.html">Constrain Support</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to create a simple plugin to retrieve content for the Overlay using the io utility.">
+                                            <a href="overlay-io-plugin.html">IO Plugin</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Shows how to create a simple plugin to animate the Overlay&#x27;s movement and visibility.">
+                                            <a href="overlay-anim-plugin.html">Animation Plugin</a>
+                                        </li>
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                            </ul>
+                        </div>
+                    </div>
+                
+
+                
+                    <div class="sidebox">
+                        <div class="hd">
+                            <h2 class="no-toc">Examples That Use This Component</h2>
+                        </div>
+
+                        <div class="bd">
+                            <ul class="examples">
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                
+                                    
+                                        <li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event&#x27;s delegation support and mouseenter event, along with the Overlay widget and Node&#x27;s support for the WAI-ARIA Roles and States.">
+                                            <a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input">
+                                            <a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a>
+                                        </li>
+                                    
+                                
+                            </ul>
+                        </div>
+                    </div>
+                
+            </div>
+        </div>
+    </div>
+</div>
+
+<script src="../assets/vendor/prettify/prettify-min.js"></script>
+<script>prettyPrint();</script>
+
+<script>
+YUI.Env.Tests = {
+    examples: [],
+    project: '../assets',
+    assets: '../assets/overlay',
+    name: 'overlay-anim-plugin',
+    title: 'Animation Plugin',
+    newWindow: '',
+    auto:  false 
+};
+YUI.Env.Tests.examples.push('overlay-xy');
+YUI.Env.Tests.examples.push('overlay-tooltip');
+YUI.Env.Tests.examples.push('overlay-align');
+YUI.Env.Tests.examples.push('overlay-stack');
+YUI.Env.Tests.examples.push('overlay-stdmod');
+YUI.Env.Tests.examples.push('overlay-constrain');
+YUI.Env.Tests.examples.push('overlay-io-plugin');
+YUI.Env.Tests.examples.push('overlay-anim-plugin');
+YUI.Env.Tests.examples.push('node-focusmanager-button');
+YUI.Env.Tests.examples.push('stylesheet-theme');
+
+</script>
+<script src="../assets/yui/test-runner.js"></script>
+
+
+
+</body>
+</html>