// // jquery.positioner // desc: keep element in fixed position during window scroll // version: 1.1 // requires: jQuery 1.7+ // author: Krzysztof Urbas, @krzysu, myviews.pl // license: available under the MIT license // homepage: https://github.com/krzysu/jquery.positioner // how to use? // init: $(selector).positionMe(options) // refresh: $(selector).positionMe('refresh') // destroy: $(selector).positionMe('destroy') // options: // parent: null // parent element that limit box position // margin: 0 // distance between positioned element and top of the window // preserveSpace: false // will add temporary element in exactly the same dimensions like positioned element to preserve page layout // pinnedCallback: -> // called once when positioned element is pinned to screen // unpinnedCallback: -> // called once when positioned element is unpinned from screen ;((function(){window.PositionerNamespace==null&&(window.PositionerNamespace={}),window.PositionerNamespace.Accountant=function(){function a(a,b){this.box=a,this.parent=b,this.box!=null&&$(this.box).length>0||(this.box="body"),this.parent!=null&&$(this.parent).length>0||(this.parent="body",this.isParentDefined=!1),this.$box=$(this.box),this.$parent=$(this.parent),this._prepareData()}return a.prototype._numberize=function(a){return parseInt(a,10)||0},a.prototype._prepareData=function(){return this._parentData=this.getParentData(),this._boxData=this.getBoxData()},a.prototype.getBoxData=function(){var a,b,c;return a=this.$box,c=this.getParentData(),b={width:a.width(),offsetLeft:a.offset().left,offsetTop:a.offset().top,marginLeft:this._numberize(a.css("margin-left")),marginTop:this._numberize(a.css("margin-top")),borderLeft:this._numberize(a.css("border-left-width")),absolutePositionTop:c.height+c.paddingTop-a.outerHeight()},b.fixedPositionLeft=b.offsetLeft-b.marginLeft,b.absolutePositionLeft=b.offsetLeft-c.offsetLeft-b.marginLeft-c.borderLeft,b},a.prototype.getParentData=function(){var a,b;return b=this.$parent,a={width:b.width(),height:b.height(),offsetLeft:b.offset().left,offsetTop:b.offset().top,borderLeft:this._numberize(b.css("border-left-width")),paddingLeft:this._numberize(b.css("padding-left")),paddingTop:this._numberize(b.css("padding-top"))}},a.prototype.getStartPoint=function(){var a,b;return a=this._boxData,b=a.offsetTop-a.marginTop},a.prototype.getEndPoint=function(){var a,b,c;return this.isParentDefined==null||this.isParentDefined!==!1?(a=this._boxData,c=this._parentData,b=c.offsetTop+this.$parent.outerHeight()-this.$box.outerHeight(!0)):b=$(document).height()},a}()})).call(this),function(){window.PositionerNamespace==null&&(window.PositionerNamespace={}),window.PositionerNamespace.Debugger=function(){function a(a,b){this.positioner=a,this.accountant=b,console.log(this.positioner,this.accountant)}return a}()}.call(this),function(){window.PositionerNamespace==null&&(window.PositionerNamespace={}),window.PositionerNamespace.Positioner=function(){function a(a,b){this.box=a,this.id=PositionerNamespace.Positioner.instanceId(),this.box!=null&&$(this.box).length>0&&(this._readSettings(b),this.accountant=new PositionerNamespace.Accountant(this.box,this.parent),this.$box=$(this.box),this._setData(),this._initEvents(),this._controlBoxPosition(),this.debugMode&&new PositionerNamespace.Debugger(this,this.accountant))}return a.instanceId=function(){var a;return a=0,function(){return a++}}(),a.prototype._readSettings=function(a){return this.parent=a.parent!=null?a.parent:void 0,this.margin=a.margin!=null?a.margin:0,this.preserveSpace=a.preserveSpace!=null?a.preserveSpace:!1,this.debugMode=a.debugMode!=null?a.debugMode:!1,this.callbacks={},this.callbacks.pinnedCallback=a.pinnedCallback,this.callbacks.unpinnedCallback=a.unpinnedCallback},a.prototype._setData=function(){return this.isBoxFixed=!1,this.isBoxAtTheBottom=!1,this.isPreserved==null&&(this.isPreserved=!1),this._unpinBox(),this.boxData=this.accountant.getBoxData(),this.startPoint=this.accountant.getStartPoint()-this.margin,this.endPoint=this.accountant.getEndPoint()-this.margin},a.prototype._initEvents=function(){var a=this;return $(window).on("scroll.positioner",function(){return a._controlBoxPosition()}),$(window).on("resize.positioner",function(){return a._setData(),a._controlBoxPosition()})},a.prototype._controlBoxPosition=function(){var a;return a=$(window).scrollTop(),a>this.startPoint&&a=this.endPoint?this._unpinBoxAtTheEnd():(this._unpinBox(),this._returnSpace())},a.prototype._pinBox=function(){return this.isBoxFixed||(this.$box.addClass("pinned").css({position:"fixed",width:this.boxData.width,left:this.boxData.fixedPositionLeft,top:this.margin,bottom:""}),typeof this.callbacks.pinnedCallback=="function"&&this.callbacks.pinnedCallback()),this.isBoxFixed=!0,this.isBoxAtTheBottom=!1},a.prototype._unpinBox=function(){return this.$box.removeClass("pinned").css({position:"",width:"",left:"",top:"",bottom:""}),this.isBoxFixed&&typeof this.callbacks.unpinnedCallback=="function"&&this.callbacks.unpinnedCallback(),this.isBoxFixed=!1,this.isBoxAtTheBottom=!1},a.prototype._unpinBoxAtTheEnd=function(){return this.$box.removeClass("pinned").css({position:"absolute",width:this.boxData.width,left:this.boxData.absolutePositionLeft,top:"",bottom:0}),this.isBoxFixed=!1,this.isBoxAtTheBottom=!0},a.prototype._preserveSpace=function(){var a,b;if(this.preserveSpace){a=$("
").addClass("positioner-spacer-"+this.id);if(!this.isPreserved)return b=this.$box.outerHeight(!0),a.css("height",b).insertAfter(this.box),this.isPreserved=!0}},a.prototype._returnSpace=function(){if(this.isPreserved)return $(".positioner-spacer-"+this.id).remove(),this.isPreserved=!1},a.prototype.refresh=function(){return this._setData()},a.prototype.destroy=function(){return this._unpinBox(),$(".positioner-spacer-"+this.id).remove(),$(window).off(".positioner")},a}()}.call(this),function(){var a,b,c;a=jQuery,c=null,a.fn.positionMe=function(c){return b[c]?b[c].apply(this,Array.prototype.slice.call(arguments,1)):typeof c=="object"||!c?b.init.apply(this,arguments):a.error("Method "+c+" does not exist on jQuery.positionMe")},b={init:function(b){var d,e;return d={parent:null,margin:0,preserveSpace:!1,debugMode:!1,pinnedCallback:function(){},unpinnedCallback:function(){}},e=a.extend({},d,b),c=new PositionerNamespace.Positioner(this,e),this},refresh:function(){return c!=null&&c.refresh(),this},destroy:function(){return c!=null&&c.destroy(),this}}}.call(this)