Fork me on GitHub

Mesour Modal

Simple use of bootstrap modals with ajax loading, front-end caching and much more.

Packagist Build Status

Installation

Suggests

  • None

Usage

// APPLICATION

$application = new \Mesour\UI\Application('mesourApp');

$application->setRequest($_REQUEST);

$application->getConfiguration()
    ->setTempDir(__DIR__ . '/tmp');

$application->run();

// MODAL

$modal = new \Mesour\UI\Modal('testModal', $application);

$modal->setTitle('Test modal');

$modal->addStringContent('test')
    ->setCallback(
        function (\Mesour\Modal\Contents\StringContent $content) {
            return 'test content';
        }
    );

$modal->addStringContent('test2')
    ->setCallback(
        function (\Mesour\Modal\Contents\StringContent $content) {
            return 'test content 2';
        }
    );

$modal->addTemplateContent('test3', __DIR__ . '/template.latte')
    ->setBlock('first')
    ->setCallback(
        function (\Mesour\Modal\Contents\TemplateContent $content, \Mesour\UI\TemplateFile $template) {
            $template->foo = 'foo variable content';
        }
    );

$modal->addTemplateContent('test4', __DIR__ . '/template.latte')
    ->setBlock('second');

$modal->showModal();

$modal->setAjaxLoading();

$modal->setCached();

$modal->getModalFooter()->addButton('testButton')
    ->setType('primary')
    ->setText('Save');

echo $modal->render();

Set AJAX loading

Info Content is loaded via AJAX after modal is show.
$modal->setAjaxLoading();

Set cache on front-end

Info If set cached and AJAX loading together, can cache modal content in JS and it will call only one AJAX request if you show modal first time.
$modal->setCached();

Show after document ready

$modal->showModal();

Add modal buttons

Info Button is instance of Button
$modal->getModalFooter()->addButton('testButton')
    ->setType('primary')
    ->setText('Save');

Disable default close button

$modal->getModalFooter()->disableCloseButton();

Disable black transparent backdrop

$modal->disableBackdrop();

Disable close modal by esc

$modal->disableKeyboard();