github.com/oinume/lekcije@v0.0.0-20231017100347-5b4c5eb6ab24/backend/infrastructure/dmm_eikaiwa/testdata/49393_files/pc-tablet-global.js (about)

     1  // open/close control for iPad
     2  var NaviApiPcTabletGlobal = function () {};
     3  
     4  var otherService = document.getElementsByClassName('_n4v1-global-other-service')[0];
     5  if (typeof otherService !== 'undefined') {
     6    otherService.addEventListener('click', function () {
     7      document.getElementsByClassName('_n4v1-global-navi')[0].style.visibility = 'hidden';
     8      document.getElementsByClassName('_n4v1-global-navi')[0].classList.remove('_n4v1-global-navi');
     9      document.getElementsByClassName('_n4v1-global-navi-extention')[0].classList.add('_n4v1-global-navi');
    10      document.getElementsByClassName('_n4v1-global-navi')[0].classList.remove('_n4v1-global-navi-extention');
    11    });
    12  }
    13  
    14  // open global navi
    15  NaviApiPcTabletGlobal.openGlobal = function () {
    16    NaviApiPcTabletGlobal.main.style.visibility = 'visible';
    17    NaviApiPcTabletGlobal.main.style.opacity = 1;
    18    NaviApiPcTabletGlobal.main.style.zIndex = 1100;
    19    NaviApiPcTabletGlobal.isOpened = true;
    20  };
    21  
    22  // close global navi
    23  NaviApiPcTabletGlobal.closeGlobal = function () {
    24    NaviApiPcTabletGlobal.main.style.visibility = 'hidden';
    25    NaviApiPcTabletGlobal.main.style.opacity = 0;
    26    NaviApiPcTabletGlobal.main.style.zIndex = 1;
    27    NaviApiPcTabletGlobal.isOpened = false;
    28  };
    29  
    30  // judge if `openNavigationElement` contains `tapTargetElement`
    31  NaviApiPcTabletGlobal.checkTarget = function (tapTargetElement, openNavigationElement) {
    32    if (tapTargetElement === openNavigationElement) {
    33      return true;
    34    }
    35    if (tapTargetElement.parentNode === null) {
    36      return false;
    37    }
    38    return NaviApiPcTabletGlobal.checkTarget(tapTargetElement.parentNode, openNavigationElement);
    39  };
    40  
    41  // script attribute defer is mandatory
    42  NaviApiPcTabletGlobal.isOpened = false;
    43  // TODO replce `class` to `id`
    44  NaviApiPcTabletGlobal.root = document.getElementsByClassName('_n4v1-global')[0];
    45  NaviApiPcTabletGlobal.icon = document.getElementsByClassName('_n4v1-global-icon')[0];
    46  NaviApiPcTabletGlobal.main = document.getElementsByClassName('_n4v1-global-navi')[0];
    47  
    48  // add event listener for tapping global navi
    49  NaviApiPcTabletGlobal.icon.addEventListener('touchend', function () {
    50    if (NaviApiPcTabletGlobal.isOpened) {
    51      NaviApiPcTabletGlobal.closeGlobal();
    52    } else {
    53      NaviApiPcTabletGlobal.openGlobal();
    54    }
    55  });
    56  
    57  // add event listener for outside of global navi
    58  document.body.addEventListener('touchend', function (e) {
    59    if (!NaviApiPcTabletGlobal.checkTarget(e.target, NaviApiPcTabletGlobal.root)) {
    60      NaviApiPcTabletGlobal.closeGlobal();
    61    }
    62  });