Ticket #5880 (closed feature: duplicate)
Method to create a copy of jQuery
|Reported by:||shadedecho||Owned by:|
For those of us who work with including jQuery (along with a mashup/widget) into abritrary pages that we don't necessarily control, having "jQuery.noConflict()" is absolutely awesome. However, there's a use case that I've run into a few times now, which is, sometimes you might need to create a sandbox'd copy/clone of jQuery (for the purposes of adding in plugins for instance), that remains separate from the existing copy of jQuery that might be on the page.
Apparently some have explored ways to create a clone of the jQuery object, but what it comes down to is that there are some private pieces of data which are held up in the closure that the jQuery function creates, which cannot be separated as it is currently. So, it's not possible to create a totally (only mostly) separate copy of jQuery from an existing instance.
The trick I'm currently using, which is a little brittle and ugly, is to search the DOM looking for the script tag that loaded jQuery (only if it matches a regex with "jquery.js" or some variation thereof in it)... if the script is found, then a new script element is created with the same source URL, which should re-request jQuery (from the cache hopefully!) and then re-execute jQuery.
Then, a jQuery.noConflict(true) call will roll back to the original copy of jQuery and the new sandboxed copy can be saved and used.
The worst part about this hack is the brittleness of having to assume that jQuery comes in its own script file, and that the name is something predictable. Secondarily, having to modify the DOM (even just a script tag) is less than desirable. But it seems to work in most cases.
So, my request is, that we get a new core function, like $.clone (not $.fn.clone), that will in some way re-execute jQuery and create a new closure and new object instance, returning that sandbox'd copy for later use.
- Keywords needsreview added
- Status changed from new to open
- Summary changed from a $/jQuery core "clone" function to Method to create a copy of jQuery
- Milestone 1.4.1 deleted
- Status changed from open to closed
- Priority changed from minor to low
- Version changed from 1.4 to 1.4.4
- Milestone set to 1.5
- Keywords needsreview removed
- Resolution set to duplicate