Guest User

Untitled

a guest
Feb 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. (($)->
  2. window.Album = class Album extends Backbone.Model
  3. isFirstTrack : (index) ->
  4. index == 0
  5.  
  6. isLastTrack : (index) ->
  7. index == (@get 'tracks').length - 1
  8.  
  9. trackUrlAtIndex : (index) ->
  10. return (@get 'tracks')[index].url if index >=0 && index < (@get 'tracks').length
  11.  
  12. window.Albums = class Albums extends Backbone.Collection
  13. model: Album
  14. url: '/albums'
  15.  
  16. window.library = new Albums()
  17.  
  18. window.AlbumView = class AlbumView extends Backbone.View
  19. tagName: 'li'
  20. className: 'album'
  21.  
  22. initialize : ->
  23. _.bindAll this, 'render'
  24. @model.bind 'change', @render
  25. @template = _.template $("#album-template").html()
  26.  
  27. render : ->
  28. renderedContent = @template @model.toJSON()
  29. $(@el).html renderedContent
  30. this
  31.  
  32.  
  33. window.LibraryAlbumView = class LibraryAlbumView extends AlbumView
  34.  
  35. window.LibraryView = class LibraryView extends Backbone.View
  36. tagName: 'section'
  37. className: 'library'
  38.  
  39. initialize : ->
  40. _.bindAll this, 'render'
  41. @template = _.template $("#library-template").html()
  42. @collection.bind 'reset', @render
  43.  
  44. render : ->
  45. ($ @el).html @template({})
  46. $albums = @$ '.albums'
  47. collection = @collection
  48. collection.each( (album) ->
  49. view = new LibraryAlbumView
  50. model: album
  51. collection: collection
  52. $albums.append view.render().el
  53. )
  54. this
  55.  
  56. window.BackboneTunes = class BackboneTunes extends Backbone.Router
  57.  
  58. routes:
  59. '' : 'home'
  60.  
  61. initialize : ->
  62. @libraryView = new LibraryView
  63. collection: window.library
  64.  
  65. home : ->
  66. $container = $ "#container"
  67. $container.empty()
  68. $container.append @libraryView.render().el
  69.  
  70.  
  71. $ ->
  72. window.App = new BackboneTunes()
  73. Backbone.history.start()
  74.  
  75. )(jQuery)
Add Comment
Please, Sign In to add comment