Application:toolkit integration
From Surebert wiki
Contents |
Overview
The surebert toolkit is part of the surebert framework by default. While you can use other javascript toolkit's the surebert javascript toolkit is encourages and built in.
Using the Surebert Toolkit
On an .view template you can include the surebert toolkit by loading the /surebert/load view. Remember, to always put javascript at the bottom of the page. /surebert/load strips the comments and documentation out of toolkit files to make them smaller when serving. If you want to see the full comments and documentation see the source in /var/www/sbf/toolkit or look in the svn repository or on the surebert.com site itself.
Here we are including just the base surebert toolkit
text code
<script type="text/javascript" src="/surebert/load/sb"></script>
If you would like to include the most useful modules use /basic
text code
<script type="text/javascript" src="/surebert/basic"></script>
If you would like to include other parts of the toolkit simply append there name to the src.
text code
<script type="text/javascript" src="/surebert/load/sb,Element.prototype.show"></script>
You can also make multiple calls to /surebert/load by including multiple script tags. This allows you to load certain file based on who the user is and what features they will require using a PHP if statment.
text code
<script type="text/javascript" src="/surebert/load/sb"></script> <script type="text/javascript" src="/surebert/load/Element.prototype.show"></script>
Once you have the toolkit loaded you can also load additional functionality from the client using the toolkits sb.include() method.
text code
<script type="text/javascript" src="/surebert/load/sb"></script>
<script type="text/javascript">
$('#myButton').events({
click : function(e){
//load md5 string prototype if they click the button
sb.include('String.prototype.md5');
alert('hello world'.md5());
}
});
</script>Overriding the default
If you would like to add additional /surebert methods to the Toolkit controller simply add a new controller called SurebertController that extends sb_Controller_Toolkit
php code
<?php /** * Serves the surebert toolkit but also combined with some other javascript */ class SurebertController extends sb_Controller_Toolkit{ /** * servable * @servable true */ public function rp(){ $protocol = $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http'; header("Content-type: application/x-javascript"); ob_start(); readfile(ROOT.'/public/js/rp.js'); readfile(ROOT.'/public/js/rp.people_search.js'); readfile(ROOT.'/public/js/rp.group_search.js'); $str = ob_get_clean(); if($protocol == 'https'){ return str_replace("http", "https", $str); } else { return $str; } } } ?>
Caching the script
If you set the $cache_enable property of /private/views/surebert/SurebertView.php, /surebert/load will cache all the scripts it renders serverside after they are compiled.