import Vue from 'vue';
import UserAgent from '@/plugins/UserAgent/index';

Vue.directive('iosfit', {
  inserted: function(el) {
    el.addEventListener('focus', e => {
      setTimeout(() => {
        e.target.scrollIntoView();
      }, 300);
    });
    el.addEventListener('blur', e => {
      if (UserAgent.isIos()) {
        setTimeout(() => {
          window.scrollTo(0, 0);
        }, 200);
      }
    });
  }
});
