MODI

Default template

  • Config
  • Styles
var defaultTplConfig = {

  html: `
  <div class="{class}" data-element="overlay" data-visible="false" data-outside-close="{outsideClose}">
    <div data-element="modal" data-small-width="500">
      <span data-element="close">×</span>
      <div data-element="content"></div>
    </div>
  </div>
  `,

  data: {
    class: 'modi',
    outsideClose: true
  }
}
$overlay-bg: rgba(0, 0, 0, .6);
$modal-bg: #fff;
$close-bg: #ccc;

body[data-modal-visible='true'] {
  overflow: hidden;
}
.modi[data-element='overlay'] {
  align-items: center;
  background: $overlay-bg;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  left: 0;
  overflow-y: auto;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 999;

  [data-element='modal'] {
    background-color: $modal-bg;
    box-sizing: border-box;
    margin: 20px auto;
    padding: 20px 30px;
    position: relative;
    width: 400px;
    z-index: 9999;

    [data-element='close'] {
      background-color: $close-bg;
      cursor: pointer;
      display: block;
      height: 20px;
      line-height: 20px;
      position: absolute;
      right: 10px;
      text-align: center;
      top: 10px;
      vertical-align: middle;
      width: 20px;
    }

    &[data-small-width-flag='true'] {
      width: 100%;
    }
  }

  &[data-small-height-flag='true'] {
    display: block;

    [data-element='modal'] {
      margin: 20px auto;
      position: relative;
    }
  }

  &[data-visible='false'] {
    display: none;
  }
}

It’s the default template config, so it’s not necessary to specify it during instantiation.

var modal = new Modi({ content: 'Hi world!' });

Changing template settings:

var modal = new Modi({
  content: 'Closing at clicking outside disabled. Close button to the rescue.',
  data: {
    outsideClose: false
  }
});

The modal will be scrollable when his height is larger than the window:

var modal = new Modi({ content: 'Wild Lotsofinfo appeared!' });