Hi
Firstly - thanks again for grocerycrud
I have a minor suggestion
I really like the notion of NOT including the same css and the same js multiple times
It's a good enhancement for faster load times
I would like to be able to use the gc set functions from my controller - so as to ensure
I don't add duplicate scripts
In order to also facilitate the adding of scripts outside the GC directory tree
I would like to suggest the following code :
//for backward compatibility public function set_css($css_file) { $this->add_include($css_file); } //for backward compatibility public function set_js($js_file) { $this->add_include($js_file); } public function add_include($inc_file){ $fn = (strpos($inc_file,"/") === 0 ) ? substr($inc_file, 1) : $inc_file; if (strripos($fn,'.js',-3) !== False) { if (! file_exists("$fn")){ $fn = $this->default_javascript_path."/$fn" ; } if(file_exists("$fn")){ $this->js_files[sha1($fn)] = base_url().$fn; } else { throw new Exception("Missing JavaScript (.js) file. Tried : $inc_file and $fn"); } } elseif (strripos($inc_file,'.css',-4) !== False) { if (! file_exists("$fn")){ $fn = $this->default_css_path."/$fn" ; } if(file_exists("$fn")){ $this->css_files[sha1($fn)] = base_url().$fn; } else { throw new Exception("Missing Stylesheet (.css) file. Tried: $inc_file and $fn"); } } else { throw new Exception("Request to include unknown file type: $inc_file"); } }
I'm also not entirely sure that a more correct algorithm would be :
sha1(basename($fn))
so we get a copy of the file included - but perhaps this may cause problems when relying on different versions of the same file - if they were-named to include their version numbers it would be fine.
What does da boss think ??
Cheers
Ez