From ca0d4fc1a65d3514a53845b0cf2a3e4c825c09c9 Mon Sep 17 00:00:00 2001 From: Burak Barakaci Date: Sat, 13 Jun 2015 23:33:47 +0200 Subject: [PATCH] Version 0.4.0 --- dist/fixto.js | 123 ++++++++++++++++++++++++---------------------- dist/fixto.min.js | 4 +- 2 files changed, 66 insertions(+), 61 deletions(-) diff --git a/dist/fixto.js b/dist/fixto.js index eff02c4..579e72b 100644 --- a/dist/fixto.js +++ b/dist/fixto.js @@ -1,11 +1,11 @@ -/*! fixto - v0.3.1 - 2014-08-07 +/*! fixto - v0.4.0 - 2015-06-08 * http://github.com/bbarakaci/fixto/*/ var fixto = (function ($, window, document) { - // Start Computed Style. Please do not modify this module here. Modify it from its own repo. See address below. - + // Start Computed Style. Please do not modify this module here. Modify it from its own repo. See address below. + /*! Computed Style - v0.1.0 - 2012-07-19 * https://github.com/bbarakaci/computed-style * Copyright (c) 2012 Burak Barakaci; Licensed MIT */ @@ -36,7 +36,7 @@ var fixto = (function ($, window, document) { }()); - // End Computed Style. Modify whatever you want to. + // End Computed Style. Modify whatever you want to. var mimicNode = (function(){ /* @@ -65,7 +65,7 @@ var fixto = (function ($, window, document) { rst.width = this._width(); rst.height = this._height(); - // Adobt margins + // Adopt margins rst.marginTop = styles.marginTop; rst.marginBottom = styles.marginBottom; rst.marginLeft = styles.marginLeft; @@ -104,10 +104,10 @@ var fixto = (function ($, window, document) { _heightOffset : function(){ return this.element.offsetHeight + 'px'; }, - + destroy: function () { $(this.replacer).remove(); - + // set properties to null to break references for (var prop in this) { if (this.hasOwnProperty(prop)) { @@ -128,7 +128,7 @@ var fixto = (function ($, window, document) { computedStyle:computedStyle }; }()); - + // Class handles vendor prefixes function Prefix() { // Cached vendor will be stored when it is detected @@ -136,16 +136,16 @@ var fixto = (function ($, window, document) { //this._dummy = document.createElement('div'); } - + Prefix.prototype = { - + _vendors: { webkit: { cssPrefix: '-webkit-', jsPrefix: 'Webkit'}, moz: { cssPrefix: '-moz-', jsPrefix: 'Moz'}, ms: { cssPrefix: '-ms-', jsPrefix: 'ms'}, opera: { cssPrefix: '-o-', jsPrefix: 'O'} }, - + _prefixJsProperty: function(vendor, prop) { return vendor.jsPrefix + prop[0].toUpperCase() + prop.substr(1); }, @@ -162,7 +162,7 @@ var fixto = (function ($, window, document) { } catch(er) { return false; - } + } }, /** @@ -220,7 +220,7 @@ var fixto = (function ($, window, document) { // Get supported property name var jsProperty = this.getJsProperty(prop); - // Try unprefixed value + // Try unprefixed value if(this._valueSupported(jsProperty, value, dummy)) { return value; } @@ -248,12 +248,12 @@ var fixto = (function ($, window, document) { return null; } }; - + var prefix = new Prefix(); // We will need this frequently. Lets have it as a global until we encapsulate properly. var transformJsProperty = prefix.getJsProperty('transform'); - + // Will hold if browser creates a positioning context for fixed elements. var fixedPositioningContext; @@ -288,11 +288,11 @@ var fixto = (function ($, window, document) { // It will return null if position fixed is not supported var fixedPositionValue = prefix.getCssValue('position', 'fixed'); - + // Dirty business var ie = navigator.appName === 'Microsoft Internet Explorer'; var ieversion; - + if(ie){ ieversion = parseFloat(navigator.appVersion.split("MSIE")[1]); } @@ -330,16 +330,16 @@ var fixto = (function ($, window, document) { } return top; }, - - // Public method to stop the behaviour of this instance. + + // Public method to stop the behaviour of this instance. stop: function () { - this._stop(); + this._stop(); this._running = false; }, // Public method starts the behaviour of this instance. start: function () { - + // Start only if it is not running not to attach event listeners multiple times. if(!this._running) { this._start(); @@ -352,10 +352,10 @@ var fixto = (function ($, window, document) { this.stop(); this._destroy(); - + // Remove jquery data from the element this._$child.removeData('fixto-instance'); - + // set properties to null to break references for (var prop in this) { if (this.hasOwnProperty(prop)) { @@ -405,40 +405,45 @@ var fixto = (function ($, window, document) { this._ghostNode = this._replacer.replacer; this._saveStyles(); - + this._saveViewportHeight(); - + // Create anonymous functions and keep references to register and unregister events. this._proxied_onscroll = this._bind(this._onscroll, this); this._proxied_onresize = this._bind(this._onresize, this); - + this.start(); } FixToContainer.prototype = new FixTo(); $.extend(FixToContainer.prototype, { - + // Returns an anonymous function that will call the given function in the given context _bind : function (fn, context) { return function () { return fn.call(context); }; }, - + // at ie8 maybe only in vm window resize event fires everytime an element is resized. _toresize : ieversion===8 ? document.documentElement : window, _onscroll: function _onscroll() { this._scrollTop = document.documentElement.scrollTop || document.body.scrollTop; - this._parentBottom = (this.parent.offsetHeight + this._fullOffset('offsetTop', this.parent)) - computedStyle.getFloat(this.parent, 'paddingBottom'); + this._parentBottom = (this.parent.offsetHeight + this._fullOffset('offsetTop', this.parent)); + + if (this.options.mindBottomPadding !== false) { + this._parentBottom -= computedStyle.getFloat(this.parent, 'paddingBottom'); + } + if (!this.fixed) { var childStyles = computedStyle.getAll(this.child); - + if ( - this._scrollTop < this._parentBottom && - this._scrollTop > (this._fullOffset('offsetTop', this.child) - this.options.top - this._mindtop()) && + this._scrollTop < this._parentBottom && + this._scrollTop > (this._fullOffset('offsetTop', this.child) - this.options.top - this._mindtop()) && this._viewportHeight > (this.child.offsetHeight + computedStyle.toFloat(childStyles.marginTop) + computedStyle.toFloat(childStyles.marginBottom)) ) { @@ -460,7 +465,7 @@ var fixto = (function ($, window, document) { var diff = 0; var childStyles = computedStyle.getAll(this.child); var context = null; - + if(fixedPositioningContext) { // Get positioning context. context = this._getContext(); @@ -469,31 +474,31 @@ var fixto = (function ($, window, document) { top = Math.abs(context.getBoundingClientRect().top); } } - + diff = (this._parentBottom - this._scrollTop) - (this.child.offsetHeight + computedStyle.toFloat(childStyles.marginBottom) + mindTop + this.options.top); - + if(diff>0) { diff = 0; } - + this.child.style.top = (diff + mindTop + top + this.options.top) - computedStyle.toFloat(childStyles.marginTop) + 'px'; }, - + // Calculate cumulative offset of the element. // Optionally according to context _fullOffset: function _fullOffset(offsetName, elm, context) { var offset = elm[offsetName]; var offsetParent = elm.offsetParent; - + // Add offset of the ascendent tree until we reach to the document root or to the given context while (offsetParent !== null && offsetParent !== context) { offset = offset + offsetParent[offsetName]; offsetParent = offsetParent.offsetParent; } - + return offset; }, - + // Get positioning context of the element. // We know that the closest parent that a transform rule applied will create a positioning context. _getContext: function() { @@ -501,14 +506,14 @@ var fixto = (function ($, window, document) { var element = this.child; var context = null; var styles; - + // Climb up the treee until reaching the context while(!context) { parent = element.parentNode; if(parent === document.documentElement) { return null; } - + styles = computedStyle.getAll(parent); // Element has a transform rule if(styles[transformJsProperty] !== 'none') { @@ -516,7 +521,7 @@ var fixto = (function ($, window, document) { break; } element = parent; - } + } return context; }, @@ -526,15 +531,15 @@ var fixto = (function ($, window, document) { var childStyles = computedStyle.getAll(child); var left = child.getBoundingClientRect().left; var width = childStyles.width; - + this._saveStyles(); - + if(document.documentElement.currentStyle){ // Function for ie<9. When hasLayout is not triggered in ie7, he will report currentStyle as auto, clientWidth as 0. Thus using offsetWidth. - // Opera also falls here + // Opera also falls here width = (child.offsetWidth) - (computedStyle.toFloat(childStyles.paddingLeft) + computedStyle.toFloat(childStyles.paddingRight) + computedStyle.toFloat(childStyles.borderLeftWidth) + computedStyle.toFloat(childStyles.borderRightWidth)) + 'px'; } - + // Ie still fixes the container according to the viewport. if(fixedPositioningContext) { var context = this._getContext(); @@ -543,9 +548,9 @@ var fixto = (function ($, window, document) { left = child.getBoundingClientRect().left - context.getBoundingClientRect().left; } } - + this._replacer.replace(); - + childStyle.left = (left - computedStyle.toFloat(childStyles.marginLeft)) + 'px'; childStyle.width = width; @@ -577,7 +582,7 @@ var fixto = (function ($, window, document) { _onresize: function () { this.refresh(); }, - + _saveViewportHeight: function () { // ie8 doesn't support innerHeight this._viewportHeight = window.innerHeight || document.documentElement.clientHeight; @@ -594,7 +599,7 @@ var fixto = (function ($, window, document) { _start: function() { // Trigger onscroll to have the effect immediately. this._onscroll(); - + // Attach event listeners $(window).bind('scroll', this._proxied_onscroll); $(this._toresize).bind('resize', this._proxied_onresize); @@ -641,7 +646,7 @@ var fixto = (function ($, window, document) { } }); - + var fixTo = function fixTo(childElement, parentElement, options) { if((nativeStickyValue && !options) || (nativeStickyValue && options && options.useNativeSticky !== false)) { @@ -666,7 +671,7 @@ var fixto = (function ($, window, document) { /* No support for ie lt 8 */ - + if(ieversion<8){ fixTo = function(){ return 'not supported'; @@ -675,22 +680,22 @@ var fixto = (function ($, window, document) { // Let it be a jQuery Plugin $.fn.fixTo = function (targetSelector, options) { - + var $targets = $(targetSelector); - + var i = 0; return this.each(function () { - + // Check the data of the element. var instance = $(this).data('fixto-instance'); - + // If the element is not bound to an instance, create the instance and save it to elements data. if(!instance) { $(this).data('fixto-instance', fixTo(this, $targets[i], options)); } else { - // If we already have the instance here, expect that targetSelector parameter will be a string - // equal to a public methods name. Run the method on the instance without checking if + // If we already have the instance here, expect that targetSelector parameter will be a string + // equal to a public methods name. Run the method on the instance without checking if // it exists or it is a public method or not. Cause nasty errors when necessary. var method = targetSelector; instance[method].call(instance, options); diff --git a/dist/fixto.min.js b/dist/fixto.min.js index a970ee4..435aba8 100644 --- a/dist/fixto.min.js +++ b/dist/fixto.min.js @@ -1,3 +1,3 @@ -/*! fixto - v0.3.1 - 2014-08-07 +/*! fixto - v0.4.0 - 2015-06-08 * http://github.com/bbarakaci/fixto/*/ -var fixto=function(a,b,c){function f(){this._vendor=null}function j(){var a=!1,b=c.createElement("div"),d=c.createElement("div");b.appendChild(d),b.style[h]="translate(0)",b.style.marginTop="10px",b.style.visibility="hidden",d.style.position="fixed",d.style.top=0,c.body.appendChild(b);var e=d.getBoundingClientRect();return e.top>0&&(a=!0),c.body.removeChild(b),a}function o(b,c,d){this.child=b,this._$child=a(b),this.parent=c,this.options={className:"fixto-fixed",top:0},this._setOptions(d)}function p(a,b,c){o.call(this,a,b,c),this._replacer=new e.MimicNode(a),this._ghostNode=this._replacer.replacer,this._saveStyles(),this._saveViewportHeight(),this._proxied_onscroll=this._bind(this._onscroll,this),this._proxied_onresize=this._bind(this._onresize,this),this.start()}function q(a,b,c){o.call(this,a,b,c),this.start()}var d=function(){var a={getAll:function(a){return c.defaultView.getComputedStyle(a)},get:function(a,b){return this.getAll(a)[b]},toFloat:function(a){return parseFloat(a,10)||0},getFloat:function(a,b){return this.toFloat(this.get(a,b))},_getAllCurrentStyle:function(a){return a.currentStyle}};return c.documentElement.currentStyle&&(a.getAll=a._getAllCurrentStyle),a}(),e=function(){function b(a){this.element=a,this.replacer=c.createElement("div"),this.replacer.style.visibility="hidden",this.hide(),a.parentNode.insertBefore(this.replacer,a)}b.prototype={replace:function(){var a=this.replacer.style,b=d.getAll(this.element);a.width=this._width(),a.height=this._height(),a.marginTop=b.marginTop,a.marginBottom=b.marginBottom,a.marginLeft=b.marginLeft,a.marginRight=b.marginRight,a.cssFloat=b.cssFloat,a.styleFloat=b.styleFloat,a.position=b.position,a.top=b.top,a.right=b.right,a.bottom=b.bottom,a.left=b.left,a.display=b.display},hide:function(){this.replacer.style.display="none"},_width:function(){return this.element.getBoundingClientRect().width+"px"},_widthOffset:function(){return this.element.offsetWidth+"px"},_height:function(){return this.element.getBoundingClientRect().height+"px"},_heightOffset:function(){return this.element.offsetHeight+"px"},destroy:function(){a(this.replacer).remove();for(var b in this)this.hasOwnProperty(b)&&(this[b]=null)}};var e=c.documentElement.getBoundingClientRect();return e.width||(b.prototype._width=b.prototype._widthOffset,b.prototype._height=b.prototype._heightOffset),{MimicNode:b,computedStyle:d}}();f.prototype={_vendors:{webkit:{cssPrefix:"-webkit-",jsPrefix:"Webkit"},moz:{cssPrefix:"-moz-",jsPrefix:"Moz"},ms:{cssPrefix:"-ms-",jsPrefix:"ms"},opera:{cssPrefix:"-o-",jsPrefix:"O"}},_prefixJsProperty:function(a,b){return a.jsPrefix+b[0].toUpperCase()+b.substr(1)},_prefixValue:function(a,b){return a.cssPrefix+b},_valueSupported:function(a,b,c){try{return c.style[a]=b,c.style[a]===b}catch(d){return!1}},propertySupported:function(a){return c.documentElement.style[a]!==undefined},getJsProperty:function(a){if(this.propertySupported(a))return a;if(this._vendor)return this._prefixJsProperty(this._vendor,a);var b;for(var c in this._vendors){b=this._prefixJsProperty(this._vendors[c],a);if(this.propertySupported(b))return this._vendor=this._vendors[c],b}return null},getCssValue:function(a,b){var d=c.createElement("div"),e=this.getJsProperty(a);if(this._valueSupported(e,b,d))return b;var f;if(this._vendor){f=this._prefixValue(this._vendor,b);if(this._valueSupported(e,f,d))return f}for(var g in this._vendors){f=this._prefixValue(this._vendors[g],b);if(this._valueSupported(e,f,d))return this._vendor=this._vendors[g],f}return null}};var g=new f,h=g.getJsProperty("transform"),i,k=g.getCssValue("position","sticky"),l=g.getCssValue("position","fixed"),m=navigator.appName==="Microsoft Internet Explorer",n;m&&(n=parseFloat(navigator.appVersion.split("MSIE")[1])),o.prototype={_mindtop:function(){var a=0;if(this._$mind){var b,c,e;for(var f=0,g=this._$mind.length;fthis._fullOffset("offsetTop",this.child)-this.options.top-this._mindtop()&&this._viewportHeight>this.child.offsetHeight+d.toFloat(a.marginTop)+d.toFloat(a.marginBottom)&&(this._fix(),this._adjust())}else{if(this._scrollTop>this._parentBottom||this._scrollTop0&&(c=0),this.child.style.top=c+b+a+this.options.top-d.toFloat(e.marginTop)+"px"},_fullOffset:function(a,b,c){var d=b[a],e=b.offsetParent;while(e!==null&&e!==c)d=d+e[a],e=e.offsetParent;return d},_getContext:function(){var a,b=this.child,e=null,f;while(!e){a=b.parentNode;if(a===c.documentElement)return null;f=d.getAll(a);if(f[h]!=="none"){e=a;break}b=a}return e},_fix:function(){var a=this.child,b=a.style,e=d.getAll(a),f=a.getBoundingClientRect().left,g=e.width;this._saveStyles(),c.documentElement.currentStyle&&(g=a.offsetWidth-(d.toFloat(e.paddingLeft)+d.toFloat(e.paddingRight)+d.toFloat(e.borderLeftWidth)+d.toFloat(e.borderRightWidth))+"px");if(i){var h=this._getContext();h&&(f=a.getBoundingClientRect().left-h.getBoundingClientRect().left)}this._replacer.replace(),b.left=f-d.toFloat(e.marginLeft)+"px",b.width=g,b.position="fixed",b.top=this._mindtop()+this.options.top-d.toFloat(e.marginTop)+"px",this._$child.addClass(this.options.className),this.fixed=!0},_unfix:function(){var a=this.child.style;this._replacer.hide(),a.position=this._childOriginalPosition,a.top=this._childOriginalTop,a.width=this._childOriginalWidth,a.left=this._childOriginalLeft,this._$child.removeClass(this.options.className),this.fixed=!1},_saveStyles:function(){var a=this.child.style;this._childOriginalPosition=a.position,this._childOriginalTop=a.top,this._childOriginalWidth=a.width,this._childOriginalLeft=a.left},_onresize:function(){this.refresh()},_saveViewportHeight:function(){this._viewportHeight=b.innerHeight||c.documentElement.clientHeight},_stop:function(){this._unfix(),a(b).unbind("scroll",this._proxied_onscroll),a(this._toresize).unbind("resize",this._proxied_onresize)},_start:function(){this._onscroll(),a(b).bind("scroll",this._proxied_onscroll),a(this._toresize).bind("resize",this._proxied_onresize)},_destroy:function(){this._replacer.destroy()},refresh:function(){this._saveViewportHeight(),this._unfix(),this._onscroll()}}),q.prototype=new o,a.extend(q.prototype,{_start:function(){var a=d.getAll(this.child);this._childOriginalPosition=a.position,this._childOriginalTop=a.top,this.child.style.position=k,this.refresh()},_stop:function(){this.child.style.position=this._childOriginalPosition,this.child.style.top=this._childOriginalTop},refresh:function(){this.child.style.top=this._mindtop()+this.options.top+"px"}});var r=function(a,b,c){return k&&!c||k&&c&&c.useNativeSticky!==!1?new q(a,b,c):l?(i===undefined&&(i=j()),new p(a,b,c)):"Neither fixed nor sticky positioning supported"};return n<8&&(r=function(){return"not supported"}),a.fn.fixTo=function(b,c){var d=a(b),e=0;return this.each(function(){var f=a(this).data("fixto-instance");if(!f)a(this).data("fixto-instance",r(this,d[e],c));else{var g=b;f[g].call(f,c)}e++})},{FixToContainer:p,fixTo:r,computedStyle:d,mimicNode:e}}(window.jQuery,window,document); \ No newline at end of file +var fixto=function(a,b,c){function f(){this._vendor=null}function j(){var a=!1,b=c.createElement("div"),d=c.createElement("div");b.appendChild(d),b.style[h]="translate(0)",b.style.marginTop="10px",b.style.visibility="hidden",d.style.position="fixed",d.style.top=0,c.body.appendChild(b);var e=d.getBoundingClientRect();return e.top>0&&(a=!0),c.body.removeChild(b),a}function o(b,c,d){this.child=b,this._$child=a(b),this.parent=c,this.options={className:"fixto-fixed",top:0},this._setOptions(d)}function p(a,b,c){o.call(this,a,b,c),this._replacer=new e.MimicNode(a),this._ghostNode=this._replacer.replacer,this._saveStyles(),this._saveViewportHeight(),this._proxied_onscroll=this._bind(this._onscroll,this),this._proxied_onresize=this._bind(this._onresize,this),this.start()}function q(a,b,c){o.call(this,a,b,c),this.start()}var d=function(){var a={getAll:function(a){return c.defaultView.getComputedStyle(a)},get:function(a,b){return this.getAll(a)[b]},toFloat:function(a){return parseFloat(a,10)||0},getFloat:function(a,b){return this.toFloat(this.get(a,b))},_getAllCurrentStyle:function(a){return a.currentStyle}};return c.documentElement.currentStyle&&(a.getAll=a._getAllCurrentStyle),a}(),e=function(){function b(a){this.element=a,this.replacer=c.createElement("div"),this.replacer.style.visibility="hidden",this.hide(),a.parentNode.insertBefore(this.replacer,a)}b.prototype={replace:function(){var a=this.replacer.style,b=d.getAll(this.element);a.width=this._width(),a.height=this._height(),a.marginTop=b.marginTop,a.marginBottom=b.marginBottom,a.marginLeft=b.marginLeft,a.marginRight=b.marginRight,a.cssFloat=b.cssFloat,a.styleFloat=b.styleFloat,a.position=b.position,a.top=b.top,a.right=b.right,a.bottom=b.bottom,a.left=b.left,a.display=b.display},hide:function(){this.replacer.style.display="none"},_width:function(){return this.element.getBoundingClientRect().width+"px"},_widthOffset:function(){return this.element.offsetWidth+"px"},_height:function(){return this.element.getBoundingClientRect().height+"px"},_heightOffset:function(){return this.element.offsetHeight+"px"},destroy:function(){a(this.replacer).remove();for(var b in this)this.hasOwnProperty(b)&&(this[b]=null)}};var e=c.documentElement.getBoundingClientRect();return e.width||(b.prototype._width=b.prototype._widthOffset,b.prototype._height=b.prototype._heightOffset),{MimicNode:b,computedStyle:d}}();f.prototype={_vendors:{webkit:{cssPrefix:"-webkit-",jsPrefix:"Webkit"},moz:{cssPrefix:"-moz-",jsPrefix:"Moz"},ms:{cssPrefix:"-ms-",jsPrefix:"ms"},opera:{cssPrefix:"-o-",jsPrefix:"O"}},_prefixJsProperty:function(a,b){return a.jsPrefix+b[0].toUpperCase()+b.substr(1)},_prefixValue:function(a,b){return a.cssPrefix+b},_valueSupported:function(a,b,c){try{return c.style[a]=b,c.style[a]===b}catch(d){return!1}},propertySupported:function(a){return c.documentElement.style[a]!==undefined},getJsProperty:function(a){if(this.propertySupported(a))return a;if(this._vendor)return this._prefixJsProperty(this._vendor,a);var b;for(var c in this._vendors){b=this._prefixJsProperty(this._vendors[c],a);if(this.propertySupported(b))return this._vendor=this._vendors[c],b}return null},getCssValue:function(a,b){var d=c.createElement("div"),e=this.getJsProperty(a);if(this._valueSupported(e,b,d))return b;var f;if(this._vendor){f=this._prefixValue(this._vendor,b);if(this._valueSupported(e,f,d))return f}for(var g in this._vendors){f=this._prefixValue(this._vendors[g],b);if(this._valueSupported(e,f,d))return this._vendor=this._vendors[g],f}return null}};var g=new f,h=g.getJsProperty("transform"),i,k=g.getCssValue("position","sticky"),l=g.getCssValue("position","fixed"),m=navigator.appName==="Microsoft Internet Explorer",n;m&&(n=parseFloat(navigator.appVersion.split("MSIE")[1])),o.prototype={_mindtop:function(){var a=0;if(this._$mind){var b,c,e;for(var f=0,g=this._$mind.length;fthis._fullOffset("offsetTop",this.child)-this.options.top-this._mindtop()&&this._viewportHeight>this.child.offsetHeight+d.toFloat(a.marginTop)+d.toFloat(a.marginBottom)&&(this._fix(),this._adjust())}else{if(this._scrollTop>this._parentBottom||this._scrollTop0&&(c=0),this.child.style.top=c+b+a+this.options.top-d.toFloat(e.marginTop)+"px"},_fullOffset:function(a,b,c){var d=b[a],e=b.offsetParent;while(e!==null&&e!==c)d=d+e[a],e=e.offsetParent;return d},_getContext:function(){var a,b=this.child,e=null,f;while(!e){a=b.parentNode;if(a===c.documentElement)return null;f=d.getAll(a);if(f[h]!=="none"){e=a;break}b=a}return e},_fix:function(){var a=this.child,b=a.style,e=d.getAll(a),f=a.getBoundingClientRect().left,g=e.width;this._saveStyles(),c.documentElement.currentStyle&&(g=a.offsetWidth-(d.toFloat(e.paddingLeft)+d.toFloat(e.paddingRight)+d.toFloat(e.borderLeftWidth)+d.toFloat(e.borderRightWidth))+"px");if(i){var h=this._getContext();h&&(f=a.getBoundingClientRect().left-h.getBoundingClientRect().left)}this._replacer.replace(),b.left=f-d.toFloat(e.marginLeft)+"px",b.width=g,b.position="fixed",b.top=this._mindtop()+this.options.top-d.toFloat(e.marginTop)+"px",this._$child.addClass(this.options.className),this.fixed=!0},_unfix:function(){var a=this.child.style;this._replacer.hide(),a.position=this._childOriginalPosition,a.top=this._childOriginalTop,a.width=this._childOriginalWidth,a.left=this._childOriginalLeft,this._$child.removeClass(this.options.className),this.fixed=!1},_saveStyles:function(){var a=this.child.style;this._childOriginalPosition=a.position,this._childOriginalTop=a.top,this._childOriginalWidth=a.width,this._childOriginalLeft=a.left},_onresize:function(){this.refresh()},_saveViewportHeight:function(){this._viewportHeight=b.innerHeight||c.documentElement.clientHeight},_stop:function(){this._unfix(),a(b).unbind("scroll",this._proxied_onscroll),a(this._toresize).unbind("resize",this._proxied_onresize)},_start:function(){this._onscroll(),a(b).bind("scroll",this._proxied_onscroll),a(this._toresize).bind("resize",this._proxied_onresize)},_destroy:function(){this._replacer.destroy()},refresh:function(){this._saveViewportHeight(),this._unfix(),this._onscroll()}}),q.prototype=new o,a.extend(q.prototype,{_start:function(){var a=d.getAll(this.child);this._childOriginalPosition=a.position,this._childOriginalTop=a.top,this.child.style.position=k,this.refresh()},_stop:function(){this.child.style.position=this._childOriginalPosition,this.child.style.top=this._childOriginalTop},refresh:function(){this.child.style.top=this._mindtop()+this.options.top+"px"}});var r=function(a,b,c){return k&&!c||k&&c&&c.useNativeSticky!==!1?new q(a,b,c):l?(i===undefined&&(i=j()),new p(a,b,c)):"Neither fixed nor sticky positioning supported"};return n<8&&(r=function(){return"not supported"}),a.fn.fixTo=function(b,c){var d=a(b),e=0;return this.each(function(){var f=a(this).data("fixto-instance");if(!f)a(this).data("fixto-instance",r(this,d[e],c));else{var g=b;f[g].call(f,c)}e++})},{FixToContainer:p,fixTo:r,computedStyle:d,mimicNode:e}}(window.jQuery,window,document); \ No newline at end of file