Skip to content

Instantly share code, notes, and snippets.

@distracteddev
Created April 29, 2012 18:54
Show Gist options
  • Save distracteddev/2552641 to your computer and use it in GitHub Desktop.
Save distracteddev/2552641 to your computer and use it in GitHub Desktop.
SafeClone to for jQuery UI so that it plays nice with Ember.js
$.fn.extend({
safeClone: function() {
var clone;
clone = $(this).clone();
clone.find('script[id^=metamorph]').remove();
clone.find('*').each(function() {
var $this;
$this = $(this);
return $.each($this[0].attributes, function(index, attr) {
if (attr.name.indexOf('data-bindattr') === -1) {
return;
}
return $this.removeAttr(attr.name);
});
});
if (clone.attr('id') && clone.attr('id').indexOf('ember') !== -1) {
clone.removeAttr('id');
}
clone.find('[id^=ember]').removeAttr('id');
return clone;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment