Guest User

Untitled

a guest
Oct 1st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. define(['backbone', 'facebook'], function (backbone, facebook) {
  2. var view = backbone.View.extend({
  3. el: '.navbar .login',
  4. message: this.$('.message'),
  5. button: this.$("button"),
  6. events: { "click button": "login" },
  7. initialize: function () {
  8. this.login();
  9. },
  10. authInfo: function (callback, id) {
  11. facebook.status(function (status) {
  12. if (status.status == 'connected') facebook.info(callback, id);
  13. else
  14. facebook.login(function (response) {
  15. if (response.authResponse) facebook.info(callback, id);
  16. });
  17. });
  18. },
  19. login: function () {
  20. var me = this;
  21. this.authInfo(function (user) {
  22. var compiledTemplate = _.template($('#login-message').html(), user);
  23. me.message.html(compiledTemplate);
  24. me.button.hide();
  25. me.message.find('i').click(function () {
  26. facebook.logout();
  27. me.button.show().siblings().empty();
  28. });
  29. });
  30. }
  31. });
  32.  
  33. return view;
  34. });
Add Comment
Please, Sign In to add comment