Q2W3 Fixed Widget - Version 6.0.1

Version Description

  • Fix: use the previous Stop ID value in the new Stop Elements section
Download this release

Release Info

Developer webzunft
Plugin Icon 128x128 Q2W3 Fixed Widget
Version 6.0.1
Comparing to
See all releases

Code changes from version 6.0.0 to 6.0.1

Files changed (4) hide show
  1. js/frontend.js +26 -12
  2. js/frontend.min.js +1 -1
  3. q2w3-fixed-widget.php +18 -4
  4. readme.txt +5 -1
js/frontend.js CHANGED
@@ -60,7 +60,7 @@ var Widget = /** @class */ (function () {
60
  if (!this.el || !this.el.parentElement) {
61
  return;
62
  }
63
- this.el.style.zIndex = "".concat(layer);
64
  this.top_offset = this.get_total_top_offset(user_margins);
65
  this.root_offset = scrollY + this.el.getBoundingClientRect().y;
66
  };
@@ -69,14 +69,14 @@ var Widget = /** @class */ (function () {
69
  };
70
  Widget.prototype.toString = function () {
71
  var _a;
72
- return "".concat((_a = this.el) === null || _a === void 0 ? void 0 : _a.innerHTML);
73
  };
74
  Widget.prototype.get_total_top_offset = function (margins) {
75
  return get_sibilings_offset(this.prevSibling, this.need_to_calc_el_offset, this.prevSibling(this.el), margins.margin_top);
76
  };
77
  Widget.queryAllWidgetsContainers = function (className) {
78
  return []
79
- .concat(Array.from(document.querySelectorAll(".".concat(className))), Array.from(document.querySelectorAll("[data-fixed_widget=".concat(className))))
80
  .map(function (el) {
81
  el.classList.remove(className);
82
  el.removeAttribute('data-fixed_widget');
@@ -88,7 +88,7 @@ var Widget = /** @class */ (function () {
88
  };
89
  Widget.from = function (root, className) {
90
  var _this = this;
91
- return Array.from(root.querySelectorAll(".".concat(className)))
92
  .filter(function (el) { return el !== null; })
93
  .map(function (e) { return new _this(e); });
94
  };
@@ -252,7 +252,7 @@ var FixedWidget = /** @class */ (function (_super) {
252
  if (!this.el) {
253
  return;
254
  }
255
- this.el.style.top = "".concat(top, "px");
256
  if (this.is_pinned) {
257
  return;
258
  }
@@ -304,7 +304,7 @@ var StickyWidget = /** @class */ (function (_super) {
304
  this.el.style.position = '-webkit-sticky';
305
  this.el.style.transition = 'transform 0s';
306
  this.el.style.boxSizing = 'border-box';
307
- this.el.style.top = "".concat(this.top_offset, "px");
308
  };
309
  StickyWidget.prototype.onScroll = function () {
310
  if (!this.el || !this.el.parentElement) {
@@ -317,7 +317,7 @@ var StickyWidget = /** @class */ (function (_super) {
317
  this.el.style.transform = "translateY(0px)";
318
  return;
319
  }
320
- this.el.style.transform = "translateY(".concat(bottom_margin - this.bottom_offset, "px)");
321
  };
322
  StickyWidget.new = function (selector) {
323
  return new StickyWidget(document.querySelector(selector));
@@ -366,27 +366,41 @@ var findIntersections = function (arr1, arr2) {
366
  ];
367
  };
368
  var splitSelectors = function (s) {
 
369
  return s.replace(/[\r\n]|[\r]/gi, '\n')
370
  .split('\n')
371
  .map(function (s) { return s.trim(); })
372
  .filter(function (s) { return s !== ''; });
373
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
374
 
375
  var initSidebars = function (options) {
376
  var fixedWidgetsContainers = Array.from(new Set(// use Set to remove duplicates
377
  Widget
378
  .queryAllWidgetsContainers(FixedWidgetClassName) // widgets by classNames from editor's plugin
379
- .concat(queryElements(options.widgets)) // widgets from option's custom selectors
380
  ));
 
381
  var stopWidgetsContainers = Array.from(new Set(// use Set to remove duplicates
382
  Widget
383
  .queryAllWidgetsContainers(StopWidgetClassName) // widgets by classNames from editor's plugin;
384
- .concat(options.stop_elements_selectors ?
385
- queryElements(splitSelectors(options.stop_elements_selectors)) // widgets from option's custom selectors
386
- : [])));
387
  var _a = findIntersections(fixedWidgetsContainers, stopWidgetsContainers), stopWidgetsUniqContainers = _a[0], duplicates = _a[1];
388
  duplicates.forEach(function (w) {
389
- console.error("The Widget is detected as fixed block and stop block!\n".concat(w.innerHTML));
390
  });
391
  fixedWidgetsContainers.forEach(function (c) { c.classList.add(FixedWidgetClassName); });
392
  stopWidgetsUniqContainers.forEach(function (c) { c.classList.add(StopWidgetClassName); });
60
  if (!this.el || !this.el.parentElement) {
61
  return;
62
  }
63
+ this.el.style.zIndex = "" + layer;
64
  this.top_offset = this.get_total_top_offset(user_margins);
65
  this.root_offset = scrollY + this.el.getBoundingClientRect().y;
66
  };
69
  };
70
  Widget.prototype.toString = function () {
71
  var _a;
72
+ return "" + ((_a = this.el) === null || _a === void 0 ? void 0 : _a.innerHTML);
73
  };
74
  Widget.prototype.get_total_top_offset = function (margins) {
75
  return get_sibilings_offset(this.prevSibling, this.need_to_calc_el_offset, this.prevSibling(this.el), margins.margin_top);
76
  };
77
  Widget.queryAllWidgetsContainers = function (className) {
78
  return []
79
+ .concat(Array.from(document.querySelectorAll("." + className)), Array.from(document.querySelectorAll("[data-fixed_widget=" + className)))
80
  .map(function (el) {
81
  el.classList.remove(className);
82
  el.removeAttribute('data-fixed_widget');
88
  };
89
  Widget.from = function (root, className) {
90
  var _this = this;
91
+ return Array.from(root.querySelectorAll("." + className))
92
  .filter(function (el) { return el !== null; })
93
  .map(function (e) { return new _this(e); });
94
  };
252
  if (!this.el) {
253
  return;
254
  }
255
+ this.el.style.top = top + "px";
256
  if (this.is_pinned) {
257
  return;
258
  }
304
  this.el.style.position = '-webkit-sticky';
305
  this.el.style.transition = 'transform 0s';
306
  this.el.style.boxSizing = 'border-box';
307
+ this.el.style.top = this.top_offset + "px";
308
  };
309
  StickyWidget.prototype.onScroll = function () {
310
  if (!this.el || !this.el.parentElement) {
317
  this.el.style.transform = "translateY(0px)";
318
  return;
319
  }
320
+ this.el.style.transform = "translateY(" + (bottom_margin - this.bottom_offset) + "px)";
321
  };
322
  StickyWidget.new = function (selector) {
323
  return new StickyWidget(document.querySelector(selector));
366
  ];
367
  };
368
  var splitSelectors = function (s) {
369
+ if (s === void 0) { s = ''; }
370
  return s.replace(/[\r\n]|[\r]/gi, '\n')
371
  .split('\n')
372
  .map(function (s) { return s.trim(); })
373
  .filter(function (s) { return s !== ''; });
374
  };
375
+ /**
376
+ * For compatabilty with Fixed Widget 5.3.0 (had a ids without #)
377
+ * Clone and add selectors with #-prefix
378
+ * @see https://github.com/webgilde/fixed-widget/issues/75
379
+ */
380
+ var compatabilty_FW_v5 = function (selectors) {
381
+ if (selectors === void 0) { selectors = []; }
382
+ /** If `selectors` includes extended selectors, not id names only, then it's v 6.0.0 */
383
+ if (selectors.some(function (s) { return !/^[a-z]/i.test(s); })) {
384
+ return selectors;
385
+ }
386
+ return selectors.concat(selectors.map(function (s) { return "#" + s; }));
387
+ };
388
 
389
  var initSidebars = function (options) {
390
  var fixedWidgetsContainers = Array.from(new Set(// use Set to remove duplicates
391
  Widget
392
  .queryAllWidgetsContainers(FixedWidgetClassName) // widgets by classNames from editor's plugin
393
+ .concat(queryElements(compatabilty_FW_v5(options.widgets))) // widgets from option's custom selectors
394
  ));
395
+ var stopWidgetsSelectors = compatabilty_FW_v5(splitSelectors(options.stop_elements_selectors));
396
  var stopWidgetsContainers = Array.from(new Set(// use Set to remove duplicates
397
  Widget
398
  .queryAllWidgetsContainers(StopWidgetClassName) // widgets by classNames from editor's plugin;
399
+ .concat(queryElements(stopWidgetsSelectors)) // widgets from option's custom selectors
400
+ ));
 
401
  var _a = findIntersections(fixedWidgetsContainers, stopWidgetsContainers), stopWidgetsUniqContainers = _a[0], duplicates = _a[1];
402
  duplicates.forEach(function (w) {
403
+ console.error("The Widget is detected as fixed block and stop block!\n" + w.innerHTML);
404
  });
405
  fixedWidgetsContainers.forEach(function (c) { c.classList.add(FixedWidgetClassName); });
406
  stopWidgetsUniqContainers.forEach(function (c) { c.classList.add(StopWidgetClassName); });
js/frontend.min.js CHANGED
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */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,layer,_max_top_offset){this.el&&this.el.parentElement&&(this.el.style.zIndex="".concat(layer),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;return Array.from(root.querySelectorAll(".".concat(className))).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.offsetHeight+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},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.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}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins,layer,max_top_offset){if(_super.prototype.mount.call(this,user_margins,layer),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=max_top_offset,this.borderBox=this.el.clientHeight+this.top_margin+this.bottom_margin}},PositionWidget.prototype.render=function(){if(this.el&&this.el.parentElement){var scrollTop=scrollY;this.onScroll(scrollTop)}},PositionWidget.from=function(root){return _super.from.call(this,root,FixedWidgetClassName)},PositionWidget.prototype.onScroll=function(_scrollTop){},PositionWidget.prototype.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)},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.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,layer,max_top_offset){_super.prototype.mount.call(this,margins,layer,max_top_offset),this.el&&(max_top_offset<this.root_offset&&(this.max_top_offset=0),this.relative_top=this.max_top_offset-this.top_offset-this.borderBox-this.bottom_offset,this.store_style(getComputedStyle(this.el)),this.clone())},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.onScroll=function(scrollTop){if(this.el){var need_to_fix=scrollTop>this.root_offset-this.top_offset,top=0!==this.max_top_offset&&scrollTop>this.relative_top?this.relative_top-scrollTop+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.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,layer,max_top_offset){_super.prototype.mount.call(this,margins,layer,max_top_offset),this.el&&this.el.parentElement&&(max_top_offset<this.el.offsetTop&&(this.max_top_offset=0),this.margins=this.el.parentElement.clientHeight-this.borderBox,this.el.style.position="sticky",this.el.style.position="-webkit-sticky",this.el.style.transition="transform 0s",this.el.style.boxSizing="border-box",this.el.style.top="".concat(this.top_offset,"px"))},StickyWidget.prototype.onScroll=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;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.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){this.el=el,this.margins=margins,this.use_sticky_position=use_sticky_position,this.widgets=[],this.stop_widgets=[],this.min_top_offset=0,this.stop_widgets=StopWidget.from(this.el);var WidgetContructor=void 0===use_sticky_position||use_sticky_position?StickyWidget:FixedWidget;this.widgets=WidgetContructor.from(this.el),use_sticky_position&&(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,i){return widget.mount({},0,0)})),this.min_top_offset=0!==this.stop_widgets.length?Math.min.apply(Math,this.stop_widgets.map(this.use_sticky_position?function(w){return w.top_offset}:function(w){return w.root_offset})):0,this.widgets.forEach((function(widget,i){return widget.mount(_this.margins,i,_this.min_top_offset)}))},Sidebar.prototype.render=function(){this.widgets.forEach((function(widget){return widget.render()}))},Sidebar.create=function(elements,options){return 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,void 0===options.use_sticky_position||options.use_sticky_position)}))},Sidebar}(),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}))},initPlugin=function(options){void 0===options&&(options=[]),function(options){var arr1,arr2,fixedWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(FixedWidgetClassName).concat(queryElements(options.widgets)))),stopWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(StopWidgetClassName).concat(options.stop_elements_selectors?queryElements(options.stop_elements_selectors.replace(/[\r\n]|[\r]/gi,"\n").split("\n").map((function(s){return s.trim()})).filter((function(s){return""!==s}))):[]))),_a=(arr1=fixedWidgetsContainers,[(arr2=stopWidgetsContainers).filter((function(e){return!arr1.includes(e)})),arr1.filter((function(e){return arr2.includes(e)}))]),stopWidgetsUniqContainers=_a[0];_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)}));var sidebars=Sidebar.create(fixedWidgetsContainers.concat(stopWidgetsUniqContainers),options);sidebars.forEach((function(sidebar){sidebar.mount()})),document.addEventListener("scroll",(function(){sidebars.forEach((function(sidebar){return sidebar.render()}))}))}(options.reduce((function(prev,cur){return __assign(__assign(__assign({},prev),cur),{widgets:prev.widgets.concat(cur.widgets||[])})}),{widgets:[]}))};function onDocumentLoaded(){var admin_panel=document.querySelector("#wpadminbar"),options=(window.q2w3_sidebar_options||[{}]).map((function(option){return option.margin_top=(option.margin_top||0)+((null==admin_panel?void 0:admin_panel.clientHeight)||0),option}));options.some((function(option){return window.innerWidth<option.screen_max_width||window.innerHeight<option.screen_max_height}))||initPlugin(options)}window.addEventListener("load",onDocumentLoaded),"complete"===document.readyState&&onDocumentLoaded();
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
  PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */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,layer,_max_top_offset){this.el&&this.el.parentElement&&(this.el.style.zIndex=""+layer,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""+(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("."+className)),Array.from(document.querySelectorAll("[data-fixed_widget="+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;return Array.from(root.querySelectorAll("."+className)).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.offsetHeight+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},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.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}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins,layer,max_top_offset){if(_super.prototype.mount.call(this,user_margins,layer),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=max_top_offset,this.borderBox=this.el.clientHeight+this.top_margin+this.bottom_margin}},PositionWidget.prototype.render=function(){if(this.el&&this.el.parentElement){var scrollTop=scrollY;this.onScroll(scrollTop)}},PositionWidget.from=function(root){return _super.from.call(this,root,FixedWidgetClassName)},PositionWidget.prototype.onScroll=function(_scrollTop){},PositionWidget.prototype.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)},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.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,layer,max_top_offset){_super.prototype.mount.call(this,margins,layer,max_top_offset),this.el&&(max_top_offset<this.root_offset&&(this.max_top_offset=0),this.relative_top=this.max_top_offset-this.top_offset-this.borderBox-this.bottom_offset,this.store_style(getComputedStyle(this.el)),this.clone())},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.onScroll=function(scrollTop){if(this.el){var need_to_fix=scrollTop>this.root_offset-this.top_offset,top=0!==this.max_top_offset&&scrollTop>this.relative_top?this.relative_top-scrollTop+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=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.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,layer,max_top_offset){_super.prototype.mount.call(this,margins,layer,max_top_offset),this.el&&this.el.parentElement&&(max_top_offset<this.el.offsetTop&&(this.max_top_offset=0),this.margins=this.el.parentElement.clientHeight-this.borderBox,this.el.style.position="sticky",this.el.style.position="-webkit-sticky",this.el.style.transition="transform 0s",this.el.style.boxSizing="border-box",this.el.style.top=this.top_offset+"px")},StickyWidget.prototype.onScroll=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;bottom_margin>=this.bottom_offset?this.el.style.transform="translateY(0px)":this.el.style.transform="translateY("+(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.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),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"#"+s})))},Sidebar=function(){function Sidebar(el,margins,use_sticky_position){this.el=el,this.margins=margins,this.use_sticky_position=use_sticky_position,this.widgets=[],this.stop_widgets=[],this.min_top_offset=0,this.stop_widgets=StopWidget.from(this.el);var WidgetContructor=void 0===use_sticky_position||use_sticky_position?StickyWidget:FixedWidget;this.widgets=WidgetContructor.from(this.el),use_sticky_position&&(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,i){return widget.mount({},0,0)})),this.min_top_offset=0!==this.stop_widgets.length?Math.min.apply(Math,this.stop_widgets.map(this.use_sticky_position?function(w){return w.top_offset}:function(w){return w.root_offset})):0,this.widgets.forEach((function(widget,i){return widget.mount(_this.margins,i,_this.min_top_offset)}))},Sidebar.prototype.render=function(){this.widgets.forEach((function(widget){return widget.render()}))},Sidebar.create=function(elements,options){return 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,void 0===options.use_sticky_position||options.use_sticky_position)}))},Sidebar}(),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}))},initPlugin=function(options){void 0===options&&(options=[]),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)&&(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];_a[1].forEach((function(w){console.error("The Widget is detected as fixed block and stop block!\n"+w.innerHTML)})),fixedWidgetsContainers.forEach((function(c){c.classList.add(FixedWidgetClassName)})),stopWidgetsUniqContainers.forEach((function(c){c.classList.add(StopWidgetClassName)}));var sidebars=Sidebar.create(fixedWidgetsContainers.concat(stopWidgetsUniqContainers),options);sidebars.forEach((function(sidebar){sidebar.mount()})),document.addEventListener("scroll",(function(){sidebars.forEach((function(sidebar){return sidebar.render()}))}))}(options.reduce((function(prev,cur){return __assign(__assign(__assign({},prev),cur),{widgets:prev.widgets.concat(cur.widgets||[])})}),{widgets:[]}))};function onDocumentLoaded(){var admin_panel=document.querySelector("#wpadminbar"),options=(window.q2w3_sidebar_options||[{}]).map((function(option){return option.margin_top=(option.margin_top||0)+((null==admin_panel?void 0:admin_panel.clientHeight)||0),option}));options.some((function(option){return window.innerWidth<option.screen_max_width||window.innerHeight<option.screen_max_height}))||initPlugin(options)}window.addEventListener("load",onDocumentLoaded),"complete"===document.readyState&&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.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.0';
27
 
28
  protected static $sidebars_widgets;
29
 
@@ -121,7 +121,7 @@ class q2w3_fixed_widget {
121
  'use_sticky_position' => $use_sticky_position,
122
  'margin_top' => $options['margin-top'],
123
  'margin_bottom' => $options['margin-bottom'],
124
- 'stop_elements_selectors' => $options['stop_elements_selectors'],
125
  'screen_max_width' => $options['screen-max-width'],
126
  'screen_max_height' => $options['screen-max-height'],
127
  'widgets' => array_values( $widgets ),
@@ -449,6 +449,16 @@ class q2w3_fixed_widget {
449
  */
450
  public static function settings_page_custom_ids_box( $options ) {
451
  $custom_ids = isset( $options['custom-ids'] ) ? $options['custom-ids'] : '';
 
 
 
 
 
 
 
 
 
 
452
  echo '<p><span >' . esc_html__( 'Add HTML element selectors that should be fixed.', 'q2w3-fixed-widget' ) . ' ' . esc_html__( 'Accepts IDs, Class, and Type selectors.', 'q2w3-fixed-widget' ) . ' ' . esc_html__( 'One entry per line.', 'q2w3-fixed-widget' ) . '</span><br/><br/><textarea name="' . esc_attr( self::ID ) . '[custom-ids]" style="width: 320px; height: 120px;" placeholder="' .
453
  "#main-navigation\n.custom-fixed-element"
454
  .'">' . esc_html( $custom_ids ) . '</textarea>' . PHP_EOL;
@@ -460,9 +470,13 @@ class q2w3_fixed_widget {
460
  * @param array $options plugin settings.
461
  */
462
  public static function settings_page_stop_element( $options ) {
 
 
 
 
463
  echo '<p><span style="display: inline-block; width: 150px;">' . esc_html__( 'Margin Top', 'q2w3-fixed-widget' ) . '</span><input type="text" name="' . esc_attr( self::ID ) . '[margin-top]" value="' . esc_attr( $options['margin-top'] ) . '" style="width: 50px; text-align: center;" />&nbsp;' . esc_html__( 'px', 'q2w3-fixed-widget' ) . ' / ' . esc_html__( 'The distance fixed elements will keep from the top of the window.', 'q2w3-fixed-widget' ) . '</p>' . PHP_EOL;
464
  echo '<p><span style="display: inline-block; width: 150px;">' . esc_html__( 'Margin Bottom', 'q2w3-fixed-widget' ) . '</span><input type="text" name="' . esc_attr( self::ID ) . '[margin-bottom]" value="' . esc_attr( $options['margin-bottom'] ) . '" style="width: 50px; text-align: center;" />&nbsp;' . esc_html__( 'px', 'q2w3-fixed-widget' ) . ' / ' . esc_html__( 'The distance fixed elements will keep from the bottom of the window.', 'q2w3-fixed-widget' ) . '</p>' . PHP_EOL;
465
- echo '<div style="display:flex"><p><span style="display: inline-block; width: 150px;">' . esc_html__( 'Stop Elements', 'q2w3-fixed-widget' ) . '</span></p><textarea name="' . esc_attr( self::ID ) . '[stop_elements_selectors]" style="width: 150px;" placeholder="'. "#footer\nfooter" .'">' . esc_html( $options['stop_elements_selectors']) . '</textarea> <div style="padding:5px">' . esc_html__( 'The stop elements will push sticky elements up as soon as they reach them while scrolling.', 'q2w3-fixed-widget' )
466
  . '<br/>' . esc_html__( 'Accepts IDs, Class, and Type selectors.', 'q2w3-fixed-widget' ) . ' ' . esc_html__( 'One entry per line.', 'q2w3-fixed-widget' ) . '</div></div>' . PHP_EOL;
467
  }
468
 
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.1
9
  Author URI: https://wpadvancedads.com/fixed-widget-wordpress/
10
  */
11
 
23
 
24
  const ID = 'q2w3_fixed_widget';
25
 
26
+ const VERSION = '6.0.1';
27
 
28
  protected static $sidebars_widgets;
29
 
121
  'use_sticky_position' => $use_sticky_position,
122
  'margin_top' => $options['margin-top'],
123
  'margin_bottom' => $options['margin-bottom'],
124
+ 'stop_elements_selectors' => isset($options['stop-id']) && $options['stop-id'] != '' && (!isset($options['stop_elements_selectors']) || $options['stop_elements_selectors'] == '') ? $options['stop-id']: $options['stop_elements_selectors'],
125
  'screen_max_width' => $options['screen-max-width'],
126
  'screen_max_height' => $options['screen-max-height'],
127
  'widgets' => array_values( $widgets ),
449
  */
450
  public static function settings_page_custom_ids_box( $options ) {
451
  $custom_ids = isset( $options['custom-ids'] ) ? $options['custom-ids'] : '';
452
+ $ids = explode( PHP_EOL, $custom_ids );
453
+ $custom_ids = '';
454
+ foreach ( $ids as $id ) {
455
+ $id = trim( $id );
456
+ if ( strpos( $id, "#" ) === 0 ) {
457
+ $custom_ids = $custom_ids . PHP_EOL . $id;
458
+ } else if ( $id != '') {
459
+ $custom_ids = $custom_ids . PHP_EOL . '#' . $id;
460
+ }
461
+ }
462
  echo '<p><span >' . esc_html__( 'Add HTML element selectors that should be fixed.', 'q2w3-fixed-widget' ) . ' ' . esc_html__( 'Accepts IDs, Class, and Type selectors.', 'q2w3-fixed-widget' ) . ' ' . esc_html__( 'One entry per line.', 'q2w3-fixed-widget' ) . '</span><br/><br/><textarea name="' . esc_attr( self::ID ) . '[custom-ids]" style="width: 320px; height: 120px;" placeholder="' .
463
  "#main-navigation\n.custom-fixed-element"
464
  .'">' . esc_html( $custom_ids ) . '</textarea>' . PHP_EOL;
470
  * @param array $options plugin settings.
471
  */
472
  public static function settings_page_stop_element( $options ) {
473
+ $stop_selectors =
474
+ isset($options['stop-id']) && $options['stop-id'] != '' && (!isset($options['stop_elements_selectors']) || $options['stop_elements_selectors'] == '')
475
+ ? '#' . $options['stop-id'] : $options['stop_elements_selectors'];
476
+
477
  echo '<p><span style="display: inline-block; width: 150px;">' . esc_html__( 'Margin Top', 'q2w3-fixed-widget' ) . '</span><input type="text" name="' . esc_attr( self::ID ) . '[margin-top]" value="' . esc_attr( $options['margin-top'] ) . '" style="width: 50px; text-align: center;" />&nbsp;' . esc_html__( 'px', 'q2w3-fixed-widget' ) . ' / ' . esc_html__( 'The distance fixed elements will keep from the top of the window.', 'q2w3-fixed-widget' ) . '</p>' . PHP_EOL;
478
  echo '<p><span style="display: inline-block; width: 150px;">' . esc_html__( 'Margin Bottom', 'q2w3-fixed-widget' ) . '</span><input type="text" name="' . esc_attr( self::ID ) . '[margin-bottom]" value="' . esc_attr( $options['margin-bottom'] ) . '" style="width: 50px; text-align: center;" />&nbsp;' . esc_html__( 'px', 'q2w3-fixed-widget' ) . ' / ' . esc_html__( 'The distance fixed elements will keep from the bottom of the window.', 'q2w3-fixed-widget' ) . '</p>' . PHP_EOL;
479
+ echo '<div style="display:flex"><p><span style="display: inline-block; width: 150px;">' . esc_html__( 'Stop Elements', 'q2w3-fixed-widget' ) . '</span></p><textarea name="' . esc_attr( self::ID ) . '[stop_elements_selectors]" style="width: 150px;" placeholder="'. "#footer\nfooter" .'">' . esc_html( $stop_selectors ) . '</textarea> <div style="padding:5px">' . esc_html__( 'The stop elements will push sticky elements up as soon as they reach them while scrolling.', 'q2w3-fixed-widget' )
480
  . '<br/>' . esc_html__( 'Accepts IDs, Class, and Type selectors.', 'q2w3-fixed-widget' ) . ' ' . esc_html__( 'One entry per line.', 'q2w3-fixed-widget' ) . '</div></div>' . PHP_EOL;
481
  }
482
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: webzunft, max-bond, advancedads
3
  Tags: fixed widget, sticky widget, sidebar, ads, widget
4
  Requires at least: 5.0
5
  Tested up to: 5.9
6
- Stable tag: 6.0.0
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
@@ -91,6 +91,10 @@ Use the options `Minimum Screen Width` and `Minimum Screen Height` to disable st
91
 
92
  == Changelog ==
93
 
 
 
 
 
94
  = 6.0.0 =
95
 
96
  Version 6.0.0 is a full rewrite of the frontend script. It fixes many edge cases like jumping, reloading, or resizing widgets.
3
  Tags: fixed widget, sticky widget, sidebar, ads, widget
4
  Requires at least: 5.0
5
  Tested up to: 5.9
6
+ Stable tag: 6.0.1
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
91
 
92
  == Changelog ==
93
 
94
+ = 6.0.1 =
95
+
96
+ - Fix: use the previous Stop ID value in the new Stop Elements section
97
+
98
  = 6.0.0 =
99
 
100
  Version 6.0.0 is a full rewrite of the frontend script. It fixes many edge cases like jumping, reloading, or resizing widgets.