Skip to content

Instantly share code, notes, and snippets.

@nicogaldamez
Created July 27, 2016 18:36
Show Gist options
  • Save nicogaldamez/e4a21f66f99585c4577d2495dc4343b4 to your computer and use it in GitHub Desktop.
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.
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