1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-01-19 01:24:05 +01:00
This commit is contained in:
8chan 2015-02-26 02:08:25 +00:00
commit 1305a79621
6 changed files with 555 additions and 335 deletions

View File

@ -133,19 +133,8 @@ function imageHoverStart(e) { //Pashe, anonish, WTFPL
if ($this.parent().attr("href").match("src")) {
fullUrl = $this.parent().attr("href");
} else if (isOnCatalog()) {
$this.css("cursor", "progress");
fullUrl = $this.attr("src");
$.ajax(($this.parent().attr("href").replace(/\.html$/, ".json")), {
success: function (result) {
$this.css("cursor", "unset");
fullUrl = result.posts[0].tim + result.posts[0].ext;
if (!isImage(getFileExtension(fullUrl))) {return;}
$("#chx_hoverImage").attr("src", "/" + thisBoard + "/" + fullUrl);
$("#chx_hoverImage").on("load", function() {$this.css("cursor", "none")});
},
async: true,
cache: true
});
fullUrl = $this.attr("data-fullimage");
if (!isImage(getFileExtension(fullUrl))) {fullUrl = $this.attr("src");}
}
if (isVideo(getFileExtension(fullUrl))) {return;}

View File

@ -158,7 +158,7 @@ $(document).ready(function(){
// on multifile posts, determin how many other images are still expanded
still_open = post_body.find('.post-image').filter(function(){
return $(this).parent().attr('data-expanded') == 'true';
return $(this).parent().data('expanded') == 'true';
}).length;
// deal with differnt boards' menu styles

View File

@ -27,34 +27,42 @@ if (active_page === 'thread' || active_page === 'index') {
list.nextPurge[boardId][threadId] = {timestamp: timestamp(), interval: 86400}; // 86400 seconds == 1 day
}
function addFilter(type, value, useRegex) {
var list = getList();
var filter = list.generalFilter;
var obj = {
type: type,
value: value,
regex: useRegex
};
for (var i=0; i<filter.length; i++) {
if (filter[i].type == type && filter[i].value == value && filter[i].regex == useRegex)
return;
}
filter.push(obj);
setList(list);
drawFilterList();
}
function removeFilter(type, value, useRegex) {
var list = getList();
var filter = list.generalFilter;
for (var i=0; i<filter.length; i++) {
if (filter[i].type == type && filter[i].value == value && filter[i].regex == useRegex) {
filter.splice(i, 1);
break;
}
}
setList(list);
drawFilterList();
}
var blacklist = {
add: {
name: function (posterName) {
var list = getList();
var filter = list.nameFilter;
for (var i in filter) {
if (filter[i].name == posterName) return;
}
filter.push({
name: posterName
});
setList(list);
drawFilterList();
},
trip: function (posterTrip) {
var list = getList();
var filter = list.nameFilter;
for (var i in filter) {
if (filter[i].trip == posterTrip) return;
}
filter.push({
trip: posterTrip
});
setList(list);
drawFilterList();
},
post: function (boardId, threadId, postId, hideReplies) {
var list = getList();
var filter = list.postFilter;
@ -87,32 +95,6 @@ if (active_page === 'thread' || active_page === 'index') {
}
},
remove: {
name: function (posterName) {
var list = getList();
var filter = list.nameFilter;
for (var i=0; i<filter.length; i++) {
if (filter[i].name == posterName) {
filter.splice(i, 1);
break;
}
}
setList(list);
drawFilterList();
},
trip: function (posterTrip) {
var list = getList();
var filter = list.nameFilter;
for (var i=0; i<filter.length; i++) {
if (filter[i].trip == posterTrip) {
filter.splice(i, 1);
break;
}
}
setList(list);
drawFilterList();
},
post: function (boardId, threadId, postId) {
var list = getList();
var filter = list.postFilter;
@ -174,10 +156,10 @@ if (active_page === 'thread' || active_page === 'index') {
function hide(ele) {
var $ele = $(ele);
if ($(ele).data('hidden') === '1')
if ($(ele).data('hidden'))
return;
$(ele).data('hidden', '1');
$(ele).data('hidden', true);
if ($ele.hasClass('op')) {
$ele.parent().find('.body, .files, .video-container').not($ele.children('.reply').children()).hide();
@ -191,7 +173,7 @@ if (active_page === 'thread' || active_page === 'index') {
function show(ele) {
var $ele = $(ele);
$(ele).data('hidden', '0');
$(ele).data('hidden', false);
if ($ele.hasClass('op')) {
$ele.parent().find('.body, .files, .video-container').show();
if (active_page == 'index') $ele.parent().find('.omitted, .reply:not(.hidden), post_no, .mentioned, br').show();
@ -204,198 +186,155 @@ if (active_page === 'thread' || active_page === 'index') {
/*
* create filter menu when the button is clicked
*/
function addMenu(e, ele, threadId, pageData) {
function initPostMenu(pageData) {
var $ele = $(ele);
var $buffer;
var submenu;
Menu.add_item('filter-menu-hide', 'Hide post');
Menu.add_item('filter-menu-unhide', 'Unhide post');
var postId = $ele.find('.post_no').not('[id]').text();
if (pageData.hasUID) {
var postUid = $ele.find('.poster_id').text();
}
var postName;
var postTrip = '';
if (!pageData.forcedAnon) {
postName = (typeof $ele.find('.name').contents()[0] == 'undefined') ? '' : $ele.find('.name').contents()[0].nodeValue.trim();
postTrip = $ele.find('.trip').text();
}
submenu = Menu.add_submenu('filter-menu-add', 'Add filter');
submenu.add_item('filter-add-post-plus', 'Post +', 'Hide post and all replies');
submenu.add_item('filter-add-id', 'ID');
submenu.add_item('filter-add-id-plus', 'ID +', 'Hide ID and all replies');
submenu.add_item('filter-add-name', 'Name');
submenu.add_item('filter-add-trip', 'Tripcode');
// get the button's position
var pos = $(e.target).offset();
submenu = Menu.add_submenu('filter-menu-remove', 'Remove filter');
submenu.add_item('filter-remove-id', 'ID');
submenu.add_item('filter-remove-name', 'Name');
submenu.add_item('filter-remove-trip', 'Tripcode');
$buffer = $('<div class="filter-menu"></div>').append(
$('<ul>').append(
$('<li>', {id: 'filter-menu-unhide'}).text('Unhide post'),
$('<li>', {id: 'filter-menu-add'}).append(
$('<ul>').append(
$('<li>', {class: 'filter-post'}).text('Post'),
$('<li>', {class: 'filter-post-plus', title: 'Hide post and all replies'}).text('Post +'),
$('<li>', {class: 'filter-id'}).text('ID'),
$('<li>', {class: 'filter-id-plus', title: 'Hide ID and all replies'}).text('ID +'),
$('<li>', {class: 'filter-name'}).text('Name'),
$('<li>', {class: 'filter-trip'}).text('Tripcode')
),
'Add filter',
$('<span>', {class: 'filter-menu-arrow'}).append('»')
),
$('<li>', {id: 'filter-menu-remove'}).append(
$('<ul>').append(
$('<li>', {class: 'filter-id'}).text('ID'),
$('<li>', {class: 'filter-name'}).text('Name'),
$('<li>', {class: 'filter-trip'}).text('Tripcode')
),
'Remove filter',
$('<span>', {class: 'filter-menu-arrow'}).append('»')
)
)
);
Menu.onclick(function (e, $buffer) {
var ele = e.target.parentElement.parentElement;
var $ele = $(ele);
/* display logic and bind click handlers
*/
var threadId = $ele.parent().attr('id').replace('thread_', '');
var postId = $ele.find('.post_no').not('[id]').text();
if (pageData.hasUID) {
var postUid = $ele.find('.poster_id').text();
}
// unhide button
if ($(ele).data('hidden') == '1' && $(ele).data('hiddenByUid') == '0' &&
$(ele).data('hiddenByName') == '0' && $(ele).data('hiddenByTrip') == '0') {
$buffer.find('#filter-menu-unhide').click(function () {
// if hidden due to post id, remove it from blacklist
// otherwise just show this post
blacklist.remove.post(pageData.boardId, threadId, postId);
show(ele);
});
} else {
$buffer.find('#filter-menu-unhide').addClass('hidden');
}
var postName;
var postTrip = '';
if (!pageData.forcedAnon) {
postName = (typeof $ele.find('.name').contents()[0] == 'undefined') ? '' : $ele.find('.name').contents()[0].nodeValue.trim();
postTrip = $ele.find('.trip').text();
}
// post id
if ($(ele).data('hiddenByPost') == '0') {
$buffer.find('#filter-menu-add .filter-post').click(function () {
blacklist.add.post(pageData.boardId, threadId, postId, false);
});
$buffer.find('#filter-menu-add .filter-post-plus').click(function () {
blacklist.add.post(pageData.boardId, threadId, postId, true);
});
} else {
$buffer.find('#filter-menu-add .filter-post').addClass('hidden');
$buffer.find('#filter-menu-add .filter-post-plus').addClass('hidden');
}
/* display logic and bind click handlers
*/
// UID
if (pageData.hasUID && $(ele).data('hiddenByUid') == '0') {
$buffer.find('#filter-menu-add .filter-id').click(function () {
blacklist.add.uid(pageData.boardId, threadId, postUid, false);
});
$buffer.find('#filter-menu-add .filter-id-plus').click(function () {
blacklist.add.uid(pageData.boardId, threadId, postUid, true);
});
// unhide button
if ($ele.data('hidden')) {
$buffer.find('#filter-menu-unhide').click(function () {
// if hidden due to post id, remove it from blacklist
// otherwise just show this post
blacklist.remove.post(pageData.boardId, threadId, postId);
show(ele);
});
$buffer.find('#filter-menu-hide').addClass('hidden');
} else {
$buffer.find('#filter-menu-unhide').addClass('hidden');
$buffer.find('#filter-menu-hide').click(function () {
blacklist.add.post(pageData.boardId, threadId, postId, false);
});
}
$buffer.find('#filter-menu-remove .filter-id').addClass('hidden');
} else if (pageData.hasUID) {
$buffer.find('#filter-menu-remove .filter-id').click(function () {
blacklist.remove.uid(pageData.boardId, threadId, postUid);
});
// post id
if (!$ele.data('hiddenByPost')) {
$buffer.find('#filter-add-post-plus').click(function () {
blacklist.add.post(pageData.boardId, threadId, postId, true);
});
} else {
$buffer.find('#filter-add-post-plus').addClass('hidden');
}
$buffer.find('#filter-menu-add .filter-id').addClass('hidden');
$buffer.find('#filter-menu-add .filter-id-plus').addClass('hidden');
} else {
// board doesn't use UID
$buffer.find('#filter-menu-add .filter-id').addClass('hidden');
$buffer.find('#filter-menu-add .filter-id-plus').addClass('hidden');
$buffer.find('#filter-menu-remove .filter-id').addClass('hidden');
}
// UID
if (pageData.hasUID && !$ele.data('hiddenByUid')) {
$buffer.find('#filter-add-id').click(function () {
blacklist.add.uid(pageData.boardId, threadId, postUid, false);
});
$buffer.find('#filter-add-id-plus').click(function () {
blacklist.add.uid(pageData.boardId, threadId, postUid, true);
});
// name
if (!pageData.forcedAnon && $(ele).data('hiddenByName') == '0') {
$buffer.find('#filter-menu-add .filter-name').click(function () {
blacklist.add.name(postName);
});
$buffer.find('#filter-remove-id').addClass('hidden');
} else if (pageData.hasUID) {
$buffer.find('#filter-remove-id').click(function () {
blacklist.remove.uid(pageData.boardId, threadId, postUid);
});
$buffer.find('#filter-menu-remove .filter-name').addClass('hidden');
} else if (!pageData.forcedAnon) {
$buffer.find('#filter-menu-remove .filter-name').click(function () {
blacklist.remove.name(postName);
});
$buffer.find('#filter-add-id').addClass('hidden');
$buffer.find('#filter-add-id-plus').addClass('hidden');
} else {
// board doesn't use UID
$buffer.find('#filter-add-id').addClass('hidden');
$buffer.find('#filter-add-id-plus').addClass('hidden');
$buffer.find('#filter-remove-id').addClass('hidden');
}
$buffer.find('#filter-menu-add .filter-name').addClass('hidden');
} else {
// board has forced anon
$buffer.find('#filter-menu-remove .filter-name').addClass('hidden');
$buffer.find('#filter-menu-add .filter-name').addClass('hidden');
}
// name
if (!pageData.forcedAnon && !$ele.data('hiddenByName')) {
$buffer.find('#filter-add-name').click(function () {
addFilter('name', postName, false);
});
// tripcode
if (!pageData.forcedAnon && $(ele).data('hiddenByTrip') == '0' && postTrip !== '') {
$buffer.find('#filter-menu-add .filter-trip').click(function () {
blacklist.add.trip(postTrip);
});
$buffer.find('#filter-remove-name').addClass('hidden');
} else if (!pageData.forcedAnon) {
$buffer.find('#filter-remove-name').click(function () {
removeFilter('name', postName, false);
});
$buffer.find('#filter-menu-remove .filter-trip').addClass('hidden');
} else if (!pageData.forcedAnon && postTrip !== '') {
$buffer.find('#filter-menu-remove .filter-trip').click(function () {
blacklist.remove.trip(postTrip);
});
$buffer.find('#filter-add-name').addClass('hidden');
} else {
// board has forced anon
$buffer.find('#filter-remove-name').addClass('hidden');
$buffer.find('#filter-add-name').addClass('hidden');
}
$buffer.find('#filter-menu-add .filter-trip').addClass('hidden');
} else {
// board has forced anon
$buffer.find('#filter-menu-remove .filter-trip').addClass('hidden');
$buffer.find('#filter-menu-add .filter-trip').addClass('hidden');
}
// tripcode
if (!pageData.forcedAnon && !$ele.data('hiddenByTrip') && postTrip !== '') {
$buffer.find('#filter-add-trip').click(function () {
addFilter('trip', postTrip, false);
});
/* hide sub menus if all items are hidden
*/
if (!$buffer.find('#filter-menu-remove > ul').children().not('.hidden').length) {
$buffer.find('#filter-menu-remove').addClass('hidden');
}
if (!$buffer.find('#filter-menu-add > ul').children().not('.hidden').length) {
$buffer.find('#filter-menu-add').addClass('hidden');
}
$buffer.find('#filter-remove-trip').addClass('hidden');
} else if (!pageData.forcedAnon && postTrip !== '') {
$buffer.find('#filter-remove-trip').click(function () {
removeFilter('trip', postTrip, false);
});
/* set menu position
*/
$buffer.css({top: pos.top + 20, left: pos.left});
$buffer.find('#filter-add-trip').addClass('hidden');
} else {
// board has forced anon
$buffer.find('#filter-remove-trip').addClass('hidden');
$buffer.find('#filter-add-trip').addClass('hidden');
}
/* finally append to page
*/
$('body').append($buffer);
/* hide sub menus if all items are hidden
*/
if (!$buffer.find('#filter-menu-remove > ul').children().not('.hidden').length) {
$buffer.find('#filter-menu-remove').addClass('hidden');
}
if (!$buffer.find('#filter-menu-add > ul').children().not('.hidden').length) {
$buffer.find('#filter-menu-add').addClass('hidden');
}
});
}
/*
* add menu button to the thread/post
* hide/unhide thread on index view
*/
function addMenuButton(ele, threadId, pageData) {
if ($(ele).find('.filter-btn').length)
$('.filter-btn').remove();
function quickToggle(ele, threadId, pageData) {
/*if ($(ele).find('.hide-thread-link').length)
$('.hide-thread-link').remove();*/
$(ele).find('.intro')
.append(
$('<a>', {href: '#', class: 'filter-btn', title: 'Filter menu'})
.text('▶')
.click(function (e) {
// button toggle
e.preventDefault();
// remove existing menu
$('.filter-menu').remove();
if ($(e.target).hasClass('filter-btn-open')) {
$('.filter-btn-open').removeClass('filter-btn-open');
} else {
// close previous button
$('.filter-btn-open').removeClass('filter-btn-open');
// mark the menu button as open
$(ele).find('.filter-btn').addClass('filter-btn-open');
addMenu(e, ele, threadId, pageData);
}
})
);
if ($(ele).hasClass('op') && !$(ele).find('.hide-thread-link').length) {
$('<a class="hide-thread-link" style="float:left;margin-right:5px" href="javascript:void(0)">[' + ($(ele).data('hidden') == '1' ? '+' : '&ndash;') + ']</a>')
$('<a class="hide-thread-link" style="float:left;margin-right:5px" href="javascript:void(0)">[' + ($(ele).data('hidden') ? '+' : '&ndash;') + ']</a>')
.insertBefore($(ele).find(':not(h2,h2 *):first'))
.click(function() {
var postId = $(ele).find('.post_no').not('[id]').text();
var hidden = ($(ele).data('hidden') == '1');
var hidden = $(ele).data('hidden');
if (hidden) {
blacklist.remove.post(pageData.boardId, threadId, postId, false);
@ -418,8 +357,8 @@ if (active_page === 'thread' || active_page === 'index') {
var $post = $(post);
var list = getList();
var postId = $post.find('.post_no').not('[id]').text();
var name, trip, uid;
var i, array; // temp variables
var name, trip, uid, subject, comment;
var i, length, array, rule, pattern; // temp variables
var boardId = pageData.boardId;
var localList = pageData.localList;
@ -427,11 +366,16 @@ if (active_page === 'thread' || active_page === 'index') {
var hasUID = pageData.hasUID;
var forcedAnon = pageData.forcedAnon;
$post.data('hidden', '0');
$post.data('hiddenByUid', '0');
$post.data('hiddenByPost', '0');
$post.data('hiddenByName', '0');
$post.data('hiddenByTrip', '0');
var hasTrip = ($post.find('.trip').length > 0);
var hasSub = ($post.find('.subject').length > 0);
$post.data('hidden', false);
$post.data('hiddenByUid', false);
$post.data('hiddenByPost', false);
$post.data('hiddenByName', false);
$post.data('hiddenByTrip', false);
$post.data('hiddenBySubject', false);
$post.data('hiddenByComment', false);
// add post with matched UID to localList
if (hasUID &&
@ -442,7 +386,7 @@ if (active_page === 'thread' || active_page === 'index') {
for (i=0; i<array.length; i++) {
if (array[i].uid == uid) {
$post.data('hiddenByUid', '1');
$post.data('hiddenByUid', true);
localList.push(postId);
if (array[i].hideReplies) noReplyList.push(postId);
break;
@ -453,23 +397,83 @@ if (active_page === 'thread' || active_page === 'index') {
// match localList
if (localList.length) {
if ($.inArray(postId, localList) != -1) {
if ($post.data('hiddenByUid') != '1') $post.data('hiddenByPost', '1');
if ($post.data('hiddenByUid') !== true) $post.data('hiddenByPost', true);
hide(post);
}
}
// match poster name and tripcode
if (!forcedAnon) {
// matches generalFilter
if (!forcedAnon)
name = (typeof $post.find('.name').contents()[0] == 'undefined') ? '' : $post.find('.name').contents()[0].nodeValue.trim();
if ($(list.nameFilter).filter(function(){if (this.name == name) return true;}).length) {
$post.data('hiddenByName', '1');
hide(post);
}
if ($post.find('.trip').length) {
trip = $post.find('.trip').text();
if ($(list.nameFilter).filter(function(){if (this.trip == trip) return true;}).length) {
$post.data('hiddenByTrip', '1');
hide(post);
if (!forcedAnon && hasTrip)
trip = $post.find('.trip').text();
if (hasSub)
subject = ' '+ $post.find('.subject').text() +' ';
array = $post.find('.body').contents().filter(function () {if ($(this).text() !== '') return true;}).toArray();
array = $.map(array, function (ele) {
return $(ele).text();
});
comment = ' '+ array.join(' ') +' ';
for (i = 0, length = list.generalFilter.length; i < length; i++) {
rule = list.generalFilter[i];
if (rule.regex) {
pattern = new RegExp(rule.value);
switch (rule.type) {
case 'name':
if (!forcedAnon && pattern.test(name)) {
$post.data('hiddenByName', true);
hide(post);
}
break;
case 'trip':
if (!forcedAnon && pattern.test(trip)) {
$post.data('hiddenByTrip', true);
hide(post);
}
break;
case 'sub':
if (hasSub && pattern.test(subject)) {
$post.data('hiddenBySubject', true);
hide(post);
}
break;
case 'com':
if (pattern.test(comment)) {
$post.data('hiddenByComment', true);
hide(post);
}
break;
}
} else {
switch (rule.type) {
case 'name':
if (!forcedAnon && rule.value == name) {
$post.data('hiddenByName', true);
hide(post);
}
break;
case 'trip':
if (!forcedAnon && hasTrip && rule.value == trip) {
$post.data('hiddenByTrip', true);
hide(post);
}
break;
case 'sub':
if (hasSub && subject.indexOf(' '+ rule.value +' ') != -1) {
$post.data('hiddenBySubject', true);
hide(post);
}
break;
case 'com':
if (comment.indexOf(' '+ rule.value +' ') != -1) {
$post.data('hiddenByComment', true);
hide(post);
}
break;
}
}
}
@ -488,12 +492,11 @@ if (active_page === 'thread' || active_page === 'index') {
});
// post didn't match any filters
if ((typeof $post.data('hidden') == 'undefined' || $post.data('hidden') == '0') &&
$post.data('hiddenByUid') === '0' &&
$post.data('hiddenByUid') == $post.data('hiddenByPost') == $post.data('hiddenByName') == $post.data('hiddenByTrip')) {
if (!$post.data('hidden')) {
show(post);
}
}
/* (re)runs the filter on the entire page
*/
function filterPage(pageData) {
@ -514,36 +517,30 @@ if (active_page === 'thread' || active_page === 'index') {
var i, array; // temp variables
// add posts to localList and noReplyList
if (typeof list.postFilter[pageData.boardId] != 'undefined') {
if (typeof list.postFilter[pageData.boardId] != 'undefined' && typeof list.postFilter[pageData.boardId][threadId] != 'undefined') {
array = list.postFilter[pageData.boardId][threadId];
if (typeof array != 'undefined') {
for (i=0; i<array.length; i++) {
if ( typeof array[i].post == 'undefined')
continue;
for (i=0; i<array.length; i++) {
if ( typeof array[i].post == 'undefined')
continue;
pageData.localList.push(array[i].post);
if (array[i].hideReplies) pageData.noReplyList.push(array[i].post);
}
pageData.localList.push(array[i].post);
if (array[i].hideReplies) pageData.noReplyList.push(array[i].post);
}
}
// run filter on OP
filter(op, threadId, pageData);
addMenuButton(op, threadId, pageData);
quickToggle(op, threadId, pageData);
// iterate filter over each post
if ($(op).data('hidden') != '1' || active_page == 'thread') {
if (!$(op).data('hidden') || active_page == 'thread') {
$thread.find('.reply').not('.hidden').each(function () {
filter(this, threadId, pageData);
addMenuButton(this, threadId, pageData);
});
}
});
}
/*
*
*/
function initStyle() {
var $ele, cssStyle, cssString;
@ -552,23 +549,9 @@ if (active_page === 'thread' || active_page === 'index') {
cssStyle.hoverBg = $('body').css('background-color');
$ele.remove();
cssString =
'\n/*** Generated by post-filter ***/\n' +
'.filter-menu {position: absolute; font-size: 12px; line-height: 1.3em;}\n' +
'.filter-menu ul {\n' +
' background-color: '+ cssStyle['background-color'] +'; border: 1px solid '+ cssStyle['border-color'] +'; border-right-width: 2px;\n' +
' list-style: none; padding: 0; margin: 0; white-space: nowrap;\n}\n' +
'.filter-menu li {cursor: pointer; position: relative; padding: 4px 4px; vertical-align: middle; border-bottom: 1px solid '+ cssStyle['border-color'] +'; white-space: normal; width: 90px;}\n' +
'.filter-menu li:hover {background-color: '+ cssStyle.hoverBg +';}\n' +
'.filter-menu ul ul {display: none; position: absolute;}\n' +
'.filter-menu li:hover ul {display: block; left: 100%; margin-top: -3px;}\n' +
'.filter-menu li ul li {white-space: nowrap; width: auto;}\n' +
'.filter-menu-arrow {float: right; margin-left: 10px;}\n' +
'.filter-menu.hidden, .filter-menu .hidden {display: none;}\n' +
'.filter-btn {transition: transform 0.1s; width: 15px; text-align: center; font-size: 12pt; opacity: 0.8; text-decoration: none; margin: -6px 0px; display: inline-block;}\n' +
'.filter-btn:hover {opacity: 1;}\n' +
'.filter-btn-open {transform: rotate(90deg);}\n';
cssString +=
cssString = '\n/*** Generated by post-filter ***/\n' +
'#filter-control input[type=text] {width: 130px;}' +
'#filter-control input[type=checkbox] {vertical-align: middle;}' +
'#filter-control #clear {float: right;}\n' +
'#filter-container {margin-top: 20px; border: 1px solid; height: 270px; overflow: auto;}\n' +
'#filter-list {width: 100%; border-collapse: collapse;}\n' +
@ -587,33 +570,40 @@ if (active_page === 'thread' || active_page === 'index') {
}
function drawFilterList() {
var list = getList().nameFilter;
var list = getList().generalFilter;
var $ele = $('#filter-list');
var $row;
var type, val;
var i, length, obj;
var $row, i, length, obj, val;
var typeName = {
name: 'name',
trip: 'tripcode',
sub: 'subject',
com: 'comment'
};
$ele.empty();
$ele.append('<tr id="header"><th>Type</th><th>Content</th><th>Remove</th></tr>');
for (i = 0, length = list.length; i < length; i++) {
obj = list[i];
for (type in obj) {
val = obj[type];
$row = $('<tr>');
$row.append(
'<td>'+ type +'</td>',
'<td>'+ val +'</td>',
$('<td>').append(
$('<a>').html('X')
.addClass('del-btn')
.attr('href', '#')
.attr('data-type', type)
.attr('data-val', val)
)
);
$ele.append($row);
}
// display formatting
val = (obj.regex) ? '/'+ obj.value +'/' : obj.value;
$row = $('<tr>');
$row.append(
'<td>'+ typeName[obj.type] +'</td>',
'<td>'+ val +'</td>',
$('<td>').append(
$('<a>').html('X')
.addClass('del-btn')
.attr('href', '#')
.data('type', obj.type)
.data('val', obj.value)
.data('useRegex', obj.regex)
)
);
$ele.append($row);
}
}
@ -622,9 +612,16 @@ if (active_page === 'thread' || active_page === 'index') {
Options.add_tab('filter', 'list', 'Filters');
Options.extend_tab('filter',
'<div id="filter-control">' +
'<input id="input" type="text"></input>' +
'<button id="name">Add Name</button>' +
'<button id="trip">Add Tripcode</button>' +
'<select>' +
'<option value="name">Name</option>' +
'<option value="trip">Tripcode</option>' +
'<option value="sub">Subject</option>' +
'<option value="com">Comment</option>' +
'</select>' +
'<input type="text">' +
'<input type="checkbox">' +
'regex ' +
'<button id="set-filter">Add</button>' +
'<button id="clear">Clear all filters</button>' +
'<div id="confirm" class="hidden">' +
'This will clear all filtering rules including hidden posts. <a id="confirm-y" href="#">yes</a> | <a id="confirm-n" href="#">no</a>' +
@ -635,15 +632,16 @@ if (active_page === 'thread' || active_page === 'index') {
drawFilterList();
// control buttons
$('#filter-control').on('click', '#name', function () {
var str = $('#filter-control #input').val().trim();
$('#filter-control #input').val('');
blacklist.add.name(str);
});
$('#filter-control').on('click', '#trip', function () {
var str = $('#filter-control #input').val().trim();
$('#filter-control #input').val('');
blacklist.add.trip(str);
$('#filter-control').on('click', '#set-filter', function () {
var type = $('#filter-control select option:selected').val();
var value = $('#filter-control input[type=text]').val();
var useRegex = $('#filter-control input[type=checkbox]').prop('checked');
//clear the input form
$('#filter-control input[type=text]').val('');
addFilter(type, value, useRegex);
drawFilterList();
});
$('#filter-control').on('click', '#clear', function () {
$('#filter-control #clear').addClass('hidden');
@ -655,7 +653,7 @@ if (active_page === 'thread' || active_page === 'index') {
$('#filter-control #clear').removeClass('hidden');
$('#filter-control #confirm').addClass('hidden');
setList({
nameFilter: [],
generalFilter: [],
postFilter: {},
nextPurge: {},
lastPurge: timestamp()
@ -675,9 +673,11 @@ if (active_page === 'thread' || active_page === 'index') {
e.preventDefault();
var $ele = $(e.target);
var type = $ele.attr('data-type');
var val = $ele.attr('data-val');
blacklist.remove[type](val);
var type = $ele.data('type');
var val = $ele.data('val');
var useRegex = $ele.data('useRegex');
removeFilter(type, val, useRegex);
});
}
}
@ -747,13 +747,40 @@ if (active_page === 'thread' || active_page === 'index') {
function init() {
if (typeof localStorage.postFilter === 'undefined') {
localStorage.postFilter = JSON.stringify({
nameFilter: [],
generalFilter: [],
postFilter: {},
nextPurge: {},
lastPurge: timestamp()
});
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Migrate from previous version of post filter
* Remember to remove next time anyone touches this file
*/
(function () {
var list = getList();
if (typeof list.nameFilter != 'undefined') {
var filter = list.nameFilter;
list.generalFilter = [];
for (var i = 0; i < filter.length; i++) {
var obj = filter[i];
for (var key in obj) {
list.generalFilter.push({
type: key,
value: obj[key],
regex: false
});
}
}
delete list.nameFilter;
localStorage.postFilter = JSON.stringify(list);
}
})();
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
var pageData = {
boardId: board_name, // get the id from the global variable
localList: [], // all the blacklisted post IDs or UIDs that apply to the current page
@ -764,27 +791,21 @@ if (active_page === 'thread' || active_page === 'index') {
initStyle();
initOptionsPanel();
initPostMenu(pageData);
filterPage(pageData);
// menu close click handler
$(document).on('click', function (e){
if ($(e.target).hasClass('filter-btn'))
return;
$('.filter-menu').remove();
$('.filter-btn-open').removeClass('filter-btn-open');
});
// on new posts
$(document).on('new_post', function (e, post) {
var threadId;
if ($(post).hasClass('reply')) {
var threadId = $(post).parent().attr('id').replace('thread_', '');
threadId = $(post).parent().attr('id').replace('thread_', '');
} else {
var threadId = $(post).attr('id').replace('thread_', '');
threadId = $(post).attr('id').replace('thread_', '');
}
filter(post, threadId, pageData);
addMenuButton(post, threadId, pageData);
quickToggle(post, threadId, pageData);
});
$(document).on('filter_page', function () {

209
js/post-menu.js Normal file
View File

@ -0,0 +1,209 @@
/*
* post-menu.js - adds dropdown menu to posts
*
* Creates a global Menu object with four public methods:
*
* Menu.onclick(fnc)
* registers a function to be executed after button click, before the menu is displayed
* Menu.add_item(id, text[, title])
* adds an item to the top level of menu
* Menu.add_submenu(id, text)
* creates and returns a List object through which to manipulate the content of the submenu
* Menu.get_submenu(id)
* returns the submenu with the specified id from the top level menu
*
* The List object contains all the methods from Menu except onclick()
*
* Example usage:
* Menu.add_item('filter-menu-hide', 'Hide post');
* Menu.add_item('filter-menu-unhide', 'Unhide post');
*
* submenu = Menu.add_submenu('filter-menu-add', 'Add filter');
* submenu.add_item('filter-add-post-plus', 'Post +', 'Hide post and all replies');
* submenu.add_item('filter-add-id', 'ID');
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/post-menu.js';
*/
(function () {
var List = function (menuId, text) {
this.id = menuId;
this.text = text;
this.items = [];
this.add_item = function (itemId, text, title) {
this.items.push(new Item(itemId, text, title));
};
this.list_items = function () {
var array = [];
var i, length, obj, $ele;
if ($.isEmptyObject(this.items))
return;
length = this.items.length;
for (i = 0; i < length; i++) {
obj = this.items[i];
$ele = $('<li>', {id: obj.id}).text(obj.text);
if ('title' in obj) $ele.attr('title', obj.title);
if (obj instanceof Item) {
$ele.addClass('post-item');
} else {
$ele.addClass('post-submenu');
$ele.prepend(obj.list_items());
$ele.append($('<span>', {class: 'post-menu-arrow'}).text('»'));
}
array.push($ele);
}
return $('<ul>').append(array);
};
this.add_submenu = function (menuId, text) {
var ele = new List(menuId, text);
this.items.push(ele);
return ele;
};
this.get_submenu = function (menuId) {
for (var i = 0; i < this.items.length; i++) {
if ((this.items[i] instanceof Item) || this.items[i].id != menuId) continue;
return this.items[i];
}
};
};
var Item = function (itemId, text, title) {
this.id = itemId;
this.text = text;
// optional
if (typeof title != 'undefined') this.title = title;
};
function buildMenu(e) {
var pos = $(e.target).offset();
var i, length;
var $menu = $('<div class="post-menu"></div>').append(mainMenu.list_items());
// execute registered click handlers
length = onclick_callbacks.length;
for (i = 0; i < length; i++) {
onclick_callbacks[i](e, $menu);
}
// set menu position and append to page
$menu.css({top: pos.top, left: pos.left + 20});
$('body').append($menu);
}
function addButton(post) {
var $ele = $(post);
$ele.find('input.delete').after(
$('<a>', {href: '#', class: 'post-btn', title: 'Post menu'}).text('▶')
);
}
/* * * * * * * * * *
Public methods
* * * * * * * * * */
var Menu = {};
var mainMenu = new List();
var onclick_callbacks = [];
Menu.onclick = function (fnc) {
onclick_callbacks.push(fnc);
};
Menu.add_item = function (itemId, text, title) {
mainMenu.add_item(itemId, text, title);
};
Menu.add_submenu = function (menuId, text) {
return mainMenu.add_submenu(menuId, text);
};
Menu.get_submenu = function (id) {
return mainMenu.get_submenu(id);
};
/* * * * * * * *
Initialize
* * * * * * * */
/* Styling
*/
var $ele, cssStyle, cssString;
$ele = $('<div>').addClass('post reply').hide().appendTo('body');
cssStyle = $ele.css(['border-top-color']);
cssStyle.hoverBg = $('body').css('background-color');
$ele.remove();
cssString =
'\n/*** Generated by post-menu ***/\n' +
'.post-menu {position: absolute; font-size: 12px; line-height: 1.3em;}\n' +
'.post-menu ul {\n' +
' background-color: '+ cssStyle['border-top-color'] +'; border: 1px solid #666;\n' +
' list-style: none; padding: 0; margin: 0; white-space: nowrap;\n}\n' +
'.post-menu .post-submenu{white-space: normal; width: 90px;}' +
'.post-menu .post-submenu>ul{white-space: nowrap; width: auto;}' +
'.post-menu li {cursor: pointer; position: relative; padding: 4px 4px; vertical-align: middle;}\n' +
'.post-menu li:hover {background-color: '+ cssStyle.hoverBg +';}\n' +
'.post-menu ul ul {display: none; position: absolute;}\n' +
'.post-menu li:hover>ul {display: block; left: 100%; margin-top: -3px;}\n' +
'.post-menu-arrow {float: right; margin-left: 10px;}\n' +
'.post-menu.hidden, .post-menu .hidden {display: none;}\n' +
'.post-btn {transition: transform 0.1s; width: 15px; text-align: center; font-size: 10pt; opacity: 0.8; text-decoration: none; margin: -6px 0px 0px -5px !important; display: inline-block;}\n' +
'.post-btn:hover {opacity: 1;}\n' +
'.post-btn-open {transform: rotate(90deg);}\n';
if (!$('style.generated-css').length) $('<style class="generated-css">').appendTo('head');
$('style.generated-css').html($('style.generated-css').html() + cssString);
/* Add buttons
*/
$('.reply:not(.hidden), .thread>.op').each(function () {
addButton(this);
});
/* event handlers
*/
$('form[name=postcontrols]').on('click', '.post-btn', function (e) {
e.preventDefault();
var post = e.target.parentElement.parentElement;
$('.post-menu').remove();
if ($(e.target).hasClass('post-btn-open')) {
$('.post-btn-open').removeClass('post-btn-open');
} else {
// close previous button
$('.post-btn-open').removeClass('post-btn-open');
$(post).find('.post-btn').addClass('post-btn-open');
buildMenu(e);
}
});
$(document).on('click', function (e){
if ($(e.target).hasClass('post-btn') || $(e.target).hasClass('post-submenu'))
return;
$('.post-menu').remove();
$('.post-btn-open').removeClass('post-btn-open');
});
// on new posts
$(document).on('new_post', function (e, post) {
addButton(post);
});
window.Menu = Menu;
})();

View File

@ -47,7 +47,7 @@
{% if post.youtube %}
<img src="https://img.youtube.com/vi/{{ post.youtube }}/0.jpg"
{% else %}
<img src="{{post.file}}"
<img src="{{post.file}}" data-fullimage="{{post.fullimage}}"
{% endif %}
id="img-{{ post.id }}" data-subject="{% if post.subject %}{{ post.subject|e }}{% endif %}" data-name="{{ post.name|e }}" data-muhdifference="{{ post.muhdifference }}" class="{{post.board}} thread-image" title="{{post.bump|date('%b %d %H:%M')}}">
</a>

View File

@ -66,6 +66,7 @@
}
else {
$post['file'] = $config['uri_thumb'] . $files[0]->thumb;
$post['fullimage'] = $config['uri_img'] . $files[0]->file;
}
}
} else {