Add file deletion in the menu. Close #587

This commit is contained in:
Nicolas Stepien 2012-07-11 23:15:06 +02:00
parent 5774217b59
commit 9c59c0d6f9
3 changed files with 77 additions and 26 deletions

View File

@ -111,7 +111,7 @@
Menu: { Menu: {
'Menu': [true, 'Add a drop-down menu in posts.'], 'Menu': [true, 'Add a drop-down menu in posts.'],
'Report Link': [true, 'Add a report link to the menu.'], 'Report Link': [true, 'Add a report link to the menu.'],
'Delete Link': [true, 'Add a delete link to the menu.'], 'Delete Link': [true, 'Add post and image deletion links to the menu.'],
'Download Link': [true, 'Add a download with original filename link to the menu. Chrome-only currently.'], 'Download Link': [true, 'Add a download with original filename link to the menu. Chrome-only currently.'],
'Archive Link': [true, 'Add an archive link to the menu.'] 'Archive Link': [true, 'Add an archive link to the menu.']
}, },
@ -4067,33 +4067,59 @@
DeleteLink = { DeleteLink = {
init: function() { init: function() {
var a; var aImage, aPost, children, div;
a = $.el('a', { div = $.el('div', {
className: 'delete_link', className: 'delete_link',
textContent: 'Delete'
});
aPost = $.el('a', {
className: 'delete_post',
href: 'javascript:;' href: 'javascript:;'
}); });
return Menu.addEntry({ aImage = $.el('a', {
el: a, className: 'delete_image',
open: function(post) { href: 'javascript:;'
if (post.isArchived) { });
return false; children = [];
} children.push({
a.textContent = 'Delete this post'; el: aPost,
$.on(a, 'click', DeleteLink["delete"]); open: function() {
aPost.textContent = 'Post';
$.on(aPost, 'click', DeleteLink["delete"]);
return true; return true;
} }
}); });
children.push({
el: aImage,
open: function(post) {
if (!post.img) {
return false;
}
aImage.textContent = 'Image';
$.on(aImage, 'click', DeleteLink["delete"]);
return true;
}
});
return Menu.addEntry({
el: div,
open: function(post) {
return !post.isArchived;
},
children: children
});
}, },
"delete": function() { "delete": function() {
var board, form, id, m, pwd, self; var board, form, id, m, menu, pwd, self;
$.off(this, 'click', DeleteLink["delete"]); $.off(this, 'click', DeleteLink["delete"]);
this.textContent = 'Deleting...'; this.textContent = 'Deleting...';
pwd = (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $.id('delPassword').value; pwd = (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $.id('delPassword').value;
id = this.parentNode.dataset.id; menu = $.id('menu');
board = $('.postNum > a[title="Highlight this post"]', $.id(this.parentNode.dataset.rootid)).pathname.split('/')[1]; id = menu.dataset.id;
board = $('.postNum > a[title="Highlight this post"]', $.id(menu.dataset.rootid)).pathname.split('/')[1];
self = this; self = this;
form = { form = {
mode: 'usrdel', mode: 'usrdel',
onlyimgdel: /\bdelete_image\b/.test(this.className),
pwd: pwd pwd: pwd
}; };
form[id] = 'delete'; form[id] = 'delete';

View File

@ -1,4 +1,6 @@
master master
- Mayhem
Divide the Delete Link in the Menu into a Post and Image deletion links.
2.34.1 2.34.1
- Mayhem - Mayhem

View File

@ -27,7 +27,7 @@ Config =
Menu: Menu:
'Menu': [true, 'Add a drop-down menu in posts.'] 'Menu': [true, 'Add a drop-down menu in posts.']
'Report Link': [true, 'Add a report link to the menu.'] 'Report Link': [true, 'Add a report link to the menu.']
'Delete Link': [true, 'Add a delete link to the menu.'] 'Delete Link': [true, 'Add post and image deletion links to the menu.']
'Download Link': [true, 'Add a download with original filename link to the menu. Chrome-only currently.'] 'Download Link': [true, 'Add a download with original filename link to the menu. Chrome-only currently.']
'Archive Link': [true, 'Add an archive link to the menu.'] 'Archive Link': [true, 'Add an archive link to the menu.']
Monitoring: Monitoring:
@ -3231,17 +3231,38 @@ Quotify =
DeleteLink = DeleteLink =
init: -> init: ->
a = $.el 'a', div = $.el 'div',
className: 'delete_link' className: 'delete_link'
textContent: 'Delete'
aPost = $.el 'a',
className: 'delete_post'
href: 'javascript:;' href: 'javascript:;'
Menu.addEntry aImage = $.el 'a',
el: a className: 'delete_image'
open: (post) -> href: 'javascript:;'
if post.isArchived
return false children = []
a.textContent = 'Delete this post'
$.on a, 'click', DeleteLink.delete children.push
el: aPost
open: ->
aPost.textContent = 'Post'
$.on aPost, 'click', DeleteLink.delete
true true
children.push
el: aImage
open: (post) ->
return false unless post.img
aImage.textContent = 'Image'
$.on aImage, 'click', DeleteLink.delete
true
Menu.addEntry
el: div
open: (post) -> !post.isArchived
children: children
delete: -> delete: ->
$.off @, 'click', DeleteLink.delete $.off @, 'click', DeleteLink.delete
@textContent = 'Deleting...' @textContent = 'Deleting...'
@ -3252,13 +3273,15 @@ DeleteLink =
else else
$.id('delPassword').value $.id('delPassword').value
id = @parentNode.dataset.id menu = $.id 'menu'
id = menu.dataset.id
board = $('.postNum > a[title="Highlight this post"]', board = $('.postNum > a[title="Highlight this post"]',
$.id @parentNode.dataset.rootid).pathname.split('/')[1] $.id menu.dataset.rootid).pathname.split('/')[1]
self = this self = @
form = form =
mode: 'usrdel' mode: 'usrdel'
onlyimgdel: /\bdelete_image\b/.test @className
pwd: pwd pwd: pwd
form[id] = 'delete' form[id] = 'delete'