window.App ||= {}

App.Visualization = require './visualization.js'
App.Story         = require './story.js'
App.Trix          = require 'script!trix'

$(document).ready ->

  $body = $('body')

  # visualizations
  if $body.hasClass 'visualizations'
    # /visualizations/:id
    # /visualizations/:id/edit
    appVisualization = new App.Visualization $('body').data('visualization-id'), $body.hasClass('edit')
    appVisualization.render()
    $( window ).resize appVisualization.resize
  # stories
  else if $body.hasClass 'stories'
    # /stories/:id
    # /stories/:id/edit
    appStory = new App.Story $('body').data('story-id'), $('body').data('visualization-id'), $body.hasClass('edit')
    appStory.render()
    $( window ).resize appStory.resize

  # Activate tooltips
  $('[data-toggle="tooltip"]').tooltip()

  # Setup select-all checkbox in Chapter new/edit
  $('#relations_select_all').change (e) ->
    $('.table tbody input[type=checkbox]').prop 'checked', $(this).prop('checked')

  # Add file input feedback 
  # based on http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
  $(document).on 'change', '.btn-file :file', () ->
      label     = $(this).val().replace(/\\/g, '/').replace(/.*\//, '')
      $(this).parent().siblings('.btn-file-output').html label

window.App ||= {}

App.Visualization = require './visualization.js'
App.Story         = require './story.js'
App.Trix          = require 'script!trix'

$(document).ready ->

  $body = $('body')

  # visualizations
  if $body.hasClass('visualizations') and ($body.hasClass('show') or $body.hasClass('edit'))
    # /visualizations/:id
    # /visualizations/:id/edit
    appVisualization = new App.Visualization $('body').data('visualization-id'), $body.hasClass('edit')
    appVisualization.render()
    $( window ).resize appVisualization.resize
  # stories
  else if $body.hasClass('stories') and ($body.hasClass('show') or $body.hasClass('edit'))
    # /stories/:id
    # /stories/:id/edit
    appStory = new App.Story $('body').data('story-id'), $('body').data('visualization-id'), $body.hasClass('edit')
    appStory.render()
    $( window ).resize appStory.resize

  # Activate tooltips
  $('[data-toggle="tooltip"]').tooltip()

  # Setup select-all checkbox in Chapter new/edit
  $('#relations_select_all').change (e) ->
    $('.table tbody input[type=checkbox]').prop 'checked', $(this).prop('checked')

  # Add file input feedback 
  # based on http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
  $(document).on 'change', '.btn-file :file', () ->
      label     = $(this).val().replace(/\\/g, '/').replace(/.*\//, '')
      $(this).parent().siblings('.btn-file-output').html label

Fix body class check to avoid initialize Visualization or Story classes in templates different to show or edit
Fix body class check to avoid initialize Visualization or Story classes in templates different to show or edit
