/**
	_enyo.Drawer_ is a control that appears or disappears based on its _open_
	property. By default, the drawer appears or disappears with a sliding
	animation whose direction is determined by the _orient_ property.

	For more information, see the documentation on
	<a href="https://github.com/enyojs/enyo/wiki/Drawers">Drawers</a> in the
	Enyo Developer Guide.
*/

enyo.kind({
	name: "enyo.Drawer",
	published: {
		//* The visibility state of the drawer's associated control
		open : true,
		/**
			Direction of the opening/closing animation--either "v" for vertical
			or "h" for horizontal
		*/
		orient : "v",
		//* If true, the opening/closing transition will be animated
		animated : true
	},
	events: {
		/**
			Fires when the drawer has been opened or closed. The handler can determine
			whether the drawer was just opened or just closed based on the _open_
			property. If _this.getOpen()_ returns true, the drawer was opened; if not,
			it was closed.
		*/
		onDrawerAnimationStep: "",
		onDrawerAnimationEnd: ""
	},
	//* @protected
	style: "overflow: hidden; position: relative;",
	tools: [
		{kind: "Animator", onStep: "animatorStep", onEnd: "animatorEnd"},
		{name: "client", style: "position: relative;", classes: "enyo-border-box"}
	],
	create: enyo.super(function (sup) {
		return function() {
			sup.apply(this, arguments);
			this.animatedChanged();
			this.openChanged();
		};
	}),
	initComponents: enyo.super(function (sup) {
		return function() {
			this.createChrome(this.tools);
			sup.apply(this, arguments);
		};
	}),
	animatedChanged: function() {
		if (!this.animated && this.hasNode() && this.$.animator.isAnimating()) {
			this.$.animator.stop();
			this.animatorEnd();
		}
	},
	openChanged: function() {
		this.$.client.show();
		if (this.hasNode()) {
			if (this.$.animator.isAnimating()) {
				this.$.animator.reverse();
			} else {
				var v = this.orient == "v";
				var d = v ? "height" : "width";
				var p = v ? "top" : "left";
				// unfixing the height/width is needed to properly
				// measure the scrollHeight/Width DOM property, but
				// can cause a momentary flash of content on some browsers
				this.applyStyle(d, null);
				var s = this.hasNode()[v ? "scrollHeight" : "scrollWidth"];
				if (this.animated) {
					this.$.animator.play({
						startValue: this.open ? 0 : s,
						endValue: this.open ? s : 0,
						dimension: d,
						position: p
					});
				} else {
					// directly run last frame if not animating
					this.animatorEnd();
				}
			}
		} else {
			this.$.client.setShowing(this.open);
		}
	},
	animatorStep: function(inSender) {
		// the actual drawer DOM node adjusts its height
		if (this.hasNode()) {
			var d = inSender.dimension;
			this.node.style[d] = this.domStyles[d] = inSender.value + "px";
		}
		// while the client inside the drawer adjusts its position to move out of the visible area
		var cn = this.$.client.hasNode();
		if (cn) {
			var p = inSender.position;
			var o = (this.open ? inSender.endValue : inSender.startValue);
			cn.style[p] = this.$.client.domStyles[p] = (inSender.value - o) + "px";
		}
		if (this.container) {
			this.container.resized();
		}
		this.doDrawerAnimationStep();
		return true;
	},
	animatorEnd: function() {
		if (!this.open) {
			this.$.client.hide();
		}
		else {
			// save changes to this.domCssText --> see ENYO-1561
			this.$.client.domCssText = enyo.Control.domStylesToCssText(this.$.client.domStyles);
			// at end of open animation, clean limit on height/width
			var v = (this.orient == "v");
			var d = v ? "height" : "width";
			var p = v ? "top" : "left";
			var cn = this.$.client.hasNode();
			// clear out changes to container position & node dimension
			if (cn) {
				cn.style[p] = this.$.client.domStyles[p] = null;
			}
			if (this.node) {
				this.node.style[d] = this.domStyles[d] = null;
			}
		}
		if (this.container) {
			this.container.resized();
		}
		this.doDrawerAnimationEnd();
		return true;
	}
});

@@ -704,16 +704,180 @@
 imated :
+ true,%0D%0A%09%09/**%0D%0A%09%09%09If true, Drawer will resize it's container as it's animating, which is useful%0D%0A%09%09%09when placed inside of a FittableLayout%0D%0A%09%09*/%0D%0A%09%09resizeContainer:
  true%0D%0A%09
@@ -3363,32 +3363,56 @@
  (this.container
+ && this.resizeContainer
 ) %7B%0D%0A%09%09%09this.con
@@ -4160,32 +4160,56 @@
  (this.container
+ && this.resizeContainer
 ) %7B%0D%0A%09%09%09this.con

Add option to defeat default container resizing behavior. This helps fix a widget regression where a widget was attempting to avoid container resizing by checking isAnimating() in the container's resizeHandler. With a recent enyo.Animator change to call cancel() before firing onEnd, isAnimating() no longer returns true in the context of the onEnd event (which seems correct, since the animation has finished), so there's no longer an external way to defeat resizing; much cleaner to make it an API of Drawer itself. Enyo-DCO-1.1-Signed-off-by: Kevin Schaaf <kevin.schaaf@lge.com>