Sha256: 5e997998f92a8b0cdd83e9846b5c5bcce80000c8d8bc565fbb6ef3c1c94f3b05

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

ELA.Views ?= {}

class ELA.Views.Viewport extends Backbone.Poised.View
  tagName: 'article'
  className: 'viewport'

  initialize: (options = {}) ->
    @views = for view in options.views
      view.options = _.omit(view, 'view')
      view.options.name = view.name or Math.random().toString(36).slice(-8)
      view.View = view.view?.toFunction() or ELA.Views.GraphView
      view

    @subviews = {}

    @layout = options.layout or
      [ _.map(@views, (view, idx) -> String.fromCharCode(97 + idx)).join(' ') ]

  _style: ->
    'grid-template-areas: "' + @layout.join('" "') + '";' +
      'grid-auto-columns: 1fr;' +
      'grid-auto-rows: 1fr;'

  render: ->
    @$el.empty().attr('style', @_style())

    for view, idx in @views
      options = _.extend
        model: @model
        parentView: this
        localePrefix: @localePrefix
        attributes:
          style: "grid-area: #{String.fromCharCode(97 + idx)}"
      , view.options
      view = @subviews[view.options.name] ?= new view.View(options)
      @$el.append(view.render().el)

    this

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ela-3.2.0 app/js/lib/views/viewport.coffee
ela-3.1.1 app/js/lib/views/viewport.coffee