1/*global jQuery */ 2/*! 3* FlexVerticalCenter.js 1.0 4* 5* Copyright 2011, Paul Sprangers http://paulsprangers.com 6* Released under the WTFPL license 7* http://sam.zoy.org/wtfpl/ 8* 9* Date: Fri Oct 28 19:12:00 2011 +0100 10*/ 11(function( $ ){ 12 13 $.fn.flexVerticalCenter = function( options ) { 14 var settings = $.extend({ 15 cssAttribute: 'margin-top', // the attribute to apply the calculated value to 16 verticalOffset: 0, // the number of pixels to offset the vertical alignment by 17 parentSelector: null, // a selector representing the parent to vertically center this element within 18 debounceTimeout: 25, // a default debounce timeout in milliseconds 19 deferTilWindowLoad: false // if true, nothing will take effect until the $(window).load event 20 }, options || {}); 21 22 return this.each(function(){ 23 var $this = $(this); // store the object 24 var debounce; 25 26 // recalculate the distance to the top of the element to keep it centered 27 var resizer = function () { 28 29 var parentHeight = (settings.parentSelector && $this.parents(settings.parentSelector).length) ? 30 $this.parents(settings.parentSelector).first().height() : $this.parent().height(); 31 32 $this.css( 33 settings.cssAttribute, ( ( ( parentHeight - $this.height() ) / 2 ) + parseInt(settings.verticalOffset) ) 34 ); 35 if (settings.complete !== undefined) { 36 settings.complete(); 37 } 38 }; 39 40 // Call on resize. Opera debounces their resize by default. 41 $(window).resize(function () { 42 clearTimeout(debounce); 43 debounce = setTimeout(resizer, settings.debounceTimeout); 44 }); 45 46 if (!settings.deferTilWindowLoad) { 47 // call it once, immediately. 48 resizer(); 49 } 50 51 // Call again to set after window (frames, images, etc) loads. 52 $(window).on('load', function () { 53 resizer(); 54 }); 55 56 }); 57 58 }; 59 60})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.