This is loaded before prototype.js to set up an environment containing
the objects prototype assumes exist:
var emptyFunction = function() {};
var window = new Object();
window.attachEvent = emptyFunction;
window.opera = false;
window.HTMLElement = new Object();
var navigator = new Object();
navigator.userAgent = new String();
var emptyElement = new Object();
emptyElement.__proto__ = false;
emptyElement.appendChild = emptyFunction;
function Element() { }
function HTMLElement() { }
var emptyTextnode = new Object();
var document = new Object();
document.evaluate = emptyFunction;
document.createElement = function() { return emptyElement; };
document.createTextNode = function() { return emptyTextnode; };
document.write = emptyFunction;
document.getElementById = function() { return emptyElement; };
One positive benefit to this method is that I do not have to touch the
source code. The downside is that I have several objects residing in
memory which cannot be used predictably, if at all.
I, too, would volunteer my services in maintaining such a project going forward.
Adam Rich
Me too. :-)
> A problem I see is that every time a new version of prototype.js comes
> out, you have to re-sift through all the code and pull out the stuff
> that belongs to the DOM. That makes me antsy. My current, albeit
> temporary, solution is posted above. With mine, every time a new
> prototype comes out, I have to check for new error messages and set
> those objects trivially. Not any better, probably worse, but there is
> no touching of the source code.
Exactly. My quick current solution is very similar to Nathan's, but I
don't think that is really viable (or at least not optimal) in the long
run in terms of maintenance.
Hence the discussion to see how this use case (i.e. Prototype in a
non-browser environment) could be included at the core if possible...
Thanks,
-Christian
That's very interesting. I had not yet looked at how Prototype was
built, and I see it looks indeed quite modular.
The build is done using Rake. Maybe an easy way would then be to add a
"dist-server" target in the Rakefile that would appropriately filter the
assembled files for server use?
-Christian