Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Para usar con turbolinks. En los cambios de página muestra mensajes de carga tipo carrousel.
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
You can’t perform that action at this time.