I wanted to select my environment on the client side based on the URL
path. For this, I have written the following EnvironmentDetector class
for Claypool, I'd like to share:
(function($, $$) {
$$.EnvironmentDetector = function(options) {
$.extend(true, this, options);
}
$.extend($$.EnvironmentDetector.prototype, {
detect:function(pattern) {
var fieldmatch, config, e, currentUrl;
fieldmatch = "client.clienturl"
if(arguments.length == 2) {
fieldmatch = arguments[0];
}
config = $.config("env");
for(e in config) {
if(e == 'default') {
continue;
}
currentUrl = $.config('env.' + e + '.' + fieldmatch);
if(currentUrl && typeof(currentUrl) == "string" &&
currentUrl.match(pattern)) {
return e;
}
}
return null;
}
});
})(jQuery, Claypool);
In my boot/client.js file I have the following lines:
try{
var d = new Claypool.EnvironmentDetector();
var envname = d.detect(location.href);
$.env('defaults', envname + ".client");
}catch(e){
When I now set the client.clienturl property in my environments, the
environment gets detected. This is nice because I can copy my source
code around without modifying client.js
I hope I haven't duplicated existing functionality. Feel free to
incorporate this into the main Claypool source. Maybe the code can be
modified so it works on the server side too. Comments on how to
improve the code are also appreciated.
Greetings,
Gabriel
--
You received this message because you are subscribed to the Google Groups "jquery-claypool" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to jquery-claypo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jquery-claypool?hl=en.