nodebb-plugin-ezoic-infinite 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.json +2 -2
- package/public/admin.js +13 -4
- package/public/client.js +46 -22
- package/public/templates/admin/plugins/ezoic-infinite.tpl +1 -1
package/package.json
CHANGED
package/plugin.json
CHANGED
package/public/admin.js
CHANGED
|
@@ -9,18 +9,27 @@
|
|
|
9
9
|
require(['settings', 'alerts'], function (Settings, alerts) {
|
|
10
10
|
Settings.load('ezoic-infinite', $form);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
e.preventDefault();
|
|
12
|
+
function doSave(e) {
|
|
13
|
+
if (e) e.preventDefault();
|
|
14
|
+
const $btn = $('#save');
|
|
15
|
+
$btn.prop('disabled', true);
|
|
14
16
|
|
|
17
|
+
// Settings.save signature differs slightly across versions; keep compatible
|
|
15
18
|
Settings.save('ezoic-infinite', $form, function () {
|
|
16
|
-
// Toast vert (NodeBB core)
|
|
17
19
|
if (alerts && typeof alerts.success === 'function') {
|
|
18
20
|
alerts.success('Enregistré');
|
|
19
21
|
} else if (window.app && typeof window.app.alertSuccess === 'function') {
|
|
20
22
|
window.app.alertSuccess('Enregistré');
|
|
21
23
|
}
|
|
24
|
+
$btn.prop('disabled', false);
|
|
22
25
|
});
|
|
23
|
-
|
|
26
|
+
|
|
27
|
+
// Fallback: re-enable even if callback not fired (mobile sometimes)
|
|
28
|
+
setTimeout(function () { $btn.prop('disabled', false); }, 4000);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$form.off('submit.ezoicInfinite').on('submit.ezoicInfinite', doSave);
|
|
32
|
+
$('#save').off('click.ezoicInfinite').on('click.ezoicInfinite', doSave);
|
|
24
33
|
});
|
|
25
34
|
}
|
|
26
35
|
|
package/public/client.js
CHANGED
|
@@ -22,17 +22,16 @@ function parsePool(raw) {
|
|
|
22
22
|
));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Harmony (topic page) selector:
|
|
27
|
-
* - Posts: [component="post"]
|
|
28
|
-
*/
|
|
29
25
|
function getTopicPosts() {
|
|
30
26
|
const $p = $('[component="post"]').not('.ezoic-ad-post');
|
|
31
27
|
if ($p.length) return $p;
|
|
32
|
-
// fallback
|
|
33
28
|
return $('.posts .post').not('.ezoic-ad-post');
|
|
34
29
|
}
|
|
35
30
|
|
|
31
|
+
function isLi($el) {
|
|
32
|
+
return ($el && $el.length && (($el.prop('tagName') || '').toUpperCase() === 'LI'));
|
|
33
|
+
}
|
|
34
|
+
|
|
36
35
|
function removePlaceholdersByPool(pool) {
|
|
37
36
|
pool.forEach(id => $('#ezoic-pub-ad-placeholder-' + id).remove());
|
|
38
37
|
}
|
|
@@ -51,6 +50,36 @@ function computeWindowSlots(totalItems, interval, poolSize) {
|
|
|
51
50
|
return out;
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
function makeBetweenWrapper($targetPost, placeholderId) {
|
|
54
|
+
if (isLi($targetPost)) {
|
|
55
|
+
return (
|
|
56
|
+
'<li class="ezoic-ad-between list-unstyled" data-ezoic-ad="1">' +
|
|
57
|
+
'<div id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>' +
|
|
58
|
+
'</li>'
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return '<div class="ezoic-ad-between" id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function makeAdMessageWrapper($targetPost, placeholderId) {
|
|
65
|
+
if (isLi($targetPost)) {
|
|
66
|
+
return (
|
|
67
|
+
'<li class="post ezoic-ad-post" data-ezoic-ad="1">' +
|
|
68
|
+
'<div class="content">' +
|
|
69
|
+
'<div id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>' +
|
|
70
|
+
'</div>' +
|
|
71
|
+
'</li>'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
'<div class="post ezoic-ad-post" data-ezoic-ad="1">' +
|
|
76
|
+
'<div class="content">' +
|
|
77
|
+
'<div id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>' +
|
|
78
|
+
'</div>' +
|
|
79
|
+
'</div>'
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
54
83
|
function insertBetweenPosts($posts, pool, interval) {
|
|
55
84
|
const total = $posts.length;
|
|
56
85
|
const slotsToRender = computeWindowSlots(total, interval, pool.length);
|
|
@@ -64,7 +93,7 @@ function insertBetweenPosts($posts, pool, interval) {
|
|
|
64
93
|
const $target = $posts.eq(index);
|
|
65
94
|
if (!$target.length) continue;
|
|
66
95
|
|
|
67
|
-
$target.after(
|
|
96
|
+
$target.after(makeBetweenWrapper($target, id));
|
|
68
97
|
activeIds.push(id);
|
|
69
98
|
}
|
|
70
99
|
return activeIds;
|
|
@@ -83,21 +112,19 @@ function insertAdMessagesBetweenReplies($posts, pool, interval) {
|
|
|
83
112
|
const $target = $posts.eq(index);
|
|
84
113
|
if (!$target.length) continue;
|
|
85
114
|
|
|
86
|
-
|
|
87
|
-
'<div class="post ezoic-ad-post" data-ezoic-ad="1">' +
|
|
88
|
-
'<div class="content">' +
|
|
89
|
-
'<div id="ezoic-pub-ad-placeholder-' + id + '"></div>' +
|
|
90
|
-
'</div>' +
|
|
91
|
-
'</div>';
|
|
92
|
-
|
|
93
|
-
$target.after(html);
|
|
115
|
+
$target.after(makeAdMessageWrapper($target, id));
|
|
94
116
|
activeIds.push(id);
|
|
95
117
|
}
|
|
96
118
|
return activeIds;
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
async function refreshAds() {
|
|
100
|
-
|
|
122
|
+
let cfg;
|
|
123
|
+
try {
|
|
124
|
+
cfg = await fetchConfig();
|
|
125
|
+
} catch (e) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
101
128
|
if (!cfg || cfg.excluded) return;
|
|
102
129
|
|
|
103
130
|
const betweenPool = parsePool(cfg.placeholderIds);
|
|
@@ -107,26 +134,22 @@ async function refreshAds() {
|
|
|
107
134
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
108
135
|
|
|
109
136
|
const $posts = getTopicPosts();
|
|
110
|
-
if (!$posts.length) return;
|
|
137
|
+
if (!$posts.length) return;
|
|
111
138
|
|
|
112
|
-
// Clean first
|
|
113
139
|
removeAdWrappers();
|
|
114
140
|
removePlaceholdersByPool(betweenPool);
|
|
115
141
|
removePlaceholdersByPool(messagePool);
|
|
116
142
|
|
|
117
143
|
const activeIds = [];
|
|
118
144
|
|
|
119
|
-
// Between posts
|
|
120
145
|
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
121
146
|
activeIds.push(...insertBetweenPosts($posts, betweenPool, betweenInterval));
|
|
122
147
|
}
|
|
123
148
|
|
|
124
|
-
// "Ad message" between replies
|
|
125
149
|
if (cfg.enableMessageAds && messagePool.length) {
|
|
126
150
|
activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
|
|
127
151
|
}
|
|
128
152
|
|
|
129
|
-
// Ezoic render
|
|
130
153
|
if (activeIds.length && window.ezstandalone && typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
131
154
|
try { window.ezstandalone.destroyPlaceholders(); } catch (e) {}
|
|
132
155
|
}
|
|
@@ -137,8 +160,9 @@ async function refreshAds() {
|
|
|
137
160
|
|
|
138
161
|
function debounceRefresh() {
|
|
139
162
|
clearTimeout(debounceTimer);
|
|
140
|
-
debounceTimer = setTimeout(refreshAds,
|
|
163
|
+
debounceTimer = setTimeout(refreshAds, 120);
|
|
141
164
|
}
|
|
142
165
|
|
|
166
|
+
$(document).ready(debounceRefresh);
|
|
143
167
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded', debounceRefresh);
|
|
144
|
-
setTimeout(debounceRefresh,
|
|
168
|
+
setTimeout(debounceRefresh, 1200);
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
<p class="form-text">Si l’utilisateur appartient à un de ces groupes, aucune pub n’est injectée.</p>
|
|
55
55
|
</div>
|
|
56
56
|
|
|
57
|
-
<button id="save" class="btn btn-primary">Enregistrer</button>
|
|
57
|
+
<button id="save" type="submit" class="btn btn-primary">Enregistrer</button>
|
|
58
58
|
</form>
|
|
59
59
|
</div>
|