#3803 closed feature (patcheswelcome)
Feature request: cloning widgets
Reported by: | d.wachss | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | ui.widget | Version: | 1.6rc4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Per this thread http://groups.google.com/group/jquery-ui/browse_thread/thread/a1cbbd784aa0dae2, clone() does not clone the widgets associated with an element. One way to do this is with a custom event:
$.fn.cloneTheWidgets = function (){ return this.clone() // don't clone events .each(function(){ var handlers = $.data(this,'events')[ 'cloneTheWidgets']; if (handlers) for (var handler in handlers) // manually trigger the clone event handlers handlers[handler].apply(this); }); };
and in the widget init function:
init: function(){ var self = this; self.element.bind('cloneTheWidgets', function() { $(this)[self.widgetName](self.options); }); ...the rest of your init }
or override the native clone() to do this with some appropriate argument.
Change History (8)
comment:1 Changed 14 years ago by
Milestone: | TBD → 1.next |
---|
comment:2 Changed 13 years ago by
comment:3 follow-up: 5 Changed 13 years ago by
Do we actually want to support cloning widgets? Still seems like a rather niche usecase.
comment:4 Changed 13 years ago by
Now it seems pretty inconsistent, as clone will result in cloning all the helper elements created by the widget, so you end up with a code, where widget does not work, but you can not reinitialize it again, as the original DOM has been cloned already in modified state.
comment:5 Changed 13 years ago by
Component: | ui.core → ui.widget |
---|---|
Milestone: | 1.next → TBD |
Replying to joern.zaefferer:
Do we actually want to support cloning widgets? Still seems like a rather niche usecase.
We haven't made a decision, and likely won't make a decision for a while. Until we do, we're leaving the ticket open. If anyone has ideas for how to make this actually work, we'd be interested in hearing them. Unfortunately this is probably way too widget-specific to be generalized.
comment:6 Changed 11 years ago by
Status: | new → open |
---|
comment:7 Changed 11 years ago by
Resolution: | → patcheswelcome |
---|---|
Status: | open → closed |
If anyone has an idea for how to accomplish this, please discuss it with the team. But for now it seems like there would need to be too much widget-specific code to handle a uncommon case.
i would suggest this behavior for 'clone':
clone(true) - automatically reinitialize the widget in the cloned DOM clone() - cleanup the widget in the cloned DOM