Opened 14 years ago

Closed 11 years ago

Last modified 11 years ago

#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 Jörn Zaefferer

Milestone: TBD1.next

comment:2 Changed 13 years ago by nxtwrld

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

comment:3 Changed 13 years ago by Jörn Zaefferer

Do we actually want to support cloning widgets? Still seems like a rather niche usecase.

comment:4 Changed 13 years ago by nxtwrld

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 in reply to:  3 Changed 13 years ago by Scott González

Component: ui.coreui.widget
Milestone: 1.nextTBD

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 Jörn Zaefferer

Status: newopen

comment:7 Changed 11 years ago by Scott González

Resolution: patcheswelcome
Status: openclosed

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.

comment:8 Changed 11 years ago by Scott González

Milestone: TBD

Milestone TBD deleted

Note: See TracTickets for help on using tickets.