Created
March 11, 2012 21:36
-
-
Save ghempton/2018290 to your computer and use it in GitHub Desktop.
Small jQuery extension to clone elements without Ember/Metamorph metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1 Thank you for this! In the end it wasn't quite what I needed but it was instrumental in developing my solution.