A user reported that problem to me on my Demopage (work in progress) for the Four Seasons Theme
http://fourseasons.forward-media.de/

I enabled the module but mystyle.css (/sites/default/files/customcssjs/css/mystyle.css) is included before style.css (/sites/all/themes/fourseasons/css/style.css).

Four Seasons includes the style.css expicitly via the themes info file
stylesheets[all][] = css/style.css

Is that by design?

CommentFileSizeAuthor
#15 fix_customcssjs_module.patch1.29 KBflateric

Comments

davebv’s picture

I had this "issue" from the beginning. I searched how a module could include its styles and javascript files after everything else but I did not find an easy solution.

Right now it is by design (to make this module simplest as possible). In fact, this is how drupal behaves. But I am trying to make a elegant way to override this and to not brake anything else.

Any help and discussion on how to do this are very welcome.

derjochenmeyer’s picture

My module Javascript Aggregator does something that could be useful for you.

It implements hook_preprocess_page() and searches the $scripts variable via a RegEx for certain scripts. You could do the same and extract the custom css and js files from the variable and add them again to the end of the array.

You could take the $styles variable, rearrange the order and return it again directly before the page gets rendered.

Here is the example from Javascript Aggregator. _javascript_aggregator_minify() does the RegEx thing.

/**
 * Implementation of hook_preprocess_page().
 *
 * Minify the aggregated JavaScript file 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']);
  }
}
davebv’s picture

Status: Active » Needs review

I just commited a patch, it shoud be in the next dev build. I tried and seems to work but I do not know if that is the best way to do it.

Please, give a try and post comments if it is working and about the code implementation. Thanks!!

If your feedback is positive, I will make a new release.

function customcssjs_preprocess_page(&$variables) {
  // We will get css and js files and rearrange them
  if (!empty($variables['styles'])) {
    $css_path = variable_get('customcssjs_css', array()) ;
    if (!empty($css_path)) {
      $css_array = explode("<link ", $variables['styles']);
      $patron = '!(.*?)'. $css_path .'(.*?)!' ;
      $css_array_last = preg_grep($patron, $css_array);
      foreach ($css_array_last as $key => $value) {
        if (is_null($value) || $value == ""){
          unset($css_array_last[$key]);
          continue;
        }
        $css_array_last[$key] = '<link '. trim($css_array_last[$key]) .'^M' ;
      }
      $css_array_in = preg_grep($patron, $css_array, PREG_GREP_INVERT);
      foreach ($css_array_in as $key => $value) {
        if (is_null($value) || $value == ""){
          unset($css_array_in[$key]);
          continue;
        }
        $css_array_in[$key] = '<link '. trim($css_array_in[$key]) .'^M' ;
      }
 
      $css_array_all = array_merge($css_array_in, $css_array_last) ;
      $variables['styles'] = implode("", $css_array_all) ;
    }
  }
  if (!empty($variables['scripts'])) {
    $js_path = variable_get('customjsjs_js', array()) ;
    if (!empty($js_path)) {
      $js_array = explode("<link ", $variables['scripts']);
      $patron = '!(.*?)'. $js_path .'(.*?)!' ;
      $js_array_last = preg_grep($patron, $js_array);
      foreach ($js_array_last as $key => $value) {
        if (is_null($value) || $value == ""){
          unset($js_array_last[$key]);
          continue;
        }
        $js_array_last[$key] = '<link '. trim($js_array_last[$key]) .'^M' ;
      }
      $js_array_in = preg_grep($patron, $js_array, PREG_GREP_INVERT);
      foreach ($js_array_in as $key => $value) {
        if (is_null($value) || $value == ""){
          unset($js_array_in[$key]);
          continue;
        }
        $js_array_in[$key] = '<link '. trim($js_array_in[$key]) .'^M' ;
      }
 
      $js_array_all = array_merge($js_array_in, $js_array_last) ;
      $variables['scripts'] = implode("", $js_array_all) ;
    }
  }

}
davebv’s picture

I modified latest patch for js files to break with <script instead of <link. Now everything shoud work as expected.

davebv’s picture

LAtest version (and working one, I hope) is released in 1.5.

davebv’s picture

Version: 6.x-1.4 » 6.x-1.5
Assigned: Unassigned » davebv
Status: Needs review » Fixed

I have been using this feature myself and did not find problems. Mark this as fixed, please report any problems you may encounter.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ahansen1’s picture

I've recently started using this module and have done so successfully on several themes. However, I've just found that with the Ad Blueprint theme it seems to inject the CSS after this module. Any thoughts on how to address the issue?

ahansen1’s picture

Status: Closed (fixed) » Active
davebv’s picture

I do not use that theme, but maybe it inserts css files and modify the registry like this module does.

In the case a theme modify the registry and put the css and js at the end of the registry, nothing can be done from a module (or so I guess)

davebv’s picture

Title: css files do not override the themes css file » Themes modifying the registry override this module functionality.
Status: Active » Closed (won't fix)
web2’s picture

subscribing

klonos’s picture

Status: Closed (won't fix) » Fixed

Having this one as 'won't fix' reflects its status on the link in the module's page. That is kinda confusing so changing it to fixed (...and letting the system auto-close it).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

flateric’s picture

StatusFileSize
new1.29 KB

The patch did not fully work for me (using custom css and js locations). I had to change the regex, patch attached.

Anyway, thanks for the module :)

flateric’s picture

Upload didn't work?

Index: src/sites/all/modules/customcssjs/customcssjs.module
===================================================================
--- src/sites/all/modules/customcssjs/customcssjs.module	(revision 35)
+++ src/sites/all/modules/customcssjs/customcssjs.module	(revision )
@@ -126,7 +126,8 @@
     $css_path = variable_get('customcssjs_css', array()) ;
     if (!empty($css_path)) {
       $css_array = explode("<link ", $variables['styles']);
-      $patron = '!(.*?)'. $css_path .'(.*?)!' ;
+      //$patron = '!(.*?)'. $css_path .'(.*?)!' ;
+      $patron = '/' . str_replace('/', '\/', base_path() . file_directory_path()) . "\/$css_path/";
       $css_array_last = preg_grep($patron, $css_array);
       foreach ($css_array_last as $key => $value) {
         if (is_null($value) || $value == ""){
@@ -154,7 +155,8 @@
     $js_path = variable_get('customjsjs_js', array()) ;
     if (!empty($js_path)) {
       $js_array = explode("<script ", $variables['scripts']);
-      $patron = '!(.*?)'. $js_path .'(.*?)!' ;
+      //$patron = '!(.*?)'. $js_path .'(.*?)!' ;
+      $patron = '/' . str_replace('/', '\/', base_path() . file_directory_path()) . "\/$js_path/";
       $js_array_last = preg_grep($patron, $js_array);
       foreach ($js_array_last as $key => $value) {
         if (is_null($value) || $value == ""){