Created
December 27, 2011 19:32
-
-
Save ppcano/1524882 to your computer and use it in GitHub Desktop.
Creating modal views with emberjs and movejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Luh.Ui.AnimationStyle = { | |
FROM_DOWN: 0 | |
, FROM_UP: 1 | |
, FROM_LEFT: 2 | |
, FROM_RIGHT: 3 | |
, NONE: 4 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.modalView = Luh.Ui.ModalView.create({ | |
classNames: ['modal'], | |
animationStyle: Luh.Ui.AnimationStyle.FROM_DOWN | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Luh.Ui.ModalView = SC.View.extend({ | |
position: null, | |
move: null, | |
defaultHidden: true, | |
duration: '1s', | |
animationStyle: Luh.Ui.AnimationStyle.FROM_RIGHT, | |
didInsertElement: function() { | |
if ( this.defaultHidden ) { | |
set(this, 'isVisible', false); | |
if ( this.animationStyle !== Luh.Ui.AnimationStyle.NONE ) { | |
var id = get( this, 'elementId'); | |
var position; | |
if ( this._isHorizontalAnimation() ) { | |
this.move = $(window).width(); | |
position = this.move; | |
if ( this.animationStyle === Luh.Ui.AnimationStyle.FROM_LEFT ) { | |
position = position*(-1); | |
} | |
var that = this; | |
move('#'+id) | |
.x(position) | |
.end(function(){ | |
set(that, 'isVisible', true); | |
set(that, 'position', position); | |
}); | |
} else { | |
this.move = $(window).height(); | |
position = this.move; | |
if ( this.animationStyle === Luh.Ui.AnimationStyle.FROM_UP ) { | |
position = position*(-1); | |
} | |
var that = this; | |
move('#'+id) | |
.y(position) | |
.end(function(){ | |
set(that, 'isVisible', true); | |
set(that, 'position', position); | |
}); | |
} | |
} | |
} | |
}, | |
toogle: function() { | |
if ( this.animationStyle !== Luh.Ui.AnimationStyle.NONE ) { | |
var id = get(this, 'elementId'); | |
var position = get(this, 'position'); | |
position = ( position !== 0 ) ? 0 : this.move; | |
if ( this.animationStyle === Luh.Ui.AnimationStyle.FROM_UP || this.animationStyle === Luh.Ui.AnimationStyle.FROM_LEFT ) { | |
position = position*(-1); | |
} | |
if ( this._isHorizontalAnimation() ) { | |
move('#'+id) | |
.x(position) | |
.duration(this.duration) | |
.end(); | |
} else { | |
move('#'+id) | |
.y(position) | |
.duration(this.duration) | |
.end(); | |
} | |
set(this, 'position', position); | |
} else { | |
var isVisible = get(this, 'isVisible'); | |
set(this, 'isVisible', !isVisible); | |
} | |
}, | |
_isHorizontalAnimation: function(){ | |
return ( this.animationStyle === Luh.Ui.AnimationStyle.FROM_LEFT | |
|| this.animationStyle === Luh.Ui.AnimationStyle.FROM_RIGHT); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment