Skip to content

Instantly share code, notes, and snippets.

@aisensiy
Created August 14, 2012 08:57
Show Gist options
  • Save aisensiy/3347670 to your computer and use it in GitHub Desktop.
Save aisensiy/3347670 to your computer and use it in GitHub Desktop.
Javascript: show message for loading
define('HeaderView', [
'jquery',
'underscore',
'backbone',
'text!templates/header.html'
], function($, _, Backbone, tpl) {
var HeaderView;
HeaderView = Backbone.View.extend({
initialize: function() {
var ajaxLoader;
this.template = _.template(tpl);
// Here is the point
// It is a good way to show loading in many scenario
$('body').ajaxStart(function() {
ajaxLoader = ajaxLoader || $('.ajax-loader');
ajaxLoader.show();
}).ajaxStop(function() {
ajaxLoader.fadeOut('fast');
});
},
render: function() {
$(this.el).html(this.template());
return this;
},
select: function(item) {
$('.nav li').removeClass('active');
$('.' + item).addClass('active');
}
});
return HeaderView;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment