Same name and namespace in other branches
  1. 7.x-1.x advagg_js_compress/advagg_js_compress.module \advagg_js_compress_jspacker() 1 commentaire

Compress a JS string using packer.

Paramètres

string $contents: Javascript string.

bool $log_errors: FALSE to disable logging to watchdog on failure.

1 string reference to 'advagg_js_compress_jspacker'
advagg_js_compress_configuration dans advagg_js_compress/advagg_js_compress.module
Generate the js compress configuration.

Fichier

advagg_js_compress/advagg_js_compress.advagg.inc, line 611

Code

function advagg_js_compress_jspacker(&$contents, $log_errors = TRUE) {
    $no_errors = TRUE;
    $contents_before = $contents;
    // Try libraries for jspacker.
    if (is_callable('libraries_load')) {
        libraries_load('jspacker');
    }
    if (!class_exists('JavaScriptPacker')) {
        include drupal_get_path('module', 'advagg_js_compress') . '/jspacker.inc';
    }
    // Add semicolons to the end of lines if missing.
    $contents = str_replace("}\n", "};\n", $contents);
    $contents = str_replace("\nfunction", ";\nfunction", $contents);
    // Use Packer on the contents of the aggregated file.
    try {
        $packer = new JavaScriptPacker($contents, 62, TRUE, FALSE);
        $contents = $packer->pack();
    } catch (Exception $e) {
        $no_errors = FALSE;
        // Log the exception thrown by JSMin+ and roll back to uncompressed content.
        if ($log_errors) {
            watchdog('advagg_js_compress', '@message <pre> @contents </pre>', array(
                '@message' => $e->getMessage(),
                '@contents' => $contents_before,
            ), WATCHDOG_WARNING);
        }
        $contents = $contents_before;
    }
    return $no_errors;
}