From 0db02f0633a758df397fab834ee1f2ed4e97e93b Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 29 May 2015 16:20:33 -0500 Subject: [PATCH] builtin animations --- ionic/animations/animation.js | 19 ++++++++++++++++++- ionic/animations/builtins.js | 16 ++++++++++++++++ ionic/components/modal/modal.js | 12 ++---------- ionic/ionic.js | 2 ++ 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 ionic/animations/builtins.js diff --git a/ionic/animations/animation.js b/ionic/animations/animation.js index bc31f5355f..cc256ece63 100644 --- a/ionic/animations/animation.js +++ b/ionic/animations/animation.js @@ -1,6 +1,8 @@ import * as util from 'ionic/util/util'; +let registry = {}; + export class Animation { constructor(el) { @@ -26,7 +28,7 @@ export class Animation { elements(el) { if (el) { if (typeof el === 'string') { - el = document.querySelectorAll(ele); + el = document.querySelectorAll(el); } if (el.length) { @@ -280,6 +282,21 @@ export class Animation { this._el = this._parent = this._children = this._players = null; } + /* + STATIC CLASSES + */ + static create(element, name) { + let AnimationClass = registry[name]; + if (!AnimationClass) { + AnimationClass = Animation; + } + return new AnimationClass(element); + } + + static register(name, AnimationClass) { + registry[name] = AnimationClass; + } + } class Animate { diff --git a/ionic/animations/builtins.js b/ionic/animations/builtins.js new file mode 100644 index 0000000000..73f2fdc30a --- /dev/null +++ b/ionic/animations/builtins.js @@ -0,0 +1,16 @@ + +import {Animation} from './animation'; + + +class SlideIn extends Animation { + constructor(element) { + super(element); + this + .easing('cubic-bezier(0.1, 0.7, 0.1, 1)') + .duration(400) + .from('translateY', '100%') + .to('translateY', '0%'); + } +} + +Animation.register('slide-in', SlideIn); diff --git a/ionic/components/modal/modal.js b/ionic/components/modal/modal.js index b6d2496441..82caf916aa 100644 --- a/ionic/components/modal/modal.js +++ b/ionic/components/modal/modal.js @@ -155,16 +155,8 @@ class ModalContainer { constructor(elementRef: ElementRef) { this.domElement = elementRef.domElement; - this.animation = new Animation(this.domElement); - console.log('Animation', this.domElement); - var slideIn = new Animation(this.domElement); - - slideIn - .easing('cubic-bezier(0.1, 0.7, 0.1, 1)') - .duration(400) - .from('translateY', '100%') - .to('translateY', '0%') - .play(); + var animation = Animation.create(this.domElement, 'slide-in'); + animation.play(); } } diff --git a/ionic/ionic.js b/ionic/ionic.js index d8d62e19a1..1b03640339 100644 --- a/ionic/ionic.js +++ b/ionic/ionic.js @@ -21,5 +21,7 @@ export * from 'ionic/engine/cordova/cordova' export * from 'ionic/engine/electron/electron' export * from 'ionic/animations/animation' +export * from 'ionic/animations/builtins' + export * from 'ionic/transitions/transition' export * from 'ionic/transitions/ios-transition'