Oh it is working, I can do anything I want to these tabs now (right
now busy pimping out eBay to suck less).  That tab. is a this
reference of the FF tab's class I use to extend it and thus resolves
those functions to the correct tab's document, or window, or whatever,
just wish I didn't have to.  here is the class that sets the tab:

var tabExtender = new Class({
        Binds: ['createTab', 'addTabEvents'],
    Implements: [Events, Chain, Options],
    initialize: function(options) {
                this.setOptions(options);
                tab = this;
                this.url = (options.url) ? options.url : null;
                this.selectTab = (options.selectTab) ? options.selectTab : null;

                this.browser;
                this.window;
                this.document;

                this.createTab();
    },

        createTab: function(){
                var browserXulTab = (this.selectTab) ? gBrowser.selectedTab =
gBrowser.addTab(tab.url) : gBrowser.addTab(tab.url);
                this.browser = gBrowser.getBrowserForTab(browserXulTab);
                this.addTabEvents();
        },

        addTabEvents: function(){
                this.browser.open = this.options.open;
                this.browser.load = this.options.load;
                this.browser.select = this.options.select;
                this.browser.move = this.options.move;
                this.browser.close = this.options.close;
        }

});

then the created tab events get captured and evaluated like this:

                xulTabContainer.addEventListener('TabOpen', function (event){
                        var browserObj = event.target.linkedBrowser;
                        gMonitor.genericEventFire(browserObj, 
['chromeOpen','tabOpen'],
'open');
                        gMonitor.genericEventFire(browserObj, 
['chromeLoad','tabLoad'],
'load');
                }, true);

                xulTabContainer.addEventListener('TabSelect', function (event){
                        var browserObj = event.target.linkedBrowser;
                        gMonitor.genericEventFire(browserObj, 
['chromeSelect','tabSelect'],
'select');
                }, true);

                xulTabContainer.addEventListener('TabMove', function (event){
                        var browserObj = event.target.linkedBrowser;
                        gMonitor.genericEventFire(browserObj, 
['chromeMove','tabMove'],
'move');
                }, true);

                xulTabContainer.addEventListener('TabClose', function (event){
                        var browserObj = event.target.linkedBrowser;
                        gMonitor.genericEventFire(browserObj, 
['chromeClose','tabClose'],
'close');
                }, true);
    },

        genericEventFire: function(browserObj, globalFunctions,
singleTabFunction){

                if(singleTabFunction == 'load')
                {
                        browserObj.addEventListener('DOMContentLoaded',
                        function(event){
                                        if (event.originalTarget instanceof 
HTMLDocument) {
                                                if 
(event.originalTarget.defaultView.frameElement){ return; }
                                                else{

                                                        
globalFunctions.each(function(e, i){
                                                                if(gMonitor[e] 
!= null){ gMonitor[e](event.originalTarget); }
                                                        });
                                                        
if(tab.browser[singleTabFunction] != null){ tab.browser
[singleTabFunction](event.originalTarget); }

                                                }
                                        }
                        }, true);
                }
                else{
                        globalFunctions.each(function(e, i){
                                if(gMonitor[e] != null){ 
gMonitor[e](browserObj); }
                        });
                        if(browserObj[singleTabFunction] != null){ browserObj
[singleTabFunction](browserObj); }
                }

        }

});

It all works fine, just clunky since my arch rival and friend here at
work is doing the jQuery version, he just goes $('.some-selector',
tab_context_here).blahblah

His isn't working as well on XUL elements and Mootools is so our
trouble are from opposite sides ironically.  jQuery's context was not
intended for the reverse, I'm sure I am being ultra confusing here but
I assure you this works, just wish there was a cleaner way.

- Daniel

On Apr 17, 10:24 am, nutron <[email protected]> wrote:
> I hate to say this but I think your efforts here are a bit misguided. "this"
> does not reference the window everywhere. It references whatever the method
> belongs to. As in my previous example, "this" points at the array inside of
> [].each.
>
> If you wanted to redefine how the few methods that reference the window
> work, you should not hack the framework but instead overwrite those methods
> within your own environment. Just redefine them. Still, I have a feeling
> this won't really work...
>
> On Fri, Apr 17, 2009 at 1:18 PM, csuwldcat (via Nabble) <
> [email protected]<ml-user%[email protected]>
>
>
>
> > wrote:
>
> > What I am doing is like a Super Greasemonkey framework that cuts
> > through all of XUL's bullshit xpcnativewrappers and garbage and let's
> > people script in addons the exact same way they do a normal web page.
> > Any ideas/help are really appreciated.
>
> > On Apr 17, 10:11 am, csuwldcat 
> > <daniel...@...<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2651907&i=0>>
> > wrote:
> > > 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
>
> > ------------------------------
> >  View message @
> >http://n2.nabble.com/-Moo--How-do-I-change-the-this-keyword-ref-in-th...
> > To start a new topic under MooTools Users, email
> > [email protected]<ml-node%[email protected]>
> > To unsubscribe from MooTools Users, click here< (link removed) >.
>
> -----
> The MooTools Tutorial:  http://www.mootorial.comwww.mootorial.com
> Clientcide:  http://www.clientcide.comwww.clientcide.com
> --
> View this message in 
> context:http://n2.nabble.com/-Moo--How-do-I-change-the-this-keyword-ref-in-th...
> Sent from the MooTools Users mailing list archive at Nabble.com.

Reply via email to