-
-
Save buzzedword/627346 to your computer and use it in GitHub Desktop.
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
jQuery.fn.innerWrap = function() { | |
var a, args = arguments; | |
return this.each(function() { | |
if (!a) | |
a = jQuery.clean(args, this.ownerDocument); | |
// Clone the structure that we're using to wrap | |
var b = a[0].cloneNode(true), | |
c = b; | |
// Find the deepest point in the wrap structure | |
while ( b.firstChild ) | |
b = b.firstChild; | |
// append the child nodes to the wrapper | |
jQuery.each(this.childNodes, function(i, node) { | |
b.appendChild(node); | |
}); | |
jQuery(this) | |
// clear the element | |
.empty() | |
// add the new wrapper with the previous child nodes appended | |
.append(c); | |
}); | |
}; | |
// Above code is located at http://codesnippets.joyent.com/posts/show/1736 | |
jQuery.fn.aspHide = function() { | |
$(this).each(function() { | |
if ($('.safety').length == 0){ | |
$(this).innerWrap('<div class="safety"></div>'); | |
} | |
$(this).data('height', $(this).height()).data('margin', {top: $(this).css('margin-top'), bottom: $(this).css('margin-bottom')}); | |
var elem = $(this).find('.safety'); | |
$(this, elem).height('0'); | |
$(this).css('margin-top', '0').css('margin-bottom', '0'); | |
elem.css('visibility', 'hidden'); | |
}); | |
}; | |
jQuery.fn.aspShow = function() { | |
$(this).each(function() { | |
var elem = $(this).find('.safety'); | |
elem.height($(this).data('height')); | |
elem.css('margin-top',$(this).data('margin').top).css('margin-bottom',$(this).data('margin').bottom); | |
elem.css('visibility', 'visible'); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment