Drupal Experts As we have covered wide range of projects for various industries our professionals are experienced and keep good knowledge of online environment. We are always open to handle challenging projects and to provide ultimate solution to our customers. Open source web development projects are one of our specialties in the range of customized services we provide to our clients.
Friday, 25 May 2012
Ajax modal windows, the easy way
We will be building a very simple module with two pages. The first
simply holds the link to the modal window, the second is the page that
will be displayed in the modal. Lets start with some basic code to set
up our test module. This is almost identical to the ajax module we built
last week. The biggest difference here, is that the class on the link
has been changed to ‘ctools-use-modal’ and we are adding the javascript
using ctools_modal_add_js().
<?php
/**
* Implementation of hook_menu().
*/
function example_menu() {
$items = array();
$items['test'] = array(
'title' => 'Ajax Test',
'page callback' => 'example_test_main',
'access arguments' => array('access content'),
);
$items['test/%ctools_js/go'] = array(
'page callback' => 'example_test_modal_callback',
'page arguments' => array(1),
'access arguments' => array('access content'),
);
return $items;
}
/**
* The main page that holds the link to the modal.
*/
function example_test_main() {
// Load the modal library and add the modal javascript.
ctools_include('modal');
ctools_modal_add_js();
$output = l('Load modal content', 'test/nojs/go', array(
'attributes' => array('class' => 'ctools-use-modal')));
return $output;
}
?>
All that is left is to define the modal callback. Since we are using
the %ctools_js wildcard, this same callback will be responsible for the
content in both modal and non-modal states. Remember that the %ctools_js
wildcard will be translated to a boolean value in which TRUE signals
that we are in a javascript context.
No comments:
Post a Comment