#8405 closed enhancement (patchwelcome)
Enhance jQuery.sub to work in its own window/document
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 )
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 (12)
comment:2 Changed 12 years ago by
Component: | unfiled → core |
---|---|
Milestone: | 1.next → 1.7 |
Priority: | undecided → low |
Status: | new → open |
comment:3 Changed 12 years ago by
Milestone: | 1.7 → 1.next |
---|
Let's bring this up for discussion again for 1.7.
comment:5 Changed 12 years ago by
Description: | modified (diff) |
---|
+0, I would prefer to explore jaubourg's "newInstance" approach
comment:6 Changed 12 years ago by
-1, sub is not the right means to do this. Internal caches will be shared and we know where this would lead.
comment:8 Changed 12 years ago by
Description: | modified (diff) |
---|
+0, Not sure how this will help, not sure when .sub is useful.
comment:9 Changed 12 years ago by
Description: | modified (diff) |
---|
+0, I think it's probably ok if we don't push for this.
comment:10 Changed 12 years ago by
Oh well, it looks like this one isn't going to make it.
I'll make one last stand for it, though...
I suggested using $.sub, but it doesn't really matter to me. I'd just like a document-aware jQuery. Here is my use case:
I've got a in-browser "intranet" browser. This HTML5+CSS3+jQuery browser runs fullscreen in webkit/firefox and it has all of your normal browser bells and whistles - like tabs (via iframes), an address bar, back/forward/refresh buttons, etc. All of the intranet web-pages "initialize" jQuery as follows:
if(!parent !parent.jQuery){ document.write("<script src='jquery.js'></script>"); </script should be escaped in the real world.
} else{
$ = jQuery = parent.jQuery.sub();
}
...which is pretty useful little trick. The draw back is that the intranet iframes can modify the parent
's jQuery object...which could potentially break our application. This is mostly fixed by $.sub
(though I imagine different document modes could cause issues with $.support
, but I'm not sure). The only other obvious issue is that all jQuery selectors need to be aware of the iframe's document
, which is doable, sure...but pretty annoying.
So yes, it's an edge-case...but also a really cool way to re-use a script resource without have to re-parse and re-execute it.
comment:11 Changed 12 years ago by
Description: | modified (diff) |
---|
+1, It would be really nice if there was a generic way to always make jQuery calls relative to another document, instead of having to flood context arguments
comment:12 Changed 12 years ago by
Keywords: | 1.7-discuss removed |
---|---|
Milestone: | 1.next → 1.7 |
Resolution: | → patchwelcome |
Status: | open → closed |
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:
We can change that to:
then update all references to
document
to pointjQuery.document
instead and then add the following tojQuery.sub
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).