Sha256: 8ca6d60a0109c2bdf9945de39cba697e72823fc670b4d4b607532a3f3645edc8

Contents?: true

Size: 1.75 KB

Versions: 11

Compression:

Stored size: 1.75 KB

Contents

# This file enables gridster integration (http://gridster.net/)
# Delete it if you'd rather handle the layout yourself.
# You'll miss out on a lot if you do, but we won't hold it against you.

MyDashboard.gridsterLayout = (positions) ->
  MyDashboard.customGridsterLayout = true
  positions = positions.replace(/^"|"$/g, '')
  positions = $.parseJSON(positions)
  widgets = $("[data-row]")
  maxRow = 1
  maxCol = 1
  numColumns = MyDashboard.numColumns || 1
  for widget, index in widgets
    if positions? and index < positions.length
      $(widget).attr('data-row', positions[index].row)
      $(widget).attr('data-col', positions[index].col)
      if positions[index].row > maxRow
        maxRow = positions[index].row
        maxCol = positions[index].col + 1
      else if positions[index].row == maxRow and positions[index].col >= maxCol
        maxCol = positions[index].col + 1
    else
      if maxCol > numColumns
        maxRow += 1
        maxCol = 1
      $(widget).attr('data-row', maxRow)
      $(widget).attr('data-col', maxCol)
      maxCol += 1

MyDashboard.getWidgetPositions = ->
  $(".gridster ul:first").gridster().data('gridster').serialize()

MyDashboard.showGridsterInstructions = ->
  newWidgetPositions = MyDashboard.getWidgetPositions()

  unless JSON.stringify(newWidgetPositions) == JSON.stringify(MyDashboard.currentWidgetPositions)
    MyDashboard.currentWidgetPositions = newWidgetPositions
    $('#save-gridster').slideDown()
    $('#gridster-code').text("
      <script type='text/javascript'>\n
      $(function() {\n
      \ \ MyDashboard.gridsterLayout('#{JSON.stringify(MyDashboard.currentWidgetPositions)}')\n
      });\n
      </script>
    ")

$ ->
  $('#save-gridster').leanModal()

  $('#save-gridster').click ->
    $('#save-gridster').slideUp()

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
my_dashboard-0.8.1 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.8.0 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.7.2 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.7.1 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.7.0 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.6.0 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.5.10 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.5.9 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.5.8 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.5.7 lib/assets/javascripts/my_dashboard.gridster.coffee
my_dashboard-0.5.6 lib/assets/javascripts/my_dashboard.gridster.coffee