Last active
August 2, 2024 09:51
-
-
Save poteto/acb720a6aa3620b262a4 to your computer and use it in GitHub Desktop.
Slack-like loading messages in an Ember app
This file contains hidden or 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
var computed; | |
App.computed = {}; | |
computed = Ember.computed; | |
App.computed.sample = function(dependentKey) { | |
return (computed("" + dependentKey + ".@each", function() { | |
var items, length; | |
items = this.getWithDefault(dependentKey, Em.A([])); | |
length = items.get('length'); | |
return items[Math.floor(Math.random() * length)] || ''; | |
})).volatile(); | |
}; |
This file contains hidden or 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.LoadingMessageComponent = Ember.Component.extend({ | |
tagName: 'h1', | |
classNames: ['loading', 'animated', 'fadeIn'], | |
showLoadingMessages: false, | |
randomLoadingMessage: App.computed.sample('loadingMessages'), | |
loadingText: Em.computed(function() { | |
return 'Loading'; | |
}), | |
loadingMessages: [ | |
'A day without sunshine is like, you know, night.', | |
'My fake plants died because I did not pretend to water them.', | |
'Weather forecast for tonight: dark.' | |
] | |
}); |
This file contains hidden or 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
.loading { | |
position: relative; | |
text-align: center; | |
margin: { | |
left: auto; | |
right: auto; | |
}; | |
small { | |
display: block; | |
line-height: 1.3em; | |
margin: 10px auto 0 auto; | |
max-width: 80%; | |
text-align: center; | |
} | |
} | |
.loading-wrapper > h1.loading { | |
position: fixed; | |
top: 40%; | |
left: 0; | |
right: 0; | |
} | |
i.ellipsis i { | |
font-style: normal; | |
opacity: 0; | |
-webkit-animation: dot 1.3s infinite; | |
-webkit-animation-delay: 0s; | |
-moz-animation: dot 1.3s infinite; | |
-moz-animation-delay: 0s; | |
-o-animation: dot 1.3s infinite; | |
-o-animation-delay: 0s; | |
animation: dot 1.3s infinite; | |
animation-delay: 0s; | |
} | |
i.ellipsis i+i { | |
opacity: 0; | |
-webkit-animation: dot 1.3s infinite; | |
-webkit-animation-delay: 0.2s; | |
-moz-animation: dot 1.3s infinite; | |
-moz-animation-delay: 0.2s; | |
-o-animation: dot 1.3s infinite; | |
-o-animation-delay: 0.2s; | |
animation: dot 1.3s infinite; | |
animation-delay: 0.2s; | |
} | |
i.ellipsis i+i+i { | |
opacity: 0; | |
-webkit-animation: dot 1.3s infinite; | |
-webkit-animation-delay: 0.3s; | |
-moz-animation: dot 1.3s infinite; | |
-moz-animation-delay: 0.3s; | |
-o-animation: dot 1.3s infinite; | |
-o-animation-delay: 0.3s; | |
animation: dot 1.3s infinite; | |
animation-delay: 0.3s; | |
} | |
@-webkit-keyframes dot { | |
0%, 50% { | |
opacity: 0; | |
} | |
100% { | |
opacity: 1; | |
} | |
} | |
@-moz-keyframes dot { | |
0%, 50% { | |
opacity: 0; | |
} | |
100% { | |
opacity: 1; | |
} | |
} | |
@-o-keyframes dot { | |
0%, 50% { | |
opacity: 0; | |
} | |
100% { | |
opacity: 1; | |
} | |
} | |
@keyframes dot { | |
0%, 50% { | |
opacity: 0; | |
} | |
100% { | |
opacity: 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! Just one quick question. How do I determine Ember initial loading state?