jsPopup is a JS Class which allow to show popup on your website.
Simply add the js file popup.js to your project and import in the head section of your html
<script type="text/javascript" src="Popup.js"¨></script>
When you want to use a popup, you have to create a new instance of the Popup
class. First argument is the type, second are params. Arguments are detailed in the section Arguments.
var myPopup = new Popup('message', {
title: 'Hello world!',
body: 'This is the body',
})
Popup is showed direct. If you don't want, add
noDirectShow = true
in the argumentparams
.
A more detailed example is available in the folder "Example"
The argument type
can takes followed string values:
- message
- save
- confirm
- error
- noClose
- goodProcess
The argument params
is an Object can take followed keys:
title
- Required - Title of the popupbody
- Required - Body in HTML of the popupautoCloseTime
- Optional - Time after which the popup closescloseCB
- Optional - A function which call when popup is closesaveCB
- Optional - A function which call when save button is pressed. Work only with typeconfirm
noDeleteOnClose
- Optional - Set it totrue
if you don't want to delete the instance when popup closes (when hidePopup is called)noDirectShow
- Optional - Set it totrue
if you don't want to show the popup direct after the instantiationcustomCSS
- Optional - Add custom css (like background or text color) to the popup box
Depends of the type, some
params
are required. If some of required one is not present, an error will be raised in the console with the name of the missed params.
These methods are available if you want to change something
showPopup()
Show popuphidePopup()
Hide popupgetBodyEl()
Get the body elementsetTitle(title)
Set title when you want to change it after the instantiationsetBody(body)
Set body when you want to change it after the instantiation (only text)setBodyEl(el)
Set body element