AjaxPopup.js is a jQuery plugin which allows you to focus on backend when you just want to display HTML requested by Ajax in a popup., (*1)
AjaxPopup.js is able to follow links and handle form submission., (*2)
Can be used with Symfony 3 or standalone., (*3)
An example application made with Symfony 3 is available here., (*4)
Installation
Standalone installation
Download this folder: src/Zz/AjaxPopupJsBundle/Resources/public/., (*5)
Include jQuery in your project:, (*6)
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
Include AjaxPopup.js:, (*7)
<script src=".../js/AjaxPopup.js"></script>
Include AjaxPopup.css:, (*8)
<link href=".../css/AjaxPopup.css" rel="stylesheet"/>
Don't forget to replace ...
by the installation folder., (*9)
Symfony 3 installation
Download via Composer:, (*10)
composer require zzortell/zz-ajaxpopupjs-bundle
Enable bundle in the kernel:, (*11)
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
...
new Zz\AjaxPopupJsBundle\ZzAjaxPopupJsBundle(),
];
...
}
}
Don't forget to install assets:, (*12)
bin/console assets:install
# or
bin/console assets:install web --symlink --relative
Include jQuery in your project:, (*13)
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
Include AjaxPopup.js:, (*14)
<script src="{{ asset('bundles/zzajaxpopupjs/js/AjaxPopup.js') }}"></script>
Include AjaxPopup.css:, (*15)
<link href="{{ asset('bundles/zzajaxpopupjs/css/AjaxPopup.css') }}" rel="stylesheet"/>
Usage
Step 1: Make AjaxPopup.js handle the request of a popup., (*16)
Step 2: Enjoy!, (*17)
When triggered (see triggering options below), AjaxPopup requests HTML via Ajax. When the new content is received, AjaxPopup checks for buttons, links and forms and handles them according to the given options., (*18)
The server HAS TO send 200 status. A 205 status can also be send to make reload the page (usefull for login for example)., (*19)
Click on the overlay or press Echap
to close the popup., (*20)
Settings options
- overlay_color: Color of the overlay, by defaut transparent grey. Set opacity to 0 to not have overlay color.
- loader_color: Color of the default loader.
- loader_circle_color: Color of the circle of the default loader.
- use_loader: If set true, will display a loader waiting for the server response.
- loader: A jQuery element. If set null, the default loader is used.
Triggering options
- open_now: Give an url to display the popup on document ready, or immediatly if modified using API.
- buttons_selector: A jQuery selector which can refers to buttons or other elements. Each of these elements has to have a
ajax-url
attribute. Cliking on these elements will display the popup. The jQuery selector can also refers to buttons inside the popup (for example, in a login form you can put a "Register" button to make AjaxPopup load a registration form).
Behavior options
- follow_links: If set true, AjaxPopup will reload the content of the popup when the user click on a link inside the popup, with the given url. Will not follow the link if the specified
target
is not _self
.
- control_forms: If set true, AjaxPopup will handle form submission inside the popup and reload the content of the popup with server's response.
- control_buttons: If set true, AjaxPopup will handle buttons inside the popup like ones outside.
API
The object returned by $().AjaxPopup() has several methods:, (*21)
popup.display(url, method = 'GET', data = null);
popup.hide();
popup.hideAll(); // Hide all popups, not only this instance.
popup.getOptions();
popup.setOptions();
Improve this library
This library is published under the MIT license., (*22)
If you find a bug, or if you want to propose a feature, please open an issue or post pull-request., (*23)
If you use this library, please let's me know!, (*24)