{"version":3,"names":[],"mappings":"","sources":["stickUp.js"],"sourcesContent":["(function ($, window, document) {\n var StickUp = function(elem, opts) {\n var lastScrollTop = 0,\n scroll = 0,\n scrollDir = '',\n scrollDistance = 0,\n active = false,\n bottom = false,\n hold = false,\n disabled = false,\n landscape = false,\n portrait = false,\n stickyHeight = 0,\n outerHeight = 0,\n\t\tcurrentOuterHeight = 0,\n viewportHeight = 0,\n scrollBottom = 0,\n elementOffset = 0,\n elementOffsetBottom = 0,\n $element = $(),\n topMargin = 0,\n offset = 0,\n $placeholder = $('
'),\n $parent = $(),\n stickpoints = {\n top:0,\n bottom:0,\n custom:[]\n },\n left,\n \n //defaults\n options = {\n scrollHide: false,\n lazyHeight: 0,\n topMargin: \"auto\",\n keepInWrapper: false,\n wrapperSelector: '',\n zIndex: 99,\n syncPosition:false,\n\t\t\tnamespaceClass: \"stuckElement\",\n\t\t\tfixedClass: \"isStuck\",\n disableOn:function(){\n return true;\n }\n },\n \n getTopMargin = function () {\n if (options.topMargin === 'auto') {\n return parseInt($element.css('marginTop'));\n } else {\n if (isNaN(options.topMargin) && options.topMargin.search(\"px\") > 0) {\n return parseInt(options.topMargin.replace(\"px\", \"\"));\n } else if (!isNaN(parseInt(options.topMargin))) {\n return parseInt(options.topMargin);\n } else {\n console.log(\"incorrect argument, ignored.\");\n return 0;\n }\n }\n },\n \n unStick = function(){\n console.log('unStick()');\n $placeholder.remove();\n $element.removeClass(options.fixedClass)\n .css({ \n maxWidth:\"\",\n marginTop: \"\", \n marginLeft:\"\",\n marginRight:\"\",\n position: \"\",\n top: \"\",\n left: \"\", \n right: \"\",\n bottom:\"\",\n width: \"\"\n });\n active = false;\n bottom = false;\n hold = false;\n if(options.syncPosition)\n syncMargins();\n },\n \n holdIt = function(forceBottom){\n console.log('holdIt()');\n $element.before($placeholder.css('height', outerHeight));\n var offsetParent = $placeholder.offsetParent();\n \n if (forceBottom){\n $element.css({\n position: \"absolute\"\n });\n var topOffset = \n ($parent.offset().top + $parent.outerHeight()) //bottom of container\n - offsetParent.offset().top - currentOuterHeight //parent-position - elementHeight\n - parseInt($parent.css(\"paddingBottom\"));\n }\n console.log($parent.offset().top + $parent.outerHeight());\n console.log(offsetParent.offset().top - currentOuterHeight);\n $element.css({\n position: \"absolute\",\n marginTop: topMargin,\n bottom:\"\",\n left:$placeholder.position().left,\n top: forceBottom? topOffset : $element.offset().top - offsetParent.offset().top - topMargin\n });\n },\n stickIt = function(){\n console.log('stickIt()');\n active = true;\n $element.before($placeholder.css('height', outerHeight));\n $element.addClass(options.fixedClass);\n var topDistance = -offset;\n\n $element.css({\n //maxWidth: parseInt($element.outerWidth()),\n marginTop: topMargin,\n position: \"fixed\",\n top: topDistance + 'px',\n left:\"\",\n right:\"\",\n //right: \"auto\",\n bottom:\"\"\n });\n },\n stickAtBottom = function(){\n console.log('stickAtBottom');\n $element.before($placeholder.css('height', outerHeight));\n $element.addClass(options.fixedClass);\n var bottomDistance = -offset;//-offset;\n\n $element.css({\n //maxWidth: parseInt($element.outerWidth()),\n marginTop: topMargin,\n position: \"fixed\",\n top: \"\",\n left:\"\",\n right:\"\",\n //right: \"auto\",\n bottom:bottomDistance\n });\n },\n syncWidth = function(){\n if($placeholder.width()!==$element.outerWidth())\n $element.outerWidth($placeholder.outerWidth());\n },\n syncPosition = function(){\n //retrieve margin\n left = $placeholder.offset().left;\n if(left !== $element.offset().left);\n $element.offset({'left':left});\n },\n syncMargins = function(){\n //retrieve margin\n $placeholder.css({\n 'margin-left':$element.css('margin-left'),\n 'margin-right':$element.css('margin-left')\n });\n $element.css({\n \"margin-left\" :$placeholder.css('margin-left'),\n \"margin-right\" :$placeholder.css('margin-right')\n });\n },\n\n stickUpScrollHandlerFn = function (event) {\n if(!options.disableOn()){\n if(!disabled){\n console.log('disable');\n unStick();\n disabled = true;\n }\n return;\n }else if(disabled){\n disabled = false;\n }\n if(options.keepInWrapper && !$parent.is(':visible')) {\n return;\n }\n scroll = $(event.target).scrollTop();\n scrollDir = (scroll >= lastScrollTop) ? 'down' : 'up';\n scrollDistance = Math.abs(lastScrollTop - scroll);\n viewportHeight = $(window).outerHeight();\n scrollBottom = scroll+viewportHeight;\n lastScrollTop = scroll;\n elementOffset = $element.offset().top;\n stickyHeight = parseInt($element.outerHeight()+topMargin)+parseInt($element.css('marginBottom'));\n\t\t\tif (!active && !hold && !bottom) {\n outerHeight = parseInt($element.outerHeight(true));\n if(!bottom && !hold)\n stickpoints.top = parseInt($element.offset().top);\n else\n stickpoints.top = parseInt($placeholder.offset().top);\n left = parseInt($element.offset().left)+5;\n }\n\t\t\tcurrentOuterHeight = parseInt($element.outerHeight())+parseInt($element.css('margin-bottom'))+topMargin;\n if(options.keepInWrapper)\n stickpoints.bottom = $parent.offset().top+$parent.outerHeight()-parseInt($parent.css('paddingBottom'));\n else\n stickpoints.bottom = $(document).outerHeight();\n elementOffsetBottom = $element.offset().top+currentOuterHeight;\n \n if(stickyHeight>viewportHeight){\n portrait = true;\n if(landscape){\n offset = 0;\n if(hold)\n holdIt();\n landscape = false;\n }\n if( hold && scrollDir === 'up' && scroll <= elementOffset - topMargin){\n console.log('sticktop');\n stickIt();\n active = true;\n bottom = false;\n hold = false;\n }\n if( !active && !bottom\n && (!options.keepInWrapper || options.keepInWrapper && scrollBottom <= stickpoints.bottom)\n && scrollBottom >= elementOffsetBottom - topMargin\n ){\n console.log('stickAtBottom');\n stickAtBottom();\n bottom = true;\n active = true;\n hold = false;\n }\n if(!hold && active && bottom && scrollDir === 'up' \n || !hold && active && !bottom && scrollDir === 'down' \n && elementOffsetBottom >= scrollBottom){\n console.log('holdIt');\n holdIt();\n active = false;\n bottom = false;\n hold = true;\n }\n //FORCE BOTTOM\n if(scrollBottom >= stickpoints.bottom && options.keepInWrapper //scroll past stickpoint while keepInWrapper\n && (!bottom && !hold //not applied yet\n || parseInt(elementOffsetBottom-topMargin) !== parseInt(stickpoints.bottom))){ // or element past stickpoint\n console.log('forceBottom');\n holdIt(true);\n active = false;\n bottom = true;\n hold = true;\n }\n }else{\n landscape = true;\n if(portrait){\n if(hold)\n holdIt();\n portrait = false;\n }\n // Google like reappearance on upward scroll\n if (options.scrollHide)\n offset = stickyHeight + options.lazyHeight; //negative offset for initial hiding\n else\n offset = options.lazyHeight;\n \n if(!active && !bottom && scroll >= stickpoints.top - topMargin + offset \n || bottom && hold && scroll <= elementOffset - topMargin + offset){\n console.log('sticktop');\n stickIt();\n active = true;\n bottom = false;\n hold = false;\n }\n //FORCE BOTTOM\n if(options.keepInWrapper\n && parseInt(elementOffsetBottom - topMargin) !== parseInt(stickpoints.bottom)\n && scroll >= stickpoints.bottom - currentOuterHeight + offset){\n console.log('forceBottom p');\n holdIt(true);\n active = false;\n bottom = true;\n hold = true;\n }\n //Calculate lazyHeight and autoHide\n if (active) {\n var topValue = parseInt($element.css('top'));\n if (scrollDir === 'up' && topValue !== 0) {\n var newTopValue = scrollDistance > -topValue ? 0 : topValue + scrollDistance;\n $element.css('top', newTopValue + 'px');\n } else if (scrollDir === \"down\" && topValue > -offset) {\n var newTopValue = scrollDistance > offset + topValue ? -offset : topValue - scrollDistance;\n $element.css('top', newTopValue + 'px');\n }\n }\n }\n //UNSTICK\n if ((active || hold || bottom) && scroll <= stickpoints.top - topMargin) {\n console.log('unstick');\n unStick();\n }\n //RESPONSIVE baby ;-)\n\t\t\tif(active || hold || bottom)\n\t\t\t\tsyncWidth();\n \n //Special cases which need a specified position like margin:0 centered elements\n if(options.syncPosition && active || hold)\n\t\t\t\tsyncPosition();\n //console.log(\"active \",active,\"hold \",hold,\"bottom \",bottom);\n },\n stickUpResponsiveHandlerFn = function(event){\n if(hold){\n holdIt();\n bottom = false;\n }\n console.log('resize');\n stickUpScrollHandlerFn(event);\n\n };\n\n //init\n var initialize = function(elem,opts){\n $element = $(elem);\n // adding a class to users div\n $element.addClass(options.namespaceClass);\n //getting options\n if (opts) {\n $.extend(true, options, opts);\n } \n topMargin = (options.topMargin !== null) ? getTopMargin() : 0;\n if(options.lazyHeight)\n topMargin = topMargin + options.lazyHeight;\n if(options.keepInWrapper){\n if(options.wrapperSelector !== '')\n $parent = $element.closest(options.wrapperSelector);\n //if no Wrapper available use offsetParent\n if(!$parent.length)\n $parent = $element.parent();\n }else{\n $parent = $('body');\n }\n if(options.zIndex)\n $element.css('z-index',options.zIndex);\n \n if(syncPosition){\n syncMargins();\n }\n \n $(window).on('scroll.stickUp', stickUpScrollHandlerFn);\n $(window).on('resize.stickUp', stickUpResponsiveHandlerFn);\n //initial round ;-)\n stickUpScrollHandlerFn({target: document});\n };\n initialize.call(this, elem, opts);\n };\n\n $.fn.stickUp = function( options ) {\n return this.each(function() {\n new StickUp( this, options );\n });\n };\n}(jQuery, window, document));\n"],"file":"stickUp.js"}