Native Javascript Module to display beautiful popups. With react support!
Features
- Demo: http://chieforz.github.io/popupS
- Native Javascript / No jQuery dependency
- Built in CSS spinner for asynchronous dialogs
- Smart focus on form elements
- AMD support
Installation
The plugin can be used as a Common JS module, an AMD module, or a global.
Usage with Browserify
Install with npm, use with Browserify
> npm install popupS
and in your code
var popupS = require('popupS');
popupS.alert({
content: 'Hello World!'
});
For the basic styling and fade in and out to be working, you have to include the popupS.css in yout header.
<link rel="stylesheet" href="popupS.css">
Usage as browser global
You can include popupS.js directly in a script tag.
For the basic styling and fade in and out to be working, you have to include the popupS.css.
<link rel="stylesheet" href="popupS.css">
<script src="popupS.js"></script>
<script>
popupS.alert({
content: 'Hello World!'
});
</script>
For both files popupS.js
and popupS.css
is a minified productive version in it's corresponding folder.
How to use
Create a popup window:
var popup = new popupS({
mode: 'alert',
content: 'Hi'
});
popupS.window({
mode: 'alert',
content: 'Hey'
});
popupS.alert({
content: 'Hello'
});
Here are multiple ways to create popupS:
Alerts
popupS.alert({
title: 'I am an',
content: 'Alert'
});
Confirm
Confirm configuration involves the use of callbacks to be applied.
popupS.confirm({
content: '<b>Do you like what you see?</b>',
labelOk: 'Yes',
labelCancel: 'No',
onSubmit: function() {
console.log(':)');
},
onClose: function() {
console.log(':(');
}
});
Prompt
Prompts are used for asking a single question.
popupS.prompt({
content: 'What is your name?',
placeholder: '>>>',
onSubmit: function(val) {
if(val) {
popupS.alert({
content: 'Hello, ' + val
});
} else {
popupS.alert({
content: ':('
});
}
}
});
Modal
With Modals you are in full control.
popupS.modal({
title: 'Himalaya',
content: {
tag: 'img#himalaya.picture',
src: 'http://static.hdw.eweb4.com/media/wallpapers_1920x1080/nature/1/1/himalaya-nature-hd-wallpaper-1920x1080-6944.jpg'
}
});
there is some magic sugar involved. learn more about it here
Ajax
It can also work in asynchronous mode and retrieve content from external pages.
popupS.ajax({
title: 'Himalaya',
ajax: {
url: 'http://static.hdw.eweb4.com/media/wallpapers_1920x1080/nature/1/1/himalaya-nature-hd-wallpaper-1920x1080-6944.jpg'
}
});
Options
popupS.window({
mode: 'alert'|'confirm'|'prompt'|'modal'|'modal-ajax',
title: 'Title',
content : 'Text'|'<div>html</div>'|{tag : 'span#id.class'},
className : 'additionalClass',
placeholder : 'Input Text',
ajax : {
url : 'http://url.com',
post : true,
str : 'post=true'
},
onOpen: function(){},
onSubmit: function(val){},
onClose: function(){}
});
Advanced Options
popupS.window({
additionalBaseClass: '',
additionalButtonHolderClass: '',
additionalButtonOkClass: '',
additionalButtonCancelClass: '',
additionalCloseBtnClass: '',
additionalFormClass: '',
additionalOverlayClass: '',
additionalPopupClass: '',
appendLocation: document.body,
closeBtn: '×',
flagBodyScroll: false,
flagButtonReverse: false,
flagCloseByEsc: true,
flagCloseByOverlay: true,
flagShowCloseBtn: true,
labelOk: 'OK',
labelCancel: 'Cancel',
loader: 'spinner',
zIndex: 10000
});
DOM Generation
The plugin is using some special magic to generating DOM Elements.
popupS.alert({
content: {
tag: 'div#id.class.class2',
css: {
width: '100px'
},
html: '<h1>Hello</h1>',
children:[
{
tag: 'label',
text: 'test',
htmlFor: 'input',
css: {
width: '50%'
}
},
{
tag: 'input#input',
type: 'checkbox',
css: {
width: '50%'
}
}
]
}
});
All attributes, that can be applied via javascript are availabe to use.
For example, as you can see in the example above:
Instead of using the regular "for"-attribute on the label element,
we have to use the "htmlFor"-attribute.
Note:
If an assigned attribute is not an valid HTML attribute, it gets assigned as an 'data-'* atribute.
License
MIT