Created
August 14, 2012 08:57
-
-
Save aisensiy/3347670 to your computer and use it in GitHub Desktop.
Javascript: show message for loading
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
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