'dynamicload/js', 'title' => t('dynamicload'), 'access' => user_access('access content'), 'type' => MENU_CALLBACK, 'callback' => 'dynamicload_js' ); } else { dynamicload_load(); } return $items; } /** * Load needed files. */ function dynamicload_load() { $path = drupal_get_path('module', 'dynamicload'); module_invoke('jstools', 'add_js', array( $path . '/dynamicload.js', 'misc/progress.js', )); } /** * Send settings to the browser. * * We do this in the footer because some of the settings are theme-dependent. Typically, * hook_footer will be called after the theme is initiated, so we have the correct theme * to load data for. */ function dynamicload_footer() { $settings = variable_get('dynamicload_settings', array()); // Allow theme-based overrides. $theme_data = module_invoke('jstools', 'theme_data', 'dynamicload'); foreach ($theme_data as $key => $selector) { if ($source = array_search($key, $settings)) { $settings[$source] = $selector; } // No theme support, unset. else { unset($settings[$source]); } } drupal_add_js(array('dynamicload' => $settings), 'setting'); return ''; } function dynamicload_form_alter($form_id, &$form) { if ($form_id == 'block_admin_configure') { $block_id = '#block-' . $form['module']['#value'] . '-' . $form['delta']['#value']; $options = array('content' => t('Main content area')); $result = db_query('SELECT module, delta FROM {blocks} WHERE status = 1 AND NOT (module = "%s" AND delta = "%s")', $form['module']['#value'], $form['delta']['#value']); while ($block = db_fetch_object($result)) { $module_blocks = module_invoke($block->module, 'block', 'list'); $options['#block-' . $block->module . '-' . $block->delta] = t('%info block', array('%info' => $module_blocks[$block->delta]['info'])); } $settings = variable_get('dynamicload_settings', array()); $form['#submit']['dynamicload_submit'] = array(); $form['dynamicload'] = array( '#type' => 'fieldset', '#title' => t('Dynamic loading'), '#description' => t('Select whether you want links on this block to be loaded dynamically rather than through a regular page refresh. If you enable this functionality for a block, make sure that you thoroughly test the result, as not all pages will perform as expected when loaded dynamically.'), '#collapsible' => true, '#weight' => -5 ); $form['dynamicload']['dynamicload_apply'] = array( '#type' => 'checkbox', '#title' => t('Apply dynamic loading'), '#default_value' => $settings[$block_id] ? 1 : 0 ); $form['dynamicload']['dynamicload_target'] = array( '#type' => 'select', '#title' => t('Target area'), '#default_value' => $settings[$block_id] ? $settings[$block_id] : '#main', '#options' => $options, '#description' => t('Select the page area for this block\'s links to load into. Only enabled blocks are available.'), ); } } function dynamicload_submit($form_id, $edit) { dynamicload_set('#block-' . $edit['module'] . '-' . $edit['delta'], $edit['dynamicload_target'], !$edit['dynamicload_apply']); } function dynamicload_set($block_id, $target, $remove = FALSE) { $settings = variable_get('dynamicload_settings', array()); if ($remove) { unset($settings[$block_id]); } else { $settings[$block_id] = $target; } variable_set('dynamicload_settings', $settings); } function dynamicload_js() { if (isset($_POST['href'])) { $response = module_invoke('pagearray', 'page', $_POST['href']); if ($response['status'] === FALSE) { switch ($response['value']) { case MENU_NOT_FOUND: case NULL: $result = array( 'result' => FALSE, 'message' => t('Item was not found.'), ); break; case MENU_ACCESS_DENIED: $result = array( 'result' => FALSE, 'message' => t('Access denied.'), ); break; case MENU_SITE_OFFLINE: $result = array( 'result' => FALSE, 'message' => t('Site offline.'), ); break; } } else { $extra = '