Commit b46af3df authored by mikeytown2's avatar mikeytown2 Committed by japerry

Issue #1149792 by mikeytown2: CTools - Allow ctools_ajax_page_preprocess to...

Issue #1149792 by mikeytown2: CTools - Allow ctools_ajax_page_preprocess to not be ran, add scripts call to js preprocess
parent 1ff50d6c
......@@ -17,7 +17,7 @@ define('CTOOLS_AJAX_INCLUDED', 1);
* spiffy functionality is necessary.
*
* Each command is an object. $object->command is the type of command and
* will be used to find the function (it will correllate directly to
* will be used to find the function (it will correlate directly to
* a function in the Drupal.CTools.AJAX.Command space). The object can
* contain any other data that the command needs to process.
*
......@@ -46,7 +46,7 @@ define('CTOOLS_AJAX_INCLUDED', 1);
* - selector: The CSS selector. This can be any selector jquery uses in $().
*
* - changed
* - selector: The CSS selector. This selector will have 'changed' added as a clas.
* - selector: The CSS selector. This selector will have 'changed' added as a class.
* - star: If set, will add a star to this selector. It must be within the 'selector' above.
*
* - alert
......@@ -391,7 +391,7 @@ function ctools_ajax_command_data($selector, $name, $value) {
/**
* Force a table to be restriped.
*
* This is usually used after a table has been modifed by a replace or append
* This is usually used after a table has been modified by a replace or append
* command.
*
* @param $selector
......@@ -587,7 +587,34 @@ function ctools_ajax_associate_url_to_element(&$form, &$form_element, $dest, $ty
);
}
/**
* Function that controls if ctools_ajax_page_preprocess() will run.
*
* Useful if not using Drupal's core CSS/JS handling & you wish to override it.
* If skipping the page_preprocess function you must provide the scripts and css
* files loaded on this page as a JS setting in the footer under CToolsAJAX.
*
* @param $value
* Bool; set to FALSE to disable ctools_ajax_page_preprocess() from running.
*/
function ctools_ajax_run_page_preprocess($value = TRUE) {
$run_hook = &ctools_static('ctools_ajax_page_preprocess', TRUE);
$run_hook = $value;
}
/**
* Implement hook_preprocess_page. Process variables for page.tpl.php
*
* @param $variables
* The existing theme data structure.
*/
function ctools_ajax_page_preprocess(&$variables) {
// See if we will be running this hook.
$run_hook = &ctools_static(__FUNCTION__, TRUE);
if (!$run_hook) {
return;
}
$js_files = $css_files = array();
ctools_process_js_files($js_files, 'header');
ctools_process_js_files($js_files, 'footer');
......@@ -606,11 +633,23 @@ function ctools_ajax_page_preprocess(&$variables) {
/**
* Create a list of javascript files that are on the page.
*
* @param $js_files
* Array of js files that are loaded on this page.
* @param $scope
* String usually containing header or footer.
* @param $scripts
* (Optional) array returned from drupal_add_js(). If NULL then it will load
* the array from drupal_add_js for the given scope.
* @return array $settings
* The JS 'setting' array for the given scope.
*/
function ctools_process_js_files(&$js_files, $scope) {
function ctools_process_js_files(&$js_files, $scope, $scripts = NULL) {
// Automatically extract any 'settings' added via drupal_add_js() and make
// them the first command.
$scripts = drupal_add_js(NULL, NULL, $scope);
if (empty($scripts)) {
$scripts = drupal_add_js(NULL, NULL, $scope);
}
// Get replacements that are going to be made by contrib modules and take
// them into account so we don't double-load scripts.
......@@ -635,7 +674,7 @@ function ctools_process_js_files(&$js_files, $scope) {
// If JS preprocessing is off, we still need to output the scripts.
// Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
foreach ($data as $path => $info) {
// If the script is being replaced, take that replacment into account.
// If the script is being replaced, take that replacement into account.
$final_path = isset($replacements[$type][$path]) ? $replacements[$type][$path] : $path;
$js_files[base_path() . $final_path] = TRUE;
}
......@@ -647,6 +686,13 @@ function ctools_process_js_files(&$js_files, $scope) {
/**
* Create a list of CSS files to add to the page.
*
* @param $css_files
* Array of css files that are loaded on this page. Passed by reference and
* previous values are wiped.
* @param $css
* Array returned from drupal_add_css() or $variables['css'] from
* hook_preprocess_page.
*/
function ctools_process_css_files(&$css_files, $css) {
// Go through all CSS files that are being added to the page and catalog them.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment