Q2W3 Fixed Widget - Version 6.0.7

Version Description

  • Improvement: Compatibility with relative padding values
Download this release

Release Info

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

Code changes from version 6.0.6 to 6.0.7

Files changed (4) hide show
  1. js/frontend.js +176 -144
  2. js/frontend.min.js +1 -1
  3. q2w3-fixed-widget.php +2 -2
  4. readme.txt +5 -1
js/frontend.js CHANGED
@@ -24,17 +24,144 @@ var __assign = function() {
24
  return __assign.apply(this, arguments);
25
  };
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  var StopWidgetClassName = 'FixedWidget__stop_widget';
28
  var FixedWidgetClassName = 'FixedWidget__fixed_widget';
29
  var Widget = (function () {
30
  function Widget(el) {
 
31
  this.el = el;
32
- this.top_offset = 0;
33
- this.root_offset = 0;
34
  this.need_to_calc_el_offset = function (_) { return false; };
35
- this.prevSibling = function (el) {
36
- return el && el.previousElementSibling;
37
- };
38
  }
39
  Widget.prototype.render = function () {
40
  throw new Error('Method is not overridden!');
@@ -44,7 +171,7 @@ var Widget = (function () {
44
  if (!this.el || !this.el.parentElement) {
45
  return;
46
  }
47
- this.top_offset = this.get_total_top_offset(user_margins);
48
  };
49
  Widget.prototype.getElement = function () {
50
  return this.el;
@@ -53,9 +180,6 @@ var Widget = (function () {
53
  var _a;
54
  return "".concat((_a = this.el) === null || _a === void 0 ? void 0 : _a.innerHTML);
55
  };
56
- Widget.prototype.get_total_top_offset = function (margins) {
57
- return get_sibilings_offset(this.prevSibling, this.need_to_calc_el_offset, this.prevSibling(this.el), margins.margin_top);
58
- };
59
  Widget.queryAllWidgetsContainers = function (className) {
60
  return []
61
  .concat(Array.from(document.querySelectorAll(".".concat(className))), Array.from(document.querySelectorAll("[data-fixed_widget=".concat(className))))
@@ -89,17 +213,6 @@ var getWidgetContainer = function (el) {
89
  el.parentElement.classList.toString().includes('wp-block-column') ||
90
  el.parentElement.classList.contains('widget')) ? getWidgetContainer(el.parentElement) : el;
91
  };
92
- var get_sibilings_offset = function (next, need_to_calc_el_offset, el, offset) {
93
- if (offset === void 0) { offset = 0; }
94
- if (!el) {
95
- return offset;
96
- }
97
- if (!need_to_calc_el_offset(el)) {
98
- return get_sibilings_offset(next, need_to_calc_el_offset, next(el), offset);
99
- }
100
- var _a = getComputedStyle(el), marginTop = _a.marginTop, marginBottom = _a.marginBottom;
101
- return get_sibilings_offset(next, need_to_calc_el_offset, next(el), offset + el.getBoundingClientRect().height + parseInt(marginTop || '0') + parseInt(marginBottom || '0'));
102
- };
103
 
104
  var findIntersections = function (arr1, arr2) {
105
  return [
@@ -139,94 +252,29 @@ function findWithProperty(el, predicate) {
139
  return findWithProperty(el.parentElement, predicate);
140
  }
141
 
142
- var reactive = function (getter, interval) {
143
- if (interval === void 0) { interval = 300; }
144
- var subs = [];
145
- var v = getter();
146
- setInterval(check, interval);
147
- function check() {
148
- if (subs.length === 0) {
149
- return;
150
- }
151
- var new_v = getter();
152
- if (v === new_v) {
153
- return;
154
- }
155
- v = new_v;
156
- for (var _i = 0, subs_1 = subs; _i < subs_1.length; _i++) {
157
- var update = subs_1[_i];
158
- update(new_v);
159
- }
160
- }
161
- return {
162
- get val() {
163
- return v;
164
- },
165
- on_change: function (update) {
166
- update(v);
167
- subs.push(update);
168
- }
169
- };
170
- };
171
-
172
  var PositionWidget = (function (_super) {
173
  __extends(PositionWidget, _super);
174
  function PositionWidget() {
175
  var _this = _super !== null && _super.apply(this, arguments) || this;
176
- _this.bottom_offset = 0;
177
- _this.top_margin = 0;
178
- _this.borderBox = 0;
179
- _this.block_height = reactive(function () { return 0; });
180
- _this.max_top_offset = 0;
181
- _this.bottom_margin = 0;
182
- _this.user_margins = {};
183
- _this.prevSibling = function (el) {
184
  return el
185
  && !el.classList.contains(StopWidgetClassName)
186
  && el.previousElementSibling
187
  || null;
188
  };
189
- _this.get_total_bottom_offset = function (margins) {
190
- var next = function (el) { return el && !el.classList.contains(StopWidgetClassName) ? el.nextElementSibling : null; };
191
- return get_sibilings_offset(next, _this.need_to_calc_el_offset, next(_this.el), margins.margin_bottom);
192
- };
193
  return _this;
194
  }
195
  PositionWidget.prototype.mount = function (user_margins) {
196
- var _this = this;
197
  _super.prototype.mount.call(this, user_margins);
198
  if (!this.el || !this.el.parentElement) {
199
  return;
200
  }
201
- this.user_margins = user_margins;
202
- var _a = getComputedStyle(this.el), marginTop = _a.marginTop, marginBottom = _a.marginBottom;
203
- this.bottom_margin = parseInt(marginBottom);
204
- this.top_margin = parseInt(marginTop);
205
- this.bottom_offset = this.get_total_bottom_offset(user_margins);
206
- this.block_height = reactive(function () {
207
- if (!_this.el) {
208
- return 0;
209
- }
210
- return Math.round(Math.max(_this.el.clientHeight, _this.el.scrollHeight, _this.el.getBoundingClientRect().height));
211
- });
212
- this.block_height.on_change(function (block_height) {
213
- _this.borderBox = block_height + _this.top_margin + _this.bottom_margin;
214
- });
215
- reactive(this.get_total_bottom_offset.bind(this, user_margins))
216
- .on_change(function (bottom_offset) {
217
- _this.bottom_offset = bottom_offset;
218
- });
219
- reactive(this.get_total_top_offset.bind(this, user_margins))
220
- .on_change(function (top_offset) {
221
- _this.top_offset = top_offset;
222
- if (!_this.el) {
223
- return;
224
- }
225
- _this.el.style.top = "".concat(top_offset, "px");
226
- });
227
  };
228
  PositionWidget.prototype.setMaxOffset = function (max_top_offset) {
229
- this.max_top_offset = max_top_offset;
230
  };
231
  PositionWidget.prototype.render = function () {
232
  this.on_scroll(scrollY);
@@ -245,9 +293,19 @@ var FixedWidget = (function (_super) {
245
  function FixedWidget(el) {
246
  var _this = _super.call(this, el) || this;
247
  _this.is_pinned = false;
248
- _this.relative_top = 0;
249
- _this.paddings = 0;
250
- _this.init_style = { position: 'static', marginTop: '', marginBottom: '', width: '', height: '' };
 
 
 
 
 
 
 
 
 
 
251
  _this.need_to_calc_el_offset = function (el) {
252
  return el.classList.contains(FixedWidgetClassName);
253
  };
@@ -263,34 +321,25 @@ var FixedWidget = (function (_super) {
263
  if (!this.el) {
264
  return;
265
  }
266
- this.paddings =
267
- this.top_offset
268
- + this.top_margin
269
- + this.bottom_margin
270
- + this.bottom_offset;
271
  this.store_style(getComputedStyle(this.el));
272
  this.clone();
273
- this.block_height.on_change(function (block_height) {
274
- _this.relative_top = _this.max_top_offset - block_height - _this.paddings;
 
 
275
  });
276
  };
277
- FixedWidget.prototype.update_root_offset = function () {
278
- var element = this.is_pinned ? this.clone_el : this.el;
279
- var new_root_offset = Math.round(scrollY + (element ? element.getBoundingClientRect().top : 0));
280
- this.root_offset = this.is_pinned ? new_root_offset : Math.max(this.root_offset, new_root_offset);
281
- };
282
  FixedWidget.prototype.setMaxOffset = function (max_top_offset) {
283
  if (max_top_offset === 0 ||
284
- max_top_offset < this.root_offset ||
285
- this.max_top_offset === max_top_offset) {
286
  return;
287
  }
288
- this.max_top_offset = max_top_offset;
289
- this.relative_top = this.max_top_offset - this.block_height.val - this.paddings;
290
  };
291
  FixedWidget.prototype.clone = function () {
292
  var _this = this;
293
- if (!this.el || !this.el.parentElement) {
294
  return;
295
  }
296
  this.clone_el = this.el.cloneNode(false);
@@ -307,6 +356,7 @@ var FixedWidget = (function (_super) {
307
  this.init_style.position = style.position;
308
  this.init_style.marginTop = style.marginTop;
309
  this.init_style.marginBottom = style.marginBottom;
 
310
  this.init_style.width = style.width;
311
  this.init_style.height = style.height;
312
  };
@@ -324,10 +374,9 @@ var FixedWidget = (function (_super) {
324
  if (!this.el) {
325
  return;
326
  }
327
- this.update_root_offset();
328
- var need_to_fix = scroll_top > this.root_offset - this.top_offset;
329
- var limited_by_stop_element = this.max_top_offset !== 0 && scroll_top > this.relative_top;
330
- var top = limited_by_stop_element ? this.relative_top - scroll_top + this.top_offset : this.top_offset;
331
  need_to_fix ?
332
  this.fix(top) :
333
  this.restore_style(this.el.style);
@@ -344,6 +393,7 @@ var FixedWidget = (function (_super) {
344
  this.el.style.position = 'fixed';
345
  this.el.style.transition = 'transform 0.5s';
346
  this.el.style.width = this.init_style.width;
 
347
  if (!this.clone_el) {
348
  return;
349
  }
@@ -363,13 +413,8 @@ var StickyWidget = (function (_super) {
363
  __extends(StickyWidget, _super);
364
  function StickyWidget(el) {
365
  var _this = _super.call(this, el) || this;
 
366
  _this.margins = 0;
367
- _this.get_margins = function () {
368
- return (_this.el && _this.el.parentElement && _this.el.parentElement.clientHeight || 0)
369
- - _this.bottom_margin
370
- - _this.top_margin
371
- - _this.block_height.val;
372
- };
373
  _this.need_to_calc_el_offset = function (el) {
374
  return el.classList.contains(FixedWidgetClassName);
375
  };
@@ -380,15 +425,10 @@ var StickyWidget = (function (_super) {
380
  return _this;
381
  }
382
  StickyWidget.prototype.mount = function (margins) {
383
- var _this = this;
384
  _super.prototype.mount.call(this, margins);
385
  if (!this.el || !this.el.parentElement) {
386
  return;
387
  }
388
- reactive(this.get_margins)
389
- .on_change(function (margins) {
390
- _this.margins = margins;
391
- });
392
  this.el.style.position = 'sticky';
393
  this.el.style.position = '-webkit-sticky';
394
  this.el.style.transition = 'transform 0s';
@@ -401,21 +441,21 @@ var StickyWidget = (function (_super) {
401
  if (max_top_offset < this.el.offsetTop) {
402
  return;
403
  }
404
- this.max_top_offset = max_top_offset;
405
  };
406
  StickyWidget.prototype.on_scroll = function () {
407
  if (!this.el || !this.el.parentElement) {
408
  return;
409
  }
410
- var bottom_margin = this.max_top_offset ?
411
- Math.min(this.max_top_offset - this.el.offsetTop - this.borderBox, this.margins - this.el.offsetTop)
412
- : this.margins - this.el.offsetTop;
413
- this.el.style.top = "".concat(this.top_offset, "px");
414
- if (bottom_margin >= this.bottom_offset) {
415
  this.el.style.transform = "translateY(0px)";
416
  return;
417
  }
418
- this.el.style.transform = "translateY(".concat(bottom_margin - this.bottom_offset, "px)");
419
  };
420
  StickyWidget.new = function (selector) {
421
  return new StickyWidget(document.querySelector(selector));
@@ -438,14 +478,6 @@ var StopWidget = (function (_super) {
438
  _this.el.classList.add(StopWidgetClassName);
439
  return _this;
440
  }
441
- StopWidget.prototype.mount = function (user_margins) {
442
- var _this = this;
443
- _super.prototype.mount.call(this, user_margins);
444
- reactive(function () { return Math.round(scrollY + (_this.el ? _this.el.getBoundingClientRect().top : 0)); })
445
- .on_change(function (root_offset) {
446
- _this.root_offset = root_offset;
447
- });
448
- };
449
  StopWidget.new = function (selector) {
450
  return new StopWidget(document.querySelector(selector));
451
  };
@@ -508,11 +540,11 @@ var Sidebar = (function () {
508
  return Math.round(document.body.scrollHeight);
509
  }
510
  var min_offset = use_top_offset ?
511
- stop_widgets[0].top_offset :
512
- stop_widgets[0].root_offset;
513
  for (var _i = 0, stop_widgets_1 = stop_widgets; _i < stop_widgets_1.length; _i++) {
514
  var widget = stop_widgets_1[_i];
515
- var offset = use_top_offset ? widget.top_offset : widget.root_offset;
516
  if (min_offset > offset) {
517
  min_offset = offset;
518
  }
@@ -543,7 +575,7 @@ var Sidebars = (function () {
543
  };
544
  this.data = Array.from(new Set(elements.map(function (widget) { return widget.parentElement; })))
545
  .filter(function (sidebar_el) { return sidebar_el !== null; })
546
- .map(function (sidebar_el) { return new Sidebar(sidebar_el, options, options.use_sticky_position); });
547
  }
548
  Sidebars.prototype.mount = function () {
549
  this.data.forEach(function (sidebar) { sidebar.mount(); });
24
  return __assign.apply(this, arguments);
25
  };
26
 
27
+ 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;
35
+ }
36
+ var new_v = getter();
37
+ if (v === new_v) {
38
+ return;
39
+ }
40
+ v = new_v;
41
+ for (var _i = 0, subs_1 = subs; _i < subs_1.length; _i++) {
42
+ var update = subs_1[_i];
43
+ update(new_v);
44
+ }
45
+ }
46
+ return {
47
+ get val() {
48
+ return v;
49
+ },
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_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) {
85
+ return offset;
86
+ }
87
+ if (!this.need_to_calc_offset(el)) {
88
+ return this.get_sibilings_offset(next, next(el), offset);
89
+ }
90
+ var _a = getComputedStyle(el), marginTop = _a.marginTop, marginBottom = _a.marginBottom;
91
+ return this.get_sibilings_offset(next, next(el), offset + el.getBoundingClientRect().height + parseInt(marginTop || '0') + parseInt(marginBottom || '0'));
92
+ };
93
+ return StaticOffsets;
94
+ }());
95
+ var DynamicOffsets = (function (_super) {
96
+ __extends(DynamicOffsets, _super);
97
+ function DynamicOffsets(el, user_margins, get_root_offset, need_to_calc_offset, get_prev_sibling, get_next_sibling) {
98
+ if (el === void 0) { el = null; }
99
+ if (user_margins === void 0) { user_margins = {}; }
100
+ if (need_to_calc_offset === void 0) { need_to_calc_offset = function () { return false; }; }
101
+ if (get_prev_sibling === void 0) { get_prev_sibling = function () { return null; }; }
102
+ if (get_next_sibling === void 0) { get_next_sibling = function () { return null; }; }
103
+ var _this = _super.call(this, el, user_margins, get_root_offset, need_to_calc_offset, get_prev_sibling) || this;
104
+ _this.get_next_sibling = get_next_sibling;
105
+ _this.bottom = 0;
106
+ _this.max_top_offset = 0;
107
+ _this.relative_top = 0;
108
+ _this.height = 0;
109
+ _this.position = { top: 0, bottom: 0 };
110
+ _this.border_box = 0;
111
+ _this.get_height = function () {
112
+ return !_this.el ? 0 :
113
+ Math.round(Math.max(_this.el.clientHeight, _this.el.scrollHeight, _this.el.getBoundingClientRect().height));
114
+ };
115
+ _this.get_bottom_offset = function () {
116
+ return _this.get_sibilings_offset(_this.get_next_sibling, _this.get_next_sibling(_this.el), _this.user_margins.margin_bottom);
117
+ };
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) {
125
+ _this.bottom = bottom;
126
+ _this.relative_top = _this.get_relative_top();
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();
133
+ };
134
+ DynamicOffsets.prototype.get_position = function () {
135
+ if (!this.el || !this.el.parentElement) {
136
+ return { top: 0, bottom: 0 };
137
+ }
138
+ return {
139
+ top: this.el.offsetTop,
140
+ bottom: this.el.parentElement.clientHeight - this.el.offsetTop - this.border_box
141
+ };
142
+ };
143
+ DynamicOffsets.prototype.get_border_box = function () {
144
+ if (!this.el) {
145
+ return 0;
146
+ }
147
+ var _a = getComputedStyle(this.el), marginTop = _a.marginTop, marginBottom = _a.marginBottom;
148
+ return this.height + parseInt(marginTop) + parseInt(marginBottom);
149
+ };
150
+ DynamicOffsets.prototype.get_relative_top = function () {
151
+ return this.max_top_offset - this.border_box - this.bottom;
152
+ };
153
+ return DynamicOffsets;
154
+ }(StaticOffsets));
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;
161
  this.el = el;
162
+ this.get_root_offset = function () { return Math.round(scrollY + (_this.el ? _this.el.getBoundingClientRect().top : 0)); };
 
163
  this.need_to_calc_el_offset = function (_) { return false; };
164
+ this.offsets = new StaticOffsets();
 
 
165
  }
166
  Widget.prototype.render = function () {
167
  throw new Error('Method is not overridden!');
171
  if (!this.el || !this.el.parentElement) {
172
  return;
173
  }
174
+ this.offsets = new StaticOffsets(this.el, user_margins, this.get_root_offset);
175
  };
176
  Widget.prototype.getElement = function () {
177
  return this.el;
180
  var _a;
181
  return "".concat((_a = this.el) === null || _a === void 0 ? void 0 : _a.innerHTML);
182
  };
 
 
 
183
  Widget.queryAllWidgetsContainers = function (className) {
184
  return []
185
  .concat(Array.from(document.querySelectorAll(".".concat(className))), Array.from(document.querySelectorAll("[data-fixed_widget=".concat(className))))
213
  el.parentElement.classList.toString().includes('wp-block-column') ||
214
  el.parentElement.classList.contains('widget')) ? getWidgetContainer(el.parentElement) : el;
215
  };
 
 
 
 
 
 
 
 
 
 
 
216
 
217
  var findIntersections = function (arr1, arr2) {
218
  return [
252
  return findWithProperty(el.parentElement, predicate);
253
  }
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  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
262
  && !el.classList.contains(StopWidgetClassName)
263
  && el.previousElementSibling
264
  || null;
265
  };
266
+ _this.get_next_sibling = function (el) { return el && !el.classList.contains(StopWidgetClassName) ? el.nextElementSibling : null; };
 
 
 
267
  return _this;
268
  }
269
  PositionWidget.prototype.mount = function (user_margins) {
 
270
  _super.prototype.mount.call(this, user_margins);
271
  if (!this.el || !this.el.parentElement) {
272
  return;
273
  }
274
+ 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);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  };
276
  PositionWidget.prototype.setMaxOffset = function (max_top_offset) {
277
+ this.offsets.setMaxOffset(max_top_offset);
278
  };
279
  PositionWidget.prototype.render = function () {
280
  this.on_scroll(scrollY);
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: '',
299
+ marginTop: '',
300
+ padding: '',
301
+ height: '',
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);
311
  };
321
  if (!this.el) {
322
  return;
323
  }
 
 
 
 
 
324
  this.store_style(getComputedStyle(this.el));
325
  this.clone();
326
+ reactive(function () { return _this.offsets.height; }).on_change(function (height) {
327
+ if (_this.clone_el) {
328
+ _this.clone_el.style.height = "".concat(height, "px");
329
+ }
330
  });
331
  };
 
 
 
 
 
332
  FixedWidget.prototype.setMaxOffset = function (max_top_offset) {
333
  if (max_top_offset === 0 ||
334
+ max_top_offset < this.offsets.root ||
335
+ this.offsets.max_top_offset === max_top_offset) {
336
  return;
337
  }
338
+ this.offsets.setMaxOffset(max_top_offset);
 
339
  };
340
  FixedWidget.prototype.clone = function () {
341
  var _this = this;
342
+ if (!this.el || !this.el.parentElement || this.clone_el) {
343
  return;
344
  }
345
  this.clone_el = this.el.cloneNode(false);
356
  this.init_style.position = style.position;
357
  this.init_style.marginTop = style.marginTop;
358
  this.init_style.marginBottom = style.marginBottom;
359
+ this.init_style.padding = style.padding;
360
  this.init_style.width = style.width;
361
  this.init_style.height = style.height;
362
  };
374
  if (!this.el) {
375
  return;
376
  }
377
+ var need_to_fix = scroll_top > this.offsets.root - this.offsets.top;
378
+ var limited_by_stop_element = this.offsets.max_top_offset !== 0 && scroll_top > this.offsets.relative_top - this.offsets.top;
379
+ var top = limited_by_stop_element ? this.offsets.relative_top - scroll_top : this.offsets.top;
 
380
  need_to_fix ?
381
  this.fix(top) :
382
  this.restore_style(this.el.style);
393
  this.el.style.position = 'fixed';
394
  this.el.style.transition = 'transform 0.5s';
395
  this.el.style.width = this.init_style.width;
396
+ this.el.style.padding = this.init_style.padding;
397
  if (!this.clone_el) {
398
  return;
399
  }
413
  __extends(StickyWidget, _super);
414
  function StickyWidget(el) {
415
  var _this = _super.call(this, el) || this;
416
+ _this.borderBox = 0;
417
  _this.margins = 0;
 
 
 
 
 
 
418
  _this.need_to_calc_el_offset = function (el) {
419
  return el.classList.contains(FixedWidgetClassName);
420
  };
425
  return _this;
426
  }
427
  StickyWidget.prototype.mount = function (margins) {
 
428
  _super.prototype.mount.call(this, margins);
429
  if (!this.el || !this.el.parentElement) {
430
  return;
431
  }
 
 
 
 
432
  this.el.style.position = 'sticky';
433
  this.el.style.position = '-webkit-sticky';
434
  this.el.style.transition = 'transform 0s';
441
  if (max_top_offset < this.el.offsetTop) {
442
  return;
443
  }
444
+ this.offsets.setMaxOffset(max_top_offset);
445
  };
446
  StickyWidget.prototype.on_scroll = function () {
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));
478
  _this.el.classList.add(StopWidgetClassName);
479
  return _this;
480
  }
 
 
 
 
 
 
 
 
481
  StopWidget.new = function (selector) {
482
  return new StopWidget(document.querySelector(selector));
483
  };
540
  return Math.round(document.body.scrollHeight);
541
  }
542
  var min_offset = use_top_offset ?
543
+ stop_widgets[0].offsets.top :
544
+ stop_widgets[0].offsets.root;
545
  for (var _i = 0, stop_widgets_1 = stop_widgets; _i < stop_widgets_1.length; _i++) {
546
  var widget = stop_widgets_1[_i];
547
+ var offset = use_top_offset ? widget.offsets.top : widget.offsets.root;
548
  if (min_offset > offset) {
549
  min_offset = offset;
550
  }
575
  };
576
  this.data = Array.from(new Set(elements.map(function (widget) { return widget.parentElement; })))
577
  .filter(function (sidebar_el) { return sidebar_el !== null; })
578
+ .map(function (sidebar_el) { return new Sidebar(sidebar_el, { margin_bottom: options.margin_bottom, margin_top: options.margin_top }, options.use_sticky_position); });
579
  }
580
  Sidebars.prototype.mount = function () {
581
  this.data.forEach(function (sidebar) { sidebar.mount(); });
js/frontend.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])},extendStatics(d,b)};function __extends(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t},__assign.apply(this,arguments)},StopWidgetClassName="FixedWidget__stop_widget",FixedWidgetClassName="FixedWidget__fixed_widget",Widget=function(){function Widget(el){this.el=el,this.top_offset=0,this.root_offset=0,this.need_to_calc_el_offset=function(_){return!1},this.prevSibling=function(el){return el&&el.previousElementSibling}}return Widget.prototype.render=function(){throw new Error("Method is not overridden!")},Widget.prototype.mount=function(user_margins){void 0===user_margins&&(user_margins={}),this.el&&this.el.parentElement&&(this.top_offset=this.get_total_top_offset(user_margins))},Widget.prototype.getElement=function(){return this.el},Widget.prototype.toString=function(){var _a;return"".concat(null===(_a=this.el)||void 0===_a?void 0:_a.innerHTML)},Widget.prototype.get_total_top_offset=function(margins){return get_sibilings_offset(this.prevSibling,this.need_to_calc_el_offset,this.prevSibling(this.el),margins.margin_top)},Widget.queryAllWidgetsContainers=function(className){return[].concat(Array.from(document.querySelectorAll(".".concat(className))),Array.from(document.querySelectorAll("[data-fixed_widget=".concat(className)))).map((function(el){el.classList.remove(className),el.removeAttribute("data-fixed_widget");var container=getWidgetContainer(el);return container.classList.remove(FixedWidgetClassName),container.classList.remove(StopWidgetClassName),container}))},Widget.from=function(root,className){var _this=this,elements=[];try{elements=Array.from(root.querySelectorAll(":scope > .".concat(className)))}catch(_e){elements=Array.from(root.children).filter((function(e){return e.classList.contains(className)}))}return elements.filter((function(el){return null!==el})).map((function(e){return new _this(e)}))},Widget}(),getWidgetContainer=function(el){return el.parentElement&&(1===el.parentElement.childElementCount||el.parentElement.classList.toString().includes("wp-block-group")||el.parentElement.classList.toString().includes("wp-block-column")||el.parentElement.classList.contains("widget"))?getWidgetContainer(el.parentElement):el},get_sibilings_offset=function(next,need_to_calc_el_offset,el,offset){if(void 0===offset&&(offset=0),!el)return offset;if(!need_to_calc_el_offset(el))return get_sibilings_offset(next,need_to_calc_el_offset,next(el),offset);var _a=getComputedStyle(el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;return get_sibilings_offset(next,need_to_calc_el_offset,next(el),offset+el.getBoundingClientRect().height+parseInt(marginTop||"0")+parseInt(marginBottom||"0"))},compatabilty_FW_v5=function(selectors){return void 0===selectors&&(selectors=[]),selectors.some((function(s){return!/^[a-z]/i.test(s)}))?selectors:selectors.concat(selectors.map((function(s){return"#".concat(s)})))},queryElements=function(selectors){return void 0===selectors&&(selectors=[]),Array.from(selectors.map((function(selector){return Array.from(document.querySelectorAll(selector))}))).reduce((function(all,elements){return all.concat(elements)}),[]).filter((function(e){return e instanceof HTMLElement}))};function findWithProperty(el,predicate){return el&&el!==document.body?predicate(getComputedStyle(el))?el:findWithProperty(el.parentElement,predicate):null}var sidebars,reactive=function(getter,interval){void 0===interval&&(interval=300);var subs=[],v=getter();return setInterval((function(){if(0===subs.length)return;var new_v=getter();if(v===new_v)return;v=new_v;for(var _i=0,subs_1=subs;_i<subs_1.length;_i++){(0,subs_1[_i])(new_v)}}),interval),{get val(){return v},on_change:function(update){update(v),subs.push(update)}}},PositionWidget=function(_super){function PositionWidget(){var _this=null!==_super&&_super.apply(this,arguments)||this;return _this.bottom_offset=0,_this.top_margin=0,_this.borderBox=0,_this.block_height=reactive((function(){return 0})),_this.max_top_offset=0,_this.bottom_margin=0,_this.user_margins={},_this.prevSibling=function(el){return el&&!el.classList.contains(StopWidgetClassName)&&el.previousElementSibling||null},_this.get_total_bottom_offset=function(margins){var next=function(el){return el&&!el.classList.contains(StopWidgetClassName)?el.nextElementSibling:null};return get_sibilings_offset(next,_this.need_to_calc_el_offset,next(_this.el),margins.margin_bottom)},_this}return __extends(PositionWidget,_super),PositionWidget.prototype.mount=function(user_margins){var _this=this;if(_super.prototype.mount.call(this,user_margins),this.el&&this.el.parentElement){this.user_margins=user_margins;var _a=getComputedStyle(this.el),marginTop=_a.marginTop,marginBottom=_a.marginBottom;this.bottom_margin=parseInt(marginBottom),this.top_margin=parseInt(marginTop),this.bottom_offset=this.get_total_bottom_offset(user_margins),this.block_height=reactive((function(){return _this.el?Math.round(Math.max(_this.el.clientHeight,_this.el.scrollHeight,_this.el.getBoundingClientRect().height)):0})),this.block_height.on_change((function(block_height){_this.borderBox=block_height+_this.top_margin+_this.bottom_margin})),reactive(this.get_total_bottom_offset.bind(this,user_margins)).on_change((function(bottom_offset){_this.bottom_offset=bottom_offset})),reactive(this.get_total_top_offset.bind(this,user_margins)).on_change((function(top_offset){_this.top_offset=top_offset,_this.el&&(_this.el.style.top="".concat(top_offset,"px"))}))}},PositionWidget.prototype.setMaxOffset=function(max_top_offset){this.max_top_offset=max_top_offset},PositionWidget.prototype.render=function(){this.on_scroll(scrollY)},PositionWidget.from=function(root){return _super.from.call(this,root,FixedWidgetClassName)},PositionWidget.prototype.on_scroll=function(_scroll_top){throw new Error("Method is not overridden!")},PositionWidget}(Widget),FixedWidget=function(_super){function FixedWidget(el){var _this=_super.call(this,el)||this;return _this.is_pinned=!1,_this.relative_top=0,_this.paddings=0,_this.init_style={position:"static",marginTop:"",marginBottom:"",width:"",height:""},_this.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.el&&_this.el.parentElement?(_this.el.classList.add(FixedWidgetClassName),_this):_this}return __extends(FixedWidget,_super),FixedWidget.prototype.mount=function(margins){var _this=this;_super.prototype.mount.call(this,margins),this.el&&(this.paddings=this.top_offset+this.top_margin+this.bottom_margin+this.bottom_offset,this.store_style(getComputedStyle(this.el)),this.clone(),this.block_height.on_change((function(block_height){_this.relative_top=_this.max_top_offset-block_height-_this.paddings})))},FixedWidget.prototype.update_root_offset=function(){var element=this.is_pinned?this.clone_el:this.el,new_root_offset=Math.round(scrollY+(element?element.getBoundingClientRect().top:0));this.root_offset=this.is_pinned?new_root_offset:Math.max(this.root_offset,new_root_offset)},FixedWidget.prototype.setMaxOffset=function(max_top_offset){0===max_top_offset||max_top_offset<this.root_offset||this.max_top_offset===max_top_offset||(this.max_top_offset=max_top_offset,this.relative_top=this.max_top_offset-this.block_height.val-this.paddings)},FixedWidget.prototype.clone=function(){var _this=this;if(this.el&&this.el.parentElement){for(var prop in this.clone_el=this.el.cloneNode(!1),this.clone_el.getAttributeNames().forEach((function(attr){_this.clone_el.removeAttribute(attr)})),this.init_style)this.clone_el.style[prop]=this.init_style[prop];this.clone_el.style.display="none",this.el.parentElement.insertBefore(this.clone_el,this.el)}},FixedWidget.prototype.store_style=function(style){this.init_style.position=style.position,this.init_style.marginTop=style.marginTop,this.init_style.marginBottom=style.marginBottom,this.init_style.width=style.width,this.init_style.height=style.height},FixedWidget.prototype.restore_style=function(style){this.is_pinned&&(this.is_pinned=!1,style.position=this.init_style.position,this.clone_el&&(this.clone_el.style.display="none"))},FixedWidget.prototype.on_scroll=function(scroll_top){if(this.el){this.update_root_offset();var need_to_fix=scroll_top>this.root_offset-this.top_offset,top=0!==this.max_top_offset&&scroll_top>this.relative_top?this.relative_top-scroll_top+this.top_offset:this.top_offset;need_to_fix?this.fix(top):this.restore_style(this.el.style)}},FixedWidget.prototype.fix=function(top){this.el&&(this.el.style.top="".concat(top,"px"),this.is_pinned||(this.is_pinned=!0,this.el.style.position="fixed",this.el.style.transition="transform 0.5s",this.el.style.width=this.init_style.width,this.clone_el&&(this.clone_el.style.display="block")))},FixedWidget.new=function(selector){return new FixedWidget(document.querySelector(selector))},FixedWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(FixedWidgetClassName)},FixedWidget}(PositionWidget),StickyWidget=function(_super){function StickyWidget(el){var _this=_super.call(this,el)||this;return _this.margins=0,_this.get_margins=function(){return(_this.el&&_this.el.parentElement&&_this.el.parentElement.clientHeight||0)-_this.bottom_margin-_this.top_margin-_this.block_height.val},_this.need_to_calc_el_offset=function(el){return el.classList.contains(FixedWidgetClassName)},_this.el&&_this.el.parentElement?(_this.el.classList.add(FixedWidgetClassName),_this):_this}return __extends(StickyWidget,_super),StickyWidget.prototype.mount=function(margins){var _this=this;_super.prototype.mount.call(this,margins),this.el&&this.el.parentElement&&(reactive(this.get_margins).on_change((function(margins){_this.margins=margins})),this.el.style.position="sticky",this.el.style.position="-webkit-sticky",this.el.style.transition="transform 0s",this.el.style.boxSizing="border-box")},StickyWidget.prototype.setMaxOffset=function(max_top_offset){this.el&&this.el.parentElement&&(max_top_offset<this.el.offsetTop||(this.max_top_offset=max_top_offset))},StickyWidget.prototype.on_scroll=function(){if(this.el&&this.el.parentElement){var bottom_margin=this.max_top_offset?Math.min(this.max_top_offset-this.el.offsetTop-this.borderBox,this.margins-this.el.offsetTop):this.margins-this.el.offsetTop;this.el.style.top="".concat(this.top_offset,"px"),bottom_margin>=this.bottom_offset?this.el.style.transform="translateY(0px)":this.el.style.transform="translateY(".concat(bottom_margin-this.bottom_offset,"px)")}},StickyWidget.new=function(selector){return new StickyWidget(document.querySelector(selector))},StickyWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(FixedWidgetClassName)},StickyWidget}(PositionWidget),StopWidget=function(_super){function StopWidget(el){var _this=_super.call(this,el)||this;return _this.need_to_calc_el_offset=function(){return!0},_this.el&&_this.el.parentElement?(_this.el.classList.add(StopWidgetClassName),_this):_this}return __extends(StopWidget,_super),StopWidget.prototype.mount=function(user_margins){var _this=this;_super.prototype.mount.call(this,user_margins),reactive((function(){return Math.round(scrollY+(_this.el?_this.el.getBoundingClientRect().top:0))})).on_change((function(root_offset){_this.root_offset=root_offset}))},StopWidget.new=function(selector){return new StopWidget(document.querySelector(selector))},StopWidget.is=function(selector){var el=document.querySelector(selector);return!!el&&el.classList.contains(StopWidgetClassName)},StopWidget.from=function(root){return _super.from.call(this,root,StopWidgetClassName)},StopWidget}(Widget),Sidebar=function(){function Sidebar(el,margins,use_sticky_position){void 0===use_sticky_position&&(use_sticky_position=!1);var _this=this;this.el=el,this.margins=margins,this.widgets=[],this.stop_widgets=[],this.isSticky=!1,this.setWidgetsMaxOffset=function(max_offset){for(var _i=0,_a=_this.widgets;_i<_a.length;_i++){_a[_i].setMaxOffset(max_offset)}};var isDeprecatedFloatMarkup=!!findWithProperty(this.el,(function(style){return"none"!==style.float})),isOverflowHiddenMarkup=!!findWithProperty(this.el,(function(style){return"hidden"===style.overflow}));(isDeprecatedFloatMarkup||isOverflowHiddenMarkup)&&use_sticky_position&&console.log("Fixed Widget: fallback to position sticky"),this.isSticky=!isDeprecatedFloatMarkup&&!isOverflowHiddenMarkup&&use_sticky_position;var WidgetContructor=this.isSticky?StickyWidget:FixedWidget;this.stop_widgets=StopWidget.from(this.el),this.widgets=WidgetContructor.from(this.el),this.isSticky&&(this.el.style.position="relative",0===this.stop_widgets.length&&(this.el.style.minHeight="100%"))}return Sidebar.prototype.mount=function(){var _this=this;this.stop_widgets.forEach((function(widget){widget.mount()})),this.widgets.forEach((function(widget){widget.mount(_this.margins)}))},Sidebar.prototype.setMaxOffset=function(general_stop_widgets){var is_local_stop_widgets=0!=this.stop_widgets.length,use_top_offset=this.isSticky&&is_local_stop_widgets,stop_widgets=is_local_stop_widgets?this.stop_widgets:general_stop_widgets,max_top_offset=reactive((function(){if(0===stop_widgets.length)return Math.round(document.body.scrollHeight);for(var min_offset=use_top_offset?stop_widgets[0].top_offset:stop_widgets[0].root_offset,_i=0,stop_widgets_1=stop_widgets;_i<stop_widgets_1.length;_i++){var widget=stop_widgets_1[_i],offset=use_top_offset?widget.top_offset:widget.root_offset;min_offset>offset&&(min_offset=offset)}return Math.round(min_offset)}));max_top_offset.on_change(this.setWidgetsMaxOffset),this.setWidgetsMaxOffset(max_top_offset.val)},Sidebar.prototype.render=function(){for(var _i=0,_a=this.widgets;_i<_a.length;_i++){_a[_i].render()}},Sidebar}(),Sidebars=function(){function Sidebars(elements,options){var _this=this;this.data=[],this.render=function(){for(var _i=0,_a=_this.data;_i<_a.length;_i++){_a[_i].render()}},this.data=Array.from(new Set(elements.map((function(widget){return widget.parentElement})))).filter((function(sidebar_el){return null!==sidebar_el})).map((function(sidebar_el){return new Sidebar(sidebar_el,options,options.use_sticky_position)}))}return Sidebars.prototype.mount=function(){this.data.forEach((function(sidebar){sidebar.mount()})),this.setMaxOffset()},Sidebars.prototype.setMaxOffset=function(){for(var general_stop_widgets=this.getGeneralStopElements(),_i=0,_a=this.data;_i<_a.length;_i++){_a[_i].setMaxOffset(general_stop_widgets)}},Sidebars.prototype.getGeneralStopElements=function(){return this.data.filter((function(sidebar){return!sidebar.isSticky||0===sidebar.widgets.length})).map((function(sidebar){return sidebar.stop_widgets})).reduce((function(all,widgets){return all.concat(widgets)}),[])},Sidebars.new=function(options){var s,arr1,arr2,fixedWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(FixedWidgetClassName).concat(queryElements(compatabilty_FW_v5(options.widgets))))),stopWidgetsSelectors=compatabilty_FW_v5((void 0===(s=options.stop_elements_selectors||options.stop_id)&&(s=""),s.replace(/[\r\n]|[\r]/gi,"\n").split("\n").map((function(s){return s.trim()})).filter((function(s){return""!==s})))),stopWidgetsContainers=Array.from(new Set(Widget.queryAllWidgetsContainers(StopWidgetClassName).concat(queryElements(stopWidgetsSelectors)))),_a=(arr1=fixedWidgetsContainers,[(arr2=stopWidgetsContainers).filter((function(e){return!arr1.includes(e)})),arr1.filter((function(e){return arr2.includes(e)}))]),stopWidgetsUniqContainers=_a[0];return _a[1].forEach((function(w){console.error("The Widget is detected as fixed block and stop block!\n".concat(w.innerHTML))})),fixedWidgetsContainers.forEach((function(c){c.classList.add(FixedWidgetClassName)})),stopWidgetsUniqContainers.forEach((function(c){c.classList.add(StopWidgetClassName)})),new Sidebars(fixedWidgetsContainers.concat(stopWidgetsUniqContainers),options)},Sidebars}();function onDocumentLoaded(){var admin_panel=document.querySelector("#wpadminbar"),options=(window.q2w3_sidebar_options||[{}]).map((function(option){return option.margin_top=(option.margin_top||0)+(admin_panel&&admin_panel.clientHeight||0),option}));options.some((function(option){return window.innerWidth<option.screen_max_width||window.innerHeight<option.screen_max_height}))||function(options){void 0===options&&(options=[]),sidebars?sidebars.render():(sidebars=Sidebars.new(options.reduce((function(prev,cur){return __assign(__assign(__assign({},prev),cur),{widgets:prev.widgets.concat(cur.widgets||[])})}),{widgets:[]})),document.addEventListener("scroll",sidebars.render),sidebars.mount())}(options)}window.addEventListener("load",onDocumentLoaded),"complete"===document.readyState&&onDocumentLoaded(),onDocumentLoaded();
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();
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.6
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.6';
27
 
28
  protected static $sidebars_widgets;
29
 
5
  Description: Use the fixed widget plugin to create sticky widgets that stay in the visible screen area when the page is scrolled up or down and boost your conversions.
6
  Text Domain: q2w3-fixed-widget
7
  Author: Thomas Maier, Max Bond
8
+ Version: 6.0.7
9
  Author URI: https://wpadvancedads.com/fixed-widget-wordpress/
10
  */
11
 
23
 
24
  const ID = 'q2w3_fixed_widget';
25
 
26
+ const VERSION = '6.0.7';
27
 
28
  protected static $sidebars_widgets;
29
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: webzunft, max-bond, advancedads
3
  Tags: fixed widget, sticky widget, sidebar, ads, widget, fixed, sticky, floating, sticky block, adsense
4
  Requires at least: 5.0
5
  Tested up to: 5.9
6
- Stable tag: 6.0.6
7
 
8
  More attention and a higher ad performance with fixed sticky widgets.
9
 
@@ -91,6 +91,10 @@ Use the options `Minimum Screen Width` and `Minimum Screen Height` to disable st
91
 
92
  == Changelog ==
93
 
 
 
 
 
94
  = 6.0.6 =
95
 
96
  - Improvement: Compatibility with dynamically loaded content pages, i.e., infinite scroll
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
 
91
 
92
  == Changelog ==
93
 
94
+ = 6.0.7 =
95
+
96
+ - Improvement: Compatibility with relative padding values
97
+
98
  = 6.0.6 =
99
 
100
  - Improvement: Compatibility with dynamically loaded content pages, i.e., infinite scroll