remodal-browserify
v1.1.1
Published
Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking.
Downloads
4
Readme
Remodal
No longer actively maintained. I am not interested to maintain jQuery plugins anymore. If you have some fixes, feel free to make PR.
Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking.
Notes
- All modern browsers are supported.
- IE8+. To enable IE8 styles add the
lt-ie9
class to thehtml
element, as modernizr does. - jQuery, jQuery2, Zepto support.
- Browserify support.
Start
Download the latest version from GitHub or via package managers:
npm install remodal
bower install remodal
Include the CSS files from the dist folder in the head section:
<link rel="stylesheet" href="../dist/remodal.css">
<link rel="stylesheet" href="../dist/remodal-default-theme.css">
Include the JS file from the dist folder before the </body>
:
<script src="../dist/remodal.min.js"></script>
You can define the background container for the modal(for effects like a blur). It can be any simple content wrapper:
<div class="remodal-bg">
...Page content...
</div>
And now create the modal dialog:
<div class="remodal" data-remodal-id="modal">
<button data-remodal-action="close" class="remodal-close"></button>
<h1>Remodal</h1>
<p>
Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking.
</p>
<br>
<button data-remodal-action="cancel" class="remodal-cancel">Cancel</button>
<button data-remodal-action="confirm" class="remodal-confirm">OK</button>
</div>
Don't use the id
attribute, if you want to avoid the anchor jump, use data-remodal-id
.
So, now you can call it with the hash:
<a href="#modal">Call the modal with data-remodal-id="modal"</a>
Or:
<a data-remodal-target="modal">Call the modal with data-remodal-id="modal"</a>
Options
You can pass additional options with the data-remodal-options
attribute.
<div class="remodal" data-remodal-id="modal"
data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
<button data-remodal-action="close" class="remodal-close"></button>
<h1>Remodal</h1>
<p>
Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking.
</p>
<br>
<button data-remodal-action="cancel" class="remodal-cancel">Cancel</button>
<button data-remodal-action="confirm" class="remodal-confirm">OK</button>
</div>
hashTracking
Default: true
To open the modal without the hash, use the data-remodal-target
attribute.
<a data-remodal-target="modal" href="#">Call the modal with data-remodal-id="modal"</a>
closeOnConfirm
Default: true
If true, closes the modal window after clicking the confirm button.
closeOnCancel
Default: true
If true, closes the modal window after clicking the cancel button.
closeOnEscape
Default: true
If true, closes the modal window after pressing the ESC key.
closeOnOutsideClick
Default: true
If true, closes the modal window by clicking anywhere on the page.
modifier
Default: ''
Modifier CSS classes for the modal that is added to the overlay, modal, background and wrapper (see CSS).
appendTo
Default: document.body
Globals
<script>
window.REMODAL_GLOBALS = {
NAMESPACE: 'modal',
DEFAULTS: {
hashTracking: false
}
};
</script>
<script src="../dist/remodal.js"></script>
NAMESPACE
Base HTML class for your modals. CSS theme should be updated to reflect this.
DEFAULTS
Extends the default settings.
Initialization with JavaScript
Do not set the 'remodal' class, if you prefer a JS initialization.
<div data-remodal-id="modal">
<button data-remodal-action="close" class="remodal-close"></button>
<h1>Remodal</h1>
<p>
Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking.
</p>
</div>
<script>
var options = {...};
$('[data-remodal-id=modal]').remodal(options);
</script>
Methods
Get the instance of the modal and call a method:
var inst = $('[data-remodal-id=modal]').remodal();
/**
* Opens the modal window
*/
inst.open();
/**
* Closes the modal window
*/
inst.close();
/**
* Returns a current state of the modal
* @returns {'closed'|'closing'|'opened'|'opening'}
*/
inst.getState();
/**
* Destroys the modal window
*/
inst.destroy();
Events
$(document).on('opening', '.remodal', function () {
console.log('Modal is opening');
});
$(document).on('opened', '.remodal', function () {
console.log('Modal is opened');
});
$(document).on('closing', '.remodal', function (e) {
// Reason: 'confirmation', 'cancellation'
console.log('Modal is closing' + (e.reason ? ', reason: ' + e.reason : ''));
});
$(document).on('closed', '.remodal', function (e) {
// Reason: 'confirmation', 'cancellation'
console.log('Modal is closed' + (e.reason ? ', reason: ' + e.reason : ''));
});
$(document).on('confirmation', '.remodal', function () {
console.log('Confirmation button is clicked');
});
$(document).on('cancellation', '.remodal', function () {
console.log('Cancel button is clicked');
});
CSS
Classes
.remodal
– the default class of modal dialogs.
.remodal-wrapper
– the additional wrapper for the .remodal
, it is not the overlay and used for the alignment.
.remodal-overlay
– the overlay of modal dialogs, it is under the wrapper.
.remodal-bg
– the background of modal dialogs, it is under the overlay and usually it is the wrapper of your content. You should add it on your own.
The remodal
prefix can be changed in the global settings. See the NAMESPACE
option.
States
States are added to the .remodal
, .remodal-overlay
, .remodal-bg
, .remodal-wrapper
classes.
List:
.remodal-is-opening
.remodal-is-opened
.remodal-is-closing
.remodal-is-closed
Modifier
A modifier that is specified in the options is added to the .remodal
, .remodal-overlay
, .remodal-bg
, .remodal-wrapper
classes.
Using with other javascript libraries
Remodal has wrappers that make it easy to use with other javascript libraries:
Ember
License
The MIT License (MIT)
Copyright (c) 2015 Ilya Makarov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.