Skip to content

Instantly share code, notes, and snippets.

@sams
Created February 25, 2011 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sams/843300 to your computer and use it in GitHub Desktop.
Save sams/843300 to your computer and use it in GitHub Desktop.
to reduce the complexity of bakingplates layouts; keep'em clean
<?php
class PlateHelper extends AppHelper {
var $helpers = array('Html', 'Form');
/*
* function js_lib
* @param host = google, lib = jquery, version = null, compressed = true
*/
function jsLib($host = 'google', $lib = 'jquery', $version = null, $compressed = true) {
$min = $compressed ? '.min' : '';
$fallback = is_null($version) ? '' : $this->Html->scriptBlock("!window.jQuery && document.write(unescape('%3Cscript src=\"libs/{$lib}-{$version}{$min}\"%3E%3C/script%3E'))");
// ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js
$cdn = ($host == 'google') ? '//ajax.googleapis.com/ajax/libs/'.$lib.'/'.$version.'/'.$lib.$min.'.js' : sprintf($host, $lib, $version, $min);
$cdn = $this->Html->script($cdn);
return $cdn.$fallback;
}
/*
* function dd_png
* @param void
*/
function pngFix($fixClasses) {
$classes = implode(',', $fixClasses);
return
$this->Html->script(array('libs/dd_belatedpng')) .
$this->Html->scriptBlock("DD_belatedPNG.fix('$classes'); ");
}
/*
* function profiling
* outputs yahoo profiling code - only if admin is logged in and debug is set
* @param void
*/
function profiling() {
if(Configure::read('site.YahooProfiling')) {
return $this->Html->script(array('profiling/yahoo-profiling.min', 'profiling/config'));
}
}
/*
* function analytics
* outputs google analytics code - only if on live domain and the GA id is set
* @param void
*/
function conditionalComment($content, $ie = '7') {
}
function chromeFrame() {
return "<!--[if IE]><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"><![endif]-->";
}
/*
* function analytics
* outputs google analytics code - only if on live domain and the GA id is set
* @param void
*/
function analytics() {
$GoogleAnalytics = Configure::read('site.GoogleAnalytics');
if(!Configure::read('debug') && $GoogleAnalytics) {
return $this->View->element('extras/google_analytics', array('google_analytics' => $GoogleAnalytics));
}
}
/*
* function modernizr
* @param $default = true
*/
function modernizr($default = true) {
$default = ($default === true) ? 'modernizr' : $default;
return $this->Html->script('libs/' . $default);
}
}
?>
@ProLoser
Copy link

ProLoser commented Mar 7, 2011

simply adding .min to all js libraries doesn't work. Each one has it's own unique naming convention for compressed versions. I recommend creating an array attribute with the 'lib' => 'url' and maybe even have 2 values, minified and standard. Putting together the path in hard-code in the function itself is... sloppy. It also makes the code hard to read. You can create another attribute array for hosts. If they are not final/private, the dev can always supplement them on run-time.

As for chromeframe, might as well use single quotes ' instead of " for returning the full line. Inconsistent, touched on in code conventions wiki page. Not important though.

@sams
Copy link
Author

sams commented Mar 7, 2011

JsLib in new version you can indeed to all of that - I have array for cdns include microsoft, jquery and google (adding your our is not something I have tested as yet); all seems well I just need to give it a final review and refresh it in my mind and browser :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment