title: How do I trigger tinymce 4.x focus and blur events
body: <p>I realize that this question has been asked and answered several times, but I still can't make many of the solutions work. It seems like most of the discussions are older and maybe not compatible with 4.x.</p>
  
  <p>My goal: be able fire some javascript functions upon focus or blur. Here's the base code:</p>
  
  <pre><code>$('.tiny-mce').tinymce({
      script_url : '/xm_js/tinymce4/tinymce.min.js',
  });
  </code></pre>
  
  <p>I tried examples like:</p>
  
  <pre><code>$('.tiny-mce').tinymce({
      script_url : '/xm_js/tinymce4/tinymce.min.js',
  
      setup : function(ed) {
          ed.onInit.add(function(ed, evt) {
  
          var dom = ed.dom;
          var doc = ed.getDoc();
  
              tinymce.dom.Event.add(doc, 'blur', function(e) {
                  alert('blur!!!');
              });
          });
      }
  });
  </code></pre>
  
  <p>returns:"Uncaught TypeError: Cannot call method 'add' of undefined"</p>
  
  <pre><code>$('.tiny-mce').tinymce({
      script_url : '/xm_js/tinymce4/tinymce.min.js',
  });
  
  tinymce.activeEditor.on('focus', function(e) {
      console.log(e.blurredEditor);
  });
  </code></pre>
  
  <p>returns: "Uncaught TypeError: Cannot call method 'on' of undefined"
  (but not sure if I have it in the right place)</p>
  
  <pre><code>$('.tiny-mce').tinymce({
      script_url : '/xm_js/tinymce4/tinymce.min.js',
  
      setup: function(editor) {
          editor.on('focus', function(e) {
              console.log('focus event', e);
          });
      }
  });
  </code></pre>
  
  <p>returns: "Uncaught SyntaxError: Unexpected identifier"</p>
  
  <p>This works but only when initiating the editor. Other things I've tried but haven't gotten to work:</p>
  
  <p>tinymce.FocusManager
  tinymce.activeEditor</p>
  
  <p>What am I missing? Thanks.</p>
  
  <p><strong>UPDATE: found a solution that worked beautifully:</strong> <a href="https://stackoverflow.com/questions/18695916/why-tinymce-get-focus-and-blur-event-when-user-jump-from-other-input-field/19670992#19670992">Why TinyMCE get focus and blur event, when user jump from other input field?</a></p>