mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-02-08 23:39:46 +01:00
thread-watcher.js: format
This commit is contained in:
parent
2ab6f371f7
commit
a3d1fe4884
@ -20,13 +20,17 @@ var watchlist = {};
|
|||||||
*/
|
*/
|
||||||
watchlist.render = function(reset) {
|
watchlist.render = function(reset) {
|
||||||
/* jshint eqnull:true */
|
/* jshint eqnull:true */
|
||||||
if (reset == null) reset = false;
|
if (reset == null) {
|
||||||
|
reset = false;
|
||||||
|
}
|
||||||
/* jshint eqnull:false */
|
/* jshint eqnull:false */
|
||||||
if (reset && $('#watchlist').length) $('#watchlist').remove();
|
if (reset && $('#watchlist').length) {
|
||||||
var threads = [];
|
$('#watchlist').remove();
|
||||||
|
}
|
||||||
|
let threads = [];
|
||||||
// Read the watchlist and create a new container for each thread.
|
// Read the watchlist and create a new container for each thread.
|
||||||
JSON.parse(localStorage.watchlist).forEach(function(e, i) {
|
JSON.parse(localStorage.watchlist).forEach(function(e, i) {
|
||||||
//look at line 69, that's what (e) is here.
|
// Look at line 69, that's what (e) is here.
|
||||||
threads.push('<div class="watchlist-inner" id="watchlist-'+i+'">' +
|
threads.push('<div class="watchlist-inner" id="watchlist-'+i+'">' +
|
||||||
'<span>/'+e[0]+'/ - ' +
|
'<span>/'+e[0]+'/ - ' +
|
||||||
'<a href="'+e[3]+'">'+e[1].replace("thread_", _("Thread #"))+'</a>' +
|
'<a href="'+e[3]+'">'+e[1].replace("thread_", _("Thread #"))+'</a>' +
|
||||||
@ -40,7 +44,7 @@ watchlist.render = function(reset) {
|
|||||||
$('#watchlist').append(threads.join(''));
|
$('#watchlist').append(threads.join(''));
|
||||||
} else {
|
} else {
|
||||||
// If the watchlist has not yet been rendered, create it.
|
// If the watchlist has not yet been rendered, create it.
|
||||||
var menuStyle = getComputedStyle($('.boardlist')[0]);
|
let menuStyle = getComputedStyle($('.boardlist')[0]);
|
||||||
$((active_page == 'ukko') ? 'hr:first' : (active_page == 'catalog') ? 'body>span:first' : 'form[name="post"]').before(
|
$((active_page == 'ukko') ? 'hr:first' : (active_page == 'catalog') ? 'body>span:first' : 'form[name="post"]').before(
|
||||||
$('<div id="watchlist">'+
|
$('<div id="watchlist">'+
|
||||||
'<div class="watchlist-controls">'+
|
'<div class="watchlist-controls">'+
|
||||||
@ -48,7 +52,8 @@ watchlist.render = function(reset) {
|
|||||||
'<span><a id="clearGhosts">['+_('Clear Ghosts')+']</a></span>'+
|
'<span><a id="clearGhosts">['+_('Clear Ghosts')+']</a></span>'+
|
||||||
'</div>'+
|
'</div>'+
|
||||||
threads.join('')+
|
threads.join('')+
|
||||||
'</div>').css("background-color", menuStyle.backgroundColor).css("border", menuStyle.borderBottomWidth+" "+menuStyle.borderBottomStyle+" "+menuStyle.borderBottomColor));
|
'</div>').css("background-color", menuStyle.backgroundColor).css("border", menuStyle.borderBottomWidth+" "+menuStyle.borderBottomStyle+" "+menuStyle.borderBottomColor)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -58,9 +63,10 @@ watchlist.render = function(reset) {
|
|||||||
* @param {[Obj/Str]} sel [An unwrapped jquery selector.]
|
* @param {[Obj/Str]} sel [An unwrapped jquery selector.]
|
||||||
*/
|
*/
|
||||||
watchlist.add = function(sel) {
|
watchlist.add = function(sel) {
|
||||||
var threadName, threadInfo;
|
let threadName;
|
||||||
|
let threadInfo;
|
||||||
|
|
||||||
var board_name = $(sel).parents('.thread').data('board');
|
let board_name = $(sel).parents('.thread').data('board');
|
||||||
|
|
||||||
if (active_page === 'thread') {
|
if (active_page === 'thread') {
|
||||||
if ($('.subject').length) {
|
if ($('.subject').length) {
|
||||||
@ -69,12 +75,10 @@ watchlist.add = function(sel) {
|
|||||||
} else { //Otherwise use the thread id.
|
} else { //Otherwise use the thread id.
|
||||||
threadName = $('.op').parent().attr('id');
|
threadName = $('.op').parent().attr('id');
|
||||||
}
|
}
|
||||||
//board name, thread name as defined above, current amount of posts, thread url
|
// Board name, thread name as defined above, current amount of posts, thread url
|
||||||
threadInfo = [board_name, threadName, $('.post').length, location.href];
|
threadInfo = [board_name, threadName, $('.post').length, location.href];
|
||||||
|
|
||||||
} else if (active_page === 'index' || active_page === 'ukko') {
|
} else if (active_page === 'index' || active_page === 'ukko') {
|
||||||
|
let postCount;
|
||||||
var postCount;
|
|
||||||
// Figure out the post count.
|
// Figure out the post count.
|
||||||
if ($(sel).parents('.op').children('.omitted').length) {
|
if ($(sel).parents('.op').children('.omitted').length) {
|
||||||
postCount = $(sel).parents('.op').children('.omitted').text().split(' ')[0];
|
postCount = $(sel).parents('.op').children('.omitted').text().split(' ')[0];
|
||||||
@ -82,7 +86,7 @@ watchlist.add = function(sel) {
|
|||||||
postCount = $(sel).parents('.op').siblings('.post').length+1;
|
postCount = $(sel).parents('.op').siblings('.post').length+1;
|
||||||
}
|
}
|
||||||
// Grab the reply link.;
|
// Grab the reply link.;
|
||||||
var threadLink = $(sel).siblings('a:not(.watchThread)').last().attr('href');
|
let threadLink = $(sel).siblings('a:not(.watchThread)').last().attr('href');
|
||||||
// Figure out the thread name. If anon, use the thread id.
|
// Figure out the thread name. If anon, use the thread id.
|
||||||
if ($(sel).parent().find('.subject').length) {
|
if ($(sel).parent().find('.subject').length) {
|
||||||
threadName = $(sel).parent().find('.subject').text().substring(0,20);
|
threadName = $(sel).parent().find('.subject').text().substring(0,20);
|
||||||
@ -91,7 +95,6 @@ watchlist.add = function(sel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
threadInfo = [board_name, threadName, postCount, threadLink];
|
threadInfo = [board_name, threadName, postCount, threadLink];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
alert('Functionality not yet implemented for this type of page.');
|
alert('Functionality not yet implemented for this type of page.');
|
||||||
return this;
|
return this;
|
||||||
@ -102,7 +105,7 @@ watchlist.add = function(sel) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _watchlist = JSON.parse(localStorage.watchlist); //Read the watchlist
|
let _watchlist = JSON.parse(localStorage.watchlist); //Read the watchlist
|
||||||
_watchlist.push(threadInfo); //Add the new watch item.
|
_watchlist.push(threadInfo); //Add the new watch item.
|
||||||
localStorage.watchlist = JSON.stringify(_watchlist); //Save the watchlist.
|
localStorage.watchlist = JSON.stringify(_watchlist); //Save the watchlist.
|
||||||
return this;
|
return this;
|
||||||
@ -113,7 +116,7 @@ watchlist.add = function(sel) {
|
|||||||
* @param {[Int]} n [The index at which to remove.]
|
* @param {[Int]} n [The index at which to remove.]
|
||||||
*/
|
*/
|
||||||
watchlist.remove = function(n) {
|
watchlist.remove = function(n) {
|
||||||
var _watchlist = JSON.parse(localStorage.watchlist);
|
let _watchlist = JSON.parse(localStorage.watchlist);
|
||||||
_watchlist.splice(n, 1);
|
_watchlist.splice(n, 1);
|
||||||
localStorage.watchlist = JSON.stringify(_watchlist);
|
localStorage.watchlist = JSON.stringify(_watchlist);
|
||||||
return this;
|
return this;
|
||||||
@ -181,7 +184,7 @@ $(document).ready(function(){
|
|||||||
// $('.watchlist-remove').on('click') won't work in case of re-renders and
|
// $('.watchlist-remove').on('click') won't work in case of re-renders and
|
||||||
// the page will need refreshing. This works around that.
|
// the page will need refreshing. This works around that.
|
||||||
$(document).on('click', '.watchlist-remove', function() {
|
$(document).on('click', '.watchlist-remove', function() {
|
||||||
var item = parseInt($(this).parent().attr('id').split('-')[1]);
|
let item = parseInt($(this).parent().attr('id').split('-')[1]);
|
||||||
watchlist.remove(item).render();
|
watchlist.remove(item).render();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -196,6 +199,4 @@ $(document).ready(function(){
|
|||||||
watchlist.exists(this);
|
watchlist.exists(this);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user