123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- goog.provide('goog.ui.AnimatedZippy');
- goog.require('goog.dom');
- goog.require('goog.dom.TagName');
- goog.require('goog.events');
- goog.require('goog.fx.Animation');
- goog.require('goog.fx.Transition');
- goog.require('goog.fx.easing');
- goog.require('goog.ui.Zippy');
- goog.require('goog.ui.ZippyEvent');
- goog.ui.AnimatedZippy = function(header, content, opt_expanded, opt_domHelper) {
- var domHelper = opt_domHelper || goog.dom.getDomHelper();
-
- var elWrapper =
- domHelper.createDom(goog.dom.TagName.DIV, {'style': 'overflow:hidden'});
- var elContent = domHelper.getElement(content);
- elContent.parentNode.replaceChild(elWrapper, elContent);
- elWrapper.appendChild(elContent);
-
- this.elWrapper_ = elWrapper;
-
- this.anim_ = null;
-
- goog.ui.Zippy.call(
- this, header, elContent, opt_expanded, undefined, domHelper);
-
-
-
- var expanded = this.isExpanded();
- this.elWrapper_.style.display = expanded ? '' : 'none';
- this.updateHeaderClassName(expanded);
- };
- goog.inherits(goog.ui.AnimatedZippy, goog.ui.Zippy);
- goog.tagUnsealableClass(goog.ui.AnimatedZippy);
- goog.ui.AnimatedZippy.Events = {
-
- TOGGLE_ANIMATION_BEGIN: goog.events.getUniqueId('toggleanimationbegin'),
-
- TOGGLE_ANIMATION_END: goog.events.getUniqueId('toggleanimationend')
- };
- goog.ui.AnimatedZippy.prototype.animationDuration = 500;
- goog.ui.AnimatedZippy.prototype.animationAcceleration = goog.fx.easing.easeOut;
- goog.ui.AnimatedZippy.prototype.isBusy = function() {
- return this.anim_ != null;
- };
- goog.ui.AnimatedZippy.prototype.setExpanded = function(expanded) {
- if (this.isExpanded() == expanded && !this.anim_) {
- return;
- }
-
-
- if (this.elWrapper_.style.display == 'none') {
- this.elWrapper_.style.display = '';
- }
-
- var h = this.getContentElement().offsetHeight;
-
- var startH = 0;
- if (this.anim_) {
- expanded = this.isExpanded();
- goog.events.removeAll(this.anim_);
- this.anim_.stop(false);
- var marginTop = parseInt(this.getContentElement().style.marginTop, 10);
- startH = h - Math.abs(marginTop);
- } else {
- startH = expanded ? 0 : h;
- }
-
- this.updateHeaderClassName(expanded);
-
- this.anim_ = new goog.fx.Animation(
- [0, startH], [0, expanded ? h : 0], this.animationDuration,
- this.animationAcceleration);
- var events = [
- goog.fx.Transition.EventType.BEGIN, goog.fx.Animation.EventType.ANIMATE,
- goog.fx.Transition.EventType.END
- ];
- goog.events.listen(this.anim_, events, this.onAnimate_, false, this);
- goog.events.listen(
- this.anim_, goog.fx.Transition.EventType.BEGIN,
- goog.bind(this.onAnimationBegin_, this, expanded));
- goog.events.listen(
- this.anim_, goog.fx.Transition.EventType.END,
- goog.bind(this.onAnimationCompleted_, this, expanded));
-
- this.anim_.play(false);
- };
- goog.ui.AnimatedZippy.prototype.onAnimate_ = function(e) {
- var contentElement = this.getContentElement();
- var h = contentElement.offsetHeight;
- contentElement.style.marginTop = (e.y - h) + 'px';
- };
- goog.ui.AnimatedZippy.prototype.onAnimationBegin_ = function(expanding) {
- this.dispatchEvent(new goog.ui.ZippyEvent(
- goog.ui.AnimatedZippy.Events.TOGGLE_ANIMATION_BEGIN, this, expanding));
- };
- goog.ui.AnimatedZippy.prototype.onAnimationCompleted_ = function(expanded) {
-
- if (expanded) {
- this.getContentElement().style.marginTop = '0';
- }
- goog.events.removeAll( (this.anim_));
- this.setExpandedInternal(expanded);
- this.anim_ = null;
- if (!expanded) {
- this.elWrapper_.style.display = 'none';
- }
-
- this.dispatchEvent(
- new goog.ui.ZippyEvent(goog.ui.Zippy.Events.TOGGLE, this, expanded));
- this.dispatchEvent(new goog.ui.ZippyEvent(
- goog.ui.AnimatedZippy.Events.TOGGLE_ANIMATION_END, this, expanded));
- };
|