Version Description
- Improvement: Compatibility with dynamically loaded content pages, i.e., infinite scroll
- Improvement: Compatibility with widgets that have large offsets
- Fix: Prevent padding from increasing on scroll
Download this release
Release Info
Developer | webzunft |
Plugin | Q2W3 Fixed Widget |
Version | 6.0.6 |
Comparing to | |
See all releases |
Code changes from version 6.0.5 to 6.0.6
- js/frontend.js +13 -17
- js/frontend.min.js +1 -1
- q2w3-fixed-widget.php +2 -2
- readme.txt +7 -1
js/frontend.js
CHANGED
@@ -36,14 +36,15 @@ var Widget = (function () {
|
|
36 |
return el && el.previousElementSibling;
|
37 |
};
|
38 |
}
|
39 |
-
Widget.prototype.render = function () {
|
|
|
|
|
40 |
Widget.prototype.mount = function (user_margins) {
|
41 |
if (user_margins === void 0) { user_margins = {}; }
|
42 |
if (!this.el || !this.el.parentElement) {
|
43 |
return;
|
44 |
}
|
45 |
this.top_offset = this.get_total_top_offset(user_margins);
|
46 |
-
this.root_offset = scrollY + this.el.getBoundingClientRect().y;
|
47 |
};
|
48 |
Widget.prototype.getElement = function () {
|
49 |
return this.el;
|
@@ -202,7 +203,6 @@ var PositionWidget = (function (_super) {
|
|
202 |
this.bottom_margin = parseInt(marginBottom);
|
203 |
this.top_margin = parseInt(marginTop);
|
204 |
this.bottom_offset = this.get_total_bottom_offset(user_margins);
|
205 |
-
this.max_top_offset = document.body.clientHeight;
|
206 |
this.block_height = reactive(function () {
|
207 |
if (!_this.el) {
|
208 |
return 0;
|
@@ -234,7 +234,9 @@ var PositionWidget = (function (_super) {
|
|
234 |
PositionWidget.from = function (root) {
|
235 |
return _super.from.call(this, root, FixedWidgetClassName);
|
236 |
};
|
237 |
-
PositionWidget.prototype.on_scroll = function (_scroll_top) {
|
|
|
|
|
238 |
return PositionWidget;
|
239 |
}(Widget));
|
240 |
|
@@ -270,13 +272,12 @@ var FixedWidget = (function (_super) {
|
|
270 |
this.clone();
|
271 |
this.block_height.on_change(function (block_height) {
|
272 |
_this.relative_top = _this.max_top_offset - block_height - _this.paddings;
|
273 |
-
_this.init_style.height = "".concat(block_height, "px");
|
274 |
});
|
275 |
};
|
276 |
FixedWidget.prototype.update_root_offset = function () {
|
277 |
var element = this.is_pinned ? this.clone_el : this.el;
|
278 |
var new_root_offset = Math.round(scrollY + (element ? element.getBoundingClientRect().top : 0));
|
279 |
-
this.root_offset = Math.max(this.root_offset, new_root_offset);
|
280 |
};
|
281 |
FixedWidget.prototype.setMaxOffset = function (max_top_offset) {
|
282 |
if (max_top_offset === 0 ||
|
@@ -343,7 +344,6 @@ var FixedWidget = (function (_super) {
|
|
343 |
this.el.style.position = 'fixed';
|
344 |
this.el.style.transition = 'transform 0.5s';
|
345 |
this.el.style.width = this.init_style.width;
|
346 |
-
this.el.style.height = this.init_style.height;
|
347 |
if (!this.clone_el) {
|
348 |
return;
|
349 |
}
|
@@ -461,8 +461,8 @@ var StopWidget = (function (_super) {
|
|
461 |
|
462 |
var Sidebar = (function () {
|
463 |
function Sidebar(el, margins, use_sticky_position) {
|
464 |
-
var _this = this;
|
465 |
if (use_sticky_position === void 0) { use_sticky_position = false; }
|
|
|
466 |
this.el = el;
|
467 |
this.margins = margins;
|
468 |
this.widgets = [];
|
@@ -503,10 +503,10 @@ var Sidebar = (function () {
|
|
503 |
var is_local_stop_widgets = this.stop_widgets.length != 0;
|
504 |
var use_top_offset = this.isSticky && is_local_stop_widgets;
|
505 |
var stop_widgets = is_local_stop_widgets ? this.stop_widgets : general_stop_widgets;
|
506 |
-
if (stop_widgets.length === 0) {
|
507 |
-
return;
|
508 |
-
}
|
509 |
var max_top_offset = reactive(function () {
|
|
|
|
|
|
|
510 |
var min_offset = use_top_offset ?
|
511 |
stop_widgets[0].top_offset :
|
512 |
stop_widgets[0].root_offset;
|
@@ -523,12 +523,8 @@ var Sidebar = (function () {
|
|
523 |
this.setWidgetsMaxOffset(max_top_offset.val);
|
524 |
};
|
525 |
Sidebar.prototype.render = function () {
|
526 |
-
for (var _i = 0, _a = this.
|
527 |
-
var
|
528 |
-
stop_widget.render();
|
529 |
-
}
|
530 |
-
for (var _b = 0, _c = this.widgets; _b < _c.length; _b++) {
|
531 |
-
var widget = _c[_b];
|
532 |
widget.render();
|
533 |
}
|
534 |
};
|
36 |
return el && el.previousElementSibling;
|
37 |
};
|
38 |
}
|
39 |
+
Widget.prototype.render = function () {
|
40 |
+
throw new Error('Method is not overridden!');
|
41 |
+
};
|
42 |
Widget.prototype.mount = function (user_margins) {
|
43 |
if (user_margins === void 0) { user_margins = {}; }
|
44 |
if (!this.el || !this.el.parentElement) {
|
45 |
return;
|
46 |
}
|
47 |
this.top_offset = this.get_total_top_offset(user_margins);
|
|
|
48 |
};
|
49 |
Widget.prototype.getElement = function () {
|
50 |
return this.el;
|
203 |
this.bottom_margin = parseInt(marginBottom);
|
204 |
this.top_margin = parseInt(marginTop);
|
205 |
this.bottom_offset = this.get_total_bottom_offset(user_margins);
|
|
|
206 |
this.block_height = reactive(function () {
|
207 |
if (!_this.el) {
|
208 |
return 0;
|
234 |
PositionWidget.from = function (root) {
|
235 |
return _super.from.call(this, root, FixedWidgetClassName);
|
236 |
};
|
237 |
+
PositionWidget.prototype.on_scroll = function (_scroll_top) {
|
238 |
+
throw new Error('Method is not overridden!');
|
239 |
+
};
|
240 |
return PositionWidget;
|
241 |
}(Widget));
|
242 |
|
272 |
this.clone();
|
273 |
this.block_height.on_change(function (block_height) {
|
274 |
_this.relative_top = _this.max_top_offset - block_height - _this.paddings;
|
|
|
275 |
});
|
276 |
};
|
277 |
FixedWidget.prototype.update_root_offset = function () {
|
278 |
var element = this.is_pinned ? this.clone_el : this.el;
|
279 |
var new_root_offset = Math.round(scrollY + (element ? element.getBoundingClientRect().top : 0));
|
280 |
+
this.root_offset = this.is_pinned ? new_root_offset : Math.max(this.root_offset, new_root_offset);
|
281 |
};
|
282 |
FixedWidget.prototype.setMaxOffset = function (max_top_offset) {
|
283 |
if (max_top_offset === 0 ||
|
344 |
this.el.style.position = 'fixed';
|
345 |
this.el.style.transition = 'transform 0.5s';
|
346 |
this.el.style.width = this.init_style.width;
|
|
|
347 |
if (!this.clone_el) {
|
348 |
return;
|
349 |
}
|
461 |
|
462 |
var Sidebar = (function () {
|
463 |
function Sidebar(el, margins, use_sticky_position) {
|
|
|
464 |
if (use_sticky_position === void 0) { use_sticky_position = false; }
|
465 |
+
var _this = this;
|
466 |
this.el = el;
|
467 |
this.margins = margins;
|
468 |
this.widgets = [];
|
503 |
var is_local_stop_widgets = this.stop_widgets.length != 0;
|
504 |
var use_top_offset = this.isSticky && is_local_stop_widgets;
|
505 |
var stop_widgets = is_local_stop_widgets ? this.stop_widgets : general_stop_widgets;
|
|
|
|
|
|
|
506 |
var max_top_offset = reactive(function () {
|
507 |
+
if (stop_widgets.length === 0) {
|
508 |
+
return Math.round(document.body.scrollHeight);
|
509 |
+
}
|
510 |
var min_offset = use_top_offset ?
|
511 |
stop_widgets[0].top_offset :
|
512 |
stop_widgets[0].root_offset;
|
523 |
this.setWidgetsMaxOffset(max_top_offset.val);
|
524 |
};
|
525 |
Sidebar.prototype.render = function () {
|
526 |
+
for (var _i = 0, _a = this.widgets; _i < _a.length; _i++) {
|
527 |
+
var widget = _a[_i];
|
|
|
|
|
|
|
|
|
528 |
widget.render();
|
529 |
}
|
530 |
};
|
js/frontend.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
"use strict";var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])},extendStatics(d,b)};function __extends(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t},__assign.apply(this,arguments)},StopWidgetClassName="FixedWidget__stop_widget",FixedWidgetClassName="FixedWidget__fixed_widget",Widget=function(){function Widget(el){this.el=el,this.top_offset=0,this.root_offset=0,this.need_to_calc_el_offset=function(_){return!1},this.prevSibling=function(el){return el&&el.previousElementSibling}}return Widget.prototype.render=function(){},Widget.prototype.mount=function(user_margins){void 0===user_margins&&(user_margins={}),this.el&&this.el.parentElement&&(this.top_offset=this.get_total_top_offset(user_margins),this.root_offset=scrollY+this.el.getBoundingClientRect().y)},Widget.prototype.getElement=function(){return this.el},Widget.prototype.toString=function(){var _a;return"".concat(null===(_a=this.el)||void 0===_a?void 0:_a.innerHTML)},Widget.prototype.get_total_top_offset=function(margins){return get_sibilings_offset(this.prevSibling,this.need_to_calc_el_offset,this.prevSibling(this.el),margins.margin_top)},Widget.queryAllWidgetsContainers=function(className){return[].concat(Array.from(document.querySelectorAll(".".concat(className))),Array.from(document.querySelectorAll("[data-fixed_widget=".concat(className)))).map((function(el){el.classList.remove(className),el.removeAttribute("data-fixed_widget");var container=getWidgetContainer(el);return container.classList.remove(FixedWidgetClassName),container.classList.remove(StopWidgetClassName),container}))},Widget.from=function(root,className){var _this=this,elements=[];try{elements=Array.from(root.querySelectorAll(":scope > .".concat(className)))}catch(_e){elements=Array.from(root.children).filter((function(e){return e.classList.contains(className)}))}return elements.filter((function(el){return null!==el})).map((function(e){return new _this(e)}))},Widget}(),getWidgetContainer=function(el){return el.parentElement&&(1===el.parentElement.childElementCount||el.parentElement.classList.toString().includes("wp-block-group")||el.parentElement.classList.toString().includes("wp-block-column")||el.parentElement.classList.contains("widget"))?getWidgetContainer(el.parentElement):el},get_sibilings_offset=function(next,need_to_calc_el_offset,el,offset){if(void 0===offset&&(offset=0),!el)return offset;if(!need_to_calc_el_offset(el))return get_sibilings_offset(next,need_to_calc_el_offset,next(el),offset);var _a=getComputedStyle(el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return get_sibilings_offset(next,need_to_calc_el_offset,next(el),offset+el.getBoundingClientRect().height+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},compatabilty_FW_v5=function(selectors){return void 0===selectors&&(selectors=[]),selectors.some((function(s){return!/^[a-z]/i.test(s)}))?selectors:selectors.concat(selectors.map((function(s){return"#".concat(s)})))},queryElements=function(selectors){return void 0===selectors&&(selectors=[]),Array.from(selectors.map((function(selector){return Array.from(document.querySelectorAll(selector))}))).reduce((function(all,elements){return all.concat(elements)}),[]).filter((function(e){return e instanceof HTMLElement}))};function findWithProperty(el,predicate){return el&&el!==document.body?predicate(getComputedStyle(el))?el:findWithProperty(el.parentElement,predicate):null}var sidebars,reactive=function(getter,interval){void 0===interval&&(interval=300);var subs=[],v=getter();return setInterval((function(){if(0===subs.length)return;var new_v=getter();if(v===new_v)return;v=new_v;for(var _i=0,subs_1=subs;_i<subs_1.length;_i++){(0,subs_1[_i])(new_v)}}),interval),{get val(){return v},on_change:function(update){update(v),subs.push(update)}}},PositionWidget=function(_super){function PositionWidget(){var _this=null!==_super&&_super.apply(this,arguments)||this;return _this.bottom_offset=0,_this.top_margin=0,_this.borderBox=0,_this.block_height=reactive((function(){return 0})),_this.max_top_offset=0,_this.bottom_margin=0,_this.user_margins={},_this.prevSibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)&&el.previousElementSibling||null},_this.get_total_bottom_offset=function(margins){var next=function(el){return el&&!el.classList.contains(StopWidgetClassName)?el.nextElementSibling:null};return get_sibilings_offset(next,_this.need_to_calc_el_offset,next(_this.el),margins.margin_bottom)},_this}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins){var _this=this;if(_super.prototype.mount.call(this,user_margins),this.el&&this.el.parentElement){this.user_margins=user_margins;var _a=getComputedStyle(this.el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;this.bottom_margin=parseInt(marginBottom),this.top_margin=parseInt(marginTop),this.bottom_offset=this.get_total_bottom_offset(user_margins),this.max_top_offset=document.body.clientHeight,this.block_height=reactive((function(){return _this.el?Math.round(Math.max(_this.el.clientHeight,_this.el.scrollHeight,_this.el.getBoundingClientRect().height)):0})),this.block_height.on_change((function(block_height){_this.borderBox=block_height+_this.top_margin+_this.bottom_margin})),reactive(this.get_total_bottom_offset.bind(this,user_margins)).on_change((function(bottom_offset){_this.bottom_offset=bottom_offset})),reactive(this.get_total_top_offset.bind(this,user_margins)).on_change((function(top_offset){_this.top_offset=top_offset,_this.el&&(_this.el.style.top="".concat(top_offset,"px"))}))}},PositionWidget.prototype.setMaxOffset=function(max_top_offset){this.max_top_offset=max_top_offset},PositionWidget.prototype.render=function(){this.on_scroll(scrollY)},PositionWidget.from=function(root){return _super.from.call(this,root,FixedWidgetClassName)},PositionWidget.prototype.on_scroll=function(_scroll_top){},PositionWidget}(Widget),FixedWidget=function(_super){function FixedWidget(el){var _this=_super.call(this,el)||this;return _this.is_pinned=!1,_this.relative_top=0,_this.paddings=0,_this.init_style={position:"static",marginTop:"",marginBottom:"",width:"",height:""},_this.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.el&&_this.el.parentElement?(_this.el.classList.add(FixedWidgetClassName),_this):_this}return __extends(FixedWidget,_super),FixedWidget.prototype.mount=function(margins){var _this=this;_super.prototype.mount.call(this,margins),this.el&&(this.paddings=this.top_offset+this.top_margin+this.bottom_margin+this.bottom_offset,this.store_style(getComputedStyle(this.el)),this.clone(),this.block_height.on_change((function(block_height){_this.relative_top=_this.max_top_offset-block_height-_this.paddings,_this.init_style.height="".concat(block_height,"px")})))},FixedWidget.prototype.update_root_offset=function(){var element=this.is_pinned?this.clone_el:this.el,new_root_offset=Math.round(scrollY+(element?element.getBoundingClientRect().top:0));this.root_offset=Math.max(this.root_offset,new_root_offset)},FixedWidget.prototype.setMaxOffset=function(max_top_offset){0===max_top_offset||max_top_offset<this.root_offset||this.max_top_offset===max_top_offset||(this.max_top_offset=max_top_offset,this.relative_top=this.max_top_offset-this.block_height.val-this.paddings)},FixedWidget.prototype.clone=function(){var _this=this;if(this.el&&this.el.parentElement){for(var prop in this.clone_el=this.el.cloneNode(!1),this.clone_el.getAttributeNames().forEach((function(attr){_this.clone_el.removeAttribute(attr)})),this.init_style)this.clone_el.style[prop]=this.init_style[prop];this.clone_el.style.display="none",this.el.parentElement.insertBefore(this.clone_el,this.el)}},FixedWidget.prototype.store_style=function(style){this.init_style.position=style.position,this.init_style.marginTop=style.marginTop,this.init_style.marginBottom=style.marginBottom,this.init_style.width=style.width,this.init_style.height=style.height},FixedWidget.prototype.restore_style=function(style){this.is_pinned&&(this.is_pinned=!1,style.position=this.init_style.position,this.clone_el&&(this.clone_el.style.display="none"))},FixedWidget.prototype.on_scroll=function(scroll_top){if(this.el){this.update_root_offset();var need_to_fix=scroll_top>this.root_offset-this.top_offset,top=0!==this.max_top_offset&&scroll_top>this.relative_top?this.relative_top-scroll_top+this.top_offset:this.top_offset;need_to_fix?this.fix(top):this.restore_style(this.el.style)}},FixedWidget.prototype.fix=function(top){this.el&&(this.el.style.top="".concat(top,"px"),this.is_pinned||(this.is_pinned=!0,this.el.style.position="fixed",this.el.style.transition="transform 0.5s",this.el.style.width=this.init_style.width,this.el.style.height=this.init_style.height,this.clone_el&&(this.clone_el.style.display="block")))},FixedWidget.new=function(selector){return new FixedWidget(document.querySelector(selector))},FixedWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(FixedWidgetClassName)},FixedWidget}(PositionWidget),StickyWidget=function(_super){function StickyWidget(el){var _this=_super.call(this,el)||this;return _this.margins=0,_this.get_margins=function(){return(_this.el&&_this.el.parentElement&&_this.el.parentElement.clientHeight||0)-_this.bottom_margin-_this.top_margin-_this.block_height.val},_this.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.el&&_this.el.parentElement?(_this.el.classList.add(FixedWidgetClassName),_this):_this}return __extends(StickyWidget,_super),StickyWidget.prototype.mount=function(margins){var _this=this;_super.prototype.mount.call(this,margins),this.el&&this.el.parentElement&&(reactive(this.get_margins).on_change((function(margins){_this.margins=margins})),this.el.style.position="sticky",this.el.style.position="-webkit-sticky",this.el.style.transition="transform 0s",this.el.style.boxSizing="border-box")},StickyWidget.prototype.setMaxOffset=function(max_top_offset){this.el&&this.el.parentElement&&(max_top_offset<this.el.offsetTop||(this.max_top_offset=max_top_offset))},StickyWidget.prototype.on_scroll=function(){if(this.el&&this.el.parentElement){var bottom_margin=this.max_top_offset?Math.min(this.max_top_offset-this.el.offsetTop-this.borderBox,this.margins-this.el.offsetTop):this.margins-this.el.offsetTop;this.el.style.top="".concat(this.top_offset,"px"),bottom_margin>=this.bottom_offset?this.el.style.transform="translateY(0px)":this.el.style.transform="translateY(".concat(bottom_margin-this.bottom_offset,"px)")}},StickyWidget.new=function(selector){return new StickyWidget(document.querySelector(selector))},StickyWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(FixedWidgetClassName)},StickyWidget}(PositionWidget),StopWidget=function(_super){function StopWidget(el){var _this=_super.call(this,el)||this;return _this.need_to_calc_el_offset=function(){return!0},_this.el&&_this.el.parentElement?(_this.el.classList.add(StopWidgetClassName),_this):_this}return __extends(StopWidget,_super),StopWidget.prototype.mount=function(user_margins){var _this=this;_super.prototype.mount.call(this,user_margins),reactive((function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))})).on_change((function(root_offset){_this.root_offset=root_offset}))},StopWidget.new=function(selector){return new StopWidget(document.querySelector(selector))},StopWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(StopWidgetClassName)},StopWidget.from=function(root){return _super.from.call(this,root,StopWidgetClassName)},StopWidget}(Widget),Sidebar=function(){function Sidebar(el,margins,use_sticky_position){var _this=this;void 0===use_sticky_position&&(use_sticky_position=!1),this.el=el,this.margins=margins,this.widgets=[],this.stop_widgets=[],this.isSticky=!1,this.setWidgetsMaxOffset=function(max_offset){for(var _i=0,_a=_this.widgets;_i<_a.length;_i++){_a[_i].setMaxOffset(max_offset)}};var isDeprecatedFloatMarkup=!!findWithProperty(this.el,(function(style){return"none"!==style.float})),isOverflowHiddenMarkup=!!findWithProperty(this.el,(function(style){return"hidden"===style.overflow}));(isDeprecatedFloatMarkup||isOverflowHiddenMarkup)&&use_sticky_position&&console.log("Fixed Widget: fallback to position sticky"),this.isSticky=!isDeprecatedFloatMarkup&&!isOverflowHiddenMarkup&&use_sticky_position;var WidgetContructor=this.isSticky?StickyWidget:FixedWidget;this.stop_widgets=StopWidget.from(this.el),this.widgets=WidgetContructor.from(this.el),this.isSticky&&(this.el.style.position="relative",0===this.stop_widgets.length&&(this.el.style.minHeight="100%"))}return Sidebar.prototype.mount=function(){var _this=this;this.stop_widgets.forEach((function(widget){widget.mount()})),this.widgets.forEach((function(widget){widget.mount(_this.margins)}))},Sidebar.prototype.setMaxOffset=function(general_stop_widgets){var is_local_stop_widgets=0!=this.stop_widgets.length,use_top_offset=this.isSticky&&is_local_stop_widgets,stop_widgets=is_local_stop_widgets?this.stop_widgets:general_stop_widgets;if(0!==stop_widgets.length){var max_top_offset=reactive((function(){for(var min_offset=use_top_offset?stop_widgets[0].top_offset:stop_widgets[0].root_offset,_i=0,stop_widgets_1=stop_widgets;_i<stop_widgets_1.length;_i++){var widget=stop_widgets_1[_i],offset=use_top_offset?widget.top_offset:widget.root_offset;min_offset>offset&&(min_offset=offset)}return Math.round(min_offset)}));max_top_offset.on_change(this.setWidgetsMaxOffset),this.setWidgetsMaxOffset(max_top_offset.val)}},Sidebar.prototype.render=function(){for(var _i=0,_a=this.stop_widgets;_i<_a.length;_i++){_a[_i].render()}for(var _b=0,_c=this.widgets;_b<_c.length;_b++){_c[_b].render()}},Sidebar}(),Sidebars=function(){function Sidebars(elements,options){var _this=this;this.data=[],this.render=function(){for(var _i=0,_a=_this.data;_i<_a.length;_i++){_a[_i].render()}},this.data=Array.from(new Set(elements.map((function(widget){return widget.parentElement})))).filter((function(sidebar_el){return null!==sidebar_el})).map((function(sidebar_el){return new Sidebar(sidebar_el,options,options.use_sticky_position)}))}return Sidebars.prototype.mount=function(){this.data.forEach((function(sidebar){sidebar.mount()})),this.setMaxOffset()},Sidebars.prototype.setMaxOffset=function(){for(var general_stop_widgets=this.getGeneralStopElements(),_i=0,_a=this.data;_i<_a.length;_i++){_a[_i].setMaxOffset(general_stop_widgets)}},Sidebars.prototype.getGeneralStopElements=function(){return this.data.filter((function(sidebar){return!sidebar.isSticky||0===sidebar.widgets.length})).map((function(sidebar){return sidebar.stop_widgets})).reduce((function(all,widgets){return all.concat(widgets)}),[])},Sidebars.new=function(options){var s,arr1,arr2,fixedWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(FixedWidgetClassName).concat(queryElements(compatabilty_FW_v5(options.widgets))))),stopWidgetsSelectors=compatabilty_FW_v5((void 0===(s=options.stop_elements_selectors||options.stop_id)&&(s=""),s.replace(/[\r\n]|[\r]/gi,"\n").split("\n").map((function(s){return s.trim()})).filter((function(s){return""!==s})))),stopWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(StopWidgetClassName).concat(queryElements(stopWidgetsSelectors)))),_a=(arr1=fixedWidgetsContainers,[(arr2=stopWidgetsContainers).filter((function(e){return!arr1.includes(e)})),arr1.filter((function(e){return arr2.includes(e)}))]),stopWidgetsUniqContainers=_a[0];return _a[1].forEach((function(w){console.error("The Widget is detected as fixed block and stop block!\n".concat(w.innerHTML))})),fixedWidgetsContainers.forEach((function(c){c.classList.add(FixedWidgetClassName)})),stopWidgetsUniqContainers.forEach((function(c){c.classList.add(StopWidgetClassName)})),new Sidebars(fixedWidgetsContainers.concat(stopWidgetsUniqContainers),options)},Sidebars}();function onDocumentLoaded(){var admin_panel=document.querySelector("#wpadminbar"),options=(window.q2w3_sidebar_options||[{}]).map((function(option){return option.margin_top=(option.margin_top||0)+(admin_panel&&admin_panel.clientHeight||0),option}));options.some((function(option){return window.innerWidth<option.screen_max_width||window.innerHeight<option.screen_max_height}))||function(options){void 0===options&&(options=[]),sidebars?sidebars.render():(sidebars=Sidebars.new(options.reduce((function(prev,cur){return __assign(__assign(__assign({},prev),cur),{widgets:prev.widgets.concat(cur.widgets||[])})}),{widgets:[]})),document.addEventListener("scroll",sidebars.render),sidebars.mount())}(options)}window.addEventListener("load",onDocumentLoaded),"complete"===document.readyState&&onDocumentLoaded(),onDocumentLoaded();
|
1 |
+
"use strict";var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])},extendStatics(d,b)};function __extends(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t},__assign.apply(this,arguments)},StopWidgetClassName="FixedWidget__stop_widget",FixedWidgetClassName="FixedWidget__fixed_widget",Widget=function(){function Widget(el){this.el=el,this.top_offset=0,this.root_offset=0,this.need_to_calc_el_offset=function(_){return!1},this.prevSibling=function(el){return el&&el.previousElementSibling}}return Widget.prototype.render=function(){throw new Error("Method is not overridden!")},Widget.prototype.mount=function(user_margins){void 0===user_margins&&(user_margins={}),this.el&&this.el.parentElement&&(this.top_offset=this.get_total_top_offset(user_margins))},Widget.prototype.getElement=function(){return this.el},Widget.prototype.toString=function(){var _a;return"".concat(null===(_a=this.el)||void 0===_a?void 0:_a.innerHTML)},Widget.prototype.get_total_top_offset=function(margins){return get_sibilings_offset(this.prevSibling,this.need_to_calc_el_offset,this.prevSibling(this.el),margins.margin_top)},Widget.queryAllWidgetsContainers=function(className){return[].concat(Array.from(document.querySelectorAll(".".concat(className))),Array.from(document.querySelectorAll("[data-fixed_widget=".concat(className)))).map((function(el){el.classList.remove(className),el.removeAttribute("data-fixed_widget");var container=getWidgetContainer(el);return container.classList.remove(FixedWidgetClassName),container.classList.remove(StopWidgetClassName),container}))},Widget.from=function(root,className){var _this=this,elements=[];try{elements=Array.from(root.querySelectorAll(":scope > .".concat(className)))}catch(_e){elements=Array.from(root.children).filter((function(e){return e.classList.contains(className)}))}return elements.filter((function(el){return null!==el})).map((function(e){return new _this(e)}))},Widget}(),getWidgetContainer=function(el){return el.parentElement&&(1===el.parentElement.childElementCount||el.parentElement.classList.toString().includes("wp-block-group")||el.parentElement.classList.toString().includes("wp-block-column")||el.parentElement.classList.contains("widget"))?getWidgetContainer(el.parentElement):el},get_sibilings_offset=function(next,need_to_calc_el_offset,el,offset){if(void 0===offset&&(offset=0),!el)return offset;if(!need_to_calc_el_offset(el))return get_sibilings_offset(next,need_to_calc_el_offset,next(el),offset);var _a=getComputedStyle(el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return get_sibilings_offset(next,need_to_calc_el_offset,next(el),offset+el.getBoundingClientRect().height+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},compatabilty_FW_v5=function(selectors){return void 0===selectors&&(selectors=[]),selectors.some((function(s){return!/^[a-z]/i.test(s)}))?selectors:selectors.concat(selectors.map((function(s){return"#".concat(s)})))},queryElements=function(selectors){return void 0===selectors&&(selectors=[]),Array.from(selectors.map((function(selector){return Array.from(document.querySelectorAll(selector))}))).reduce((function(all,elements){return all.concat(elements)}),[]).filter((function(e){return e instanceof HTMLElement}))};function findWithProperty(el,predicate){return el&&el!==document.body?predicate(getComputedStyle(el))?el:findWithProperty(el.parentElement,predicate):null}var sidebars,reactive=function(getter,interval){void 0===interval&&(interval=300);var subs=[],v=getter();return setInterval((function(){if(0===subs.length)return;var new_v=getter();if(v===new_v)return;v=new_v;for(var _i=0,subs_1=subs;_i<subs_1.length;_i++){(0,subs_1[_i])(new_v)}}),interval),{get val(){return v},on_change:function(update){update(v),subs.push(update)}}},PositionWidget=function(_super){function PositionWidget(){var _this=null!==_super&&_super.apply(this,arguments)||this;return _this.bottom_offset=0,_this.top_margin=0,_this.borderBox=0,_this.block_height=reactive((function(){return 0})),_this.max_top_offset=0,_this.bottom_margin=0,_this.user_margins={},_this.prevSibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)&&el.previousElementSibling||null},_this.get_total_bottom_offset=function(margins){var next=function(el){return el&&!el.classList.contains(StopWidgetClassName)?el.nextElementSibling:null};return get_sibilings_offset(next,_this.need_to_calc_el_offset,next(_this.el),margins.margin_bottom)},_this}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins){var _this=this;if(_super.prototype.mount.call(this,user_margins),this.el&&this.el.parentElement){this.user_margins=user_margins;var _a=getComputedStyle(this.el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;this.bottom_margin=parseInt(marginBottom),this.top_margin=parseInt(marginTop),this.bottom_offset=this.get_total_bottom_offset(user_margins),this.block_height=reactive((function(){return _this.el?Math.round(Math.max(_this.el.clientHeight,_this.el.scrollHeight,_this.el.getBoundingClientRect().height)):0})),this.block_height.on_change((function(block_height){_this.borderBox=block_height+_this.top_margin+_this.bottom_margin})),reactive(this.get_total_bottom_offset.bind(this,user_margins)).on_change((function(bottom_offset){_this.bottom_offset=bottom_offset})),reactive(this.get_total_top_offset.bind(this,user_margins)).on_change((function(top_offset){_this.top_offset=top_offset,_this.el&&(_this.el.style.top="".concat(top_offset,"px"))}))}},PositionWidget.prototype.setMaxOffset=function(max_top_offset){this.max_top_offset=max_top_offset},PositionWidget.prototype.render=function(){this.on_scroll(scrollY)},PositionWidget.from=function(root){return _super.from.call(this,root,FixedWidgetClassName)},PositionWidget.prototype.on_scroll=function(_scroll_top){throw new Error("Method is not overridden!")},PositionWidget}(Widget),FixedWidget=function(_super){function FixedWidget(el){var _this=_super.call(this,el)||this;return _this.is_pinned=!1,_this.relative_top=0,_this.paddings=0,_this.init_style={position:"static",marginTop:"",marginBottom:"",width:"",height:""},_this.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.el&&_this.el.parentElement?(_this.el.classList.add(FixedWidgetClassName),_this):_this}return __extends(FixedWidget,_super),FixedWidget.prototype.mount=function(margins){var _this=this;_super.prototype.mount.call(this,margins),this.el&&(this.paddings=this.top_offset+this.top_margin+this.bottom_margin+this.bottom_offset,this.store_style(getComputedStyle(this.el)),this.clone(),this.block_height.on_change((function(block_height){_this.relative_top=_this.max_top_offset-block_height-_this.paddings})))},FixedWidget.prototype.update_root_offset=function(){var element=this.is_pinned?this.clone_el:this.el,new_root_offset=Math.round(scrollY+(element?element.getBoundingClientRect().top:0));this.root_offset=this.is_pinned?new_root_offset:Math.max(this.root_offset,new_root_offset)},FixedWidget.prototype.setMaxOffset=function(max_top_offset){0===max_top_offset||max_top_offset<this.root_offset||this.max_top_offset===max_top_offset||(this.max_top_offset=max_top_offset,this.relative_top=this.max_top_offset-this.block_height.val-this.paddings)},FixedWidget.prototype.clone=function(){var _this=this;if(this.el&&this.el.parentElement){for(var prop in this.clone_el=this.el.cloneNode(!1),this.clone_el.getAttributeNames().forEach((function(attr){_this.clone_el.removeAttribute(attr)})),this.init_style)this.clone_el.style[prop]=this.init_style[prop];this.clone_el.style.display="none",this.el.parentElement.insertBefore(this.clone_el,this.el)}},FixedWidget.prototype.store_style=function(style){this.init_style.position=style.position,this.init_style.marginTop=style.marginTop,this.init_style.marginBottom=style.marginBottom,this.init_style.width=style.width,this.init_style.height=style.height},FixedWidget.prototype.restore_style=function(style){this.is_pinned&&(this.is_pinned=!1,style.position=this.init_style.position,this.clone_el&&(this.clone_el.style.display="none"))},FixedWidget.prototype.on_scroll=function(scroll_top){if(this.el){this.update_root_offset();var need_to_fix=scroll_top>this.root_offset-this.top_offset,top=0!==this.max_top_offset&&scroll_top>this.relative_top?this.relative_top-scroll_top+this.top_offset:this.top_offset;need_to_fix?this.fix(top):this.restore_style(this.el.style)}},FixedWidget.prototype.fix=function(top){this.el&&(this.el.style.top="".concat(top,"px"),this.is_pinned||(this.is_pinned=!0,this.el.style.position="fixed",this.el.style.transition="transform 0.5s",this.el.style.width=this.init_style.width,this.clone_el&&(this.clone_el.style.display="block")))},FixedWidget.new=function(selector){return new FixedWidget(document.querySelector(selector))},FixedWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(FixedWidgetClassName)},FixedWidget}(PositionWidget),StickyWidget=function(_super){function StickyWidget(el){var _this=_super.call(this,el)||this;return _this.margins=0,_this.get_margins=function(){return(_this.el&&_this.el.parentElement&&_this.el.parentElement.clientHeight||0)-_this.bottom_margin-_this.top_margin-_this.block_height.val},_this.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.el&&_this.el.parentElement?(_this.el.classList.add(FixedWidgetClassName),_this):_this}return __extends(StickyWidget,_super),StickyWidget.prototype.mount=function(margins){var _this=this;_super.prototype.mount.call(this,margins),this.el&&this.el.parentElement&&(reactive(this.get_margins).on_change((function(margins){_this.margins=margins})),this.el.style.position="sticky",this.el.style.position="-webkit-sticky",this.el.style.transition="transform 0s",this.el.style.boxSizing="border-box")},StickyWidget.prototype.setMaxOffset=function(max_top_offset){this.el&&this.el.parentElement&&(max_top_offset<this.el.offsetTop||(this.max_top_offset=max_top_offset))},StickyWidget.prototype.on_scroll=function(){if(this.el&&this.el.parentElement){var bottom_margin=this.max_top_offset?Math.min(this.max_top_offset-this.el.offsetTop-this.borderBox,this.margins-this.el.offsetTop):this.margins-this.el.offsetTop;this.el.style.top="".concat(this.top_offset,"px"),bottom_margin>=this.bottom_offset?this.el.style.transform="translateY(0px)":this.el.style.transform="translateY(".concat(bottom_margin-this.bottom_offset,"px)")}},StickyWidget.new=function(selector){return new StickyWidget(document.querySelector(selector))},StickyWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(FixedWidgetClassName)},StickyWidget}(PositionWidget),StopWidget=function(_super){function StopWidget(el){var _this=_super.call(this,el)||this;return _this.need_to_calc_el_offset=function(){return!0},_this.el&&_this.el.parentElement?(_this.el.classList.add(StopWidgetClassName),_this):_this}return __extends(StopWidget,_super),StopWidget.prototype.mount=function(user_margins){var _this=this;_super.prototype.mount.call(this,user_margins),reactive((function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))})).on_change((function(root_offset){_this.root_offset=root_offset}))},StopWidget.new=function(selector){return new StopWidget(document.querySelector(selector))},StopWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(StopWidgetClassName)},StopWidget.from=function(root){return _super.from.call(this,root,StopWidgetClassName)},StopWidget}(Widget),Sidebar=function(){function Sidebar(el,margins,use_sticky_position){void 0===use_sticky_position&&(use_sticky_position=!1);var _this=this;this.el=el,this.margins=margins,this.widgets=[],this.stop_widgets=[],this.isSticky=!1,this.setWidgetsMaxOffset=function(max_offset){for(var _i=0,_a=_this.widgets;_i<_a.length;_i++){_a[_i].setMaxOffset(max_offset)}};var isDeprecatedFloatMarkup=!!findWithProperty(this.el,(function(style){return"none"!==style.float})),isOverflowHiddenMarkup=!!findWithProperty(this.el,(function(style){return"hidden"===style.overflow}));(isDeprecatedFloatMarkup||isOverflowHiddenMarkup)&&use_sticky_position&&console.log("Fixed Widget: fallback to position sticky"),this.isSticky=!isDeprecatedFloatMarkup&&!isOverflowHiddenMarkup&&use_sticky_position;var WidgetContructor=this.isSticky?StickyWidget:FixedWidget;this.stop_widgets=StopWidget.from(this.el),this.widgets=WidgetContructor.from(this.el),this.isSticky&&(this.el.style.position="relative",0===this.stop_widgets.length&&(this.el.style.minHeight="100%"))}return Sidebar.prototype.mount=function(){var _this=this;this.stop_widgets.forEach((function(widget){widget.mount()})),this.widgets.forEach((function(widget){widget.mount(_this.margins)}))},Sidebar.prototype.setMaxOffset=function(general_stop_widgets){var is_local_stop_widgets=0!=this.stop_widgets.length,use_top_offset=this.isSticky&&is_local_stop_widgets,stop_widgets=is_local_stop_widgets?this.stop_widgets:general_stop_widgets,max_top_offset=reactive((function(){if(0===stop_widgets.length)return Math.round(document.body.scrollHeight);for(var min_offset=use_top_offset?stop_widgets[0].top_offset:stop_widgets[0].root_offset,_i=0,stop_widgets_1=stop_widgets;_i<stop_widgets_1.length;_i++){var widget=stop_widgets_1[_i],offset=use_top_offset?widget.top_offset:widget.root_offset;min_offset>offset&&(min_offset=offset)}return Math.round(min_offset)}));max_top_offset.on_change(this.setWidgetsMaxOffset),this.setWidgetsMaxOffset(max_top_offset.val)},Sidebar.prototype.render=function(){for(var _i=0,_a=this.widgets;_i<_a.length;_i++){_a[_i].render()}},Sidebar}(),Sidebars=function(){function Sidebars(elements,options){var _this=this;this.data=[],this.render=function(){for(var _i=0,_a=_this.data;_i<_a.length;_i++){_a[_i].render()}},this.data=Array.from(new Set(elements.map((function(widget){return widget.parentElement})))).filter((function(sidebar_el){return null!==sidebar_el})).map((function(sidebar_el){return new Sidebar(sidebar_el,options,options.use_sticky_position)}))}return Sidebars.prototype.mount=function(){this.data.forEach((function(sidebar){sidebar.mount()})),this.setMaxOffset()},Sidebars.prototype.setMaxOffset=function(){for(var general_stop_widgets=this.getGeneralStopElements(),_i=0,_a=this.data;_i<_a.length;_i++){_a[_i].setMaxOffset(general_stop_widgets)}},Sidebars.prototype.getGeneralStopElements=function(){return this.data.filter((function(sidebar){return!sidebar.isSticky||0===sidebar.widgets.length})).map((function(sidebar){return sidebar.stop_widgets})).reduce((function(all,widgets){return all.concat(widgets)}),[])},Sidebars.new=function(options){var s,arr1,arr2,fixedWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(FixedWidgetClassName).concat(queryElements(compatabilty_FW_v5(options.widgets))))),stopWidgetsSelectors=compatabilty_FW_v5((void 0===(s=options.stop_elements_selectors||options.stop_id)&&(s=""),s.replace(/[\r\n]|[\r]/gi,"\n").split("\n").map((function(s){return s.trim()})).filter((function(s){return""!==s})))),stopWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(StopWidgetClassName).concat(queryElements(stopWidgetsSelectors)))),_a=(arr1=fixedWidgetsContainers,[(arr2=stopWidgetsContainers).filter((function(e){return!arr1.includes(e)})),arr1.filter((function(e){return arr2.includes(e)}))]),stopWidgetsUniqContainers=_a[0];return _a[1].forEach((function(w){console.error("The Widget is detected as fixed block and stop block!\n".concat(w.innerHTML))})),fixedWidgetsContainers.forEach((function(c){c.classList.add(FixedWidgetClassName)})),stopWidgetsUniqContainers.forEach((function(c){c.classList.add(StopWidgetClassName)})),new Sidebars(fixedWidgetsContainers.concat(stopWidgetsUniqContainers),options)},Sidebars}();function onDocumentLoaded(){var admin_panel=document.querySelector("#wpadminbar"),options=(window.q2w3_sidebar_options||[{}]).map((function(option){return option.margin_top=(option.margin_top||0)+(admin_panel&&admin_panel.clientHeight||0),option}));options.some((function(option){return window.innerWidth<option.screen_max_width||window.innerHeight<option.screen_max_height}))||function(options){void 0===options&&(options=[]),sidebars?sidebars.render():(sidebars=Sidebars.new(options.reduce((function(prev,cur){return __assign(__assign(__assign({},prev),cur),{widgets:prev.widgets.concat(cur.widgets||[])})}),{widgets:[]})),document.addEventListener("scroll",sidebars.render),sidebars.mount())}(options)}window.addEventListener("load",onDocumentLoaded),"complete"===document.readyState&&onDocumentLoaded(),onDocumentLoaded();
|
q2w3-fixed-widget.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: https://wpadvancedads.com/fixed-widget-wordpress/
|
|
5 |
Description: Use the fixed widget plugin to create sticky widgets that stay in the visible screen area when the page is scrolled up or down and boost your conversions.
|
6 |
Text Domain: q2w3-fixed-widget
|
7 |
Author: Thomas Maier, Max Bond
|
8 |
-
Version: 6.0.
|
9 |
Author URI: https://wpadvancedads.com/fixed-widget-wordpress/
|
10 |
*/
|
11 |
|
@@ -23,7 +23,7 @@ class q2w3_fixed_widget {
|
|
23 |
|
24 |
const ID = 'q2w3_fixed_widget';
|
25 |
|
26 |
-
const VERSION = '6.0.
|
27 |
|
28 |
protected static $sidebars_widgets;
|
29 |
|
5 |
Description: Use the fixed widget plugin to create sticky widgets that stay in the visible screen area when the page is scrolled up or down and boost your conversions.
|
6 |
Text Domain: q2w3-fixed-widget
|
7 |
Author: Thomas Maier, Max Bond
|
8 |
+
Version: 6.0.6
|
9 |
Author URI: https://wpadvancedads.com/fixed-widget-wordpress/
|
10 |
*/
|
11 |
|
23 |
|
24 |
const ID = 'q2w3_fixed_widget';
|
25 |
|
26 |
+
const VERSION = '6.0.6';
|
27 |
|
28 |
protected static $sidebars_widgets;
|
29 |
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: webzunft, max-bond, advancedads
|
|
3 |
Tags: fixed widget, sticky widget, sidebar, ads, widget, fixed, sticky, floating, sticky block, adsense
|
4 |
Requires at least: 5.0
|
5 |
Tested up to: 5.9
|
6 |
-
Stable tag: 6.0.
|
7 |
|
8 |
More attention and a higher ad performance with fixed sticky widgets.
|
9 |
|
@@ -91,6 +91,12 @@ Use the options `Minimum Screen Width` and `Minimum Screen Height` to disable st
|
|
91 |
|
92 |
== Changelog ==
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
= 6.0.5 =
|
95 |
|
96 |
- Fix: Prevent overlapping of fixed widgets with non-fixed widgets when scrolling up
|
3 |
Tags: fixed widget, sticky widget, sidebar, ads, widget, fixed, sticky, floating, sticky block, adsense
|
4 |
Requires at least: 5.0
|
5 |
Tested up to: 5.9
|
6 |
+
Stable tag: 6.0.6
|
7 |
|
8 |
More attention and a higher ad performance with fixed sticky widgets.
|
9 |
|
91 |
|
92 |
== Changelog ==
|
93 |
|
94 |
+
= 6.0.6 =
|
95 |
+
|
96 |
+
- Improvement: Compatibility with dynamically loaded content pages, i.e., infinite scroll
|
97 |
+
- Improvement: Compatibility with widgets that have large offsets
|
98 |
+
- Fix: Prevent padding from increasing on scroll
|
99 |
+
|
100 |
= 6.0.5 =
|
101 |
|
102 |
- Fix: Prevent overlapping of fixed widgets with non-fixed widgets when scrolling up
|