Bug Tracker

Opened 9 years ago

Last modified 8 years ago

#8405 closed enhancement

Enhance jQuery.sub to work in its own window/document — at Version 5

Reported by: musicisair Owned by:
Priority: low Milestone: 1.7
Component: core Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by Rick Waldron)

It would be nice if we could pass a DOM Window or Document to jQuery.sub in order to force selector context to any document we want WITHOUT having to $(document).find("selector") or $("selector", document)

Basically, we could then copy jQuery into an iframe or window (window.open) and execute it in its own context without the cost of loading and initializing.

In certain scenarios I could see how support tests may need to be re-run if the document-mode isn't the same.

---

On a side note: any hints on to implementing this right now as a plugin would be much appreciated.

Change History (5)

comment:1 Changed 9 years ago by musicisair

After looking at the source it looks like if we made the document a jQuery property instead of a private variable we could make jQuery document-aware relatively easily.

At the top of jquery we've got:

var document = window.document;

We can change that to:

jQuery.document = window.document;

then update all references to document to point jQuery.document instead and then add the following to jQuery.sub

    sub: function(document){
        /* ... */
        jQuerySubclass.document = window.document || jQuery.document;
        /* ... */
    };

There may be some issues with even binding and we may want to make window a jQuery property in order circumvent those issues also.

DaveMethvin pointed out that there may be some memory-leak issues when "remote-controlling" an iframe this way if the iframe is closed or navigated to another page.

Also, Sizzle will need to be updated to allow for setting the default document (context).

Last edited 9 years ago by musicisair (previous) (diff)

comment:2 Changed 9 years ago by dmethvin

Component: unfiledcore
Milestone: 1.next1.7
Priority: undecidedlow
Status: newopen

comment:3 Changed 9 years ago by john

Milestone: 1.71.next

Let's bring this up for discussion again for 1.7.

comment:4 Changed 9 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:5 Changed 9 years ago by Rick Waldron

Description: modified (diff)

+0, I would prefer to explore jaubourg's "newInstance" approach

Note: See TracTickets for help on using tickets.