title: TinyMCE editor inside jQuery dialog autoscrolls top when unfocusing the editor
body: <p>I am having a problem with TinyMCE text editor inside a jQuery dialog. Whenever the text editor's textarea is focused and I unfocus it, the page scrolls to top of the dialog. This obviously only happens if the page is scrollable and the page is not currently scrolled to top. Occurs always with Firefox, sometimes with Chrome.</p>
  
  <p><a href="https://jsfiddle.net/dqrarcv3/" rel="nofollow">https://jsfiddle.net/dqrarcv3/</a></p>
  
  <p>To test it, make sure the Result window is scrollable and not scrolled to top.</p>
  
  <p><strong>Steps to reproduce:</strong></p>
  
  <ol>
  <li>Focus the text editor's textarea</li>
  <li>Click outside of it</li>
  </ol>
  
  <p>Or</p>
  
  <ol>
  <li>Focus the text editor's textarea</li>
  <li>Click a contextmenu (ex. File)</li>
  <li>Hover over another contextmenu (ex. Edit)</li>
  </ol>
  
  <p>Simplified HTML:</p>
  
  <pre><code>&lt;div id="dialog"&gt;
      &lt;div style="height:100px"&gt;
          Lorem ipsum lorem ipsum Lorem ipsum
          lorem ipsum Lorem ipsum lorem ipsum
      &lt;/div&gt;
      &lt;textarea id="editor"&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Simplified JavaScript:</p>
  
  <pre><code>$(document).ready(function () {
      $("#dialog").dialog({
          autoOpen: true,
          width: "auto",
          position: {
              my: "center top",
              at: "center top",
              of: window
          },
          modal: true
      });
  
      $("#editor").css("height", "250px");
      tinymce.init({
          selector: "#editor"
      });
  });
  </code></pre>
  
  <p>It seems that the unfocusing makes TinyMCE focus the dialog's close button which then makes the page scroll to it. If the dialog doesn't have any buttons but some input elements instead, it focuses on the first of them.</p>
  
  <p>I have tracked down the place in TinyMCE code where this happens but commenting the function isn't fixing the problem.</p>
  
  <pre><code>d.on("focusout", function() {
      console.log("FOCUSOUT");
      window.setTimeout(function() {
          var t = e.focusedEditor;
          u(s()) || t != d || (d.fire("blur", {
              focusedEditor: null
          }), e.focusedEditor = null, d.selection &amp;&amp; (d.selection.lastFocusBookmark = null))
      }, 0)
  })
  </code></pre>
  
  <p>Any ideas how to fix this odd behaviour or what is actually causing it?</p>
  
  <h1>EDIT:</h1>
  
  <p>Still having the same issue. Here's a gif of the issue: <a href="http://gfycat.com/SneakyImpartialAmazontreeboa" rel="nofollow">http://gfycat.com/SneakyImpartialAmazontreeboa</a></p>
  
  <p>As seen there, the first focusable element within the dialog gets focused when the TinyMCE editor loses focus (by either clicking somewhere else or switching contextmenu). I added the "FOCUSOUT" console message to TinyMCE's source code but I still couldn't find what is causing it.</p>
  
  <p>Exact code used in the gif above:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Test&lt;/title&gt;
  &lt;link rel="stylesheet" href="/js/jquery-ui/css/redmond/jquery-ui-1.10.4.custom.css"&gt;
  &lt;script src="/js/jquery-1.10.2.js"&gt;&lt;/script&gt;
  &lt;script src="/js/jquery-ui/js/jquery-ui-1.10.4.custom.min.js"&gt;&lt;/script&gt;
  &lt;script src="/js/tinymce/tinymce.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="dialog"&gt;
      &lt;p&gt;Lorem ipsum!&lt;/p&gt;
      &lt;button&gt;BUTTON&lt;/button&gt;
      &lt;p&gt;...text...&lt;/p&gt;
      &lt;p&gt;...text...&lt;/p&gt;
      &lt;p&gt;...text...&lt;/p&gt;
      &lt;p&gt;...text...&lt;/p&gt;
      &lt;textarea id="editor" rows="5"&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  $(document).ready(function()
  {
      $("#dialog").dialog(
      {
          autoOpen: true,
          modal: true,
          width: window.innerWidth / 1.75,
          position: { my: "center top", at: "center top", of: window },
      });
      tinyMCE.init(
      {
          selector: "#editor"
      });
  
      $(".ui-dialog-titlebar").hide(); // Hide dialog titlebar
      $(".ui-dialog").css("border", "1px solid black"); // Add border
  });
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>