nodebb-plugin-poll 1.1.7 → 2.0.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.
@@ -1,12 +1,10 @@
1
- "use strict";
2
- /* globals require, utils */
3
-
4
- (function(module) {
1
+ 'use strict';
5
2
 
3
+ (function (module) {
6
4
  var utils;
7
5
  var Serializer = {};
8
6
 
9
- if ('undefined' === typeof window) {
7
+ if (typeof window === 'undefined') {
10
8
  utils = require.main.require('./src/utils');
11
9
  } else {
12
10
  utils = window.utils;
@@ -19,52 +17,52 @@
19
17
  test: function (value) {
20
18
  return value.length > 0;
21
19
  },
22
- parse: function(value) {
20
+ parse: function (value) {
23
21
  return utils.stripHTMLTags(value).trim();
24
- }
22
+ },
25
23
  },
26
24
  maxvotes: {
27
25
  test: function (value) {
28
26
  return !isNaN(value);
29
27
  },
30
- parse: function(value) {
28
+ parse: function (value) {
31
29
  return parseInt(value, 10);
32
- }
30
+ },
33
31
  },
34
32
  disallowVoteUpdate: {
35
33
  test: function (value) {
36
34
  return /true|false/.test(value);
37
35
  },
38
- parse: function(value) {
39
- return value === "true" || value === true ? 1 : 0;
40
- }
36
+ parse: function (value) {
37
+ return value === 'true' || value === true ? 1 : 0;
38
+ },
41
39
  },
42
40
  end: {
43
41
  test: function (value) {
44
42
  return (!isNaN(value) && parseInt(value, 10) > Date.now());
45
43
  },
46
- parse: function(value) {
44
+ parse: function (value) {
47
45
  return parseInt(value, 10);
48
- }
49
- }
46
+ },
47
+ },
50
48
  };
51
49
 
52
- Serializer.canSerialize = function(post) {
50
+ Serializer.canSerialize = function (post) {
53
51
  pollRegex.lastIndex = 0;
54
52
  return pollRegex.test(post);
55
53
  };
56
54
 
57
- Serializer.removeMarkup = function(content, replace) {
55
+ Serializer.removeMarkup = function (content, replace) {
58
56
  return content.replace(pollRegex, replace || '');
59
57
  };
60
58
 
61
- Serializer.hasMarkup = function(content) {
59
+ Serializer.hasMarkup = function (content) {
62
60
  pollRegex.lastIndex = 0;
63
61
  const has = pollRegex.test(content);
64
62
  return has;
65
63
  };
66
64
 
67
- Serializer.serialize = function(post, config) {
65
+ Serializer.serialize = function (post, config) {
68
66
  pollRegex.lastIndex = 0;
69
67
  var match = pollRegex.exec(post);
70
68
 
@@ -74,15 +72,15 @@
74
72
 
75
73
  return {
76
74
  options: serializeOptions(match.groups.content, config),
77
- settings: serializeSettings(match.groups.settings, config)
75
+ settings: serializeSettings(match.groups.settings, config),
78
76
  };
79
77
  };
80
78
 
81
- Serializer.deserialize = function(poll, config) {
79
+ Serializer.deserialize = function (poll, config) {
82
80
  var options = deserializeOptions(poll.options, config);
83
81
  var settings = deserializeSettings(poll.settings, config);
84
82
 
85
- return '[poll' + settings +']\n' + options + '\n[/poll]';
83
+ return '[poll' + settings + ']\n' + options + '\n[/poll]';
86
84
  };
87
85
 
88
86
  function serializeOptions(raw, config) {
@@ -92,7 +90,7 @@
92
90
  rawOptions.map(raw => utils.stripHTMLTags(raw));
93
91
  var maxOptions = parseInt(config.limits.maxOptions, 10);
94
92
 
95
- rawOptions.forEach(function(option) {
93
+ rawOptions.forEach(function (option) {
96
94
  if (option.length) {
97
95
  option = option.split('-')[1].trim();
98
96
 
@@ -128,13 +126,13 @@
128
126
  function serializeSettings(raw, config) {
129
127
  var settings = {};
130
128
 
131
- Object.keys(config.defaults).forEach(function(key) {
129
+ Object.keys(config.defaults).forEach(function (key) {
132
130
  settings[key] = config.defaults[key];
133
131
  });
134
132
 
135
133
  const stripped = utils.stripHTMLTags(raw).replace(/\\/g, '\');
136
134
  let match;
137
- while ((match = settingsRegex.exec(stripped)) !== null) {
135
+ while ((match = settingsRegex.exec(stripped)) !== null) { // eslint-disable-line no-cond-assign
138
136
  var key = match.groups.key.trim();
139
137
  var value = match.groups.value.trim();
140
138
 
@@ -169,12 +167,11 @@
169
167
 
170
168
  module.exports = Serializer;
171
169
 
172
- if ('undefined' !== typeof window) {
173
- Poll.serializer = module.exports;
170
+ if (typeof window !== 'undefined') {
171
+ window.Poll.serializer = module.exports;
174
172
  }
175
-
176
- })('undefined' === typeof module ? {
173
+ }(typeof module === 'undefined' ? {
177
174
  module: {
178
- exports: {}
179
- }
180
- } : module);
175
+ exports: {},
176
+ },
177
+ } : module));
@@ -1,56 +1,55 @@
1
- "use strict";
2
- /* globals socket */
1
+ 'use strict';
3
2
 
4
- (function(Poll) {
3
+ (function (Poll) {
5
4
  var messages = [
6
5
  {
7
6
  method: 'getPoll',
8
- message: 'plugins.poll.get'
7
+ message: 'plugins.poll.get',
9
8
  },
10
9
  {
11
10
  method: 'vote',
12
- message: 'plugins.poll.vote'
11
+ message: 'plugins.poll.vote',
13
12
  },
14
13
  {
15
14
  method: 'updateVote',
16
- message: 'plugins.poll.updateVote'
15
+ message: 'plugins.poll.updateVote',
17
16
  },
18
17
  {
19
18
  method: 'removeVote',
20
- message: 'plugins.poll.removeVote'
19
+ message: 'plugins.poll.removeVote',
21
20
  },
22
21
  {
23
22
  method: 'getOptionDetails',
24
- message: 'plugins.poll.getOptionDetails'
23
+ message: 'plugins.poll.getOptionDetails',
25
24
  },
26
25
  {
27
26
  method: 'getConfig',
28
- message: 'plugins.poll.getConfig'
27
+ message: 'plugins.poll.getConfig',
29
28
  },
30
29
  {
31
30
  method: 'canCreate',
32
- message: 'plugins.poll.canCreate'
33
- }
31
+ message: 'plugins.poll.canCreate',
32
+ },
34
33
  ];
35
34
 
36
35
  var handlers = [
37
36
  {
38
37
  event: 'event:poll.voteChange',
39
- handle: function(data) {
38
+ handle: function (data) {
40
39
  Poll.view.update(data);
41
- }
42
- }
40
+ },
41
+ },
43
42
  ];
44
43
 
45
44
  function init() {
46
- handlers.forEach(function(handler) {
45
+ handlers.forEach(function (handler) {
47
46
  if (socket.listeners(handler.event).length === 0) {
48
47
  socket.on(handler.event, handler.handle);
49
48
  }
50
49
  });
51
50
 
52
- messages.forEach(function(message) {
53
- Poll.sockets[message.method] = function(data, callback) {
51
+ messages.forEach(function (message) {
52
+ Poll.sockets[message.method] = function (data, callback) {
54
53
  socket.emit(message.message, data, callback);
55
54
  };
56
55
  });
@@ -59,5 +58,4 @@
59
58
  Poll.sockets = {};
60
59
 
61
60
  init();
62
-
63
- })(window.Poll);
61
+ }(window.Poll));