nodebb-plugin-poll
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -29,4 +29,7 @@ { | ||
"error.not_main": "Can only add poll in main post.", | ||
"error.privilege.create": "You're not allowed to create a poll", | ||
"warning.redactor": "You're using Redactor. Do <strong>not</strong> edit the markup manually. Instead, re-open the poll creator.", | ||
"vote": "Vote", | ||
@@ -33,0 +36,0 @@ "to_voting": "To Voting", |
@@ -29,4 +29,7 @@ { | ||
"error.not_main": "Can only add poll in main post.", | ||
"error.privilege.create": "You're not allowed to create a poll", | ||
"warning.redactor": "You're using Redactor. Do <strong>not</strong> edit the markup manually. Instead, re-open the poll creator.", | ||
"vote": "Vote", | ||
@@ -33,0 +36,0 @@ "to_voting": "To Voting", |
{ | ||
"name": "nodebb-plugin-poll", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "NodeBB Poll Plugin", | ||
@@ -5,0 +5,0 @@ "main": "library.js", |
@@ -9,4 +9,14 @@ "use strict"; | ||
function init() { | ||
$(window).on('action:composer.enhanced', function() { | ||
initComposer(); | ||
$(window).on('action:composer.enhanced', initComposer); | ||
$(window).on('action:redactor.load', initRedactor); | ||
$(window).on('action:composer.loaded', function(ev, data) { | ||
if ($.Redactor) { | ||
if (data.composerData.isMain && $.Redactor.opts.plugins.indexOf('poll') === -1) { | ||
$.Redactor.opts.plugins.push('poll'); | ||
} else if ($.Redactor.opts.plugins.indexOf('poll') !== -1) { | ||
$.Redactor.opts.plugins.splice($.Redactor.opts.plugins.indexOf('poll'), 1); | ||
} | ||
} | ||
}); | ||
@@ -25,6 +35,33 @@ } | ||
function initRedactor() { | ||
$.Redactor.prototype.poll = function () { | ||
return { | ||
init: function () { | ||
var self = this; | ||
translator.translate('[[poll:creator_title]]', function(translated) { | ||
var button = self.button.add('poll', translated); | ||
self.button.setAwesome('poll', 'fa fa-bar-chart-o'); | ||
self.button.addCallback(button, self.poll.onClick); | ||
}); | ||
}, | ||
onClick: function () { | ||
var self = this; | ||
var code = this.code.get(); | ||
require(['composer'], function(composer) { | ||
composerBtnHandle(composer, { | ||
value: code, | ||
redactor: function (code) { | ||
self.code.set(code); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
}; | ||
} | ||
function composerBtnHandle(composer, textarea) { | ||
var post = composer.posts[composer.active]; | ||
if (!post || !post.isMain || !post.cid || isNaN(parseInt(post.cid, 10))) { | ||
return app.alertError('Can only add poll in main post.'); | ||
return app.alertError('[[poll:error.not_main]]'); | ||
} | ||
@@ -64,2 +101,4 @@ | ||
textarea.value += markup; | ||
if ($.Redactor) textarea.redactor('<p>' + textarea.value + '</p>'); | ||
}); | ||
@@ -75,3 +114,3 @@ }); | ||
app.parseAndTranslate('poll/creator', { poll: poll, config: config }, function(html) { | ||
app.parseAndTranslate('poll/creator', { poll: poll, config: config, isRedactor: !!$.Redactor }, function(html) { | ||
// Initialise modal | ||
@@ -78,0 +117,0 @@ var modal = bootbox.dialog({ |
@@ -18,3 +18,3 @@ "use strict"; | ||
var pollRegex = XRegExp('(?:(?:\\[poll(?<settings>.*?)\\])\n(?<content>(?:-.+?\n)+)(?:\\[\/poll\\]))', 'g'); | ||
var settingsRegex = XRegExp('(?<key>.+?)="(?<value>.+?)"', 'g'); | ||
var settingsRegex = XRegExp('(?<key>.+?)=(?:"|")(?<value>.+?)(?:"|")', 'g'); | ||
var settingsValidators = { | ||
@@ -21,0 +21,0 @@ title: { |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
189171
2024
5