Skip to content

Instantly share code, notes, and snippets.

@rodneyrehm
Created May 9, 2012 15:44
Show Gist options
  • Select an option

  • Save rodneyrehm/2645722 to your computer and use it in GitHub Desktop.

Select an option

Save rodneyrehm/2645722 to your computer and use it in GitHub Desktop.
jQuery.phase (to improve performance of heavy dom-manipulation)
/*
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