Modal.js
A modern and simple modal
NPM
npm install --save modal.js
What does it do?
- Build a modal customizable.
- By default create text, image modal.
- You can customize it with parameters
- Its possible to create different styles of the same modal and then choose one
Browser support (Only tested on)
- Chrome (last two)
- Firefox (last two)
Modal on!
Default mode
Not recommended! My use of styles is disgusting, You are warned!
$().modal({"content": {"type":"text","data": "Hola mundo!" }});
$().modal({"content": {"type":"image", "data": "http://lorempixel.com/400/200/"}})
Newbie mode
The parameter is json with this structure:
'content' : {
'type' : String,
'data' : Object,
'className' : String,
},
'shape' : {
'className' : String,
'style' : String
}
'layout' : String,
'header' : {
'icon' : String,
'title' : {
'className' : String,
'content' : String
}
},
'close' : {
'button' : Boolean,
'escape' : Boolean
},
'acc' : {
'text' : String
},
'btns' : [{
'value' : String,
'shape' : String,
'type' : String,
'action' : String,
'close' : Boolean,
'key' : CharCode
}],
'overlay' : {
'className' : String,
'click' : Boolean
},
'width' : String
Pro mode
You can modify defaults modal.json.
"dfts" : {
"shapeClassname":"modalShape-dft",
"shapeStyle":"modalStyle-dft",
"layout":"modalType-dft",
"icon":"",
"contentClassname":"modalContent-dft",
"acc":"Ventana modal abierta. Presiona escape para cerrar la ventana"
}
Use text plugin for guide you.
God mode
Not only can create a different templates of same modal, different modal too!
You have access a args (parameter of modal), and you add custom variables on parameters.
I create a youtube video modal:
"iframe" : {
"element" : "iframe",
"objAttrs" :{
"id": "'mFrame-content'",
"width": "args.content.width",
"height": "args.content.height",
"src" : "data"
},
"attrs" : {
"frameborder" : "'0'",
"allowfullscreen" : "''",
"mozallowfullscreen" : "''",
"webkitallowfullscreen" : "''",
"hspace" : "'0'",
"vspace" : "'0'",
"scrolling" : "'auto'"
},
"dfts" : {
"shapeClassname":"",
"shapeStyle":"",
"layout":"",
"icon":"",
"contentClassname":"",
"acc":""
}
}
NOTE: Important! objAttrs and attrs is under eval. You can use variables of args (parameter of modal) and set new parameters. Example: width, height and id. If you pass string need double quotes " ' ' ".
Json url
Url of "plugins" or types of modals need this structure:
- index.html -> calls modal js
- js/modal.json
- js/modal.js
but before call modal js you can overwrite url:
urlModal = "js/modal.json" -> Default
Acknowledgements
Modal.js is a project by Rodrigo Perrote.