Returns a themed presentation of all JavaScript code for the current page.

Paramètres

$js_code: An array with all JavaScript code. Key it the region

$noagg: (optional) Bool indicating that aggregation should be disabled if TRUE.

Return value

All JavaScript code segments and includes for the scope as HTML tags.

Voir aussi

drupal_get_js()

References to JavaScript files are placed in a certain order: first, all 'core' files, then all 'module' and finally all 'theme' JavaScript files are added to the page. Then, all settings are output, followed by 'inline' JavaScript code. If running update.php, all preprocessing is disabled.

2 calls to advagg_process_js()
advagg_get_js_css_get_array dans ./advagg.module
Return a large array of the CSS & JS files loaded on this page.
advagg_process_html_js dans includes/js.inc

Fichier

./advagg.module, line 1880

Code

function advagg_process_js($master_set, $noagg = FALSE) {
    global $conf;
    if ((!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') && function_exists('locale_update_js_files')) {
        locale_update_js_files();
    }
    // Get useful info.
    list($preprocess_js, $scheme, $query_string) = advagg_process_css_js_prep($noagg, 'js');
    $advagg_json_encode_function = variable_get('advagg_json_encode_function', 'advagg_drupal_to_js');
    $output = array();
    foreach ($master_set as $scope => $javascript) {
        if ($scope != 'header' && $scope != 'footer' && empty($javascript)) {
            continue;
        }
        // Invoke hook_advagg_js_pre_alter() to give installed modules a chance to
        // modify the data in the $javascript array if necessary.
        drupal_alter('advagg_js_pre', $javascript, $preprocess_js, $scheme, $scope);
        $master_set[$scope] = $javascript;
    }
    // Invoke hook_advagg_js_header_footer_alter() to give installed modules a chance to
    // modify the data in the header and footer JS if necessary.
    drupal_alter('advagg_js_header_footer', $master_set, $preprocess_js, $scheme);
    foreach ($master_set as $scope => $javascript) {
        if (empty($javascript)) {
            continue;
        }
        // Set variables.
        $setting_no_preprocess = array();
        $inline_no_preprocess = array();
        $external_no_preprocess = array();
        $output_no_preprocess = array(
            'core' => array(),
            'module' => array(),
            'theme' => array(),
        );
        $output_preprocess = array();
        $preprocess_list = array();
        $js_settings_array = array();
        $inline_included = array();
        $files_included = array();
        $files_aggregates_included = array();
        // Process input.
        foreach ($javascript as $type => $data) {
            if (empty($data)) {
                continue;
            }
            // Add the prefix and suffix to the info array if not there.
            if ($type != 'setting') {
                foreach ($data as &$info) {
                    $info['prefix'] = isset($info['prefix']) ? $info['prefix'] : '';
                    $info['suffix'] = isset($info['suffix']) ? $info['suffix'] : '';
                }
                // $info needs to be unset, otherwise foreach loops below will break.
                unset($info);
            }
            switch ($type) {
                case 'setting':
                    $data = call_user_func_array('array_merge_recursive', $data);
                    $js_settings_array[] = $data;
                    $js_settings = $advagg_json_encode_function($data);
                    $js_settings = preg_replace(array(
                        '/"DRUPAL_JS_RAW\\:/',
                        '/\\:DRUPAL_JS_RAW"/',
                    ), array(
                        '',
                        '',
                    ), $js_settings);
                    $setting_no_preprocess[] = 'jQuery.extend(Drupal.settings, ' . $js_settings . ");";
                    break;
                case 'inline':
                    foreach ($data as $info) {
                        // Invoke hook_advagg_js_inline_alter() to give installed modules a
                        // chance to modify the contents of $info['code'] if necessary.
                        drupal_alter('advagg_js_inline', $info['code']);
                        $inline_no_preprocess[] = array(
                            $info['code'],
                            $info['defer'],
                            $info['prefix'],
                            $info['suffix'],
                        );
                        $inline_included[] = $info['code'];
                    }
                    break;
                case 'external':
                    foreach ($data as $path => $info) {
                        $external_no_preprocess[] = array(
                            $path,
                            $info['defer'],
                            $info['prefix'],
                            $info['suffix'],
                        );
                        $files_included[$path] = TRUE;
                    }
                    break;
                default:
                    // 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 (!$info['preprocess'] || $scheme !== 'public' || !$preprocess_js) {
                            $output_no_preprocess[$type][] = array(
                                advagg_build_uri($path) . ($info['cache'] ? $query_string : '?' . REQUEST_TIME),
                                $info['defer'],
                                $info['prefix'],
                                $info['suffix'],
                            );
                            $files_included[$path] = $info['preprocess'];
                        }
                        else {
                            $preprocess_list[$path] = $info;
                        }
                    }
                    break;
            }
        }
        // Aggregate any remaining JS files that haven't already been output.
        if ($scheme === 'public' && $preprocess_js && count($preprocess_list) > 0) {
            $files_aggregates_included = $files_included;
            $files = array();
            foreach ($preprocess_list as $path => $info) {
                if ($info['preprocess']) {
                    $files[] = $path;
                    $files_included[$path] = TRUE;
                }
            }
            if (!empty($files)) {
                $preprocess_files = advagg_css_js_file_builder('js', $files, $query_string);
                if (!empty($preprocess_files)) {
                    $good = TRUE;
                    foreach ($preprocess_files as $preprocess_file => $extra) {
                        // Empty aggregate, skip
                        if (empty($preprocess_file)) {
                            continue;
                        }
                        if ($extra !== FALSE && is_array($extra)) {
                            $prefix = $extra['prefix'];
                            $suffix = $extra['suffix'];
                            $output_preprocess[] = array(
                                advagg_build_uri($preprocess_file),
                                $prefix,
                                $suffix,
                            );
                            $files_aggregates_included[$preprocess_file] = $extra;
                        }
                        else {
                            $good = FALSE;
                            break;
                        }
                    }
                }
                if (empty($good)) {
                    // Redo with aggregation turned off and return the new value.
                    watchdog('advagg', 'JS aggregation failed. %filename could not be saved correctly.', array(
                        '%filename' => $preprocess_file,
                    ), WATCHDOG_ERROR);
                    $data = advagg_process_js($master_set, TRUE);
                    return $data;
                }
            }
        }
        // Default function called: advagg_js_builder
        $function = variable_get('advagg_js_render_function', ADVAGG_JS_RENDER_FUNCTION);
        $output[$scope] = $function($external_no_preprocess, $output_preprocess, $output_no_preprocess, $setting_no_preprocess, $inline_no_preprocess, $scope, $js_settings_array, $inline_included, $files_included, $files_aggregates_included);
    }
    return $output;
}