Skip to content

Instantly share code, notes, and snippets.

@nirewen
Created April 26, 2016 19:46
Show Gist options
  • Save nirewen/8cd0166723188402cd8a65c31fc63778 to your computer and use it in GitHub Desktop.
Save nirewen/8cd0166723188402cd8a65c31fc63778 to your computer and use it in GitHub Desktop.
Message Delete - A plugin that creates an easy button to delete the messages!
//META{"name":"Delete"}*//
//Inspired on Jiiks dblClickEdit plugin and Reply plugin by CosmicSalad (Hammock)
var Delete = function () {};
Delete.prototype.start = function() {
$(document).on("mouseover.rpr", function(e) {
var target = $(e.target);
if(target.parents(".message").length > 0) {
var allmessages = $('.message-text');
var posMsg = $('.messages .message-group .comment .message .markup');
var delBtn = '<span class="delete" style="cursor:pointer;color:#fff !important;position:relative;top:-1px;margin-left:5px;text-transform:uppercase;font-size:10px;padding:3px 5px;box-sizing:border-box;background:rgba(255,0,0,0.4)">X</span>';
allmessages.on('mouseover',function() {
if(posMsg.find('.delete').length == 0) {
$(this).find(posMsg).append(delBtn);
$(this).find('.delete').click(function() {
var msg = target.parents(".message").first();
var opt = msg.find(".btn-option");
opt.click();
var popout = $(".option-popout");
popout.children().eq(1).click();
var e = new Event("keydown");
e.which = 13;
document.dispatchEvent(e);
});
}
});
allmessages.on('mouseleave',function() {
if(posMsg.find('.delete').length == 1) {
$(this).find('.delete').empty().remove();
}
});
}
});
console.log('Delete messages started.');
};
Delete.prototype.load = function() {};
Delete.prototype.unload = function() {
$(document).off("mouseover.rpr");
$('.messages .message-group').off('mouseover');
$('.messages .message-group').off('mouseleave');
};
Delete.prototype.stop = function() {
$(document).off("mouseover.rpr");
$('.messages .message-group').off('mouseover');
$('.messages .message-group').off('mouseleave');
};
Delete.prototype.getSettingsPanel = function() {
return null;
};
Delete.prototype.getName = function() {
return "Message deleter";
};
Delete.prototype.getDescription = function() {
return "Deletes the message with a button";
};
Delete.prototype.getVersion = function() {
return "1.0";
};
Delete.prototype.getAuthor = function() {
return "Nirewen";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment