PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/views/sitelistview.js

https://bitbucket.org/gordonbrander/rjs-compile-test
JavaScript | 65 lines | 45 code | 13 blank | 7 comment | 3 complexity | 6139ceb76f04be523304ccd0517d4541 MD5 | raw file
  1. define([
  2. 'underscore', 'backbone',
  3. 'models/sitecollection',
  4. 'views/listview',
  5. 'views/siteview'
  6. ],
  7. function (util, Backbone, SiteCollection, ListView, SiteView) {
  8. var superproto = ListView.prototype;
  9. // A widget that contains the views for a collection of sites.
  10. var SiteListView = ListView.extend({
  11. className: 'sites',
  12. initialize: function (options) {
  13. var self = this;
  14. options = options || {};
  15. options.view = options.view || SiteView;
  16. options.collection = options.collection || new SiteCollection();
  17. superproto.initialize.call(this, options);
  18. // Collection Events
  19. this.collection
  20. .bind('fetch', this.renderLoader, this)
  21. .bind('success', this.removeLoader, this);
  22. // View events
  23. },
  24. fetch: function () {
  25. var collection = this.collection;
  26. collection.fetch.apply(collection, arguments);
  27. },
  28. renderLoader: function () {
  29. // Create a new loader and assign it to a property so we can easily
  30. // remove it later. Creating a new loader every time means we don't
  31. // have to undo the animation leftovers from removeLoader.
  32. this.$loader = $('<div class="loading pin-center">Loading&hellip;</div>')
  33. .css({ opacity: 0 });
  34. $(this.el).append(this.$loader);
  35. this.$loader.animate({ opacity: 0.5, scale: 1 }, 500, 'ease-out');
  36. return this;
  37. },
  38. removeLoader: function () {
  39. var $loader = this.$loader;
  40. $loader.animate(
  41. { opacity: 0, scale: 1.5 },
  42. 400,
  43. 'ease-in',
  44. // After animating the loader, remove it from the DOM.
  45. function () { $loader.remove(); }
  46. );
  47. return this;
  48. },
  49. render: function () { return this; }
  50. });
  51. return SiteListView;
  52. });