nodebb-plugin-shoutbox
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -44,3 +44,9 @@ 'use strict'; | ||
return await getShouts(sids); | ||
const shoutData = await getShouts(sids); | ||
shoutData.forEach((s, index) => { | ||
if (s) { | ||
s.index = start + index; | ||
} | ||
}); | ||
return shoutData; | ||
}; | ||
@@ -47,0 +53,0 @@ |
@@ -34,3 +34,3 @@ 'use strict'; | ||
start = parsedStart; | ||
end = start + shoutLimit; | ||
end = start + shoutLimit - 1; | ||
} | ||
@@ -37,0 +37,0 @@ } |
{ | ||
"name": "nodebb-plugin-shoutbox", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "NodeBB Shoutbox Plugin", | ||
@@ -5,0 +5,0 @@ "main": "library.js", |
@@ -14,8 +14,28 @@ 'use strict'; | ||
this.settings.load(); | ||
getShouts(); | ||
this.createAutoComplete(); | ||
const shoutsPerPage = config.shoutbox.settings['shoutbox:shoutLimit']; | ||
if (this.dom.shoutsContainer) { | ||
const container = $(this.dom.shoutsContainer) | ||
$(this.dom.shoutsContainer).on('scroll', utils.debounce(function () { | ||
const st = container.scrollTop(); | ||
if (st < 150) { | ||
const first = container.find('.shoutbox-shout[data-index]'); | ||
if (first.length) { | ||
const index = parseInt(first.attr('data-index'), 10) - shoutsPerPage; | ||
getShouts(index, 'before'); | ||
} | ||
} | ||
}, 500)); | ||
} | ||
getShouts(-shoutsPerPage); | ||
window.sb = this; | ||
function getShouts() { | ||
self.sockets.getShouts(function (err, shouts) { | ||
function getShouts(start, direction) { | ||
self.sockets.getShouts({ | ||
start: start, | ||
}, function (err, shouts) { | ||
if (err) { | ||
@@ -31,3 +51,3 @@ return app.alertError(err); | ||
} else { | ||
self.addShouts(shouts); | ||
self.addShouts(shouts, direction); | ||
} | ||
@@ -46,3 +66,3 @@ }); | ||
Instance.prototype.addShouts = function (shouts) { | ||
Instance.prototype.addShouts = function (shouts, direction = 'after') { | ||
if (!shouts.length) { | ||
@@ -99,5 +119,9 @@ return; | ||
}, function (html) { | ||
self.dom.shoutsContainer.append(html); | ||
if (direction === 'before') { | ||
self.dom.shoutsContainer.prepend(html); | ||
} else { | ||
self.dom.shoutsContainer.append(html); | ||
self.utils.scrollToBottom(shouts.length > 1); | ||
} | ||
html.find('.timeago').timeago(); | ||
self.utils.scrollToBottom(shouts.length > 1); | ||
}); | ||
@@ -150,2 +174,31 @@ }; | ||
Instance.prototype.createAutoComplete = function () { | ||
if (!this.dom.textInput) { | ||
return; | ||
} | ||
const element = $(this.dom.textInput); | ||
require(['composer/autocomplete'], function (autocomplete) { | ||
const data = { | ||
element: element, | ||
strategies: [], | ||
options: { | ||
style: { | ||
'z-index': 20000, | ||
flex: 0, | ||
top: 'inherit', | ||
}, | ||
placement: 'bottom', | ||
}, | ||
}; | ||
$(window).trigger('chat:autocomplete:init', data); | ||
if (data.strategies.length) { | ||
const autoComplete = autocomplete.setup(data); | ||
$(window).one('action:ajaxify.start', () => { | ||
autoComplete.destroy(); | ||
}); | ||
} | ||
}); | ||
}; | ||
Instance.prototype.showUserPanel = function () { | ||
@@ -152,0 +205,0 @@ this.dom.onlineUsers.parent().removeClass('hidden'); |
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
495983
1789
1