Created
May 9, 2012 15:44
-
-
Save rodneyrehm/2645722 to your computer and use it in GitHub Desktop.
jQuery.phase (to improve performance of heavy dom-manipulation)
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
| /* | |
| The point of this uitlity is to detach nodes while preserving their original | |
| position (which $.fn.detach() doesn't) so they can be re-injected later on. | |
| naming stuff is a bitch and "phase" ("shift phase in/out") | |
| is the "best" (science-finctiony) word I could come up with. | |
| got a better Idea? tell me on twitter: @rodneyrehm | |
| ideas so far: | |
| dompulate, teleport, phase, manipulateOffscreen | |
| hyperspace (slip stream?), translocate | |
| displace | |
| backstage, ghostify | |
| oppend, as in operate or offend, and you can prepend anything to "pend" | |
| transpose | |
| */ | |
| $.fn.phase = function() { | |
| return this.each(function() { | |
| var $this = $(this), | |
| placeholder = $this.data('redetach'); | |
| if (placeholder) { | |
| placeholder.parentNode.replaceChild(this, placeholder); | |
| $this.removeData('redetach'); | |
| } else { | |
| placeholder = document.createTextNode(''), | |
| this.parentNode.replaceChild(placeholder, this); | |
| $this.data('redetach', placeholder); | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment