function 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 112

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', array(
                'path' => ctools_image_path('ajax-loader.gif', 'ctools_ajax_sample'),
                'alt' => t('Loading...'),
                'title' => 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, prefixed with 'ctools-modal'.
        $links[] = ctools_modal_text_button(t('Modal Login (custom style)'), 'ctools_ajax_sample/nojs/login', t('Login via modal'), 'ctools-modal-ctools-sample-style');
    }
    // Four ways to do our animal picking wizard.
    $button_form = ctools_ajax_sample_ajax_button_form();
    $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[] = drupal_render($button_form);
    $links[] = ctools_ajax_text_button(t('Hello world!'), "ctools_ajax_sample/nojs/hello", t('Replace text with "hello world"'));
    $output = theme('item_list', array(
        'items' => $links,
        'title' => t('Actions'),
    ));
    // This container will have data AJAXed into it.
    $output .= theme('ctools_ajax_sample_container', array(
        'content' => '<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' => array(
                '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', array(
        'header' => $header,
        'rows' => $rows,
        'attributes' => array(
            'class' => array(
                'ajax-sample-table',
            ),
        ),
    ));
    // Show examples of ctools javascript widgets.
    $output .= '<h2>' . t('CTools Javascript Widgets') . '</h2>';
    // Create a drop down menu.
    $links = array();
    $links[] = array(
        'title' => t('Link 1'),
        'href' => $_GET['q'],
    );
    $links[] = array(
        'title' => t('Link 2'),
        'href' => $_GET['q'],
    );
    $links[] = array(
        'title' => t('Link 3'),
        'href' => $_GET['q'],
    );
    $output .= '<h3>' . t('Drop Down Menu') . '</h3>';
    $output .= theme('ctools_dropdown', array(
        'title' => t('Click to Drop Down'),
        'links' => $links,
    ));
    // Create a collapsible div.
    $handle = t('Click to Collapse');
    $content = 'Nulla ligula ante, aliquam at adipiscing egestas, varius vel arcu. Etiam laoreet elementum mi vel consequat. Etiam scelerisque lorem vel neque consequat quis bibendum libero congue. Nulla facilisi. Mauris a elit a leo feugiat porta. Phasellus placerat cursus est vitae elementum.';
    $output .= '<h3>' . t('Collapsible Div') . '</h3>';
    $output .= theme('ctools_collapsible', array(
        'handle' => $handle,
        'content' => $content,
        'collapsed' => FALSE,
    ));
    // Create a jump menu.
    ctools_include('jump-menu');
    $form = drupal_get_form('ctools_ajax_sample_jump_menu_form');
    $output .= '<h3>' . t('Jump Menu') . '</h3>';
    $output .= drupal_render($form);
    return array(
        'markup' => array(
            '#markup' => $output,
        ),
    );
}