MENU_CALLBACK, 'page callback' => '_popups_get_raw_content', 'access callback' => TRUE, ); $items['popups/test'] = array( 'title' => 'Popup Test', 'page callback' => 'popups_test_popups', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); $items['popups/test/response'] = array( 'page callback' => 'popups_test_response', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); $items['admin/settings/popups'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('popups_admin_settings'), 'title' => 'Popups Settings', ); return $items; } /** * hook_form_alter * * TODO: These values only work for the garlard theme. * * @param unknown_type $form * @param unknown_type $form_state * @param unknown_type $form_id */ function popups_form_alter(&$form, $form_state, $form_id) { switch ($form_id) { case 'menu_overview_form': popups_add_popups( 'table#menu-overview td:nth-child(5) a, table#menu-overview td:nth-child(6) a, div#tabs-wrapper a:eq(1)', 'div.left-corner > div:eq(3)' ); break; case 'block_admin_display_form': popups_add_popups( 'table#blocks td:nth-child(4) a, div#tabs-wrapper a:eq(1)', 'div.left-corner > div:eq(3)' ); break; case 'path_admin_filter_form': popups_add_popups( 'div#tabs-wrapper a:eq(1), table td:nth-child(3) a, table td:nth-child(4) a', 'div.left-corner > div:eq(3)' ); break; } } // ************************************************************************** // UTILITY FUNCTIONS ******************************************************** // ************************************************************************** /* * Return the content of a path as html, without the page's theming wrapper * Used by dialogs.js for a popups with the content of a link */ function _popups_get_raw_content() { global $base_url; //TODO - need to do something to fix up path in actions of forms being created in the next step? if (!isset($_GET['path'])) { print "Hey Baby!"; return "Foo bar"; // t("No path provided"); } //return "foo"; $path = $_GET['path']; $path = substr( $path, strlen($base_url) + 1 ); $content = menu_execute_active_handler( $path ); // does this test for access rights? // todo - move into a theme function? $output = '
'. drupal_get_title() .'
'; if( $content == MENU_NOT_FOUND ) { $output .= t("Path not found: "). $path; } elseif($content == MENU_ACCESS_DENIED) { drupal_access_denied(); } else { $output .= '
'. $content .'
'; } print $output; } /* http://localhost/d6/popups/raw?path=http://localhost/d6/admin/build/menu/item/8/reset& confirm=1& op=Reset& form_build_id=form-54784cc3713fc03f6776dd1c8e5fe6b8& form_token=29e493dc04fc6765795d5e8786e4829d& form_id=menu_reset_item_confirm */ function popups_add_popups($popup_selector=NULL, $content_selector=NULL) { static $added = FALSE; if (!$added) { drupal_add_js(drupal_get_path('module', 'popups') .'/popups.js'); drupal_add_js('misc/jquery.form.js'); $settings = array( 'popups' => array( 'popupSelector' => $popup_selector, 'titleSelector' => variable_get('popups_title_selector', 'div.left-corner h2'), 'contentSelector' => isset($content_selector) ? $content_selector : variable_get('popups_content_selector', 'div.left-corner div:eq(1)'), )); drupal_add_js( $settings, 'setting' ); //drupal_add_js( array( 'popups'=> array('base_path'=>base_path()) ), 'setting' ); drupal_add_css(drupal_get_path('module', 'popups') .'/popups.css'); $added = TRUE; } } // ************************************************************************** // ADMIN SETTINGS ********************************************************* // ************************************************************************** function popups_admin_settings() { drupal_set_title("Popups Settings"); $form = array(); $form['popups_test'] = array( '#type' => 'textfield', '#title' => t('Popups Test Value'), '#default_value' => variable_get('popups_test', ''), '#description' => t('This value is only used for testing'), ); $form['popups_title_selector'] = array( '#type' => 'textfield', '#title' => t('Title Selector'), '#default_value' => variable_get('popups_title_selector', 'div.left-corner h2'), '#description' => t('jQuery selector to define the title on a page. (TODO: per theme).'), ); $form['popups_content_selector'] = array( '#type' => 'textfield', '#title' => t('Content Selector'), '#default_value' => variable_get('popups_content_selector', 'div.left-corner div:eq(1)'), '#description' => t('jQuery selector to define the content area on a page. (TODO: per theme).'), ); return system_settings_form($form); } // ************************************************************************** // TESTING **************************************************************** // ************************************************************************** function popups_test_popups() { popups_add_popups(); $output = ''; $output .= l("Pop Me Up", 'popups/test/response', array( 'attributes'=>array('popups'=>TRUE) ) ) ."
"; $output .= l("Swap Me Out", // 'popups/test/response', 'node/2', array( 'attributes'=>array( 'swap' => 'div.left-corner h2, div.left-corner div:eq(1)', ) )) . "
"; $output .= l("AHAH Reload", '/', array('attributes'=>array('onclick'=>"Drupal.popups.reload(); return false;") ) ) .'
'; $output .= l("Settings: ". variable_get('popups_test', ''), 'admin/settings/popups', array( 'attributes'=>array('popups'=>TRUE) ) ); return $output; } function popups_test_response() { drupal_set_title("A Popup Test"); return "
Hello World
"; }