ember.js - Ember, show spinner after changing route -


i show spinner (loading, please wait..) when user has wait data loaded.

let's assume loading data takes considerable time (1+ seconds). want show visual feedback happening, instance when user navigates pressing "next item" from

http://localhost:9000/#/somedata/1 

to

http://localhost:9000/#/somedata/2 

i found few articles problem, however, none of them seem work. article here describes displaying spinner instance https://gist.github.com/tomdale/3981133. however, article outdated. able access isloaded state of array changing {{#if isloaded}} {{#if content.isloaded}}. however, content.isloaded 'true' while new data fetched using ember-data.

another promissing article found template loading delay ember.js. however, here while transitioning url, layout displayed, once data loaded.

i using ember-data revision: 12 , ember 1.0.0-rc.3.

i implemented solution using combination of jquery's ajaxstart , ajaxstop functions , spin.js.

i run in app.ready function:

spinner: -> opts =   lines: 13 # // number of lines draw   length: 20 # // length of each line   width: 10 # // line thickness   radius: 30 # // radius of inner circle   corners: 1 # // corner roundness (0..1)   rotate: 0 # // rotation offset   direction: 1 # // 1: clockwise, -1: counterclockwise   color: '#000' # // #rgb or #rrggbb or array of colors   speed: 1 # // rounds per second   trail: 60 # // afterglow percentage   shadow: true # // whether render shadow   hwaccel: false # // whether use hardware acceleration   classname: 'spinner' # // css class assign spinner   zindex: 2e9 # // z-index (defaults 2000000000)   top: 'auto' # // top position relative parent in px   left: 'auto' #// left position relative parent in px  target = document.getelementbyid('centre') spinner = new spinner(opts) $( document ).ajaxstart( =>   spinner.spin(target) ) $( document ).ajaxstop( =>   spinner.stop() ) 

centre empty centred div positioning spinner:

#centre{style: "position:fixed;top:50%;left:50%"} 

the nice thing ajaxstart tracks concurrent downloads. ajaxstart fires when first call starts , ajaxstop called when ajax calls have finished. makes nice spinner experience.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -