There is a way to better check on the files available for edition by using hook_css_alter. I'm just throwing this for discussion, but I think this could be working just fine. Of course, we can use whatever we need (system path, file name, or url) in the settings to be available in the js.

The function below is just an quick example, which does not deal with all the possible cases. The real question is what to do with that once available in the js.

/**
 * Implements hook_css_alter().
 * We can determine the stylesheets available for live edition.
 */
function live_css_css_alter(&$css){
  if(variable_get('live_css_hidemodules', 0) == 1){
    $settings['stylesheets'] = array();
    foreach ($css as $key => $value) {
      // Get all the CSS files of themes only
      if ($value['group'] == CSS_THEME) {
        $settings['stylesheets'][$_SERVER['DOCUMENT_ROOT'] . $key] = $key;
      };
    }
  }
  drupal_add_js(array('live_css' => $settings), 'setting');
}

Comments

guybedford’s picture

There are a couple of benefits to this - we get to control the save url on the server, which is more secure and we also get better control over the file listing process.

So I would suggest that in doing this, it would also be beneficial to maintain the save path in the session itself. So that when saving, the url is looked up in the session cache for the corresponding file path, where both have been extracted from the css hook.

So if the above sounds plausible, the javascript update would be trivial based on the following settings output:

Drupal.settings.css_files = [
{
name: 'admin.css',
url: '/sites/all/themes/mytheme/css/admin.css',
}, ...
]

guybedford’s picture

Status: Active » Closed (won't fix)

Patches welcome along these lines, please reopen for any implementations.