/*
===
4.1 Modal
===

### Modal

モーダルウインドウを生成します。
`a`要素の`href`属性の値で、モーダルウインドウに表示する要素が決定します。

* アンカーリンクの場合は同じHTML内のアンカーリンクの要素を表示

* 画像の場合は、画像を表示

* それ以外の場合はURLとみなし、`iframe`要素を表示

#### HTML

```html
<ul>
  <li>
    <a class="modal" href="#target">Anchor link</a>
  </li>
  <li>
    <a class="modal" href="/assets/images/sample.jpg">Image</a>
  </li>
  <li>
    <a class="modal" href="/index.html">Iframe</a>
  </li>
</ul>
```

#### JavaScript

第一引数にNodeListを指定し、第二引数にパラメーターオブジェクトを指定します。

```js
document.addEventListener('DOMContentLoaded', () => {
  const targetList = document.querySelectorAll('.modal');
  const param = {
    useControls: true,
    isLoadingTest: false, // check loading animation
    onOpenBefore: function () {},
    onOpenAfter: function () {},
    onResized: function () {}
  };
  const modal = new Frontwork.Modal(targetList, param);
});
```

*/

@keyframes MODAL_OPENING {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes MODAL_LOADING {
  25% {
    transform: perspective(100px) rotateX(180deg) rotateY(0);
  }

  50% {
    transform: perspective(100px) rotateX(180deg) rotateY(180deg);
  }

  75% {
    transform: perspective(100px) rotateX(0) rotateY(180deg);
  }

  100% {
    transform: perspective(100px) rotateX(0) rotateY(0);
  }
}

.js-modal,
.js-modal__controls {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.js-modal__content,
.js-modal__controls-container {
  position: relative;
  max-width: calc(100% - 20px);
  max-height: calc(100% - 80px);
}

.js-modal {
  position: fixed;
  z-index: 100000;
  background-color: rgba(0, 0, 0, .8);

  &:not(.is-show) {
    display: none;
  }
}

.js-modal__controls {
  position: absolute;
}

.js-modal__content {
  background-color: transparent;
  visibility: hidden;
  z-index: 2;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow-x: auto;
  overflow-y: auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;

  &:focus {
    outline: 0;
  }

  &.is-show {
    visibility: visible;
    animation: MODAL_OPENING .2s ease-in-out 0s;
  }

  & > img { // photo gallary
    display: block;
  }
}

.js-modal__frame {
  visibility: hidden;
}

.js-modal__loading {
  font-size: 0;
  width: 50px;
  height: 50px;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  background-color: rgba(255, 255, 255, .5);
  animation: MODAL_LOADING 3s 0s cubic-bezier(.09, .57, .49, .9) infinite;
}

.js-modal__prev,
.js-modal__next,
.js-modal__close {
  display: block;
  position: fixed;
  overflow: hidden;
  width: 40px;
  height: 40px;
  top: 0;
  font-size: 0;
  z-index: 3;
}

.js-modal__prev,
.js-modal__next {
  &::before {
    content: '';
    display: block;
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-top: 4px solid rgba(255, 255, 255, .5);
    border-left: 4px solid rgba(255, 255, 255, .5);
  }

  &:hover::before {
    border-top-color: #fff;
    border-left-color: #fff;
  }
}

.js-modal__prev {
  right: 80px;

  &::before {
    transform: rotate(-45deg);
    left: 6px;
  }
}

.js-modal__next {
  right: 40px;

  &::before {
    transform: rotate(135deg);
    right: 6px;
  }
}

.js-modal__close {
  opacity: .5;
  right: 0;

  &::before,
  &::after {
    content: '';
    display: block;
    width: 20px;
    height: 3px;
    background-color: #fff;
    margin: auto;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    position: absolute;
  }

  &::before {
    transform: rotate(45deg);
  }

  &::after {
    transform: rotate(-45deg);
  }

  &:hover {
    opacity: 1;
  }
}
