PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/src/views/filmstripview.js

https://bitbucket.org/gordonbrander/rjs-compile-test
JavaScript | 59 lines | 48 code | 8 blank | 3 comment | 1 complexity | 203f1b607125e698bca3193bc465cb87 MD5 | raw file
  1. define([
  2. 'underscore',
  3. 'backbone',
  4. 'lib/template',
  5. 'views/listview',
  6. 'views/sitesingleview'
  7. ], function (
  8. util,
  9. Backbone,
  10. template,
  11. ListView,
  12. SiteSingleView
  13. ) {
  14. var superproto = ListView.prototype;
  15. var FilmstripView = ListView.extend({
  16. className: 'filmstrip',
  17. itemSize: 160, /* 150px + 10px padding */
  18. template: template('<ul class="menu"></ul>'),
  19. initialize: function (options) {
  20. options = options || {};
  21. util.defaults(options, {
  22. view: SiteSingleView,
  23. target: '.menu'
  24. });
  25. // Create a curried factory for views that makes sure their wrapping
  26. // element is an "li".
  27. this.createView = util.bind(this.createView, this, { tagName: 'li' });
  28. $(this.el).html(this.template());
  29. // Run superconstructor to bind events.
  30. superproto.initialize.call(this, options);
  31. var render = this.render;
  32. this.collection
  33. .bind('add', render, this)
  34. .bind('reset', render, this)
  35. .bind('remove', render, this);
  36. },
  37. resetViews: function (collection) {
  38. $(this.target).html('');
  39. collection.each(function (model, i) {
  40. setTimeout(util.bind(this.addView, this, model), i * 30);
  41. }, this);
  42. },
  43. render: function () {
  44. this.$('.menu').css({
  45. width: (this.itemSize * this.collection.length)
  46. });
  47. return this;
  48. }
  49. });
  50. return FilmstripView;
  51. });