New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nodebb-plugin-cards

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodebb-plugin-cards - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

4

package.json
{
"name": "nodebb-plugin-cards",
"version": "0.1.4",
"version": "0.2.0",
"description": "NodeBB plugin that extends the mentions plugin with hover cards",

@@ -26,4 +26,4 @@ "main": "library.js",

"nbbpm": {
"compatibility": "^0.9.0"
"compatibility": "^0.9.0 || ^1.0.0"
}
}

@@ -14,45 +14,5 @@ "use strict";

$(document).ready(function() {
//Listen for events on body, we don't have to re-add on every ajaxify
$(document.body).off(events, selector).on(events, selector, function(e) {
var target = $(e.currentTarget),
href = regex.exec(target.attr('href'));
// Listen for events on body, we don't have to re-add on every ajaxify
$(document.body).off(events, selector).on(events, selector, onEvent);
//Check if it's a valid link
if (href && (!utils.invalidLatinChars.test(href[2]) && !utils.invalidUnicodeChars.test(href[2]))) {
if (target.children('img')) {
//Destroy tooltips added by NodeBB
target.children('img').tooltip('destroy');
}
if (e.type === "mouseenter" && !target.is(currentCard)) {
//If it's a mouseenter event, set a timeout to create a new card
delay = setTimeout(function() {
createCard(target, href[1]);
}, 500);
targetCard = target;
} else {
//Otherwise add some handlers for destroying a card
if (target.is(currentCard)) {
destroyDelay = setTimeout(function() {
destroyCard(target);
}, 500);
target.data('bs.popover')['$tip'].off(events).on(events, function(e) {
if (e.type === "mouseenter") {
clearTimeout(destroyDelay);
} else {
destroyDelay = setTimeout(function() {
destroyCard(target);
}, 500);
}
});
}
//Also clear the timeout for creating a new card
clearTimeout(delay);
targetCard = null;
}
}
});
$(window).on('action:ajaxify.start', function() {

@@ -64,3 +24,3 @@ if (delay) {

//Destroy any cards before ajaxifying
// Destroy any cards before ajaxifying
if (currentCard) {

@@ -74,62 +34,139 @@ destroyCard(currentCard);

function destroyCard(target) {
target.popover('destroy');
currentCard = null;
function onEvent(e) {
var target = $(e.currentTarget),
href = regex.exec(target.attr('href'));
// Check if it's a valid link
if (href && (!utils.invalidLatinChars.test(href[2]) || !utils.invalidUnicodeChars.test(href[2]))) {
// Destroy tooltips added by NodeBB
if (target.children('img')) {
target.children('img').tooltip('destroy');
}
// If it's a mouseenter event, set a timeout to create a new card
if (e.type === "mouseenter" && !target.is(currentCard)) {
delay = createCard(target, href[1]);
targetCard = target;
} else {
// Otherwise add some handlers for destroying a card
if (target.is(currentCard)) {
destroyDelay = destroyCard(target);
target.data('bs.popover')['$tip'].off(events).on(events, function(e) {
if (e.type === "mouseenter") {
clearTimeout(destroyDelay);
} else {
destroyDelay = destroyCard(target);
}
});
}
// Also clear the timeout for creating a new card
clearTimeout(delay);
targetCard = null;
}
}
}
function createCard(target, url) {
var api = '/api' + url;
$.ajax({
url: api,
success: function(result) {
result.name = result.fullname || result.username;
app.parseAndTranslate('cards/profile', result, function(html) {
//If target is not the currentCard and if the target is the targetCard
if (!target.is(currentCard) && target.is(targetCard)) {
//If there's an existing card, destroy it
if (currentCard) {
destroyCard(currentCard);
return setTimeout(function() {
var api = '/api' + url;
$.ajax({
url: api,
success: function(result) {
result.name = result.fullname || result.username;
app.parseAndTranslate('cards/profile', result, function(cardHTML) {
// If target is not the currentCard and if the target is the targetCard
if (!target.is(currentCard) && target.is(targetCard)) {
// If there's an existing card, destroy it
if (currentCard) {
destroyCard(currentCard);
}
// Bind chat button
cardHTML.find('[component="account/chat"]').on('click', function() {
socket.emit('modules.chats.hasPrivateChat', result.uid, function(err, roomId) {
if (err) {
return app.alertError(err.message);
}
if (roomId) {
app.openChat(roomId);
} else {
app.newChat(result.uid);
}
});
});
// Create card
target.popover({
html: true,
content: cardHTML,
placement: calculatePopoverPosition(target),
trigger: 'manual',
container: 'body'
}).popover('show').data('bs.popover')['$tip'].css('z-index', 1000000);
// Bind some other stuff
$('.profile-card .timeago').timeago();
$('.card-fab button').dropdown();
utils.makeNumbersHumanReadable($('.profile-card .human-readable-number'));
// Bind exit events
$('html').off(exitEvent).on(exitEvent, function() {
if (currentCard) {
destroyCard(currentCard);
}
});
// I don't remember what this does
$('.profile-card').off(exitEvent).on(exitEvent, function(e) {
e.stopPropagation();
});
currentCard = target;
}
});
},
cache: false
});
}, 500);
}
//Create card
target.popover({
html: true,
content: html,
placement: 'top',
trigger: 'manual',
container: 'body'
}).popover('show');
function destroyCard(target) {
return setTimeout(function() {
target.popover('destroy');
currentCard = null;
}, 500);
}
$('.profile-card-stats li').tooltip();
function calculatePopoverPosition(target){
var offset = target.offset();
var width = $(document).width();
var height = $(document).height();
utils.makeNumbersHumanReadable($('.profile-card-stats li span'));
if (offset.left > 300) {
return 'left';
}
$('.profile-card-chat').off('click.card').on('click.card', function(e) {
var card = $(e.currentTarget).parents('.profile-card');
app.openChat(card.data('username'), card.data('uid'));
return false;
});
if (width - offset.left > 300) {
return 'right';
}
currentCard = target;
if (offset.top > 400) {
return 'top';
}
$('html').off(exitEvent).on(exitEvent, function() {
if (currentCard) {
destroyCard(currentCard);
}
});
if (height - offset.top > 400) {
return 'bottom';
}
$('.profile-card').off(exitEvent).on(exitEvent, function(e) {
e.stopPropagation();
});
}
});
},
cache: false
});
return 'right';
}
app.createUserTooltips = function() {
//override with empty function because we don't want this function to execute
//so metal
}
// override with empty function because we don't want this function to execute
// so metal
};
})(window);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc