code: function(type, target, relatedTarget) {
      var event, canBubble, cancelable;
      if('focusin' === type || 'focusout' === type) {
        canBubble = cancelable = true;
      } else if('blur' === type || 'focus' === type) {
        canBubble = cancelable = false;
      } else {
        throw Error('Unknow focus event type "' + type + '".');
      }
      try {
        // First try to use the constructor
        try {
          var event = new FocusEvent(type, {
            bubbles: canBubble,
            cancelable: cancelable,
            view: window,
            detail: 0,
            relatedTarget: relatedTarget
          });
        } catch(e) {
          // the standard interface is FocusEvent, but not always provided
          if('FocusEvent' in window) {
            event = document.createEvent("FocusEvent");
          } else {
            event = document.createEvent("Event");
          }
          // IE9+ provides a initFocusEvent method
          // http://msdn.microsoft.com/en-us/library/ie/ff974341(v=vs.85).aspx
          if('initFocusEvent' in event) {
            event.initFocusEvent(type, canBubble, cancelable, window, 0,
              relatedTarget);
          } else {
            event.initEvent(type, canBubble, cancelable);
            this.setEventProperty(event, 'relatedTarget', relatedTarget);
          }
          
        }
        return target.dispatchEvent(event);
      } catch(e) {
        // old IE fallback
        event = document.createEventObject();
        event.eventType = type;
        event.relatedTarget = relatedTarget;
        return target.fireEvent('on'+type, event)
      }
    }
docs: dispatch a focus event http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent