Download
Demo
- Overview
- Documents
User Rating: 4.5/5 ( 4 votes)
Your Rating:
PgwModal - Responsive modal / dialog window for jQuery / Zepto
- Less than 2.5 KB (minified and gzipped)
- Fully responsive modal (desktop and mobile devices)
- AngularJS native implementation (activated or not)
- Full customization with the CSS file included
1. INCLUDE CSS AND JS FILES
<link rel="stylesheet" href="pgwmodal.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="pgwmodal.js"></script>
2. HTML
<a href="javascript:void(0)" class="openModal">Open Modal</a>
3. JAVASCRIPT
$('.openModal').click(function() { $.pgwModal({ content: 'Modal Example' }); });
4. OPTIONS
LOAD THE MODAL CONTENT
To load a content into the modal, you have 3 possibilities :
Content - The value will be pushed into the modal.
content: 'Plain text' | '<span>HTML content</span>'
OR
Target - The selector (#div or .class) will be used for push its HTML content into the modal.
target: '#myContent' | '.myContent'
OR
Url - This URL will be loaded by an AJAX request, and the result will be pushed into the modal.
url: 'http://domain.com/test.html' | 'test.php'
Title - This parameter must be a string, and is displayed on the top of the modal.
title: 'My modal'
MaxWidth - The MaxWidth parameter must be a number in pixels, and it defines the maximum width of the modal. This modal is responsive, so if the browser width is inferior to this parameter, the modal width will be the browser width.
maxWidth: 600
ajaxOptions - This parameter must be an object. If you want add one or more options to the jQuery Ajax Request (e.g. a HTTP header), you can add your options and it will be merged with the plugin default options.
ajaxOptions: { headers : { X-My-Header : 'test' } }
Loading - The Loading parameter must be a string or a HTML content, it will be displayed during the loading of the Ajax Request.
loading: 'Loading in progress...' | '<img src="images/loading.gif">'
Error - This parameter must be a string or a HTML content, it will be displayed if the Ajax request returns an error.
loading: 'An error has occured' | '<img src="images/error.png">'
Angular - If the loaded content contains Angular code, this option will compile it to activate.
angular: true
modalData - if you need to pass data into the modal, you can set an object via the modalData parameter, and you will be able to get this object via the function "$.pgwModal('getData')" in the modal.
modalData: { myVar : 'test' }
5. METHODS
Global - To create a modal, this function requires an object.
$.pgwModal({ content: 'Modal Example 1' });
Close - To close a modal, you can create a new link or a JavaScript action with this function.
$.pgwModal('close');
Reposition - In some cases, you might need to refocus your modal in the height, this function does it.
$.pgwModal('reposition');
GetData - If you have saved an object modalData during the creation, you can get it with the following function.
$.pgwModal('getData');
PushContent - If the query result contains several elements, but only one must be sent to the modal, this function allows you to select and send only the right item.
$.pgwModal({ pushContent: 'string or <span>HTML content</span>' });
An example to explain how to use this function:
$.pgwModal({ url: 'modals.php?get=userData' // Returns the object "{status: 200, response: '<div class="user">John Doe</div>'}" ajaxOptions : { success : function(data) { if (data.response) { $.pgwModal({ pushContent: data.response }); } else { $.pgwModal({ pushContent: 'An error has occured' }); } } } });