Q2W3 Fixed Widget - Version 6.1.0

Version Description

  • Feature: Add the FixedWidget__fixed_widget__pinned class to the fixed widget while it is sticky and remove it when it is unfixed. This allows users to apply their own styling only during a fixed state.
  • Improvement: rename "Test new version" option into "Improved version" and changed the option description to make it more clear that both script versions will be kept.
  • Improvement: change "Fixed Widget Options" menu item into "Fixed Widget"
  • Improvement: Handle edge cases where the Minimum Width option doesnt work for specific themes
Download this release

Release Info

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

Code changes from version 6.0.7 to 6.1.0

Files changed (4) hide show
  1. js/frontend.js +69 -35
  2. js/frontend.min.js +1 -1
  3. q2w3-fixed-widget.php +11 -9
  4. readme.txt +19 -22
js/frontend.js CHANGED
@@ -72,13 +72,15 @@ var StaticOffsets = (function () {
72
  this.get_top_offset = function () {
73
  return _this.get_sibilings_offset(_this.get_prev_sibling, _this.get_prev_sibling(_this.el), _this.user_margins.margin_top);
74
  };
75
- reactive(this.get_root_offset).on_change(function (root) {
76
- _this.root = root;
77
- });
78
  reactive(this.get_top_offset).on_change(function (top) {
79
  _this.top = top;
80
  });
 
 
 
81
  }
 
 
82
  StaticOffsets.prototype.get_sibilings_offset = function (next, el, offset) {
83
  if (offset === void 0) { offset = 0; }
84
  if (!el) {
@@ -118,7 +120,6 @@ var DynamicOffsets = (function (_super) {
118
  reactive(_this.get_height).on_change(function (height) {
119
  _this.height = height;
120
  _this.border_box = _this.get_border_box();
121
- _this.position = _this.get_position();
122
  _this.relative_top = _this.get_relative_top();
123
  });
124
  reactive(_this.get_bottom_offset).on_change(function (bottom) {
@@ -127,6 +128,9 @@ var DynamicOffsets = (function (_super) {
127
  });
128
  return _this;
129
  }
 
 
 
130
  DynamicOffsets.prototype.setMaxOffset = function (max_top_offset) {
131
  this.max_top_offset = max_top_offset;
132
  this.relative_top = this.get_relative_top();
@@ -155,6 +159,7 @@ var DynamicOffsets = (function (_super) {
155
 
156
  var StopWidgetClassName = 'FixedWidget__stop_widget';
157
  var FixedWidgetClassName = 'FixedWidget__fixed_widget';
 
158
  var Widget = (function () {
159
  function Widget(el) {
160
  var _this = this;
@@ -164,7 +169,7 @@ var Widget = (function () {
164
  this.offsets = new StaticOffsets();
165
  }
166
  Widget.prototype.render = function () {
167
- throw new Error('Method is not overridden!');
168
  };
169
  Widget.prototype.mount = function (user_margins) {
170
  if (user_margins === void 0) { user_margins = {}; }
@@ -256,6 +261,7 @@ var PositionWidget = (function (_super) {
256
  __extends(PositionWidget, _super);
257
  function PositionWidget() {
258
  var _this = _super !== null && _super.apply(this, arguments) || this;
 
259
  _this.offsets = new DynamicOffsets();
260
  _this.get_prev_sibling = function (el) {
261
  return el
@@ -277,7 +283,8 @@ var PositionWidget = (function (_super) {
277
  this.offsets.setMaxOffset(max_top_offset);
278
  };
279
  PositionWidget.prototype.render = function () {
280
- this.on_scroll(scrollY);
 
281
  };
282
  PositionWidget.from = function (root) {
283
  return _super.from.call(this, root, FixedWidgetClassName);
@@ -285,6 +292,20 @@ var PositionWidget = (function (_super) {
285
  PositionWidget.prototype.on_scroll = function (_scroll_top) {
286
  throw new Error('Method is not overridden!');
287
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  return PositionWidget;
289
  }(Widget));
290
 
@@ -292,7 +313,6 @@ var FixedWidget = (function (_super) {
292
  __extends(FixedWidget, _super);
293
  function FixedWidget(el) {
294
  var _this = _super.call(this, el) || this;
295
- _this.is_pinned = false;
296
  _this.init_style = {
297
  position: 'static',
298
  marginBottom: '',
@@ -302,9 +322,15 @@ var FixedWidget = (function (_super) {
302
  width: '',
303
  };
304
  _this.get_root_offset = function () {
305
- var element = _this.is_pinned ? _this.clone_el : _this.el;
306
- var new_root_offset = Math.round(scrollY + (element ? element.getBoundingClientRect().top : 0));
307
- return _this.is_pinned ? new_root_offset : Math.max(_this.offsets.root, new_root_offset);
 
 
 
 
 
 
308
  };
309
  _this.need_to_calc_el_offset = function (el) {
310
  return el.classList.contains(FixedWidgetClassName);
@@ -364,7 +390,7 @@ var FixedWidget = (function (_super) {
364
  if (!this.is_pinned) {
365
  return;
366
  }
367
- this.is_pinned = false;
368
  style.position = this.init_style.position;
369
  if (this.clone_el) {
370
  this.clone_el.style.display = 'none';
@@ -389,7 +415,7 @@ var FixedWidget = (function (_super) {
389
  if (this.is_pinned) {
390
  return;
391
  }
392
- this.is_pinned = true;
393
  this.el.style.position = 'fixed';
394
  this.el.style.transition = 'transform 0.5s';
395
  this.el.style.width = this.init_style.width;
@@ -447,15 +473,17 @@ var StickyWidget = (function (_super) {
447
  if (!this.el || !this.el.parentElement) {
448
  return;
449
  }
450
- var bottom = this.offsets.max_top_offset ?
451
- Math.min(this.offsets.max_top_offset - (this.el.parentElement.clientHeight - this.offsets.position.bottom), this.offsets.bottom)
 
 
452
  : this.offsets.bottom;
453
  this.el.style.top = "".concat(this.offsets.top, "px");
454
- if (bottom >= this.offsets.bottom) {
455
  this.el.style.transform = "translateY(0px)";
456
  return;
457
  }
458
- this.el.style.transform = "translateY(".concat(bottom - this.offsets.bottom, "px)");
459
  };
460
  StickyWidget.new = function (selector) {
461
  return new StickyWidget(document.querySelector(selector));
@@ -505,6 +533,7 @@ var Sidebar = (function () {
505
  var widget = _a[_i];
506
  widget.setMaxOffset(max_offset);
507
  }
 
508
  };
509
  var isDeprecatedFloatMarkup = !!findWithProperty(this.el, function (style) { return style.float !== 'none'; });
510
  var isOverflowHiddenMarkup = !!findWithProperty(this.el, function (style) { return style.overflow === 'hidden'; });
@@ -535,7 +564,7 @@ var Sidebar = (function () {
535
  var is_local_stop_widgets = this.stop_widgets.length != 0;
536
  var use_top_offset = this.isSticky && is_local_stop_widgets;
537
  var stop_widgets = is_local_stop_widgets ? this.stop_widgets : general_stop_widgets;
538
- var max_top_offset = reactive(function () {
539
  if (stop_widgets.length === 0) {
540
  return Math.round(document.body.scrollHeight);
541
  }
@@ -550,13 +579,15 @@ var Sidebar = (function () {
550
  }
551
  }
552
  return Math.round(min_offset);
553
- });
554
- max_top_offset.on_change(this.setWidgetsMaxOffset);
555
- this.setWidgetsMaxOffset(max_top_offset.val);
556
  };
557
  Sidebar.prototype.render = function () {
558
- for (var _i = 0, _a = this.widgets; _i < _a.length; _i++) {
559
- var widget = _a[_i];
 
 
 
 
560
  widget.render();
561
  }
562
  };
@@ -616,17 +647,20 @@ var Sidebars = (function () {
616
  return Sidebars;
617
  }());
618
 
619
- var sidebars;
620
- var initPlugin = function (options) {
621
- if (options === void 0) { options = []; }
622
- if (sidebars) {
623
- sidebars.render();
624
- return;
 
 
 
 
 
625
  }
626
- sidebars = Sidebars.new(options.reduce(function (prev, cur) { return (__assign(__assign(__assign({}, prev), cur), { widgets: prev.widgets.concat(cur.widgets || []) })); }, { widgets: [] }));
627
- document.addEventListener('scroll', sidebars.render);
628
- sidebars.mount();
629
- };
630
 
631
  window.addEventListener('load', onDocumentLoaded);
632
  document.readyState === "complete" && onDocumentLoaded();
@@ -639,10 +673,10 @@ function onDocumentLoaded() {
639
  return option;
640
  });
641
  if (options.some(function (option) {
642
- return window.innerWidth < option.screen_max_width ||
643
- window.innerHeight < option.screen_max_height;
644
  })) {
645
  return;
646
  }
647
- initPlugin(options);
648
  }
72
  this.get_top_offset = function () {
73
  return _this.get_sibilings_offset(_this.get_prev_sibling, _this.get_prev_sibling(_this.el), _this.user_margins.margin_top);
74
  };
 
 
 
75
  reactive(this.get_top_offset).on_change(function (top) {
76
  _this.top = top;
77
  });
78
+ reactive(this.get_root_offset).on_change(function (root) {
79
+ _this.root = root;
80
+ });
81
  }
82
+ StaticOffsets.prototype.update = function () {
83
+ };
84
  StaticOffsets.prototype.get_sibilings_offset = function (next, el, offset) {
85
  if (offset === void 0) { offset = 0; }
86
  if (!el) {
120
  reactive(_this.get_height).on_change(function (height) {
121
  _this.height = height;
122
  _this.border_box = _this.get_border_box();
 
123
  _this.relative_top = _this.get_relative_top();
124
  });
125
  reactive(_this.get_bottom_offset).on_change(function (bottom) {
128
  });
129
  return _this;
130
  }
131
+ DynamicOffsets.prototype.update = function () {
132
+ this.position = this.get_position();
133
+ };
134
  DynamicOffsets.prototype.setMaxOffset = function (max_top_offset) {
135
  this.max_top_offset = max_top_offset;
136
  this.relative_top = this.get_relative_top();
159
 
160
  var StopWidgetClassName = 'FixedWidget__stop_widget';
161
  var FixedWidgetClassName = 'FixedWidget__fixed_widget';
162
+ var FixedWidgetPinnedClassName = 'FixedWidget__fixed_widget__pinned';
163
  var Widget = (function () {
164
  function Widget(el) {
165
  var _this = this;
169
  this.offsets = new StaticOffsets();
170
  }
171
  Widget.prototype.render = function () {
172
+ this.offsets.update();
173
  };
174
  Widget.prototype.mount = function (user_margins) {
175
  if (user_margins === void 0) { user_margins = {}; }
261
  __extends(PositionWidget, _super);
262
  function PositionWidget() {
263
  var _this = _super !== null && _super.apply(this, arguments) || this;
264
+ _this.is_pinned = false;
265
  _this.offsets = new DynamicOffsets();
266
  _this.get_prev_sibling = function (el) {
267
  return el
283
  this.offsets.setMaxOffset(max_top_offset);
284
  };
285
  PositionWidget.prototype.render = function () {
286
+ _super.prototype.render.call(this);
287
+ this.on_scroll(Math.round(scrollY));
288
  };
289
  PositionWidget.from = function (root) {
290
  return _super.from.call(this, root, FixedWidgetClassName);
292
  PositionWidget.prototype.on_scroll = function (_scroll_top) {
293
  throw new Error('Method is not overridden!');
294
  };
295
+ PositionWidget.prototype.pin = function () {
296
+ if (this.is_pinned) {
297
+ return;
298
+ }
299
+ this.is_pinned = true;
300
+ this.el && this.el.classList.add(FixedWidgetPinnedClassName);
301
+ };
302
+ PositionWidget.prototype.unpin = function () {
303
+ if (!this.is_pinned) {
304
+ return;
305
+ }
306
+ this.is_pinned = false;
307
+ this.el && this.el.classList.remove(FixedWidgetPinnedClassName);
308
+ };
309
  return PositionWidget;
310
  }(Widget));
311
 
313
  __extends(FixedWidget, _super);
314
  function FixedWidget(el) {
315
  var _this = _super.call(this, el) || this;
 
316
  _this.init_style = {
317
  position: 'static',
318
  marginBottom: '',
322
  width: '',
323
  };
324
  _this.get_root_offset = function () {
325
+ if (!_this.el) {
326
+ return Number.MAX_VALUE;
327
+ }
328
+ var top = _this.el.getBoundingClientRect().top;
329
+ var new_root_offset = Math.round(scrollY + top);
330
+ if (top < 0) {
331
+ return new_root_offset;
332
+ }
333
+ return (_this.is_pinned ? Math.min : Math.max)(_this.offsets.root, new_root_offset);
334
  };
335
  _this.need_to_calc_el_offset = function (el) {
336
  return el.classList.contains(FixedWidgetClassName);
390
  if (!this.is_pinned) {
391
  return;
392
  }
393
+ this.unpin();
394
  style.position = this.init_style.position;
395
  if (this.clone_el) {
396
  this.clone_el.style.display = 'none';
415
  if (this.is_pinned) {
416
  return;
417
  }
418
+ this.pin();
419
  this.el.style.position = 'fixed';
420
  this.el.style.transition = 'transform 0.5s';
421
  this.el.style.width = this.init_style.width;
473
  if (!this.el || !this.el.parentElement) {
474
  return;
475
  }
476
+ (this.offsets.position.top > this.offsets.top) ? this.pin() : this.unpin();
477
+ var actual_bottom = this.offsets.position.bottom;
478
+ var expected_bottom = this.offsets.max_top_offset ?
479
+ Math.min(this.offsets.max_top_offset - (this.el.parentElement.clientHeight - actual_bottom), actual_bottom)
480
  : this.offsets.bottom;
481
  this.el.style.top = "".concat(this.offsets.top, "px");
482
+ if (expected_bottom >= this.offsets.bottom) {
483
  this.el.style.transform = "translateY(0px)";
484
  return;
485
  }
486
+ this.el.style.transform = "translateY(".concat(expected_bottom - this.offsets.bottom, "px)");
487
  };
488
  StickyWidget.new = function (selector) {
489
  return new StickyWidget(document.querySelector(selector));
533
  var widget = _a[_i];
534
  widget.setMaxOffset(max_offset);
535
  }
536
+ _this.render();
537
  };
538
  var isDeprecatedFloatMarkup = !!findWithProperty(this.el, function (style) { return style.float !== 'none'; });
539
  var isOverflowHiddenMarkup = !!findWithProperty(this.el, function (style) { return style.overflow === 'hidden'; });
564
  var is_local_stop_widgets = this.stop_widgets.length != 0;
565
  var use_top_offset = this.isSticky && is_local_stop_widgets;
566
  var stop_widgets = is_local_stop_widgets ? this.stop_widgets : general_stop_widgets;
567
+ reactive(function () {
568
  if (stop_widgets.length === 0) {
569
  return Math.round(document.body.scrollHeight);
570
  }
579
  }
580
  }
581
  return Math.round(min_offset);
582
+ }).on_change(this.setWidgetsMaxOffset);
 
 
583
  };
584
  Sidebar.prototype.render = function () {
585
+ for (var _i = 0, _a = this.stop_widgets; _i < _a.length; _i++) {
586
+ var stop_widget = _a[_i];
587
+ stop_widget.render();
588
+ }
589
+ for (var _b = 0, _c = this.widgets; _b < _c.length; _b++) {
590
+ var widget = _c[_b];
591
  widget.render();
592
  }
593
  };
647
  return Sidebars;
648
  }());
649
 
650
+ var Plugin = (function () {
651
+ function Plugin(options, version) {
652
+ if (options === void 0) { options = []; }
653
+ Plugin.version = version;
654
+ if (Plugin.sidebars) {
655
+ Plugin.sidebars.render();
656
+ return;
657
+ }
658
+ Plugin.sidebars = Sidebars.new(options.reduce(function (prev, cur) { return (__assign(__assign(__assign({}, prev), cur), { widgets: prev.widgets.concat(cur.widgets || []) })); }, { widgets: [] }));
659
+ document.addEventListener('scroll', Plugin.sidebars.render);
660
+ Plugin.sidebars.mount();
661
  }
662
+ return Plugin;
663
+ }());
 
 
664
 
665
  window.addEventListener('load', onDocumentLoaded);
666
  document.readyState === "complete" && onDocumentLoaded();
673
  return option;
674
  });
675
  if (options.some(function (option) {
676
+ return document.body.clientWidth < option.screen_max_width ||
677
+ document.body.clientHeight < option.screen_max_height;
678
  })) {
679
  return;
680
  }
681
+ new Plugin(options, '6.0.7-3');
682
  }
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)},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)}}},StaticOffsets=function(){function StaticOffsets(el,user_margins,get_root_offset,need_to_calc_offset,get_prev_sibling){void 0===el&&(el=null),void 0===user_margins&&(user_margins={}),void 0===get_root_offset&&(get_root_offset=function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))}),void 0===need_to_calc_offset&&(need_to_calc_offset=function(){return!1}),void 0===get_prev_sibling&&(get_prev_sibling=function(){return null});var _this=this;this.el=el,this.user_margins=user_margins,this.get_root_offset=get_root_offset,this.need_to_calc_offset=need_to_calc_offset,this.get_prev_sibling=get_prev_sibling,this.root=0,this.top=0,this.get_top_offset=function(){return _this.get_sibilings_offset(_this.get_prev_sibling,_this.get_prev_sibling(_this.el),_this.user_margins.margin_top)},reactive(this.get_root_offset).on_change((function(root){_this.root=root})),reactive(this.get_top_offset).on_change((function(top){_this.top=top}))}return StaticOffsets.prototype.get_sibilings_offset=function(next,el,offset){if(void 0===offset&&(offset=0),!el)return offset;if(!this.need_to_calc_offset(el))return this.get_sibilings_offset(next,next(el),offset);var _a=getComputedStyle(el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return this.get_sibilings_offset(next,next(el),offset+el.getBoundingClientRect().height+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},StaticOffsets}(),DynamicOffsets=function(_super){function DynamicOffsets(el,user_margins,get_root_offset,need_to_calc_offset,get_prev_sibling,get_next_sibling){void 0===el&&(el=null),void 0===user_margins&&(user_margins={}),void 0===need_to_calc_offset&&(need_to_calc_offset=function(){return!1}),void 0===get_prev_sibling&&(get_prev_sibling=function(){return null}),void 0===get_next_sibling&&(get_next_sibling=function(){return null});var _this=_super.call(this,el,user_margins,get_root_offset,need_to_calc_offset,get_prev_sibling)||this;return _this.get_next_sibling=get_next_sibling,_this.bottom=0,_this.max_top_offset=0,_this.relative_top=0,_this.height=0,_this.position={top:0,bottom:0},_this.border_box=0,_this.get_height=function(){return _this.el?Math.round(Math.max(_this.el.clientHeight,_this.el.scrollHeight,_this.el.getBoundingClientRect().height)):0},_this.get_bottom_offset=function(){return _this.get_sibilings_offset(_this.get_next_sibling,_this.get_next_sibling(_this.el),_this.user_margins.margin_bottom)},reactive(_this.get_height).on_change((function(height){_this.height=height,_this.border_box=_this.get_border_box(),_this.position=_this.get_position(),_this.relative_top=_this.get_relative_top()})),reactive(_this.get_bottom_offset).on_change((function(bottom){_this.bottom=bottom,_this.relative_top=_this.get_relative_top()})),_this}return __extends(DynamicOffsets,_super),DynamicOffsets.prototype.setMaxOffset=function(max_top_offset){this.max_top_offset=max_top_offset,this.relative_top=this.get_relative_top()},DynamicOffsets.prototype.get_position=function(){return this.el&&this.el.parentElement?{top:this.el.offsetTop,bottom:this.el.parentElement.clientHeight-this.el.offsetTop-this.border_box}:{top:0,bottom:0}},DynamicOffsets.prototype.get_border_box=function(){if(!this.el)return 0;var _a=getComputedStyle(this.el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return this.height+parseInt(marginTop)+parseInt(marginBottom)},DynamicOffsets.prototype.get_relative_top=function(){return this.max_top_offset-this.border_box-this.bottom},DynamicOffsets}(StaticOffsets),StopWidgetClassName="FixedWidget__stop_widget",FixedWidgetClassName="FixedWidget__fixed_widget",Widget=function(){function Widget(el){var _this=this;this.el=el,this.get_root_offset=function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))},this.need_to_calc_el_offset=function(_){return!1},this.offsets=new StaticOffsets}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.offsets=new StaticOffsets(this.el,user_margins,this.get_root_offset))},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.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},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,PositionWidget=function(_super){function PositionWidget(){var _this=null!==_super&&_super.apply(this,arguments)||this;return _this.offsets=new DynamicOffsets,_this.get_prev_sibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)&&el.previousElementSibling||null},_this.get_next_sibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)?el.nextElementSibling:null},_this}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins){_super.prototype.mount.call(this,user_margins),this.el&&this.el.parentElement&&(this.offsets=new DynamicOffsets(this.el,user_margins,this.get_root_offset,this.need_to_calc_el_offset,this.get_prev_sibling,this.get_next_sibling))},PositionWidget.prototype.setMaxOffset=function(max_top_offset){this.offsets.setMaxOffset(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.init_style={position:"static",marginBottom:"",marginTop:"",padding:"",height:"",width:""},_this.get_root_offset=function(){var element=_this.is_pinned?_this.clone_el:_this.el,new_root_offset=Math.round(scrollY+(element?element.getBoundingClientRect().top:0));return _this.is_pinned?new_root_offset:Math.max(_this.offsets.root,new_root_offset)},_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.store_style(getComputedStyle(this.el)),this.clone(),reactive((function(){return _this.offsets.height})).on_change((function(height){_this.clone_el&&(_this.clone_el.style.height="".concat(height,"px"))})))},FixedWidget.prototype.setMaxOffset=function(max_top_offset){0===max_top_offset||max_top_offset<this.offsets.root||this.offsets.max_top_offset===max_top_offset||this.offsets.setMaxOffset(max_top_offset)},FixedWidget.prototype.clone=function(){var _this=this;if(this.el&&this.el.parentElement&&!this.clone_el){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.padding=style.padding,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){var need_to_fix=scroll_top>this.offsets.root-this.offsets.top,top=0!==this.offsets.max_top_offset&&scroll_top>this.offsets.relative_top-this.offsets.top?this.offsets.relative_top-scroll_top:this.offsets.top;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.padding=this.init_style.padding,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.borderBox=0,_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){_super.prototype.mount.call(this,margins),this.el&&this.el.parentElement&&(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.offsets.setMaxOffset(max_top_offset))},StickyWidget.prototype.on_scroll=function(){if(this.el&&this.el.parentElement){var bottom=this.offsets.max_top_offset?Math.min(this.offsets.max_top_offset-(this.el.parentElement.clientHeight-this.offsets.position.bottom),this.offsets.bottom):this.offsets.bottom;this.el.style.top="".concat(this.offsets.top,"px"),bottom>=this.offsets.bottom?this.el.style.transform="translateY(0px)":this.el.style.transform="translateY(".concat(bottom-this.offsets.bottom,"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){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].offsets.top:stop_widgets[0].offsets.root,_i=0,stop_widgets_1=stop_widgets;_i<stop_widgets_1.length;_i++){var widget=stop_widgets_1[_i],offset=use_top_offset?widget.offsets.top:widget.offsets.root;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,{margin_bottom:options.margin_bottom,margin_top:options.margin_top},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)},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)}}},StaticOffsets=function(){function StaticOffsets(el,user_margins,get_root_offset,need_to_calc_offset,get_prev_sibling){void 0===el&&(el=null),void 0===user_margins&&(user_margins={}),void 0===get_root_offset&&(get_root_offset=function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))}),void 0===need_to_calc_offset&&(need_to_calc_offset=function(){return!1}),void 0===get_prev_sibling&&(get_prev_sibling=function(){return null});var _this=this;this.el=el,this.user_margins=user_margins,this.get_root_offset=get_root_offset,this.need_to_calc_offset=need_to_calc_offset,this.get_prev_sibling=get_prev_sibling,this.root=0,this.top=0,this.get_top_offset=function(){return _this.get_sibilings_offset(_this.get_prev_sibling,_this.get_prev_sibling(_this.el),_this.user_margins.margin_top)},reactive(this.get_top_offset).on_change((function(top){_this.top=top})),reactive(this.get_root_offset).on_change((function(root){_this.root=root}))}return StaticOffsets.prototype.update=function(){},StaticOffsets.prototype.get_sibilings_offset=function(next,el,offset){if(void 0===offset&&(offset=0),!el)return offset;if(!this.need_to_calc_offset(el))return this.get_sibilings_offset(next,next(el),offset);var _a=getComputedStyle(el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return this.get_sibilings_offset(next,next(el),offset+el.getBoundingClientRect().height+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},StaticOffsets}(),DynamicOffsets=function(_super){function DynamicOffsets(el,user_margins,get_root_offset,need_to_calc_offset,get_prev_sibling,get_next_sibling){void 0===el&&(el=null),void 0===user_margins&&(user_margins={}),void 0===need_to_calc_offset&&(need_to_calc_offset=function(){return!1}),void 0===get_prev_sibling&&(get_prev_sibling=function(){return null}),void 0===get_next_sibling&&(get_next_sibling=function(){return null});var _this=_super.call(this,el,user_margins,get_root_offset,need_to_calc_offset,get_prev_sibling)||this;return _this.get_next_sibling=get_next_sibling,_this.bottom=0,_this.max_top_offset=0,_this.relative_top=0,_this.height=0,_this.position={top:0,bottom:0},_this.border_box=0,_this.get_height=function(){return _this.el?Math.round(Math.max(_this.el.clientHeight,_this.el.scrollHeight,_this.el.getBoundingClientRect().height)):0},_this.get_bottom_offset=function(){return _this.get_sibilings_offset(_this.get_next_sibling,_this.get_next_sibling(_this.el),_this.user_margins.margin_bottom)},reactive(_this.get_height).on_change((function(height){_this.height=height,_this.border_box=_this.get_border_box(),_this.relative_top=_this.get_relative_top()})),reactive(_this.get_bottom_offset).on_change((function(bottom){_this.bottom=bottom,_this.relative_top=_this.get_relative_top()})),_this}return __extends(DynamicOffsets,_super),DynamicOffsets.prototype.update=function(){this.position=this.get_position()},DynamicOffsets.prototype.setMaxOffset=function(max_top_offset){this.max_top_offset=max_top_offset,this.relative_top=this.get_relative_top()},DynamicOffsets.prototype.get_position=function(){return this.el&&this.el.parentElement?{top:this.el.offsetTop,bottom:this.el.parentElement.clientHeight-this.el.offsetTop-this.border_box}:{top:0,bottom:0}},DynamicOffsets.prototype.get_border_box=function(){if(!this.el)return 0;var _a=getComputedStyle(this.el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return this.height+parseInt(marginTop)+parseInt(marginBottom)},DynamicOffsets.prototype.get_relative_top=function(){return this.max_top_offset-this.border_box-this.bottom},DynamicOffsets}(StaticOffsets),StopWidgetClassName="FixedWidget__stop_widget",FixedWidgetClassName="FixedWidget__fixed_widget",Widget=function(){function Widget(el){var _this=this;this.el=el,this.get_root_offset=function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))},this.need_to_calc_el_offset=function(_){return!1},this.offsets=new StaticOffsets}return Widget.prototype.render=function(){this.offsets.update()},Widget.prototype.mount=function(user_margins){void 0===user_margins&&(user_margins={}),this.el&&this.el.parentElement&&(this.offsets=new StaticOffsets(this.el,user_margins,this.get_root_offset))},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.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},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 PositionWidget=function(_super){function PositionWidget(){var _this=null!==_super&&_super.apply(this,arguments)||this;return _this.is_pinned=!1,_this.offsets=new DynamicOffsets,_this.get_prev_sibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)&&el.previousElementSibling||null},_this.get_next_sibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)?el.nextElementSibling:null},_this}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins){_super.prototype.mount.call(this,user_margins),this.el&&this.el.parentElement&&(this.offsets=new DynamicOffsets(this.el,user_margins,this.get_root_offset,this.need_to_calc_el_offset,this.get_prev_sibling,this.get_next_sibling))},PositionWidget.prototype.setMaxOffset=function(max_top_offset){this.offsets.setMaxOffset(max_top_offset)},PositionWidget.prototype.render=function(){_super.prototype.render.call(this),this.on_scroll(Math.round(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.prototype.pin=function(){this.is_pinned||(this.is_pinned=!0,this.el&&this.el.classList.add("FixedWidget__fixed_widget__pinned"))},PositionWidget.prototype.unpin=function(){this.is_pinned&&(this.is_pinned=!1,this.el&&this.el.classList.remove("FixedWidget__fixed_widget__pinned"))},PositionWidget}(Widget),FixedWidget=function(_super){function FixedWidget(el){var _this=_super.call(this,el)||this;return _this.init_style={position:"static",marginBottom:"",marginTop:"",padding:"",height:"",width:""},_this.get_root_offset=function(){if(!_this.el)return Number.MAX_VALUE;var top=_this.el.getBoundingClientRect().top,new_root_offset=Math.round(scrollY+top);return top<0?new_root_offset:(_this.is_pinned?Math.min:Math.max)(_this.offsets.root,new_root_offset)},_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.store_style(getComputedStyle(this.el)),this.clone(),reactive((function(){return _this.offsets.height})).on_change((function(height){_this.clone_el&&(_this.clone_el.style.height="".concat(height,"px"))})))},FixedWidget.prototype.setMaxOffset=function(max_top_offset){0===max_top_offset||max_top_offset<this.offsets.root||this.offsets.max_top_offset===max_top_offset||this.offsets.setMaxOffset(max_top_offset)},FixedWidget.prototype.clone=function(){var _this=this;if(this.el&&this.el.parentElement&&!this.clone_el){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.padding=style.padding,this.init_style.width=style.width,this.init_style.height=style.height},FixedWidget.prototype.restore_style=function(style){this.is_pinned&&(this.unpin(),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){var need_to_fix=scroll_top>this.offsets.root-this.offsets.top,top=0!==this.offsets.max_top_offset&&scroll_top>this.offsets.relative_top-this.offsets.top?this.offsets.relative_top-scroll_top:this.offsets.top;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.pin(),this.el.style.position="fixed",this.el.style.transition="transform 0.5s",this.el.style.width=this.init_style.width,this.el.style.padding=this.init_style.padding,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.borderBox=0,_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){_super.prototype.mount.call(this,margins),this.el&&this.el.parentElement&&(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.offsets.setMaxOffset(max_top_offset))},StickyWidget.prototype.on_scroll=function(){if(this.el&&this.el.parentElement){this.offsets.position.top>this.offsets.top?this.pin():this.unpin();var actual_bottom=this.offsets.position.bottom,expected_bottom=this.offsets.max_top_offset?Math.min(this.offsets.max_top_offset-(this.el.parentElement.clientHeight-actual_bottom),actual_bottom):this.offsets.bottom;this.el.style.top="".concat(this.offsets.top,"px"),expected_bottom>=this.offsets.bottom?this.el.style.transform="translateY(0px)":this.el.style.transform="translateY(".concat(expected_bottom-this.offsets.bottom,"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){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)}_this.render()};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;reactive((function(){if(0===stop_widgets.length)return Math.round(document.body.scrollHeight);for(var min_offset=use_top_offset?stop_widgets[0].offsets.top:stop_widgets[0].offsets.root,_i=0,stop_widgets_1=stop_widgets;_i<stop_widgets_1.length;_i++){var widget=stop_widgets_1[_i],offset=use_top_offset?widget.offsets.top:widget.offsets.root;min_offset>offset&&(min_offset=offset)}return Math.round(min_offset)})).on_change(this.setWidgetsMaxOffset)},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,{margin_bottom:options.margin_bottom,margin_top:options.margin_top},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}(),Plugin=function Plugin(options,version){void 0===options&&(options=[]),Plugin.version=version,Plugin.sidebars?Plugin.sidebars.render():(Plugin.sidebars=Sidebars.new(options.reduce((function(prev,cur){return __assign(__assign(__assign({},prev),cur),{widgets:prev.widgets.concat(cur.widgets||[])})}),{widgets:[]})),document.addEventListener("scroll",Plugin.sidebars.render),Plugin.sidebars.mount())};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 document.body.clientWidth<option.screen_max_width||document.body.clientHeight<option.screen_max_height}))||new Plugin(options,"6.0.7-3")}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.7
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.7';
27
 
28
  protected static $sidebars_widgets;
29
 
@@ -290,7 +290,7 @@ class q2w3_fixed_widget {
290
  public static function admin_menu() {
291
  remove_action( 'admin_menu', array( 'q2w3_fixed_widget', 'admin_menu' ) ); // Remove free version plugin
292
 
293
- self::$settings_page_hook = add_submenu_page( 'themes.php', esc_html__( 'Fixed Widget Options', 'q2w3-fixed-widget' ), esc_html__( 'Fixed Widget Options', 'q2w3-fixed-widget' ), 'activate_plugins', self::ID, array( __CLASS__, 'settings_page' ) );
294
  }
295
 
296
  /**
@@ -388,7 +388,7 @@ class q2w3_fixed_widget {
388
 
389
  $options = self::load_options();
390
 
391
- echo '<div class="wrap"><div id="icon-themes" class="icon32"><br /></div><h2>' . esc_html__( 'Fixed Widget Options', 'q2w3-fixed-widget' ) . '</h2>' . PHP_EOL;
392
 
393
  if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == 'true' ) {
394
  echo '<div id="message" class="updated"><p>' . esc_html__( 'Settings saved.', 'q2w3-fixed-widget' ) . '</p></div>' . PHP_EOL;
@@ -428,11 +428,13 @@ class q2w3_fixed_widget {
428
  */
429
  public static function settings_page_general_box( $options ) {
430
  echo '<p>
431
- <span style="display: inline-block; width: 150px;">' . esc_html__( 'Test new version', 'q2w3-fixed-widget' ) . '</span>
432
- <input type="checkbox" name="' . esc_attr( self::ID ) . '[use_sticky_position]" value="yes" ' . checked( 'yes', $options['use_sticky_position'], false ) . ' /> </p>' . PHP_EOL;
433
- echo '<p style="font-weight: bold;">';
434
- esc_html_e( 'Use our completely updated script which takes care of common issues and a bad Web Vitals score caused by layout shifts. This version is rolled out to all users in the near future.', 'q2w3-fixed-widget' );
435
- echo '<br/>';
 
 
436
  printf(
437
  wp_kses(
438
  // translators: %1$s is an opening a tag, %2ds is a closing one
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.1.0
9
  Author URI: https://wpadvancedads.com/fixed-widget-wordpress/
10
  */
11
 
23
 
24
  const ID = 'q2w3_fixed_widget';
25
 
26
+ const VERSION = '6.1.0';
27
 
28
  protected static $sidebars_widgets;
29
 
290
  public static function admin_menu() {
291
  remove_action( 'admin_menu', array( 'q2w3_fixed_widget', 'admin_menu' ) ); // Remove free version plugin
292
 
293
+ self::$settings_page_hook = add_submenu_page( 'themes.php', esc_html__( 'Fixed Widget', 'q2w3-fixed-widget' ), esc_html__( 'Fixed Widget', 'q2w3-fixed-widget' ), 'activate_plugins', self::ID, array( __CLASS__, 'settings_page' ) );
294
  }
295
 
296
  /**
388
 
389
  $options = self::load_options();
390
 
391
+ echo '<div class="wrap"><div id="icon-themes" class="icon32"><br /></div><h2>' . esc_html__( 'Fixed Widget', 'q2w3-fixed-widget' ) . '</h2>' . PHP_EOL;
392
 
393
  if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == 'true' ) {
394
  echo '<div id="message" class="updated"><p>' . esc_html__( 'Settings saved.', 'q2w3-fixed-widget' ) . '</p></div>' . PHP_EOL;
428
  */
429
  public static function settings_page_general_box( $options ) {
430
  echo '<p>
431
+ <span style="display: inline-block; width: 150px;">' . esc_html__( 'Improved version', 'q2w3-fixed-widget' ) . '</span>
432
+ <input type="checkbox" name="' . esc_attr( self::ID ) . '[use_sticky_position]" value="yes" ' . checked( 'yes', $options['use_sticky_position'], false ) . ' /></p>' . PHP_EOL;
433
+ echo '<p>';
434
+ esc_html_e( 'Enable this option to use the completely updated script. It takes care of common issues and layout shifts.', 'q2w3-fixed-widget' );
435
+ echo ' ';
436
+ esc_html_e( 'The improved script works best with themes that support flexbox instead of float.', 'q2w3-fixed-widget' );
437
+ echo ' ';
438
  printf(
439
  wp_kses(
440
  // translators: %1$s is an opening a tag, %2ds is a closing one
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  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
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
@@ -17,24 +17,9 @@ That's why this option is worthwhile for ads or other elements that visitors sho
17
 
18
  * [Manual and demo](https://wpadvancedads.com/fixed-widget-wordpress/)
19
 
20
- = Changes in version 6.0.0 =
21
-
22
- Version 6.0.0 is a full rewrite of the frontend script. It fixes many edge cases like jumping, reloading, or resizing widgets.
23
- The rewrite also resolves bad Cumulative Layout Shifts.
24
-
25
- Enable "Test new version" under Appearance > Fixed Widget Options.
26
-
27
- - the frontend script does not need jQuery anymore
28
- - removed unneeded options that previously helped resolving edge cases
29
- - "Stop Elements" and "Custom Fixed Elements" now accept any selector, including IDs, Class, and Type selectors.
30
- - works with the widget block editor introduced in WordPress 5.8
31
- - added "stop" option to widget blocks
32
-
33
- Please test and [let us know](https://wordpress.org/support/plugin/q2w3-fixed-widget/) if you discover any issues.
34
-
35
  = Features =
36
 
37
- All the features are free.
38
 
39
  * **Sticky Widgets** Use the Fixed Widget option on any widget and blocks in the sidebar
40
  * **Sticky Elements** Choose any element on your site and make it sticky
@@ -43,6 +28,7 @@ All the features are free.
43
  * **Stop Elements** push sticky elements up when they are scrolling into view
44
  * **Stop Blocks** defines blocks in your sidebar that push fixed blocks out of the page
45
  * **Minimum Screen Width** and **Minimum Screen Height** allow you to disable sticky behavior on small screens
 
46
 
47
  = Compatibility =
48
 
@@ -56,7 +42,7 @@ Theme requirements:
56
  1. Follow the standard WordPress plugin installation procedure
57
  2. Activate the plugin through the plugins menu in WordPress
58
  3. Go to Appearance -> Widgets, enable the "Fixed Widget" option on any active widget
59
- 4. Fine tune plugin parameters on Appearance -> Fixed Widget Options page
60
 
61
  == Frequently Asked Questions ==
62
 
@@ -73,9 +59,13 @@ There are several reasons:
73
 
74
  Yes, it is possible to fix more than one widget even if they are located in different sidebars.
75
 
 
 
 
 
76
  = How to prevent overlapping with the footer? =
77
 
78
- Go to WP admin area, Appearance -> Fixed Widget Options. Here you can define the top and bottom margins. Set bottom margin value >= footer height. Check the result, please.
79
  If your footer height is changing from page to page it is better to use the `Stop ID` option. Here you need to provide the HTML tag ID. The position of that HTML element will determine the margin bottom value. For example, let's take the Twenty Sixteen default theme. The theme's footer container has an ID="colophon". In the `Stop Element Selectors` option I need to enter `#colophon`.
80
 
81
  = How to disable the plugin on mobile devices? =
@@ -91,6 +81,13 @@ Use the options `Minimum Screen Width` and `Minimum Screen Height` to disable st
91
 
92
  == Changelog ==
93
 
 
 
 
 
 
 
 
94
  = 6.0.7 =
95
 
96
  - Improvement: Compatibility with relative padding values
@@ -130,7 +127,7 @@ Use the options `Minimum Screen Width` and `Minimum Screen Height` to disable st
130
  Version 6.0.0 is a full rewrite of the frontend script. It fixes many edge cases like jumping, reloading, or resizing widgets.
131
  The rewrite also resolves bad Cumulative Layout Shifts.
132
 
133
- Most changes are available when you enable "Test new version" under Appearance > Fixed Widget Options.
134
 
135
  Please test and [let us know](https://wordpress.org/support/plugin/q2w3-fixed-widget/) if you discover any issues.
136
 
@@ -277,7 +274,7 @@ Please test and [let us know](https://wordpress.org/support/plugin/q2w3-fixed-wi
277
  * Fixed javascript error when no sidebars exists on a page.
278
 
279
  = 2.0 =
280
- * Fixed footer overlapping problem! Now users can customize top and bottom margins for the fixed widgets from the admin area (Appearance -> Fixed Widget Options).
281
  * Added localization support
282
 
283
  = 1.0.3 =
2
  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: 6.0
6
+ Stable tag: 6.1.0
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
17
 
18
  * [Manual and demo](https://wpadvancedads.com/fixed-widget-wordpress/)
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  = Features =
21
 
22
+ Fixed Widget is completely free of charge.
23
 
24
  * **Sticky Widgets** Use the Fixed Widget option on any widget and blocks in the sidebar
25
  * **Sticky Elements** Choose any element on your site and make it sticky
28
  * **Stop Elements** push sticky elements up when they are scrolling into view
29
  * **Stop Blocks** defines blocks in your sidebar that push fixed blocks out of the page
30
  * **Minimum Screen Width** and **Minimum Screen Height** allow you to disable sticky behavior on small screens
31
+ * Written in plain JavaScript for better performance
32
 
33
  = Compatibility =
34
 
42
  1. Follow the standard WordPress plugin installation procedure
43
  2. Activate the plugin through the plugins menu in WordPress
44
  3. Go to Appearance -> Widgets, enable the "Fixed Widget" option on any active widget
45
+ 4. Fine tune plugin parameters on Appearance -> Fixed Widget page
46
 
47
  == Frequently Asked Questions ==
48
 
59
 
60
  Yes, it is possible to fix more than one widget even if they are located in different sidebars.
61
 
62
+ = How can I style a fixed element only while it is sticky? =
63
+
64
+ Fixed elements carry the `FixedWidget__fixed_widget__pinned` class, which allows developers to change the styling only while the element is fixed.
65
+
66
  = How to prevent overlapping with the footer? =
67
 
68
+ Go to WP admin area, Appearance -> Fixed Widget. Here you can define the top and bottom margins. Set bottom margin value >= footer height. Check the result, please.
69
  If your footer height is changing from page to page it is better to use the `Stop ID` option. Here you need to provide the HTML tag ID. The position of that HTML element will determine the margin bottom value. For example, let's take the Twenty Sixteen default theme. The theme's footer container has an ID="colophon". In the `Stop Element Selectors` option I need to enter `#colophon`.
70
 
71
  = How to disable the plugin on mobile devices? =
81
 
82
  == Changelog ==
83
 
84
+ = 6.1.0 =
85
+
86
+ - Feature: Add the `FixedWidget__fixed_widget__pinned` class to the fixed widget while it is sticky and remove it when it is unfixed. This allows users to apply their own styling only during a fixed state.
87
+ - Improvement: rename "Test new version" option into "Improved version" and changed the option description to make it more clear that both script versions will be kept.
88
+ - Improvement: change "Fixed Widget Options" menu item into "Fixed Widget"
89
+ - Improvement: Handle edge cases where the Minimum Width option doesn’t work for specific themes
90
+
91
  = 6.0.7 =
92
 
93
  - Improvement: Compatibility with relative padding values
127
  Version 6.0.0 is a full rewrite of the frontend script. It fixes many edge cases like jumping, reloading, or resizing widgets.
128
  The rewrite also resolves bad Cumulative Layout Shifts.
129
 
130
+ Most changes are available when you enable "Improved version" under Appearance > Fixed Widget.
131
 
132
  Please test and [let us know](https://wordpress.org/support/plugin/q2w3-fixed-widget/) if you discover any issues.
133
 
274
  * Fixed javascript error when no sidebars exists on a page.
275
 
276
  = 2.0 =
277
+ * Fixed footer overlapping problem! Now users can customize top and bottom margins for the fixed widgets from the admin area (Appearance -> Fixed Widget).
278
  * Added localization support
279
 
280
  = 1.0.3 =