nodebb-plugin-facebook-post 1.0.10 → 1.0.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Auto-post new NodeBB topics to a fixed Facebook Page (text + NodeBB uploads + place id).",
5
5
  "main": "library.js",
6
6
  "dependencies": {
@@ -5,14 +5,15 @@
5
5
  function toCsv(arr) {
6
6
  return (arr || []).map(String).map(s => s.trim()).filter(Boolean).join(',');
7
7
  }
8
+ function fromCsv(s) {
9
+ return (s || '').split(',').map(v => v.trim()).filter(Boolean);
10
+ }
8
11
 
9
12
  function init() {
10
13
  const $form = $('.facebook-post-settings');
11
14
  if (!$form.length) return;
12
15
 
13
16
  require(['settings', 'alerts'], function (Settings, alerts) {
14
- Settings.load('facebook-post', $form);
15
-
16
17
  const $select = $('#allowedGroupsSelect');
17
18
  const $hidden = $('#allowedGroups');
18
19
 
@@ -20,15 +21,21 @@
20
21
  $hidden.val(toCsv($select.val() || []));
21
22
  }
22
23
 
23
- // initial sync (after Settings.load fills hidden input)
24
- const existing = ($hidden.val() || '').split(',').map(s => s.trim()).filter(Boolean);
25
- if (existing.length) {
26
- $select.val(existing);
27
- }
28
- syncHidden();
24
+ // Prevent full page refresh if user hits Enter
25
+ $form.off('submit.fbpost').on('submit.fbpost', function (e) { e.preventDefault(); return false; });
26
+
27
+ // IMPORTANT: wait for Settings.load to finish before reading hidden input
28
+ Settings.load('facebook-post', $form, function () {
29
+ const existing = fromCsv($hidden.val());
30
+ if (existing.length) {
31
+ $select.val(existing);
32
+ } else {
33
+ $select.val([]);
34
+ }
35
+ syncHidden();
36
+ });
29
37
 
30
38
  $select.off('change.fbpost').on('change.fbpost', syncHidden);
31
- $form.off('submit.fbpost').on('submit.fbpost', function (e) { e.preventDefault(); return false; });
32
39
 
33
40
  $('#save').off('click.fbpost').on('click.fbpost', function (e) {
34
41
  e.preventDefault();