diff --git a/inc/js/classes/BxDolPage.js b/inc/js/classes/BxDolPage.js index ad595373f2..12da867bfa 100644 --- a/inc/js/classes/BxDolPage.js +++ b/inc/js/classes/BxDolPage.js @@ -5,8 +5,7 @@ * @defgroup UnaCore UNA Core * @{ */ -function BxDolPage(oOptions) -{ +function BxDolPage(oOptions) { this._sObjName = oOptions.sObjName == undefined ? 'oBxDolPage' : oOptions.sObjName; this._isStickyColumns = oOptions.isStickyColumns == undefined ? false : oOptions.isStickyColumns; this._iLastSc = 0; @@ -19,53 +18,10 @@ function BxDolPage(oOptions) BxDolPage.prototype.init = function () { var $this = this; if ($this._isStickyColumns && !$('html').hasClass('bx-media-phone')) { - $(window).resize(function () { $this.stickyBlocks() }); - $(window).scroll(function () { $this.stickyBlocks() }); + $('.bx-layout-col').theiaStickySidebar({ + additionalMarginTop: 30 + }); } }; -BxDolPage.prototype.stickyBlocks = function () { - iSc = $(window).scrollTop(); - $.each($('.bx-layout-col'), function (index, val) { - if ($(this).css('position') == 'sticky') { - var iCh = $(this).height(); - var iWh = $(window).height(); - - if ($('#bx-toolbar').css('position') == 'fixed') { - console.log($('#bx-content-main').offset().top - $('.bx-menu-toolbar-padding').height()); - $(this).css('top', $('#bx-toolbar').height()+ 'px'); - } - else { - $(this).css('top', '60px'); - } - - if (iCh > iWh) { - if (iCh - $(window).scrollTop() - $(window).height() < 0) { - var iMinS = (iWh - iCh); - if ($(this).css('top') == '') { - $(this).css('top', iMinS + 'px'); - } - else { - var iCurS = new Number($(this).css('top').replace('px', '')) - iSc + this._iLastSc; - if (iCurS > 0) { - console.log(2); - $(this).css('top', '0px'); - } - if (iCurS < iMinS) { - console.log(3); - $(this).css('top', iMinS + 'px'); - } - if (iCurS < 0 && iCurS > iMinS) { - console.log(4); - $(this).css('top', iCurS + 'px'); - } - } - } - } - } - }); - this._iLastSc = iSc <= 0 ? 0 : iSc; -} - - /** @} */ diff --git a/plugins_public/theia-sticky-sidebar/LICENSE.txt b/plugins_public/theia-sticky-sidebar/LICENSE.txt new file mode 100644 index 0000000000..059403f236 --- /dev/null +++ b/plugins_public/theia-sticky-sidebar/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Liviu Cristian Mirea Ghiban + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/plugins_public/theia-sticky-sidebar/ResizeSensor.min.js b/plugins_public/theia-sticky-sidebar/ResizeSensor.min.js new file mode 100644 index 0000000000..8fb2c6b7bd --- /dev/null +++ b/plugins_public/theia-sticky-sidebar/ResizeSensor.min.js @@ -0,0 +1,2 @@ +!function(){var e=function(t,i){function s(){this.q=[],this.add=function(e){this.q.push(e)};var e,t;this.call=function(){for(e=0,t=this.q.length;e
',e.appendChild(e.resizeSensor),{fixed:1,absolute:1}[o(e,"position")]||(e.style.position="relative");var d,r,l=e.resizeSensor.childNodes[0],c=l.childNodes[0],h=e.resizeSensor.childNodes[1],a=(h.childNodes[0],function(){c.style.width=l.offsetWidth+10+"px",c.style.height=l.offsetHeight+10+"px",l.scrollLeft=l.scrollWidth,l.scrollTop=l.scrollHeight,h.scrollLeft=h.scrollWidth,h.scrollTop=h.scrollHeight,d=e.offsetWidth,r=e.offsetHeight});a();var f=function(){e.resizedAttached&&e.resizedAttached.call()},u=function(e,t,i){e.attachEvent?e.attachEvent("on"+t,i):e.addEventListener(t,i)},p=function(){e.offsetWidth==d&&e.offsetHeight==r||f(),a()};u(l,"scroll",p),u(h,"scroll",p)}var d=Object.prototype.toString.call(t),r="[object Array]"===d||"[object NodeList]"===d||"[object HTMLCollection]"===d||"undefined"!=typeof jQuery&&t instanceof jQuery||"undefined"!=typeof Elements&&t instanceof Elements;if(r)for(var l=0,c=t.length;l.theiaStickySidebar:after {content: ""; display: table; clear: both;}')),e.each(function(){function e(){a.fixedScrollTop=0,a.sidebar.css({"min-height":"1px"}),a.stickySidebar.css({position:"static",width:"",transform:"none"})}function o(t){var e=t.height();return t.children().each(function(){e=Math.max(e,i(this).height())}),e}var a={};if(a.sidebar=i(this),a.options=t||{},a.container=i(a.options.containerSelector),0==a.container.length&&(a.container=a.sidebar.parent()),a.sidebar.parents().css("-webkit-transform","none"),a.sidebar.css({position:a.options.defaultPosition,overflow:"visible","-webkit-box-sizing":"border-box","-moz-box-sizing":"border-box","box-sizing":"border-box"}),a.stickySidebar=a.sidebar.find(".theiaStickySidebar"),0==a.stickySidebar.length){var s=/(?:text|application)\/(?:x-)?(?:javascript|ecmascript)/i;a.sidebar.find("script").filter(function(i,t){return 0===t.type.length||t.type.match(s)}).remove(),a.stickySidebar=i("
").addClass("theiaStickySidebar").append(a.sidebar.children()),a.sidebar.append(a.stickySidebar)}a.marginBottom=parseInt(a.sidebar.css("margin-bottom")),a.paddingTop=parseInt(a.sidebar.css("padding-top")),a.paddingBottom=parseInt(a.sidebar.css("padding-bottom"));var r=a.stickySidebar.offset().top,d=a.stickySidebar.outerHeight();a.stickySidebar.css("padding-top",1),a.stickySidebar.css("padding-bottom",1),r-=a.stickySidebar.offset().top,d=a.stickySidebar.outerHeight()-d-r,0==r?(a.stickySidebar.css("padding-top",0),a.stickySidebarPaddingTop=0):a.stickySidebarPaddingTop=1,0==d?(a.stickySidebar.css("padding-bottom",0),a.stickySidebarPaddingBottom=0):a.stickySidebarPaddingBottom=1,a.previousScrollTop=null,a.fixedScrollTop=0,e(),a.onScroll=function(a){if(a.stickySidebar.is(":visible")){if(i("body").width()a.container.width())return void e()}var r=i(document).scrollTop(),d="static";if(r>=a.sidebar.offset().top+(a.paddingTop-a.options.additionalMarginTop)){var c,p=a.paddingTop+t.additionalMarginTop,b=a.paddingBottom+a.marginBottom+t.additionalMarginBottom,l=a.sidebar.offset().top,f=a.sidebar.offset().top+o(a.container),h=0+t.additionalMarginTop,g=a.stickySidebar.outerHeight()+p+b0?Math.min(y,h):Math.max(y,c-a.stickySidebar.outerHeight()),y=Math.max(y,u),y=Math.min(y,S-a.stickySidebar.outerHeight());var k=a.container.height()==a.stickySidebar.outerHeight();d=(k||y!=h)&&(k||y!=c-a.stickySidebar.outerHeight())?r+y-a.sidebar.offset().top-a.paddingTop<=t.additionalMarginTop?"static":"absolute":"fixed"}if("fixed"==d){var v=i(document).scrollLeft();a.stickySidebar.css({position:"fixed",width:n(a.stickySidebar)+"px",transform:"translateY("+y+"px)",left:a.sidebar.offset().left+parseInt(a.sidebar.css("padding-left"))-v+"px",top:"0px"})}else if("absolute"==d){var x={};"absolute"!=a.stickySidebar.css("position")&&(x.position="absolute",x.transform="translateY("+(r+y-a.sidebar.offset().top-a.stickySidebarPaddingTop-a.stickySidebarPaddingBottom)+"px)",x.top="0px"),x.width=n(a.stickySidebar)+"px",x.left="",a.stickySidebar.css(x)}else"static"==d&&e();"static"!=d&&1==a.options.updateSidebarHeight&&a.sidebar.css({"min-height":a.stickySidebar.outerHeight()+a.stickySidebar.offset().top-a.sidebar.offset().top+a.paddingBottom}),a.previousScrollTop=r}},a.onScroll(a),i(document).on("scroll."+a.options.namespace,function(i){return function(){i.onScroll(i)}}(a)),i(window).on("resize."+a.options.namespace,function(i){return function(){i.stickySidebar.css({position:"static"}),i.onScroll(i)}}(a)),"undefined"!=typeof ResizeSensor&&new ResizeSensor(a.stickySidebar[0],function(i){return function(){i.onScroll(i)}}(a))})}function n(i){var t;try{t=i[0].getBoundingClientRect().width}catch(i){}return"undefined"==typeof t&&(t=i.width()),t}var s={containerSelector:"",additionalMarginTop:0,additionalMarginBottom:0,updateSidebarHeight:!0,minWidth:0,disableOnResponsiveLayouts:!0,sidebarBehavior:"modern",defaultPosition:"relative",namespace:"TSS"};return t=i.extend(s,t),t.additionalMarginTop=parseInt(t.additionalMarginTop)||0,t.additionalMarginBottom=parseInt(t.additionalMarginBottom)||0,e(t,this),this}}(jQuery); +//# sourceMappingURL=maps/theia-sticky-sidebar.min.js.map diff --git a/template/scripts/BxBasePage.php b/template/scripts/BxBasePage.php index d3e6f9288f..3bccacf05d 100644 --- a/template/scripts/BxBasePage.php +++ b/template/scripts/BxBasePage.php @@ -480,9 +480,7 @@ protected function _getBlockCode($aBlock, $iAsync = 0) */ protected function _addJsCss() { - $this->_oTemplate->addJs('BxDolPage.js'); - if ($this->_bStickyColumns) - $this->_oTemplate->addCss('page_sticky.css'); + $this->_oTemplate->addJs(array('BxDolPage.js', 'theia-sticky-sidebar/ResizeSensor.min.js', 'theia-sticky-sidebar/theia-sticky-sidebar.min.js')); $this->_oTemplate->addCss('page_layouts.css'); }