<% if @message.persisted? %>
  $('#messages-new-partial')
    .before("<%= j(render 'messages/message', message: @message, thread: @thread ) %>")
    .html("<%= j(render 'messages/new') %>")
  window.streetViewInit()
  window.leafletMapInit()
  window.initImageEdit()
  $('#messages-new-partial').find(".tabs").parent().tabs()
  var el = document.getElementById("<%= dom_id(@message) %>")
  el.scrollIntoView()
  window.scrollBy(0, -80) // Top fix header
  $(el).parent().addClass("new-message-highlight")
<% end %>
<%= render 'shared/flash' %>
<% if flash[:alert].present? %>
  $('html, body').animate({ scrollTop: 0 }, 0)
<% end %>

<% if @message.persisted? %>
  tinyMCE.remove()
  $('#messages-new-partial')
    .before("<%= j(render 'messages/message', message: @message, thread: @thread ) %>")
    .html("<%= j(render 'messages/new') %>")
  window.streetViewInit()
  window.leafletMapInit()
  window.initImageEdit()
  $('#messages-new-partial').find(".tabs").parent().tabs()
  var el = document.getElementById("<%= dom_id(@message) %>")
  el.scrollIntoView()
  window.scrollBy(0, -80) // Top fix header
  $(el).parent().addClass("new-message-highlight")
  // Without a setTimeout tinyMCE has a bug where in initializes
  // but it has no container so the editor is not selectable in FireFox.
  setTimeout(function() {
    tinyMCE.init(window.tinymceOpts)
  }, 1)
<% end %>
<%= render 'shared/flash' %>
<% if flash[:alert].present? %>
  $('html, body').animate({ scrollTop: 0 }, 0)
<% end %>

Fix tinymce after message posting
Fix tinymce after message posting

Fixes #894
