Same name and namespace in other branches
  1. 7.x-1.x advagg.module \advagg_get_full_js() 1 commentaire

Get full JS array.

Note that hook_js_alter(&$javascript) is called during this function call to allow alterations of the JavaScript during its presentation. Calls to drupal_add_js() from hook_js_alter() will not be added to the output presentation. The correct way to add JavaScript during hook_js_alter() is to add another element to the $javascript array, deriving from drupal_js_defaults(). See locale_js_alter() for an example of this.

Paramètres

array $javascript: (optional) An array with all JavaScript code. Defaults to the default JavaScript array for the given scope.

bool $skip_alter: (optional) If set to TRUE, this function skips calling drupal_alter() on $javascript, useful when the calling function passes a $javascript array that has already been altered.

Return value

array The raw JavaScript array.

Voir aussi

drupal_add_js()

locale_js_alter()

drupal_js_defaults()

2 calls to advagg_get_full_js()
advagg_get_js dans ./advagg.module
Returns a themed presentation of all JavaScript code for the current page.
_advagg_build_js_arrays_for_rendering dans ./advagg.module
Builds the arrays needed for js rendering and caching.

Fichier

./advagg.module, line 2821

Code

function advagg_get_full_js(array $javascript = array(), $skip_alter = FALSE) {
    if (empty($javascript)) {
        $javascript = drupal_add_js();
    }
    // Return an empty array if
    // no javascript is used,
    // only the settings array is used and scope is header.
    if (empty($javascript) || isset($javascript['settings']) && count($javascript) == 1) {
        return array();
    }
    // Allow modules to alter the JavaScript.
    if (!$skip_alter) {
        advagg_add_default_dns_lookups($javascript, 'js');
        if (is_callable('advagg_mod_js_pre_alter')) {
            advagg_mod_js_pre_alter($javascript);
        }
        // Call hook_js_alter().
        drupal_alter('js', $javascript);
        // Call hook_js_post_alter().
        drupal_alter('js_post', $javascript);
        // Call these advagg functions after the hook_js_alter was called.
        advagg_fix_type($javascript, 'js');
    }
    elseif (is_callable('advagg_mod_js_move_to_footer')) {
        if (variable_get('advagg_mod_js_footer', ADVAGG_MOD_JS_FOOTER) == 3) {
            advagg_mod_js_move_to_footer($javascript);
        }
    }
    // If in development mode make sure the ajaxPageState css is there.
    if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) < 0) {
        $have_css = FALSE;
        foreach ($javascript['settings']['data'] as $setting) {
            if (!empty($setting['ajaxPageState']['css'])) {
                $have_css = TRUE;
                break;
            }
        }
        if (!$have_css) {
            $css = drupal_add_css();
            if (!empty($css)) {
                // Cast the array to an object to be on the safe side even if not empty.
                $javascript['settings']['data'][]['ajaxPageState']['css'] = (object) array_fill_keys(array_keys($css), 1);
            }
        }
    }
    // Remove empty files.
    advagg_remove_empty_files($javascript);
    return $javascript;
}