Q2W3 Fixed Widget - Version 6.1.1

Version Description

  • Improvement: reposition the fixed widget when the screen is resized, e.g., a mobile device turned into landscape mode
  • Improvement: various optimizations for specific themes and setups reported by users
Download this release

Release Info

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

Code changes from version 6.1.0 to 6.1.1

Files changed (4) hide show
  1. js/frontend.js +221 -114
  2. js/frontend.min.js +1 -1
  3. q2w3-fixed-widget.php +2 -2
  4. readme.txt +6 -1
js/frontend.js CHANGED
@@ -28,7 +28,7 @@ var reactive = function (getter, interval) {
28
  if (interval === void 0) { interval = 300; }
29
  var subs = [];
30
  var v = getter();
31
- setInterval(check, interval);
32
  function check() {
33
  if (subs.length === 0) {
34
  return;
@@ -50,37 +50,48 @@ var reactive = function (getter, interval) {
50
  on_change: function (update) {
51
  update(v);
52
  subs.push(update);
 
 
 
53
  }
54
  };
55
  };
56
 
57
  var StaticOffsets = (function () {
58
- function StaticOffsets(el, user_margins, get_root_offset, need_to_calc_offset, get_prev_sibling) {
59
  if (el === void 0) { el = null; }
60
- if (user_margins === void 0) { user_margins = {}; }
61
  if (get_root_offset === void 0) { get_root_offset = function () { return Math.round(scrollY + (_this.el ? _this.el.getBoundingClientRect().top : 0)); }; }
62
  if (need_to_calc_offset === void 0) { need_to_calc_offset = function () { return false; }; }
63
  if (get_prev_sibling === void 0) { get_prev_sibling = function () { return null; }; }
64
  var _this = this;
65
  this.el = el;
66
- this.user_margins = user_margins;
67
  this.get_root_offset = get_root_offset;
68
  this.need_to_calc_offset = need_to_calc_offset;
69
  this.get_prev_sibling = get_prev_sibling;
 
70
  this.root = 0;
71
  this.top = 0;
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) {
@@ -96,13 +107,12 @@ var StaticOffsets = (function () {
96
  }());
97
  var DynamicOffsets = (function (_super) {
98
  __extends(DynamicOffsets, _super);
99
- function DynamicOffsets(el, user_margins, get_root_offset, need_to_calc_offset, get_prev_sibling, get_next_sibling) {
100
  if (el === void 0) { el = null; }
101
- if (user_margins === void 0) { user_margins = {}; }
102
  if (need_to_calc_offset === void 0) { need_to_calc_offset = function () { return false; }; }
103
  if (get_prev_sibling === void 0) { get_prev_sibling = function () { return null; }; }
104
  if (get_next_sibling === void 0) { get_next_sibling = function () { return null; }; }
105
- var _this = _super.call(this, el, user_margins, get_root_offset, need_to_calc_offset, get_prev_sibling) || this;
106
  _this.get_next_sibling = get_next_sibling;
107
  _this.bottom = 0;
108
  _this.max_top_offset = 0;
@@ -112,26 +122,37 @@ var DynamicOffsets = (function (_super) {
112
  _this.border_box = 0;
113
  _this.get_height = function () {
114
  return !_this.el ? 0 :
115
- Math.round(Math.max(_this.el.clientHeight, _this.el.scrollHeight, _this.el.getBoundingClientRect().height));
116
  };
117
  _this.get_bottom_offset = function () {
118
  return _this.get_sibilings_offset(_this.get_next_sibling, _this.get_next_sibling(_this.el), _this.user_margins.margin_bottom);
119
  };
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) {
 
126
  _this.bottom = bottom;
127
  _this.relative_top = _this.get_relative_top();
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();
137
  };
@@ -166,17 +187,17 @@ var Widget = (function () {
166
  this.el = el;
167
  this.get_root_offset = function () { return Math.round(scrollY + (_this.el ? _this.el.getBoundingClientRect().top : 0)); };
168
  this.need_to_calc_el_offset = function (_) { return false; };
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 = {}; }
176
- if (!this.el || !this.el.parentElement) {
177
- return;
178
- }
179
- this.offsets = new StaticOffsets(this.el, user_margins, this.get_root_offset);
 
 
 
180
  };
181
  Widget.prototype.getElement = function () {
182
  return this.el;
@@ -259,10 +280,20 @@ function findWithProperty(el, predicate) {
259
 
260
  var PositionWidget = (function (_super) {
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
268
  && !el.classList.contains(StopWidgetClassName)
@@ -270,6 +301,10 @@ var PositionWidget = (function (_super) {
270
  || null;
271
  };
272
  _this.get_next_sibling = function (el) { return el && !el.classList.contains(StopWidgetClassName) ? el.nextElementSibling : null; };
 
 
 
 
273
  return _this;
274
  }
275
  PositionWidget.prototype.mount = function (user_margins) {
@@ -277,34 +312,74 @@ var PositionWidget = (function (_super) {
277
  if (!this.el || !this.el.parentElement) {
278
  return;
279
  }
280
- 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);
281
  };
282
- PositionWidget.prototype.setMaxOffset = function (max_top_offset) {
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);
291
  };
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));
@@ -313,14 +388,6 @@ var FixedWidget = (function (_super) {
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: '',
319
- marginTop: '',
320
- padding: '',
321
- height: '',
322
- width: '',
323
- };
324
  _this.get_root_offset = function () {
325
  if (!_this.el) {
326
  return Number.MAX_VALUE;
@@ -332,9 +399,6 @@ var FixedWidget = (function (_super) {
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);
337
- };
338
  if (!_this.el || !_this.el.parentElement) {
339
  return _this;
340
  }
@@ -347,21 +411,43 @@ var FixedWidget = (function (_super) {
347
  if (!this.el) {
348
  return;
349
  }
350
- this.store_style(getComputedStyle(this.el));
351
  this.clone();
352
- reactive(function () { return _this.offsets.height; }).on_change(function (height) {
 
 
 
 
353
  if (_this.clone_el) {
354
  _this.clone_el.style.height = "".concat(height, "px");
355
  }
356
  });
357
  };
358
- FixedWidget.prototype.setMaxOffset = function (max_top_offset) {
359
- if (max_top_offset === 0 ||
360
- max_top_offset < this.offsets.root ||
361
- this.offsets.max_top_offset === max_top_offset) {
 
 
 
 
 
 
 
 
362
  return;
363
  }
364
- this.offsets.setMaxOffset(max_top_offset);
 
 
 
 
 
 
 
 
 
 
 
365
  };
366
  FixedWidget.prototype.clone = function () {
367
  var _this = this;
@@ -378,35 +464,16 @@ var FixedWidget = (function (_super) {
378
  this.clone_el.style.display = 'none';
379
  this.el.parentElement.insertBefore(this.clone_el, this.el);
380
  };
381
- FixedWidget.prototype.store_style = function (style) {
382
- this.init_style.position = style.position;
383
- this.init_style.marginTop = style.marginTop;
384
- this.init_style.marginBottom = style.marginBottom;
385
- this.init_style.padding = style.padding;
386
- this.init_style.width = style.width;
387
- this.init_style.height = style.height;
388
- };
389
- FixedWidget.prototype.restore_style = function (style) {
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';
397
  }
398
  };
399
- FixedWidget.prototype.on_scroll = function (scroll_top) {
400
- if (!this.el) {
401
- return;
402
- }
403
- var need_to_fix = scroll_top > this.offsets.root - this.offsets.top;
404
- var limited_by_stop_element = this.offsets.max_top_offset !== 0 && scroll_top > this.offsets.relative_top - this.offsets.top;
405
- var top = limited_by_stop_element ? this.offsets.relative_top - scroll_top : this.offsets.top;
406
- need_to_fix ?
407
- this.fix(top) :
408
- this.restore_style(this.el.style);
409
- };
410
  FixedWidget.prototype.fix = function (top) {
411
  if (!this.el) {
412
  return;
@@ -441,9 +508,6 @@ var StickyWidget = (function (_super) {
441
  var _this = _super.call(this, el) || this;
442
  _this.borderBox = 0;
443
  _this.margins = 0;
444
- _this.need_to_calc_el_offset = function (el) {
445
- return el.classList.contains(FixedWidgetClassName);
446
- };
447
  if (!_this.el || !_this.el.parentElement) {
448
  return _this;
449
  }
@@ -452,7 +516,7 @@ var StickyWidget = (function (_super) {
452
  }
453
  StickyWidget.prototype.mount = function (margins) {
454
  _super.prototype.mount.call(this, margins);
455
- if (!this.el || !this.el.parentElement) {
456
  return;
457
  }
458
  this.el.style.position = 'sticky';
@@ -460,16 +524,20 @@ var StickyWidget = (function (_super) {
460
  this.el.style.transition = 'transform 0s';
461
  this.el.style.boxSizing = 'border-box';
462
  };
463
- StickyWidget.prototype.setMaxOffset = function (max_top_offset) {
 
464
  if (!this.el || !this.el.parentElement) {
465
  return;
466
  }
467
- if (max_top_offset < this.el.offsetTop) {
 
 
 
468
  return;
469
  }
470
- this.offsets.setMaxOffset(max_top_offset);
471
  };
472
- StickyWidget.prototype.on_scroll = function () {
473
  if (!this.el || !this.el.parentElement) {
474
  return;
475
  }
@@ -528,13 +596,28 @@ var Sidebar = (function () {
528
  this.widgets = [];
529
  this.stop_widgets = [];
530
  this.isSticky = false;
531
- this.setWidgetsMaxOffset = function (max_offset) {
532
  for (var _i = 0, _a = _this.widgets; _i < _a.length; _i++) {
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'; });
540
  var isFallbackToSticky = (isDeprecatedFloatMarkup || isOverflowHiddenMarkup) && use_sticky_position;
@@ -546,6 +629,7 @@ var Sidebar = (function () {
546
  var WidgetContructor = this.isSticky ? StickyWidget : FixedWidget;
547
  this.stop_widgets = StopWidget.from(this.el);
548
  this.widgets = WidgetContructor.from(this.el);
 
549
  if (!this.isSticky) {
550
  return;
551
  }
@@ -557,38 +641,45 @@ var Sidebar = (function () {
557
  }
558
  Sidebar.prototype.mount = function () {
559
  var _this = this;
 
 
 
560
  this.stop_widgets.forEach(function (widget) { widget.mount(); });
561
  this.widgets.forEach(function (widget) { widget.mount(_this.margins); });
 
562
  };
563
- Sidebar.prototype.setMaxOffset = function (general_stop_widgets) {
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
  }
571
- var min_offset = use_top_offset ?
572
- stop_widgets[0].offsets.top :
573
- stop_widgets[0].offsets.root;
574
- for (var _i = 0, stop_widgets_1 = stop_widgets; _i < stop_widgets_1.length; _i++) {
575
- var widget = stop_widgets_1[_i];
576
- var offset = use_top_offset ? widget.offsets.top : widget.offsets.root;
577
- if (min_offset > offset) {
578
- min_offset = offset;
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
  };
594
  return Sidebar;
@@ -610,13 +701,16 @@ var Sidebars = (function () {
610
  }
611
  Sidebars.prototype.mount = function () {
612
  this.data.forEach(function (sidebar) { sidebar.mount(); });
613
- this.setMaxOffset();
 
 
 
614
  };
615
- Sidebars.prototype.setMaxOffset = function () {
616
  var general_stop_widgets = this.getGeneralStopElements();
617
  for (var _i = 0, _a = this.data; _i < _a.length; _i++) {
618
  var sidebar = _a[_i];
619
- sidebar.setMaxOffset(general_stop_widgets);
620
  }
621
  };
622
  Sidebars.prototype.getGeneralStopElements = function () {
@@ -642,7 +736,14 @@ var Sidebars = (function () {
642
  });
643
  fixedWidgetsContainers.forEach(function (c) { c.classList.add(FixedWidgetClassName); });
644
  stopWidgetsUniqContainers.forEach(function (c) { c.classList.add(StopWidgetClassName); });
645
- return new Sidebars(fixedWidgetsContainers.concat(stopWidgetsUniqContainers), options);
 
 
 
 
 
 
 
646
  };
647
  return Sidebars;
648
  }());
@@ -655,16 +756,22 @@ var Plugin = (function () {
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();
667
- onDocumentLoaded();
668
  function onDocumentLoaded() {
669
  var admin_panel = document.querySelector('#wpadminbar');
670
  var user_options = window['q2w3_sidebar_options'] || [{}];
@@ -678,5 +785,5 @@ function onDocumentLoaded() {
678
  })) {
679
  return;
680
  }
681
- new Plugin(options, '6.0.7-3');
682
  }
28
  if (interval === void 0) { interval = 300; }
29
  var subs = [];
30
  var v = getter();
31
+ var interval_id = setInterval(check, interval);
32
  function check() {
33
  if (subs.length === 0) {
34
  return;
50
  on_change: function (update) {
51
  update(v);
52
  subs.push(update);
53
+ },
54
+ clear: function () {
55
+ clearInterval(interval_id);
56
  }
57
  };
58
  };
59
 
60
  var StaticOffsets = (function () {
61
+ function StaticOffsets(el, get_root_offset, need_to_calc_offset, get_prev_sibling) {
62
  if (el === void 0) { el = null; }
 
63
  if (get_root_offset === void 0) { get_root_offset = function () { return Math.round(scrollY + (_this.el ? _this.el.getBoundingClientRect().top : 0)); }; }
64
  if (need_to_calc_offset === void 0) { need_to_calc_offset = function () { return false; }; }
65
  if (get_prev_sibling === void 0) { get_prev_sibling = function () { return null; }; }
66
  var _this = this;
67
  this.el = el;
 
68
  this.get_root_offset = get_root_offset;
69
  this.need_to_calc_offset = need_to_calc_offset;
70
  this.get_prev_sibling = get_prev_sibling;
71
+ this.user_margins = {};
72
  this.root = 0;
73
  this.top = 0;
74
  this.get_top_offset = function () {
75
  return _this.get_sibilings_offset(_this.get_prev_sibling, _this.get_prev_sibling(_this.el), _this.user_margins.margin_top);
76
  };
77
+ }
78
+ StaticOffsets.prototype.init = function (user_margins) {
79
+ var _this = this;
80
+ this.user_margins = user_margins;
81
+ this.top_watcher = reactive(this.get_top_offset);
82
+ this.top_watcher.on_change(function (top) {
83
  _this.top = top;
84
  });
85
+ this.root_watcher = reactive(this.get_root_offset);
86
+ this.root_watcher.on_change(function (root) {
87
  _this.root = root;
88
  });
 
 
89
  };
90
+ StaticOffsets.prototype.clear = function () {
91
+ this.top_watcher && this.top_watcher.clear();
92
+ this.root_watcher && this.root_watcher.clear();
93
+ };
94
+ StaticOffsets.prototype.update = function () { };
95
  StaticOffsets.prototype.get_sibilings_offset = function (next, el, offset) {
96
  if (offset === void 0) { offset = 0; }
97
  if (!el) {
107
  }());
108
  var DynamicOffsets = (function (_super) {
109
  __extends(DynamicOffsets, _super);
110
+ function DynamicOffsets(el, get_root_offset, need_to_calc_offset, get_prev_sibling, get_next_sibling) {
111
  if (el === void 0) { el = null; }
 
112
  if (need_to_calc_offset === void 0) { need_to_calc_offset = function () { return false; }; }
113
  if (get_prev_sibling === void 0) { get_prev_sibling = function () { return null; }; }
114
  if (get_next_sibling === void 0) { get_next_sibling = function () { return null; }; }
115
+ var _this = _super.call(this, el, get_root_offset, need_to_calc_offset, get_prev_sibling) || this;
116
  _this.get_next_sibling = get_next_sibling;
117
  _this.bottom = 0;
118
  _this.max_top_offset = 0;
122
  _this.border_box = 0;
123
  _this.get_height = function () {
124
  return !_this.el ? 0 :
125
+ Math.round(Math.max(_this.el.clientHeight, _this.el.getBoundingClientRect().height));
126
  };
127
  _this.get_bottom_offset = function () {
128
  return _this.get_sibilings_offset(_this.get_next_sibling, _this.get_next_sibling(_this.el), _this.user_margins.margin_bottom);
129
  };
130
+ return _this;
131
+ }
132
+ DynamicOffsets.prototype.init = function (user_margins) {
133
+ var _this = this;
134
+ _super.prototype.init.call(this, user_margins);
135
+ this.height_watcher = reactive(this.get_height);
136
+ this.height_watcher.on_change(function (height) {
137
  _this.height = height;
138
  _this.border_box = _this.get_border_box();
139
  _this.relative_top = _this.get_relative_top();
140
  });
141
+ this.bottom_offset = reactive(this.get_bottom_offset);
142
+ this.bottom_offset.on_change(function (bottom) {
143
  _this.bottom = bottom;
144
  _this.relative_top = _this.get_relative_top();
145
  });
146
+ };
147
+ DynamicOffsets.prototype.clear = function () {
148
+ _super.prototype.clear.call(this);
149
+ this.height_watcher && this.height_watcher.clear();
150
+ this.bottom_offset && this.bottom_offset.clear();
151
+ };
152
  DynamicOffsets.prototype.update = function () {
153
  this.position = this.get_position();
154
  };
155
+ DynamicOffsets.prototype.set_max_offset = function (max_top_offset) {
156
  this.max_top_offset = max_top_offset;
157
  this.relative_top = this.get_relative_top();
158
  };
187
  this.el = el;
188
  this.get_root_offset = function () { return Math.round(scrollY + (_this.el ? _this.el.getBoundingClientRect().top : 0)); };
189
  this.need_to_calc_el_offset = function (_) { return false; };
190
+ this.offsets = new StaticOffsets(this.el, this.get_root_offset);
191
  }
 
 
 
192
  Widget.prototype.mount = function (user_margins) {
193
  if (user_margins === void 0) { user_margins = {}; }
194
+ this.offsets.init(user_margins);
195
+ };
196
+ Widget.prototype.render = function (_reject) {
197
+ this.offsets.update();
198
+ };
199
+ Widget.prototype.unmount = function () {
200
+ this.offsets.clear();
201
  };
202
  Widget.prototype.getElement = function () {
203
  return this.el;
280
 
281
  var PositionWidget = (function (_super) {
282
  __extends(PositionWidget, _super);
283
+ function PositionWidget(el) {
284
+ var _this = _super.call(this, el) || this;
285
  _this.is_pinned = false;
286
+ _this.init_style = {
287
+ position: 'static',
288
+ marginBottom: '',
289
+ transition: '',
290
+ transform: '',
291
+ marginTop: '',
292
+ padding: '',
293
+ height: '',
294
+ width: '',
295
+ top: ''
296
+ };
297
  _this.get_prev_sibling = function (el) {
298
  return el
299
  && !el.classList.contains(StopWidgetClassName)
301
  || null;
302
  };
303
  _this.get_next_sibling = function (el) { return el && !el.classList.contains(StopWidgetClassName) ? el.nextElementSibling : null; };
304
+ _this.need_to_calc_el_offset = function (el) {
305
+ return el.classList.contains(FixedWidgetClassName);
306
+ };
307
+ _this.offsets = new DynamicOffsets(_this.el, _this.get_root_offset, _this.need_to_calc_el_offset, _this.get_prev_sibling, _this.get_next_sibling);
308
  return _this;
309
  }
310
  PositionWidget.prototype.mount = function (user_margins) {
312
  if (!this.el || !this.el.parentElement) {
313
  return;
314
  }
315
+ this.store_style(getComputedStyle(this.el));
316
  };
317
+ PositionWidget.prototype.unmount = function () {
318
+ _super.prototype.unmount.call(this);
319
+ this.unpin();
320
+ this.reset_styles();
321
+ };
322
+ PositionWidget.prototype.reset_styles = function () {
323
+ if (!this.el) {
324
+ return;
325
+ }
326
+ for (var prop in this.init_style) {
327
+ this.el.style[prop] = '';
328
+ }
329
+ this.init_style = {
330
+ position: 'static',
331
+ marginBottom: '',
332
+ transition: '',
333
+ transform: '',
334
+ marginTop: '',
335
+ padding: '',
336
+ height: '',
337
+ width: '',
338
+ top: '',
339
+ };
340
  };
341
+ PositionWidget.prototype.render = function (reject) {
342
+ _super.prototype.render.call(this, reject);
343
+ this.on_scroll(Math.round(scrollY), reject);
344
  };
345
  PositionWidget.from = function (root) {
346
  return _super.from.call(this, root, FixedWidgetClassName);
347
  };
348
+ PositionWidget.prototype.on_scroll = function (_scroll_top, _reject) {
349
  throw new Error('Method is not overridden!');
350
  };
351
  PositionWidget.prototype.pin = function () {
352
+ if (this.is_pinned || !this.el) {
353
  return;
354
  }
355
  this.is_pinned = true;
356
+ this.el.classList.add(FixedWidgetPinnedClassName);
357
  };
358
  PositionWidget.prototype.unpin = function () {
359
+ if (!this.is_pinned || !this.el) {
360
  return;
361
  }
362
  this.is_pinned = false;
363
+ this.el.classList.remove(FixedWidgetPinnedClassName);
364
+ };
365
+ PositionWidget.prototype.store_style = function (style) {
366
+ this.init_style.position = style.position;
367
+ this.init_style.top = style.top;
368
+ this.init_style.marginTop = style.marginTop;
369
+ this.init_style.marginBottom = style.marginBottom;
370
+ this.init_style.padding = style.padding;
371
+ this.init_style.width = style.width;
372
+ this.init_style.height = style.height;
373
+ this.init_style.transition = style.transition;
374
+ this.init_style.transform = style.transform;
375
+ };
376
+ PositionWidget.prototype.restore_style = function () {
377
+ if (!this.el) {
378
+ return;
379
+ }
380
+ for (var prop in this.init_style) {
381
+ this.el.style[prop] = this.init_style[prop];
382
+ }
383
  };
384
  return PositionWidget;
385
  }(Widget));
388
  __extends(FixedWidget, _super);
389
  function FixedWidget(el) {
390
  var _this = _super.call(this, el) || this;
 
 
 
 
 
 
 
 
391
  _this.get_root_offset = function () {
392
  if (!_this.el) {
393
  return Number.MAX_VALUE;
399
  }
400
  return (_this.is_pinned ? Math.min : Math.max)(_this.offsets.root, new_root_offset);
401
  };
 
 
 
402
  if (!_this.el || !_this.el.parentElement) {
403
  return _this;
404
  }
411
  if (!this.el) {
412
  return;
413
  }
 
414
  this.clone();
415
+ this.offsets.clear();
416
+ this.offsets = new DynamicOffsets(this.clone_el, this.get_root_offset, this.need_to_calc_el_offset, this.get_prev_sibling, this.get_next_sibling);
417
+ this.offsets.init(margins);
418
+ this.height_watcher = reactive(function () { return _this.offsets.height; });
419
+ this.height_watcher.on_change(function (height) {
420
  if (_this.clone_el) {
421
  _this.clone_el.style.height = "".concat(height, "px");
422
  }
423
  });
424
  };
425
+ FixedWidget.prototype.unmount = function () {
426
+ var _a;
427
+ _super.prototype.unmount.call(this);
428
+ this.height_watcher.clear();
429
+ (_a = this.clone_el) === null || _a === void 0 ? void 0 : _a.remove();
430
+ };
431
+ FixedWidget.prototype.set_max_offset = function (max_top_offsets) {
432
+ var _this = this;
433
+ var max_top_offset = max_top_offsets.find(function (offset) {
434
+ return offset !== 0 && offset > _this.offsets.root;
435
+ });
436
+ if (!max_top_offset) {
437
  return;
438
  }
439
+ this.offsets.set_max_offset(max_top_offset);
440
+ };
441
+ FixedWidget.prototype.on_scroll = function (scroll_top) {
442
+ if (!this.el) {
443
+ return;
444
+ }
445
+ var need_to_fix = scroll_top > this.offsets.root - this.offsets.top;
446
+ var limited_by_stop_element = this.offsets.max_top_offset !== 0 && scroll_top > this.offsets.relative_top - this.offsets.top;
447
+ var top = limited_by_stop_element ? this.offsets.relative_top - scroll_top : this.offsets.top;
448
+ need_to_fix ?
449
+ this.fix(top) :
450
+ this.restore_style();
451
  };
452
  FixedWidget.prototype.clone = function () {
453
  var _this = this;
464
  this.clone_el.style.display = 'none';
465
  this.el.parentElement.insertBefore(this.clone_el, this.el);
466
  };
467
+ FixedWidget.prototype.restore_style = function () {
468
+ if (!this.is_pinned || !this.el) {
 
 
 
 
 
 
 
 
469
  return;
470
  }
471
  this.unpin();
472
+ _super.prototype.restore_style.call(this);
473
  if (this.clone_el) {
474
  this.clone_el.style.display = 'none';
475
  }
476
  };
 
 
 
 
 
 
 
 
 
 
 
477
  FixedWidget.prototype.fix = function (top) {
478
  if (!this.el) {
479
  return;
508
  var _this = _super.call(this, el) || this;
509
  _this.borderBox = 0;
510
  _this.margins = 0;
 
 
 
511
  if (!_this.el || !_this.el.parentElement) {
512
  return _this;
513
  }
516
  }
517
  StickyWidget.prototype.mount = function (margins) {
518
  _super.prototype.mount.call(this, margins);
519
+ if (!this.el) {
520
  return;
521
  }
522
  this.el.style.position = 'sticky';
524
  this.el.style.transition = 'transform 0s';
525
  this.el.style.boxSizing = 'border-box';
526
  };
527
+ StickyWidget.prototype.set_max_offset = function (max_top_offsets) {
528
+ var _this = this;
529
  if (!this.el || !this.el.parentElement) {
530
  return;
531
  }
532
+ var max_top_offset = max_top_offsets.find(function (offset) {
533
+ return _this.el && (offset > _this.el.offsetTop);
534
+ });
535
+ if (!max_top_offset) {
536
  return;
537
  }
538
+ this.offsets.set_max_offset(max_top_offset);
539
  };
540
+ StickyWidget.prototype.on_scroll = function (_scroll_top, _reject) {
541
  if (!this.el || !this.el.parentElement) {
542
  return;
543
  }
596
  this.widgets = [];
597
  this.stop_widgets = [];
598
  this.isSticky = false;
599
+ this.setWidgetsMaxOffset = function (max_offsets) {
600
  for (var _i = 0, _a = _this.widgets; _i < _a.length; _i++) {
601
  var widget = _a[_i];
602
+ widget.set_max_offset(max_offsets);
603
  }
604
  _this.render();
605
  };
606
+ this.logWidgetRenderError = function () {
607
+ console.log("Fixed Widget: fallback to position sticky");
608
+ };
609
+ this.onWidgetRenderError = function (w) {
610
+ _this.logWidgetRenderError();
611
+ if (!(w instanceof StickyWidget)) {
612
+ return;
613
+ }
614
+ w.unmount();
615
+ var i = _this.widgets.findIndex(function (widget) { return w === widget; });
616
+ var widget = new FixedWidget(w.getElement());
617
+ widget.mount(_this.margins);
618
+ widget.render(_this.logWidgetRenderError);
619
+ _this.widgets[i] = widget;
620
+ };
621
  var isDeprecatedFloatMarkup = !!findWithProperty(this.el, function (style) { return style.float !== 'none'; });
622
  var isOverflowHiddenMarkup = !!findWithProperty(this.el, function (style) { return style.overflow === 'hidden'; });
623
  var isFallbackToSticky = (isDeprecatedFloatMarkup || isOverflowHiddenMarkup) && use_sticky_position;
629
  var WidgetContructor = this.isSticky ? StickyWidget : FixedWidget;
630
  this.stop_widgets = StopWidget.from(this.el);
631
  this.widgets = WidgetContructor.from(this.el);
632
+ this.offsets = new DynamicOffsets(this.el);
633
  if (!this.isSticky) {
634
  return;
635
  }
641
  }
642
  Sidebar.prototype.mount = function () {
643
  var _this = this;
644
+ this.offsets.clear();
645
+ this.max_offset_watcher && this.max_offset_watcher.clear();
646
+ this.offsets.init(this.margins);
647
  this.stop_widgets.forEach(function (widget) { widget.mount(); });
648
  this.widgets.forEach(function (widget) { widget.mount(_this.margins); });
649
+ this.widgets = this.widgets.sort(function (a, b) { return a.offsets.root - b.offsets.root; });
650
  };
651
+ Sidebar.prototype.set_max_offset = function (general_stop_widgets) {
652
  var is_local_stop_widgets = this.stop_widgets.length != 0;
653
  var use_top_offset = this.isSticky && is_local_stop_widgets;
654
  var stop_widgets = is_local_stop_widgets ? this.stop_widgets : general_stop_widgets;
655
+ this.max_offset_watcher = reactive(function () {
656
  if (stop_widgets.length === 0) {
657
+ return [Math.round(document.body.scrollHeight)];
658
  }
659
+ return stop_widgets
660
+ .map(function (widget) { return Math.round(use_top_offset ? widget.offsets.top : widget.offsets.root); })
661
+ .sort();
662
+ });
663
+ this.max_offset_watcher.on_change(this.setWidgetsMaxOffset);
 
 
 
 
 
 
 
664
  };
665
  Sidebar.prototype.render = function () {
666
  for (var _i = 0, _a = this.stop_widgets; _i < _a.length; _i++) {
667
  var stop_widget = _a[_i];
668
+ stop_widget.render(this.logWidgetRenderError);
669
+ }
670
+ for (var _b = 0, _c = this.widgets; _b < _c.length; _b++) {
671
+ var widget = _c[_b];
672
+ widget.render(this.onWidgetRenderError);
673
+ }
674
+ };
675
+ Sidebar.prototype.unmount = function () {
676
+ for (var _i = 0, _a = this.stop_widgets; _i < _a.length; _i++) {
677
+ var stop_widget = _a[_i];
678
+ stop_widget.unmount();
679
  }
680
  for (var _b = 0, _c = this.widgets; _b < _c.length; _b++) {
681
  var widget = _c[_b];
682
+ widget.unmount();
683
  }
684
  };
685
  return Sidebar;
701
  }
702
  Sidebars.prototype.mount = function () {
703
  this.data.forEach(function (sidebar) { sidebar.mount(); });
704
+ this.set_max_offset();
705
+ };
706
+ Sidebars.prototype.unmonut = function () {
707
+ this.data.forEach(function (sidebar) { sidebar.unmount(); });
708
  };
709
+ Sidebars.prototype.set_max_offset = function () {
710
  var general_stop_widgets = this.getGeneralStopElements();
711
  for (var _i = 0, _a = this.data; _i < _a.length; _i++) {
712
  var sidebar = _a[_i];
713
+ sidebar.set_max_offset(general_stop_widgets);
714
  }
715
  };
716
  Sidebars.prototype.getGeneralStopElements = function () {
736
  });
737
  fixedWidgetsContainers.forEach(function (c) { c.classList.add(FixedWidgetClassName); });
738
  stopWidgetsUniqContainers.forEach(function (c) { c.classList.add(StopWidgetClassName); });
739
+ var widgetContainers = fixedWidgetsContainers.concat(stopWidgetsUniqContainers)
740
+ .filter(function (container) {
741
+ var hasNestedWidget = container.innerHTML.includes(FixedWidgetClassName) ||
742
+ container.innerHTML.includes(StopWidgetClassName);
743
+ hasNestedWidget && console.warn('Fixed Widget: Detected nested widget in ', container);
744
+ return !hasNestedWidget;
745
+ });
746
+ return new Sidebars(widgetContainers, options);
747
  };
748
  return Sidebars;
749
  }());
756
  Plugin.sidebars.render();
757
  return;
758
  }
759
+ Plugin.sidebars = Sidebars.new(options.reduce(function (prev, cur) { return (__assign(__assign(__assign({}, prev), cur), { stop_elements_selectors: "".concat(prev.stop_elements_selectors, "\n").concat(cur.stop_elements_selectors), widgets: (prev.widgets || []).concat(cur.widgets || []) })); }));
760
  document.addEventListener('scroll', Plugin.sidebars.render);
761
+ window.addEventListener('resize', function () {
762
+ Plugin.sidebars.unmonut();
763
+ setTimeout(function () {
764
+ Plugin.sidebars.mount();
765
+ Plugin.sidebars.render();
766
+ });
767
+ });
768
  Plugin.sidebars.mount();
769
  }
770
  return Plugin;
771
  }());
772
 
773
+ document.addEventListener("DOMContentLoaded", onDocumentLoaded);
774
  document.readyState === "complete" && onDocumentLoaded();
 
775
  function onDocumentLoaded() {
776
  var admin_panel = document.querySelector('#wpadminbar');
777
  var user_options = window['q2w3_sidebar_options'] || [{}];
785
  })) {
786
  return;
787
  }
788
+ new Plugin(options, '6.0.7-9');
789
  }
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_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();
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(),interval_id=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);return{get val(){return v},on_change:function(update){update(v),subs.push(update)},clear:function(){clearInterval(interval_id)}}},StaticOffsets=function(){function StaticOffsets(el,get_root_offset,need_to_calc_offset,get_prev_sibling){void 0===el&&(el=null),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.get_root_offset=get_root_offset,this.need_to_calc_offset=need_to_calc_offset,this.get_prev_sibling=get_prev_sibling,this.user_margins={},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)}}return StaticOffsets.prototype.init=function(user_margins){var _this=this;this.user_margins=user_margins,this.top_watcher=reactive(this.get_top_offset),this.top_watcher.on_change((function(top){_this.top=top})),this.root_watcher=reactive(this.get_root_offset),this.root_watcher.on_change((function(root){_this.root=root}))},StaticOffsets.prototype.clear=function(){this.top_watcher&&this.top_watcher.clear(),this.root_watcher&&this.root_watcher.clear()},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,get_root_offset,need_to_calc_offset,get_prev_sibling,get_next_sibling){void 0===el&&(el=null),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,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.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)},_this}return __extends(DynamicOffsets,_super),DynamicOffsets.prototype.init=function(user_margins){var _this=this;_super.prototype.init.call(this,user_margins),this.height_watcher=reactive(this.get_height),this.height_watcher.on_change((function(height){_this.height=height,_this.border_box=_this.get_border_box(),_this.relative_top=_this.get_relative_top()})),this.bottom_offset=reactive(this.get_bottom_offset),this.bottom_offset.on_change((function(bottom){_this.bottom=bottom,_this.relative_top=_this.get_relative_top()}))},DynamicOffsets.prototype.clear=function(){_super.prototype.clear.call(this),this.height_watcher&&this.height_watcher.clear(),this.bottom_offset&&this.bottom_offset.clear()},DynamicOffsets.prototype.update=function(){this.position=this.get_position()},DynamicOffsets.prototype.set_max_offset=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(this.el,this.get_root_offset)}return Widget.prototype.mount=function(user_margins){void 0===user_margins&&(user_margins={}),this.offsets.init(user_margins)},Widget.prototype.render=function(_reject){this.offsets.update()},Widget.prototype.unmount=function(){this.offsets.clear()},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(el){var _this=_super.call(this,el)||this;return _this.is_pinned=!1,_this.init_style={position:"static",marginBottom:"",transition:"",transform:"",marginTop:"",padding:"",height:"",width:"",top:""},_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.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.offsets=new DynamicOffsets(_this.el,_this.get_root_offset,_this.need_to_calc_el_offset,_this.get_prev_sibling,_this.get_next_sibling),_this}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins){_super.prototype.mount.call(this,user_margins),this.el&&this.el.parentElement&&this.store_style(getComputedStyle(this.el))},PositionWidget.prototype.unmount=function(){_super.prototype.unmount.call(this),this.unpin(),this.reset_styles()},PositionWidget.prototype.reset_styles=function(){if(this.el){for(var prop in this.init_style)this.el.style[prop]="";this.init_style={position:"static",marginBottom:"",transition:"",transform:"",marginTop:"",padding:"",height:"",width:"",top:""}}},PositionWidget.prototype.render=function(reject){_super.prototype.render.call(this,reject),this.on_scroll(Math.round(scrollY),reject)},PositionWidget.from=function(root){return _super.from.call(this,root,FixedWidgetClassName)},PositionWidget.prototype.on_scroll=function(_scroll_top,_reject){throw new Error("Method is not overridden!")},PositionWidget.prototype.pin=function(){!this.is_pinned&&this.el&&(this.is_pinned=!0,this.el.classList.add("FixedWidget__fixed_widget__pinned"))},PositionWidget.prototype.unpin=function(){this.is_pinned&&this.el&&(this.is_pinned=!1,this.el.classList.remove("FixedWidget__fixed_widget__pinned"))},PositionWidget.prototype.store_style=function(style){this.init_style.position=style.position,this.init_style.top=style.top,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,this.init_style.transition=style.transition,this.init_style.transform=style.transform},PositionWidget.prototype.restore_style=function(){if(this.el)for(var prop in this.init_style)this.el.style[prop]=this.init_style[prop]},PositionWidget}(Widget),FixedWidget=function(_super){function FixedWidget(el){var _this=_super.call(this,el)||this;return _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.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.clone(),this.offsets.clear(),this.offsets=new DynamicOffsets(this.clone_el,this.get_root_offset,this.need_to_calc_el_offset,this.get_prev_sibling,this.get_next_sibling),this.offsets.init(margins),this.height_watcher=reactive((function(){return _this.offsets.height})),this.height_watcher.on_change((function(height){_this.clone_el&&(_this.clone_el.style.height="".concat(height,"px"))})))},FixedWidget.prototype.unmount=function(){var _a;_super.prototype.unmount.call(this),this.height_watcher.clear(),null===(_a=this.clone_el)||void 0===_a||_a.remove()},FixedWidget.prototype.set_max_offset=function(max_top_offsets){var _this=this,max_top_offset=max_top_offsets.find((function(offset){return 0!==offset&&offset>_this.offsets.root}));max_top_offset&&this.offsets.set_max_offset(max_top_offset)},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()}},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.restore_style=function(){this.is_pinned&&this.el&&(this.unpin(),_super.prototype.restore_style.call(this),this.clone_el&&(this.clone_el.style.display="none"))},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.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.style.position="sticky",this.el.style.position="-webkit-sticky",this.el.style.transition="transform 0s",this.el.style.boxSizing="border-box")},StickyWidget.prototype.set_max_offset=function(max_top_offsets){var _this=this;if(this.el&&this.el.parentElement){var max_top_offset=max_top_offsets.find((function(offset){return _this.el&&offset>_this.el.offsetTop}));max_top_offset&&this.offsets.set_max_offset(max_top_offset)}},StickyWidget.prototype.on_scroll=function(_scroll_top,_reject){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_offsets){for(var _i=0,_a=_this.widgets;_i<_a.length;_i++){_a[_i].set_max_offset(max_offsets)}_this.render()},this.logWidgetRenderError=function(){console.log("Fixed Widget: fallback to position sticky")},this.onWidgetRenderError=function(w){if(_this.logWidgetRenderError(),w instanceof StickyWidget){w.unmount();var i=_this.widgets.findIndex((function(widget){return w===widget})),widget=new FixedWidget(w.getElement());widget.mount(_this.margins),widget.render(_this.logWidgetRenderError),_this.widgets[i]=widget}};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.offsets=new DynamicOffsets(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.offsets.clear(),this.max_offset_watcher&&this.max_offset_watcher.clear(),this.offsets.init(this.margins),this.stop_widgets.forEach((function(widget){widget.mount()})),this.widgets.forEach((function(widget){widget.mount(_this.margins)})),this.widgets=this.widgets.sort((function(a,b){return a.offsets.root-b.offsets.root}))},Sidebar.prototype.set_max_offset=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;this.max_offset_watcher=reactive((function(){return 0===stop_widgets.length?[Math.round(document.body.scrollHeight)]:stop_widgets.map((function(widget){return Math.round(use_top_offset?widget.offsets.top:widget.offsets.root)})).sort()})),this.max_offset_watcher.on_change(this.setWidgetsMaxOffset)},Sidebar.prototype.render=function(){for(var _i=0,_a=this.stop_widgets;_i<_a.length;_i++){_a[_i].render(this.logWidgetRenderError)}for(var _b=0,_c=this.widgets;_b<_c.length;_b++){_c[_b].render(this.onWidgetRenderError)}},Sidebar.prototype.unmount=function(){for(var _i=0,_a=this.stop_widgets;_i<_a.length;_i++){_a[_i].unmount()}for(var _b=0,_c=this.widgets;_b<_c.length;_b++){_c[_b].unmount()}},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.set_max_offset()},Sidebars.prototype.unmonut=function(){this.data.forEach((function(sidebar){sidebar.unmount()}))},Sidebars.prototype.set_max_offset=function(){for(var general_stop_widgets=this.getGeneralStopElements(),_i=0,_a=this.data;_i<_a.length;_i++){_a[_i].set_max_offset(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).filter((function(container){var hasNestedWidget=container.innerHTML.includes(FixedWidgetClassName)||container.innerHTML.includes(StopWidgetClassName);return hasNestedWidget&&console.warn("Fixed Widget: Detected nested widget in ",container),!hasNestedWidget})),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),{stop_elements_selectors:"".concat(prev.stop_elements_selectors,"\n").concat(cur.stop_elements_selectors),widgets:(prev.widgets||[]).concat(cur.widgets||[])})}))),document.addEventListener("scroll",Plugin.sidebars.render),window.addEventListener("resize",(function(){Plugin.sidebars.unmonut(),setTimeout((function(){Plugin.sidebars.mount(),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-9")}document.addEventListener("DOMContentLoaded",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.1.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.1.0';
27
 
28
  protected static $sidebars_widgets;
29
 
5
  Description: Use the fixed widget plugin to create sticky widgets that stay in the visible screen area when the page is scrolled up or down and boost your conversions.
6
  Text Domain: q2w3-fixed-widget
7
  Author: Thomas Maier, Max Bond
8
+ Version: 6.1.1
9
  Author URI: https://wpadvancedads.com/fixed-widget-wordpress/
10
  */
11
 
23
 
24
  const ID = 'q2w3_fixed_widget';
25
 
26
+ const VERSION = '6.1.1';
27
 
28
  protected static $sidebars_widgets;
29
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: webzunft, max-bond, advancedads
3
  Tags: fixed widget, sticky widget, sidebar, ads, widget, fixed, sticky, floating, sticky block, adsense
4
  Requires at least: 5.0
5
  Tested up to: 6.0
6
- Stable tag: 6.1.0
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
@@ -81,6 +81,11 @@ Use the options `Minimum Screen Width` and `Minimum Screen Height` to disable st
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.
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.1
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
81
 
82
  == Changelog ==
83
 
84
+ = 6.1.1 =
85
+
86
+ - Improvement: reposition the fixed widget when the screen is resized, e.g., a mobile device turned into landscape mode
87
+ - Improvement: various optimizations for specific themes and setups reported by users
88
+
89
  = 6.1.0 =
90
 
91
  - 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.