Haha this thread is getting funny, Aaron I mean the this keyword
reference in the lib (here are some functions inside Mootools:
newElement: function(tag, props){
if (Browser.Engine.trident && props){
['name', 'type', 'checked'].each(function(attribute){
if (!props[attribute]) return;
tag += ' ' + attribute + '="' +
props[attribute] + '"';
if (attribute != 'checked') delete
props[attribute];
});
tag = '<' + tag + '>';
}
return $.element(this.createElement(tag)).set(props);
},
newTextNode: function(text){
return this.createTextNode(text);
},
getDocument: function(){
return this;
},
getWindow: function(){
this.window;
}
So I want to change the 'this' ref in the library, set a new context
if you will. So not THIS window object, but THAT window object.
This is from the base event constructor:
Syntax:
new Event([event[, win]]);
Arguments:
event - (event) An HTMLEvent Object.
win - (window, optional: defaults to window) The context of the event.
I want to be able to set a context for all actions to something
different, jQuery does this with a context option in its $ selector
function. I have hacked the core lib the to do what I want but i
would rather not, here is the same lines of code modified:
newElement: function(tag, props){
if (Browser.Engine.trident && props){
['name', 'type', 'checked'].each(function(attribute){
if (!props[attribute]) return;
tag += ' ' + attribute + '="' +
props[attribute] + '"';
if (attribute != 'checked') delete
props[attribute];
});
tag = '<' + tag + '>';
}
if(typeof tab == 'undefined'){return
$.element(this.createElement
(tag)).set(props);} else{ return $(tab.document.createElement(tag)).set
(props); }
},
newTextNode: function(text){
return this.createTextNode(text);
},
getDocument: function(){
return (typeof tab == 'undefined') ? this : tab.document; //
this
line used to be: return this
},
getWindow: function(){
return (typeof tab == 'undefined') ? this.window : tab.window;
//
this line used to be: return this.window
}
See all those tab. references, that is what I am doing to give these
functions new contexts in which to operate on. I am doing so because
I am writing a compatibility layer for working fluidly across FF tab
documents from a central XUL overlay via FF addon. You see the this
natively referred to in Mootools kept referencing the wrond window,
the XUL overlay window of the FF addon. I had to make sure it always
thought in terms of the tab I was intending to deal with, thus the
mods.
What I needed was a way to change the refs globally in the Mootools
object, so that the context can be changed fluidly. Any thoughts? I
am submitting this framework to Rey Bango and it is going to be a
tutorial thing on MDC, it would benefit us all if there was a better
way to change contexts than through lib modifications.
- Daniel