-
-
Save panayi/3347755 to your computer and use it in GitHub Desktop.
Small jQuery extension to clone elements without Ember/Metamorph metadata
This file contains hidden or 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 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