Created
January 3, 2013 09:53
-
-
Save rentalcustard/4442302 to your computer and use it in GitHub Desktop.
Opening console config for extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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