<% content_for :specific_javascript do %>
  <script>
    var eventName = <%= event[:name].to_json.html_safe %>;
    var eventDetails = <%= event[:details].to_json.to_json.html_safe %>;
    var origin = <%= request.env['omniauth.origin'].to_json.html_safe %>;

    if(window.opener) {
      var evt = window.opener.document.createEvent('CustomEvent');
      evt.initCustomEvent(eventName, true, true, eventDetails);

      window.opener.document.dispatchEvent(evt);
      window.close();
    } else if(origin) {
      window.location = origin;
    }
  </script>
<% end %>

<% content_for :account_popup_content do %>
  <h1 class="accounts-popup-heading">Redirecting you back to the application!</h1>
  <p class="accounts-popup-just-a-second">
    Just a second.
  </p>
<% end %>

<% content_for :specific_javascript do %>
  <script>
    var eventName = <%= event[:name].to_json.html_safe %>;
    var eventDetails = <%= event[:details].to_json.to_json.html_safe
     # Note: double-json-ing result in json-string.
     # Sending a string to another window works more reliably than sending and object due to security restrictions in IE.
     %>;
    var origin = <%= request.env['omniauth.origin'].to_json.html_safe %>;

    if(window.opener) {
      var evt = window.opener.document.createEvent('CustomEvent');
      evt.initCustomEvent(eventName, true, true, eventDetails);

      window.opener.document.dispatchEvent(evt);
      window.close();
    } else if(origin) {
      window.location = origin;
    }
  </script>
<% end %>

<% content_for :account_popup_content do %>
  <h1 class="accounts-popup-heading">Redirecting you back to the application!</h1>
  <p class="accounts-popup-just-a-second">
    Just a second.
  </p>
<% end %>

Add comment explaining weird code
Add comment explaining weird code
