Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created January 3, 2013 09:53
Show Gist options
  • Save rentalcustard/4442302 to your computer and use it in GitHub Desktop.
Save rentalcustard/4442302 to your computer and use it in GitHub Desktop.
Opening console config for extension
(function() {
var C = JS.Console;
var adapterConditions = {};
var registerAdapterCondition = function(check, initializer) {
adapterConditions[check] = initializer;
};
var configureC = function() {
C.adapter = new C.Base();
for(condition in adapterConditions) {
if (condition()) {
C.adapter = adapterConditions[condition]();
break; //only needed if more than one can be true and you want a priority order
}
}
return C;
};
for (var key in C.ESCAPE_CODES) (function(key) {
C.define(key, function() {
JS.Console.adapter.format(key);
});
})(key);
C.extend(C);
//default configurations
this.registerAdapterConfiguration(function () {
return (typeof window !== 'undefined');
}, function () {
return new C.Browser();
});
this.registerAdapterConfiguration(function () {
return (typeof process === 'object');
}, function () {
return new C.Node();
});
this.registerAdapterConfiguration(function () {
return (typeof phantom !== 'undefined');
}, function () {
return new C.Phantom();
});
this.registerAdapterConfiguration(function () {
return (typeof java !== 'undefined' && typeof java.lang !== 'undefined');
}, function () {
return new C.Rhino();
});
this.registerAdapterConfiguration(function () {
return (typeof WScript !== 'undefined');;
}, function () {
return new C.Windows();
});
})();
//and now you need to call configureC from config somewhere to get a C.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment