Guest User

Untitled

a guest
Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import StateMachine from './StateMachine'
  2.  
  3. export default {
  4.  
  5. data() {
  6. return {
  7. screenWidth: 0,
  8. screenHeight: 0,
  9. }
  10. },
  11.  
  12. computed: {
  13. aspect: (aspectIntWidth, aspectIntHeight) => aspectIntWidth / aspectIntHeight,
  14. letterbox: (screenWidth, screenHeight, aspect) => screenWidth / aspect > screenHeight ? false : true,
  15. classes: (hasAspect, letterbox) => hasAspect ? (letterbox ? 'letterbox' : 'windowbox') : '',
  16. },
  17.  
  18. oncreate() {
  19. StateMachine.connect(this, [
  20. 'hasAspect',
  21. 'aspectIntWidth',
  22. 'aspectIntHeight',
  23. ])
  24. this.setDimensions()
  25. this.observe('hasAspect', () => this.setDimensions(), { defer: true })
  26. },
  27.  
  28. methods: {
  29. setDimensions() {
  30. this.set({
  31. screenWidth: this.refs.screen.offsetWidth,
  32. screenHeight: this.refs.screen.offsetHeight,
  33. })
  34. StateMachine.setState({ aspectWidth: this.refs.aspect.offsetWidth })
  35. StateMachine.setState({ aspectHeight: this.refs.aspect.offsetHeight })
  36. },
  37. },
  38.  
  39. }
Add Comment
Please, Sign In to add comment