Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

PicoModal Build StatusBower versionnpm version

A small, self-contained JavaScript modal library

  • Small: At around 2kb minified & gzipped, it's small and easily embeddable
  • No Dependencies: PicoModal does not depend on any other JS libraries, so you can use it in places where you don't have access to one
  • Self-contained: No extra CSS or images required; just the JS
  • Simple: The interface is straight forward and easy to use
  • Customizable: By changing a few settings you can customize or completely replace the default styles and behaviour
  • Accessible: Handles focus management, keyboard events and Aria tags

Download

The latest version of PicoModal is available here: Download

Browser Support

Browser Support Matrix

Basic Example

If all you want to do is display a modal, it's as easy as this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").show();

If you plan on showing the same modal multiple times, make sure you keep a reference to the instance, like this: (Run this code)

varmodal=picoModal("Ah, the pitter patter of tiny feet in huge combat boots.");document.getElementById("modal").addEventListener("click",function(){modal.show();});

For more control over the behaviour of the modal, you can pass in a settings object: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: {backgroundColor: "#169",opacity: 0.75}}).show();

A full list of settings is documented below.

Manually Closing a Modal

If you want to programatically close the modal you can do it like this: (Run this code)

varmodal=picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").show();document.body.addEventListener('click',function(event){if(/\bdismiss\b/.test(event.target.className)){modal.close();}});

Or you can use a more targetted implementation with the afterCreate event: (Run this code)

picoModal("<p>Ah, the pitter patter of tiny feet in huge combat boots.<p>"+"<p><a href='#' class='dismiss'>Dismiss</a></p>").afterCreate(function(modal){modal.modalElem().getElementsByClassName("dismiss")[0].addEventListener('click',modal.close);}).show();

You can also attach an event to fire when the modal is closed: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(){alert("Closed");}).show();

Customizing Behavior

To disable the close button, and instead just rely on someone clicking outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeButton: false}).show();

Or, to disable closing when someone clicks outside of the modal, you can do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayClose: false}).show();

To use custom HTML for the close button, do this: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",closeHtml: "<span>Close</span>",closeStyles: {position: "absolute",top: "-10px",right: "-10px",background: "#eee",padding: "5px 10px",cursor: "pointer",borderRadius: "5px",border: "1px solid #ccc"}}).show();

Events

There are a few events you can hook into for watching and sometimes monitoring the behavior of a modal. The events are:

  • afterCreate: Triggered when the DOM Nodes for a modal are created
  • beforeShow: Triggered before a modal is shown. Allows for cancellation
  • afterShow: Triggered after a modal is shown
  • beforeClose: Triggered before a modal is closed. Allows for cancellation
  • afterClose: triggered after a modal is closed

These exist as methods on the PicoModal instance. You can use them like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){alert("Modal Closed: "+modal.modalElem().innerText);}).show();

The first argument passed to the callback is the PicoModal instance for the specific modal.

For two of the events, beforeShow and beforeClose, there is a second argument passed that lets you cancel the behavior in question. For example: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").beforeShow(function(modal,event){if(!confirm("Are you sure you want to open this modal?")){event.preventDefault();}}).show();

Single Shot Modal

You can use the afterClose event and the destroy method to create a modal that will clean up after itself when it is closed, like this: (Run this code)

picoModal("Ah, the pitter patter of tiny feet in huge combat boots.").afterClose(function(modal){modal.destroy();}).show();

Animation

PicoModal doesn't have any built in animations, but you can use the event system to add some of your own. For example, the following snippet adds a fade in and out using jQuery: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0;},modalStyles: function(styles){styles.opacity=0;}}).afterShow(function(modal){$(modal.overlayElem()).animate({opacity: .5});$(modal.modalElem()).animate({opacity: 1});}).beforeClose(function(modal,event){event.preventDefault();$(modal.overlayElem()).add(modal.modalElem()).animate({opacity: 0},{complete: modal.forceClose});}).show();

Settings

The following settings are available when creating a modal:

  • content: The data to display to the user
  • width: The forced width of the modal
  • closeButton: Boolean whether to display the close button
  • closeHtml: Custom HTML content for the close button
  • closeStyles: A hash of CSS properties to apply to the close button
  • closeClass: A class to attach to the close button
  • overlayClose: Boolean whether a click on the shadow should close the modal
  • overlayStyles: A hash of additional CSS properties to apply to the overlay behind the modal
  • overlayClass: A class to attach to the overlay element
  • modalStyles: A hash of additional CSS properties to apply to the modal element
  • modalClass: A class to attach to the main modal element
  • modalId: The ID to assign to the modal element. A default ID is generated used if none is provided.
  • parent: By default, the modal dialog elements are attached to document.body. This options allows you to select an alternative parent element by specifying a node or a selector
  • escCloses: When false, disables pressing the escape key to close this modal. This defaults to true.
  • focus: Whether to automatically set focus on the first focusable element within this modal when it opens. This defaults to true.
  • ariaDescribedBy: The id of the element that contains the main content of this modal. This sets the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute. This defaults to the ID of the modal if none is provided.
  • ariaLabelledBy: The id of the element that contains the general label for this modal. This sets the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute) attributed. It is left blank if none is provided.
  • bodyOverflow: Whether to set overflow: hidden on the body when the modal is displayed. This prevents the main page from scrolling when a modal is open

If a method is passed as an argument for any of the settings, it will be called. The first argument passed in is the default value for that setting. This makes it easy to modify the defaults instead of having to totally define your own, like so: (Run this code)

picoModal({content: "Ah, the pitter patter of tiny feet in huge combat boots.",overlayStyles: function(styles){styles.opacity=0.1;returnstyles;}}).show();

Modal Instance API

The following methods are available on the object returned by picoModal:

  • modalElem: Returns the modal DOM Node
  • closeElem: Returns the close button DOM Node
  • overlayElem: Returns the overlay DOM Node
  • show: Displays the modal
  • buildDom: Builds the DOM for the modal, but without showing it
  • close: Hides the modal
  • forceClose: Hides the modal without calling the beforeClose events
  • destroy: Detaches all DOM Nodes and unhooks this modal
  • isVisible: Whether this modal is currently being displayed
  • options: Updates the options for this modal. This will only let you change options that are re-evaluted regularly, such as overlayClose.
  • afterCreate: Registers a callback to invoke when the modal is created
  • beforeShow: Registers a callback to invoke before the modal is shown
  • afterShow: Registers a callback to invoke when the modal is shown
  • beforeClose: Registers a callback to invoke before the modal is closed
  • afterClose: Registers a callback to invoke when the modal is closed

License

PicoModal is released under the MIT License, which is pretty spiffy. You should have received a copy of the MIT License along with this program. If not, see http://www.opensource.org/licenses/mit-license.php

About

A small, self-contained JavaScript modal library

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages