Created
July 27, 2016 18:36
-
-
Save nicogaldamez/e4a21f66f99585c4577d2495dc4343b4 to your computer and use it in GitHub Desktop.
Para usar con turbolinks. En los cambios de página muestra mensajes de carga tipo carrousel.
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
class App.LoadingManager | |
# CUSTOMIZABLE | |
MESSAGES: [ | |
'Cargando...' | |
'Sigo cargando...' | |
'Y sigo cargando...' | |
'Parece que se está extendiendo bastante la espera, ¿no?' | |
'Mmmm...capaz que algo se rompió' | |
'Lo dejo a tu criterio el seguir esperando...' | |
'...' | |
] | |
interval: 8000 | |
# ----------------- | |
# | |
index: 0 | |
constructor: () -> | |
$(document).off('page:before-change').on 'page:before-change', => | |
@onBeforePageChanged() | |
$(document).on 'page:change', => | |
clearTimeout(@timer) | |
onBeforePageChanged: () -> | |
@index = 0 | |
@displayLoadingMessage() | |
displayLoadingMessage: () -> | |
App.flash_snackbar_render [@currentMessage()] | |
@setTimer() | |
setTimer: -> | |
@timer = setTimeout (=> | |
@displayLoadingMessage() | |
), @interval | |
currentMessage: -> | |
msg = MESSAGES[@index] | |
@index++ unless @index == MESSAGES.length-1 | |
msg | |
# You must create an instance on page-change | |
$(document).on "page:change", -> | |
new App.LoadingManager() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment