'. t('Uses the JSMin library to minify the aggregated JavaScript file when JavaScript optimization has been enabled in the Performance settings.', array('@performance' => url('admin/settings/performance'), '@jsmin' => 'http://code.google.com/p/jsmin-php/')) .'
'; return $output; } } /** * Implementation of hook_form_alter(). */ function javascript_aggregator_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'system_performance_settings') { $form['bandwidth_optimizations']['preprocess_js']['#title'] = t('Optimize and Minify JavaScript files'); $form['bandwidth_optimizations']['preprocess_js']['#description'] .= t(' Once the JavaScript files have been aggregated, they will be minified.'); $form['bandwidth_optimizations']['preprocess_js']['#weight'] = 2; $form['bandwidth_optimizations']['javascript_aggregator_gzip'] = array( '#type' => 'checkbox', '#title' => t('GZip JavaScript'), '#description' => t('Once minified, optionally GZip the aggregated JavaScript file to dramatically decrease its size.', array('@gzip' => 'http://en.wikipedia.org/wiki/Gzip')), '#default_value' => variable_get('javascript_aggregator_gzip', FALSE), '#weight' => 3, ); $form['bandwidth_optimizations']['javascript_aggregator_no_htaccess'] = array( '#type' => 'checkbox', '#title' => t('Do not auto generate .htaccess file (experts only)'), '#description' => t("If you want to use GZipping and your host doesn't like multiple .htaccess files check this option, together with the option above to bypass htaccess file generation and follow directions in the README.txt."), '#default_value' => variable_get('javascript_aggregator_no_htaccess', FALSE), '#weight' => 5, ); $form['bandwidth_optimizations']['javascript_aggregator_jsminplus'] = array( '#type' => 'checkbox', '#title' => t('Use JSMin+ instead of JSMin'), '#description' => t('Check this option to use JSMin+ instead of JSMin.', array('@jsminplus' => 'http://crisp.tweakblogs.net/blog/1665/a-new-javascript-minifier-jsmin+.html')), '#default_value' => variable_get('javascript_aggregator_jsminplus', FALSE), '#weight' => 4, ); } } /** * Implementation of hook_theme_registry_alter(). * * Make javascript_aggregator's page preprocess function run *after* everything * else's (even jQuery Update). */ function javascript_aggregator_theme_registry_alter(&$theme_registry) { if (isset($theme_registry['page'])) { // If javascript_aggregator's preprocess function is there already, remove it. if (is_array($theme_registry['page']['preprocess functions']) && $key = array_search('javascript_aggregator_preprocess_page', $theme_registry['page']['preprocess functions'])) { unset($theme_registry['page']['preprocess functions'][$key]); } // Now tack it on at the end so it runs after everything else. $theme_registry['page']['preprocess functions'][] = 'javascript_aggregator_preprocess_page'; } } /** * Implementation of hook_preprocess_hook(). * * Minify the aggregated JavaScript file in the page header if JavaScript * Optimization is turned on. */ function javascript_aggregator_preprocess_page(&$variables) { // Only do this for pages that have JavaScript on them. if (!empty($variables['scripts'])) { $variables['scripts'] = _javascript_aggregator_minify($variables['scripts']); } } /** * Implementation of theme_closure(). * * Minify the aggregated JavaScript file in the page footer if JavaScript * Optimization is turned on. */ function phptemplate_closure($main = 0) { $footer = module_invoke_all('footer', $main); $js_footer = drupal_get_js('footer'); // Only do this for pages that have JavaScript on them. if (!empty($js_footer)) { $js_footer = _javascript_aggregator_minify($js_footer); } return implode("\n", $footer) . $js_footer; } /** * Helper function to minify and gzip files. */ function _javascript_aggregator_minify($scripts) { // Only process it is JavaScript Optimization is enabled. if (variable_get('preprocess_js', 0)) { // Strip out the aggregated JavaScript file. $path_to_files_directory = base_path() . file_directory_path(); $pattern = "!(