nodebb-plugin-poll
Advanced tools
Comparing version 0.2.12 to 0.2.13
@@ -16,14 +16,7 @@ var NodeBB = require('./nodebb'), | ||
Hooks.filter.postSave = function(postData, callback) { | ||
if (Serializer.hasMarkup(postData.content)) { | ||
// Is this the first post? | ||
NodeBB.Topics.getPostCount(postData.tid, function(err, postCount) { | ||
if (parseInt(postCount, 10) !== 0) { | ||
return callback(null, postData); | ||
} | ||
savePoll(postData, callback); | ||
}); | ||
Hooks.filter.postCreate = function(obj, callback) { | ||
if (Serializer.hasMarkup(obj.post.content) && obj.data.isMain) { | ||
savePoll(obj, callback); | ||
} else { | ||
return callback(null, postData); | ||
return callback(null, obj); | ||
} | ||
@@ -113,18 +106,18 @@ }; | ||
function savePoll(postData, callback) { | ||
var pollData = Serializer.serialize(postData.content, Config.settings.get()); | ||
function savePoll(obj, callback) { | ||
var pollData = Serializer.serialize(obj.post.content, Config.settings.get()); | ||
if (!pollData || !pollData.options.length) { | ||
return callback(null, postData); | ||
return callback(null, obj); | ||
} | ||
Poll.add(pollData, postData, function(err, pollId) { | ||
Poll.add(pollData, obj.post, function(err, pollId) { | ||
if (err) { | ||
return callback(err, postData); | ||
return callback(err, obj); | ||
} | ||
postData.pollId = pollId; | ||
postData.content = Serializer.removeMarkup(postData.content); | ||
obj.post.pollId = pollId; | ||
obj.post.content = Serializer.removeMarkup(obj.post.content); | ||
callback(null, postData); | ||
callback(null, obj); | ||
}); | ||
@@ -131,0 +124,0 @@ } |
{ | ||
"name": "nodebb-plugin-poll", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"description": "NodeBB Poll Plugin", | ||
@@ -5,0 +5,0 @@ "main": "library.js", |
@@ -19,3 +19,3 @@ { | ||
{ "hook": "filter:parse.raw", "method": "hooks.filter.parseRaw", "priority": 1 }, | ||
{ "hook": "filter:post.save", "method": "hooks.filter.postSave" }, | ||
{ "hook": "filter:post.create", "method": "hooks.filter.postCreate" }, | ||
{ "hook": "filter:post.edit", "method": "hooks.filter.postEdit" }, | ||
@@ -22,0 +22,0 @@ |
@@ -102,5 +102,4 @@ "use strict"; | ||
textarea.value += markup; | ||
if ($.Redactor) textarea.redactor('<p>' + textarea.value + '</p>'); | ||
if ($.Redactor) textarea.redactor(textarea.value + '<p>' + markup + '</p>'); | ||
else textarea.value += markup | ||
}); | ||
@@ -107,0 +106,0 @@ }); |
255960
46
3227