Implements hook_libraries_info().

Sujets associés

Fichier

advagg_mod/advagg_mod.module, line 1176

Code

function advagg_mod_libraries_info() {
    $libraries['loadCSS'] = array(
        'name' => 'loadCSS',
        'vendor url' => 'https://github.com/filamentgroup/loadCSS',
        'download url' => 'https://github.com/filamentgroup/loadCSS/archive/master.zip',
        'version arguments' => array(
            'file' => 'package.json',
            'pattern' => '/"version":\\s+"([0-9\\.]+)"/',
            'lines' => 100,
        ),
        // Called before the library is loaded.
'callbacks' => array(
            'pre-load' => array(
                'advagg_mod_libraries_preload_callback',
            ),
        ),
        'local version' => '2.0.1',
        'remote' => array(
            'callback' => 'advagg_get_github_version_json',
            'url' => 'https://cdn.jsdelivr.net/gh/filamentgroup/loadCSS@master/package.json',
        ),
        'files' => array(
            'js' => array(
                'src/loadCSS.js' => array(
                    'type' => 'file',
                    'async' => TRUE,
                ),
            ),
        ),
    );
    // Get the latest tagged version for external file loading.
    $version = advagg_get_remote_libraries_version('loadCSS', $libraries['loadCSS']);
    // Get the advagg_mod path for local loading.
    $advagg_mod_path = drupal_get_path('module', 'advagg_mod');
    $libraries['loadCSS'] += array(
        'variants' => array(
            'normal-preload' => array(
                'files' => array(
                    'js' => array(
                        'src/cssrelpreload.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'normal-onload' => array(
                'files' => array(
                    'js' => array(
                        'src/loadCSS.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                        'src/onloadCSS.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'minified' => array(
                'files' => array(
                    'js' => array(
                        'src/loadCSS.min.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'minified-preload' => array(
                'files' => array(
                    'js' => array(
                        'src/cssrelpreload.min.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'minified-onload' => array(
                'files' => array(
                    'js' => array(
                        'src/loadCSS.min.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                        'src/onloadCSS.min.js' => array(
                            'type' => 'file',
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'external' => array(
                'files' => array(
                    'js' => array(
                        "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/loadCSS.js" => array(
                            'type' => 'external',
                            'data' => "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/loadCSS.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'external-preload' => array(
                'files' => array(
                    'js' => array(
                        "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/cssrelpreload.js" => array(
                            'type' => 'external',
                            'data' => "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/cssrelpreload.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'external-onload' => array(
                'files' => array(
                    'js' => array(
                        "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/loadCSS.js" => array(
                            'type' => 'external',
                            'data' => "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/loadCSS.js",
                            'async' => TRUE,
                        ),
                        "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/onloadCSS.js" => array(
                            'type' => 'external',
                            'data' => "//cdn.jsdelivr.net/gh/filamentgroup/loadCSS@v{$version}/src/onloadCSS.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'local' => array(
                'version' => '1.3.1',
                'files' => array(
                    'js' => array(
                        "{$advagg_mod_path}/loadCSS.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/loadCSS.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'local-preload' => array(
                'version' => '1.3.1',
                'files' => array(
                    'js' => array(
                        "{$advagg_mod_path}/cssrelpreload.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/cssrelpreload.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'local-onload' => array(
                'version' => '1.3.1',
                'files' => array(
                    'js' => array(
                        "{$advagg_mod_path}/loadCSS.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/loadCSS.js",
                            'async' => TRUE,
                        ),
                        "{$advagg_mod_path}/onloadCSS.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/onloadCSS.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'local-minified' => array(
                'version' => '1.3.1',
                'files' => array(
                    'js' => array(
                        "{$advagg_mod_path}/loadCSS.min.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/loadCSS.min.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'local-minified-preload' => array(
                'version' => '1.3.1',
                'files' => array(
                    'js' => array(
                        "{$advagg_mod_path}/cssrelpreload.min.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/cssrelpreload.min.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
            'local-minified-onload' => array(
                'version' => '1.3.1',
                'files' => array(
                    'js' => array(
                        "{$advagg_mod_path}/loadCSS.min.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/loadCSS.min.js",
                            'async' => TRUE,
                        ),
                        "{$advagg_mod_path}/onloadCSS.min.js" => array(
                            'type' => 'file',
                            'data' => "{$advagg_mod_path}/onloadCSS.min.js",
                            'async' => TRUE,
                        ),
                    ),
                ),
            ),
        ),
    );
    // Add inline data.
    $loadcss_loc = "{$advagg_mod_path}/loadCSS.min.js";
    $cssrelpreload_loc = "{$advagg_mod_path}/cssrelpreload.min.js";
    $onloadcss_loc = "{$advagg_mod_path}/onloadCSS.min.js";
    // Use given library if there.
    $libraries_paths = array();
    if (is_callable('libraries_get_libraries')) {
        $libraries_paths = libraries_get_libraries();
    }
    if (isset($libraries_paths['loadCSS'])) {
        // Get location of loadCSS.
        if (is_readable($libraries_paths['loadCSS'] . '/src/loadCSS.min.js')) {
            $loadcss_loc = $libraries_paths['loadCSS'] . '/src/loadCSS.min.js';
            $libraries['loadCSS']['variants']['minified']['#files_exists'] = TRUE;
        }
        elseif (is_readable($libraries_paths['loadCSS'] . '/src/loadCSS.js')) {
            $loadcss_loc = $libraries_paths['loadCSS'] . '/src/loadCSS.js';
        }
        // Get location of cssrelpreload.
        if (is_readable($libraries_paths['loadCSS'] . '/src/cssrelpreload.min.js')) {
            $cssrelpreload_loc = $libraries_paths['loadCSS'] . '/src/cssrelpreload.min.js';
            if ($libraries['loadCSS']['variants']['minified']['#files_exists']) {
                $libraries['loadCSS']['variants']['minified-preload']['#files_exists'] = TRUE;
            }
        }
        elseif (is_readable($libraries_paths['loadCSS'] . '/src/cssrelpreload.js')) {
            $cssrelpreload_loc = $libraries_paths['loadCSS'] . '/src/cssrelpreload.js';
        }
        // Get location of onloadCSS.
        if (is_readable($libraries_paths['loadCSS'] . '/src/onloadCSS.min.js')) {
            $onloadcss_loc = $libraries_paths['loadCSS'] . '/src/onloadCSS.min.js';
            if ($libraries['loadCSS']['variants']['minified']['#files_exists']) {
                $libraries['loadCSS']['variants']['minified-preload']['#files_exists'] = TRUE;
            }
        }
        elseif (is_readable($libraries_paths['loadCSS'] . '/src/onloadCSS.js')) {
            $onloadcss_loc = $libraries_paths['loadCSS'] . '/src/onloadCSS.js';
        }
    }
    // Add inline scripts.
    $libraries['loadCSS']['variants'] += array(
        'inline' => array(
            'files' => array(
                'js' => array(
                    'loadCSS_inline' => array(
                        'type' => 'inline',
                        'data' => (string) @advagg_file_get_contents($loadcss_loc),
                        'no_defer' => TRUE,
                    ),
                ),
            ),
        ),
        'inline-preload' => array(
            'files' => array(
                'js' => array(
                    'cssrelpreload_inline' => array(
                        'type' => 'inline',
                        'data' => (string) @advagg_file_get_contents($cssrelpreload_loc),
                        'no_defer' => TRUE,
                    ),
                ),
            ),
        ),
        'inline-onload' => array(
            'files' => array(
                'js' => array(
                    'loadCSS_inline' => array(
                        'type' => 'inline',
                        'data' => (string) @advagg_file_get_contents($loadcss_loc),
                        'no_defer' => TRUE,
                    ),
                    'onloadCSS_inline' => array(
                        'type' => 'inline',
                        'data' => (string) @advagg_file_get_contents($onloadcss_loc),
                        'no_defer' => TRUE,
                    ),
                ),
            ),
        ),
    );
    if (!is_callable('libraries_detect')) {
        // Set defaults.
        $default_options = advagg_mod_loadcss_js_defaults();
        foreach ($libraries['loadCSS']['files']['js'] as &$value) {
            $value += $default_options;
        }
        foreach ($libraries['loadCSS']['variants'] as &$values) {
            foreach ($values['files']['js'] as &$value) {
                $value += $default_options;
            }
        }
    }
    return $libraries;
}