Support links in polls

This commit is contained in:
calzoneman 2013-12-01 17:20:42 -06:00
parent 6cf2c40240
commit 3ced278bd0
3 changed files with 17 additions and 5 deletions

View File

@ -826,7 +826,7 @@ Channel.prototype.handlePendingJoins = function () {
};
Channel.prototype.userJoin = function(user, password) {
if (password.length > 100) {
if (typeof password === "string" && password.length > 100) {
password = password.substring(0, 100);
}
var self = this;
@ -1932,6 +1932,10 @@ Channel.prototype.tryOpenPoll = function(user, data) {
return;
}
for (var i = 0; i < data.opts.length; i++) {
data.opts[i] = ""+data.opts[i];
}
var obscured = (data.obscured === true);
var poll = new Poll(user.name, data.title, data.opts, obscured);
this.poll = poll;

View File

@ -8,11 +8,19 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const link = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
var XSS = require("./xss");
var Poll = function(initiator, title, options, obscured) {
this.initiator = initiator;
this.title = title;
title = XSS.sanitizeText(title);
this.title = title.replace(link, "<a href=\"$1\" target=\"_blank\">$1</a>");
this.options = options;
for (var i = 0; i < this.options.length; i++) {
this.options[i] = XSS.sanitizeText(this.options[i]);
this.options[i] = this.options[i].replace(link, "<a href=\"$1\" target=\"_blank\">$1</a>");
}
this.obscured = obscured || false;
this.counts = new Array(options.length);
for(var i = 0; i < this.counts.length; i++) {

View File

@ -1100,7 +1100,7 @@ Callbacks = {
newPoll: function(data) {
Callbacks.closePoll();
var pollMsg = $("<div/>").addClass("poll-notify")
.text(data.initiator + " opened a poll: \"" + data.title + "\"")
.html(data.initiator + " opened a poll: \"" + data.title + "\"")
.appendTo($("#messagebuffer"));
scrollChat();
@ -1116,7 +1116,7 @@ Callbacks = {
});
}
$("<h3/>").text(data.title).appendTo(poll);
$("<h3/>").html(data.title).appendTo(poll);
for(var i = 0; i < data.options.length; i++) {
(function(i) {
var callback = function () {
@ -1129,7 +1129,7 @@ Callbacks = {
$(this).parent().addClass("option-selected");
}
$("<button/>").addClass("btn").text(data.counts[i])
.prependTo($("<div/>").addClass("option").text(data.options[i])
.prependTo($("<div/>").addClass("option").html(data.options[i])
.appendTo(poll))
.click(callback);
})(i);