Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chrishumboldt/rocket-modal
A Javascript modal component.
https://github.com/chrishumboldt/rocket-modal
javascript modal rocket
Last synced: 2 months ago
JSON representation
A Javascript modal component.
- Host: GitHub
- URL: https://github.com/chrishumboldt/rocket-modal
- Owner: chrishumboldt
- Created: 2014-06-30T15:09:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-14T07:13:58.000Z (over 7 years ago)
- Last Synced: 2024-05-08T22:59:54.548Z (8 months ago)
- Topics: javascript, modal, rocket
- Language: JavaScript
- Homepage:
- Size: 331 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**NO LONGER SUPPORTED**
# Rocket Modal
A Javascript modal module.* [Getting Started](#getting-started)
* [Basic Example](#basic-example)
* [Manual Initialisation](#manual-initialisation)
* [Javascript Options](#javascript-options)
* [Defaults](#defaults)
* [Modal Target](#modal-target)
* [On Done](#on-done)
* [Modal Methods](#modal-methods)
* [Advanced Example](#advanced-example)
* [Modalplate Deprecated](#modalplate-deprecated)## Getting Started
Install via NPM.```
npm install rocket-modal
```**NOTE** that this module has a dependency [Rocket Tools (21kb)](https://github.com/chrishumboldt/Rocket-Tools) which will automatically be installed as well.
Start by including the necessary files.
```html
```
## Basic Example
See a basic example of how to use the module.```html
Open New ModalRocket.modal({
trigger: '#modal-link-1',
heading: 'Example Modal',
body: 'Here is the body text.'
});```
#### Manual Initialisation
It is also possible to manually trigger a modal if you so choose. This is not recommended for [targeted modals](#modal-target) as you will be initialising each time which is redundant. In this case you probably want to parse the `event` to prevent odd click behaviors. For example:```html
Open New Modaldocument.getElementById('modal-link-1').addEventListener('click', event => {
Rocket.modal({
heading: 'Example Modal',
body: 'Here is the body text.',
parseEvent: event
});
});```
## Javascript Options
See the different options you have available on module call.Name | Default | Options | Description
---- | ---- | ---- | ----
`body` | | | You can make the body whatever you would like to display.
`breakpoint` | `700` | | Set the breakpoint of the modal (in pixels) to change from a fullscreen modal to a standard content modal.
`buttons` | `true` | `true` `false` | Display the modal buttons.
**NOTE** that the true button will only display if the `onTrue` argument is set.
`buttonFalse` | `Cancel` | | Set the false button text.
`buttonTrue` | `Ok` | | Set the true button text.
`classAdd` | | | Set a class to the containing modal.
`closeText` | `close` | | Set the text or inner HTML of the close link.
`heading` | | | You can make the heading whatever you would like.
`onDone` | | | Set a function that will execute once the modal is either created or the link is triggered.
`onTrue` | | | Set a function that will execute when the true button is clicked.
`parseEvent` | | | Parse the event of a click to prevent the default link behavior. Only required for manual initialisations.
`reveal` | `slidefromtop` | `appear` `appearscale`
`slidefrombottom`
`slidefromleft`
`slidefromright`
`slidefromtop` | Set the reveal animation.
`revealLarge` | | `appear` `appearscale`
`slidefrombottom`
`slidefromleft`
`slidefromright`
`slidefromtop` | Set the reveal animation after the breakpoint has been reached.
**NOTE** that false means the already existing reveal animation will be used.
`target` | `false` | | Instead of creating a new modal, you can open an existing modal with a particular selector.
`trigger` | | | Set the elements that will trigger the modal event.#### Defaults
You can also set or overwrite the above options globally by altering the Rocket defaults. To do so reference the defaults object property. For example:```js
Rocket.defaults.modal.reveal = 'appearscale';
Rocket.defaults.modal.close = 'Exit';
Rocket.defaults.modal.buttonTrue = 'Yup';
```## Modal Target
If you want to open a modal that has existing HTML, then target that modal. **Note** that a predefined HTML structure is required.```html
Open Target Modal
The Linked Modal Heading
This is the modal body.
Rocket.modal({
trigger: 'modal-link-2',
target: '#modal-2'
});```
## On Done
You can declare a function that will trigger once the modal is created or once the linked modal is set to reveal. See an example below.```js
Rocket.modal({
trigger: '#modal-link',
heading: 'Text Heading',
body: 'This is a simple test'
onDone: () => {
console.log('All done! Here is the modal element:');
}
});
```## Modal Methods
Once you have initialised a modal instance, there are some methods and references that you have access to. See below:```js
// This modal is immediately shown as it has no trigger.
var myModal = Rocket.modal({
heading: 'Text Heading',
body: 'This is a simple test'
});// Manually close the modal
setTimeout(() => {
myModal.close();
}, 1000);// Manually show the modal again
setTimeout(() => {
myModal.show();
}, 2000);
```## Advanced Example
See an advanced example below with options as per the above.```html
Open Modallet myModal = Rocket.modal({
trigger: '#example',
heading: 'Advanced Modal',
body: 'Here is the body text.',
buttons: true,
close: '<i class="icon-close"></i>',
breakpoint: 320,
reveal: 'slidefromright',
revealLarge: 'slidefromtop',
onDone: () => {
console.log('Modal Loaded!');
},
onTrue: () => {
console.log('The true button was clicked!');
myModal.close();}
});```
## Modalplate Deprecated
The original library, Modalplate, has been deprecated. The entire Webplate project is being refactored and rebranded with a new development philosophy. Modalplate will be maintained only with bug fixes under the **modalplate** branch.## Author
Created and maintained by Chris Humboldt
Website: chrishumboldt.com
GitHub github.com/chrishumboldt## Copyright and License
Copyright 2017 Rocket ProjectLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.