Skip to content

Instantly share code, notes, and snippets.

@panayi
Forked from ghempton/safeClone.jquery.js.coffee
Created August 14, 2012 09:20
Show Gist options
  • Select an option

  • Save panayi/3347755 to your computer and use it in GitHub Desktop.

Select an option

Save panayi/3347755 to your computer and use it in GitHub Desktop.
Small jQuery extension to clone elements without Ember/Metamorph metadata
# Small extension to create a clone of the element without
# metamorph binding tags and ember metadata
$.fn.extend
safeClone: ->
clone = $(@).clone()
# remove content bindings
clone.find('script[id^=metamorph]').remove()
# remove attr bindings
clone.find('*').each ->
$this = $(@)
$.each $this[0].attributes, (index, attr) ->
return if attr.name.indexOf('data-bindattr') == -1
$this.removeAttr(attr.name)
# remove ember IDs
clone.removeAttr('id') if clone.attr('id') && clone.attr('id').indexOf('ember') != -1
clone.find('[id^=ember]').removeAttr('id')
clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment