title: Magnific popup closes on content click after replacing content
body: <p>I am using <strong>Magnific Popup version 0.8.9.</strong></p>
  
  <p>I am loading content into it via Ajax, and I use a callback for <code>ajaxContentAdded</code>. This callback sets up an event handler for submitting a form that was loaded into the popup, like so:</p>
  
  <pre><code>$('.add-item-btn').magnificPopup({ 
      type: 'ajax',
      closeOnContentClick: false,
      callbacks: {
          ajaxContentAdded: HandleItemFormSubmit
      }
  });
  </code></pre>
  
  <p>This works fine, the form submit is handled correctly. The event handler function posts it to the server, which (in case of errors) returns the entire form including error messages.
  For this purpose I let it replace the popup's content with the returned form, and setup the submit handler again.</p>
  
  <pre><code>function HandleItemFormSubmit()
  {
      var popup = this;
      // Submit form using ajax
      $('form.item-form').submit(function()
      {
          var data = $(this).serialize();
          var url = $(this).attr('action');
  
          $.post(url, data, function(resp)
          {
              if (resp == 'OK')
              {
                  // All good, close up
                  popup.close();  
              }
              else
              {
                  // Show HTML from response (with errors)
                  popup.closeOnContentClick = false;
                  popup.content.replaceWith(resp);
                  popup.updateItemHTML();
                  HandleItemFormSubmit();
              }
          });
  
          return false;
      });
  }
  </code></pre>
  
  <p>However, despite setting <code>closeOnContentClick</code> to false at two different points, the popup immediately closes when content is clicked after the content was replaced (it does work the first time).</p>
  
  <p>The content in the popup has a single root element by the way.</p>
  
  <p>I hope the author or someone else can help out here, I have no idea what is wrong here.</p>
  
  <p>Thank you very much!</p>