function ctools_ajax_sample_page in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 ctools_ajax_sample/ctools_ajax_sample.module \ctools_ajax_sample_page()
Page callback to display links and render a container for AJAX stuff.
1 string reference to 'ctools_ajax_sample_page'
- ctools_ajax_sample_menu in ctools_ajax_sample/
ctools_ajax_sample.module - Implementation of hook_menu()
File
- ctools_ajax_sample/
ctools_ajax_sample.module, line 81 - Sample AJAX functionality so people can see some of the CTools AJAX features in use.
Code
function ctools_ajax_sample_page() {
global $user;
// Include the CTools tools that we need.
ctools_include('ajax');
ctools_include('modal');
// Add CTools' javascript to the page.
ctools_modal_add_js();
// Create our own javascript that will be used to theme a modal.
$sample_style = array(
'ctools-sample-style' => array(
'modalSize' => array(
'type' => 'fixed',
'width' => 500,
'height' => 300,
'addWidth' => 20,
'addHeight' => 15,
),
'modalOptions' => array(
'opacity' => 0.5,
'background-color' => '#000',
),
'animation' => 'fadeIn',
'modalTheme' => 'CToolsSampleModal',
'throbber' => theme('image', ctools_image_path('ajax-loader.gif', 'ctools_ajax_sample'), t('Loading...'), t('Loading')),
),
);
drupal_add_js($sample_style, 'setting');
// Since we have our js, css and images in well-known named directories,
// CTools makes it easy for us to just use them without worrying about
// using drupal_get_path() and all that ugliness.
ctools_add_js('ctools-ajax-sample', 'ctools_ajax_sample');
ctools_add_css('ctools-ajax-sample', 'ctools_ajax_sample');
// Create a list of clickable links.
$links = array();
// Only show login links to the anonymous user.
if ($user->uid == 0) {
$links[] = ctools_modal_text_button(t('Modal Login (default style)'), 'ctools_ajax_sample/nojs/login', t('Login via modal'));
// The extra class points to the info in ctools-sample-style which we added to the settings.
$links[] = ctools_modal_text_button(t('Modal Login (custom style)'), 'ctools_ajax_sample/nojs/login', t('Login via modal'), 'ctools-modal-ctools-sample-style');
}
// Three ways to do our animal picking wizard.
$links[] = l(t('Wizard (no modal)'), 'ctools_ajax_sample/nojs/animal');
$links[] = ctools_modal_text_button(t('Wizard (default modal)'), 'ctools_ajax_sample/nojs/animal', t('Pick an animal'));
$links[] = ctools_modal_text_button(t('Wizard (custom modal)'), 'ctools_ajax_sample/nojs/animal', t('Pick an animal'), 'ctools-modal-ctools-sample-style');
$links[] = ctools_ajax_text_button(t('Hello world!'), "ctools_ajax_sample/nojs/hello", t('Replace text with "hello world"'));
$output = theme('item_list', $links, t('Actions'));
// This container will have data AJAXed into it.
$output .= theme('ctools_ajax_sample_container', '<h1>' . t('Sample Content') . '</h1>');
// Create a table that we can have data removed from via AJAX.
$header = array(
t('Row'),
t('Content'),
t('Actions'),
);
$rows = array();
for ($i = 1; $i < 11; $i++) {
$rows[] = array(
'class' => 'ajax-sample-row-' . $i,
'data' => array(
$i,
md5($i),
ctools_ajax_text_button("remove", "ctools_ajax_sample/nojs/tablenix/{$i}", t('Delete this row')),
),
);
}
$output .= theme('table', $header, $rows, array(
'class' => 'ajax-sample-table',
));
return $output;
}