npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

r-modalwindow

v2.0.6

Published

Simple JS Library for modal

Downloads

21

Readme

Modal


Описание плагина

Простая библиотека модальных окон. Есть возможность передвигаться по открытому модальному окну с клавиатуры, фокус автоматически перемещается к нему по открытию, что делает взаимодействие с сайтом более доступным.

Есть возможность открывать модальные окна внутри отрытого модального окна. По мимо этого при открытии / закрытии не происходит "сдвига" страницы из-за скрывающейся полосы прокрутки, что делает пользовательский опыт более приятным.

Демо: https://codepen.io/arti-set-dev/pen/YzgJomo

Загрузка и инициализация

Для загрузки введите команду: npm i r-modalwindow.

после загрузки перед инициализацией пропишите необходимые для работы плагина атрибуты. Для кнопки открытия модального окна задайте атрибут data-modal-btn с индивидуальным значением. Например,

<button type="button" data-modal-btn="my-modal">Открыть модальное окно</button>

Модальному окну задайте атрибут data-modal-window и тоже значение что и кнопке:

<div class="modal__window" data-modal-window="my-modal">Модальное окно</div>

Внешней обёртке (modal) задайте атрибут data-modal-overlay

Если внутри модального окна должна присутствовать кнопка, закрывающая его, то задайте такой кнопке атрибут data-modal-close.

В итоге html разметка может выглядеть примерно так:

<button type="button" data-modal-btn="first-modal" data-modal-speed="300">
  Модальное окно 1
</button>
<button type="button" data-modal-btn="second-modal">Модальное окно 2</button>
<button type="button" data-modal-btn="last-modal" data-modal-speed="600">
  Модальное окно 3
</button>

<div class="modal" data-modal-overlay>
  <div class="modal__window" data-modal-window="first-modal">
    Модальное окно 1
    <button type="button" data-modal-btn="last-modal">Модальное окно 3</button>
    <button type="button" data-modal-close>Закрыть окно</button>
    <input type="text" />
  </div>
  <div class="modal__window" data-modal-window="second-modal">
    Модальное окно 2
    <button type="button" data-modal-close>Закрыть окно</button>
    <button type="button" data-modal-btn="first-modal">Модальное окно 1</button>
  </div>
  <div class="modal__window" data-modal-window="last-modal">
    Модальное окно 3
    <button type="button">button</button>
    <button type="button">button</button>
    <button type="button" data-modal-btn="second-modal">
      Модальное окно 2
    </button>
  </div>
  <div class="modal__window" data-modal-window="promo-modal">
    promo
    <button type="button" data-modal-btn="first-modal">Модальное окно 1</button>
  </div>
</div>

Для инициализации пропишите следующий код:

const modal = new ModalWindow("[data-modal-btn]");

Настройки

speed

По умолчанию 300. Для изменения скорости пропишите кнопке открытия модального окна атрибут data-modal-speed с нужным значением:

<button type="button" class="btn" data-modal="my-modal" data-modal-speed="400">
  Модальное окно
</button>

Если нужно изменить скорость по умолчанию - используйте параметр defaultSpeed и задайте нужное значение:

const modal = new ModalWindow("[data-modal]", {
  speed: 700,
});

Убрать "прыжок" у фиксированных элементов

Если на странице присутвуют элементы со свойством position: fixed, задайте таким элементам атрибут data-modal-fix.

Динамический рендер контента в шаблоне модального окна

<button
  type="button"
  data-modal-content="<img src='images.jpg' alt='' class='image'>"
  data-modal-btn="render-modal"
  data-modal-speed="600"
>
  картинка 1
</button>

Результат:

<div
  class="modal__window show active"
  data-modal-window="render-modal"
  role="dialog"
  aria-modal="true"
  aria-hidden="false"
>

  <div class="modal__content">
    <img src="images.jpg" alt="" class="image" />
  </div>
</div>

Изменение атрибутов и классов

Для изменения атрибутов и классов - пропишите следующее:

const modal = new ModalWindow("[data-modal-btn]", {
  classNames: {
    modal: "modal",
    window: "modal__window",
    show: "show",
    active: "active",
  },

  dataAttributes: {
    overlay: "data-modal-overlay",
    modal: "data-modal-btn",
    window: "data-modal-window",
    btnClose: "data-modal-close",
    fixBlock: "data-modal-fix",
  },
});