Fri 2 Jun 2006
In order to implement advanced features/missing features of the proposed enhanced Editor widget, the core of the dojo packages need to be extended. One of the most fundamental one is the impossibility of using dojo from another window/document except the window which loads it.
In MochiKit the concept of " context " is introduced. It provides 4 APIs to handle context (see the table below).
| Signature | Description |
|---|---|
| withWindow(win, func) | Execute function func in the context of window win (and with document win.document) |
| withDocument(doc, …) | Execute function func in the context of document doc |
| currentWindow() | Retrieve the current window in use |
| currentDocument() | Retrieve the current document in use |
For example, creating DOM nodes in a child window in MochiKit is like this:
withWindow(child, function () {
var doc = currentDocument();
appendChildNodes(doc.body, H1(null, "This is in the child!"));
});
Paul suggested to borrow this API to dojo, so we can do something like this:
dojo.html.withWindow(child, function () {
var doc = dojo.html.currentDocument();
var h1 = doc.createElement('H1');
h1.appendChild(doc.createTextElement('This is in the child!'));
dojo.html.body().appendChild(h1);
});
Alex consider this would lead to "error- prone usage". I agree with that. However, as I need this functionality for the Editor, so we have to come up a better idea or stick with this syntax.
RSS feed for comments on this post. TrackBack this post