Skip to content

Instantly share code, notes, and snippets.

@ghempton
Created March 11, 2012 21:36
Show Gist options
  • Save ghempton/2018290 to your computer and use it in GitHub Desktop.
Save ghempton/2018290 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 unless attr && (attr.name.indexOf('data-bindattr') || attr.name.indexOf('data-ember'))
$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
@bobjackman
Copy link

+1 Thank you for this! In the end it wasn't quite what I needed but it was instrumental in developing my solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment