mirror of
https://github.com/Circlepuller/Tinyboard.git
synced 2025-01-17 13:28:31 +01:00
Updating JavaScript code and removing crud
This commit is contained in:
parent
3fcbb137f9
commit
5c66436c0c
@ -21,73 +21,74 @@
|
||||
* //$config['additional_javascript'][] = 'js/watch.js';
|
||||
*
|
||||
*/
|
||||
var compact_boardlist;
|
||||
|
||||
if (device_type == 'desktop') {
|
||||
compact_boardlist = true;
|
||||
onready(() => {
|
||||
if (device_type == 'desktop') {
|
||||
compact_boardlist = true;
|
||||
|
||||
do_boardlist = function() {
|
||||
var categories = [];
|
||||
var topbl = $('.boardlist:first');
|
||||
do_boardlist = function() {
|
||||
let categories = [];
|
||||
let topbl = $('.boardlist:first');
|
||||
|
||||
topbl.find('>.sub').each(function() {
|
||||
var cat = {name: $(this).data('description'), boards: []};
|
||||
$(this).find('a').each(function() {
|
||||
var board = {name: $(this).prop('title'), uri: $(this).html(), href: $(this).prop('href') }
|
||||
cat.boards.push(board);
|
||||
topbl.find('>.sub').each(function() {
|
||||
var cat = {name: $(this).data('description'), boards: []};
|
||||
$(this).find('a').each(function() {
|
||||
var board = {name: $(this).prop('title'), uri: $(this).html(), href: $(this).prop('href') }
|
||||
cat.boards.push(board);
|
||||
});
|
||||
categories.push(cat);
|
||||
});
|
||||
categories.push(cat);
|
||||
});
|
||||
|
||||
topbl.addClass("compact-boardlist")
|
||||
.html("");
|
||||
topbl.addClass("compact-boardlist")
|
||||
.html("");
|
||||
|
||||
for (var i in categories) {
|
||||
var item = categories[i];
|
||||
for (let i in categories) {
|
||||
let item = categories[i];
|
||||
|
||||
if (item.name.match(/^icon_/)) {
|
||||
var icon = item.name.replace(/^icon_/, '')
|
||||
$("<a class='cb-item cb-icon' href='"+categories[i].boards[0].href+"'><img src='/static/icons/"+icon+".png'></a>")
|
||||
.appendTo(topbl)
|
||||
if (item.name.match(/^icon_/)) {
|
||||
let icon = item.name.replace(/^icon_/, '')
|
||||
$("<a class='cb-item cb-icon' href='"+categories[i].boards[0].href+"'><img src='/static/icons/"+icon+".png'></a>")
|
||||
.appendTo(topbl)
|
||||
}
|
||||
else if (item.name.match(/^fa_/)) {
|
||||
let icon = item.name.replace(/^fa_/, '')
|
||||
$('<a class="cb-item cb-fa" href="'+categories[i].boards[0].href+'"><i class="fa-'+icon+' fa"></i></a>')
|
||||
.appendTo(topbl)
|
||||
}
|
||||
else if (item.name.match(/^d_/)) {
|
||||
let icon = item.name.replace(/^d_/, '')
|
||||
$('<a class="cb-item cb-cat" href="'+categories[i].boards[0].href+'">'+icon+'</a>')
|
||||
.appendTo(topbl)
|
||||
}
|
||||
else {
|
||||
$("<a class='cb-item cb-cat' href='javascript:void(0)'>"+item.name+"</a>")
|
||||
.appendTo(topbl)
|
||||
.mouseenter(function() {
|
||||
let list = $("<div class='boardlist top cb-menu'></div>")
|
||||
.css("top", $(this).position().top + 13 + $(this).height())
|
||||
.css("left", $(this).position().left)
|
||||
.css("right", "auto")
|
||||
.appendTo(this);
|
||||
|
||||
for (let j in this.item.boards) {
|
||||
let board = this.item.boards[j];
|
||||
let tag;
|
||||
|
||||
if (board.name)
|
||||
tag = $("<a href='"+board.href+"'><span>"+board.name+"</span><span class='cb-uri'>/"+board.uri+"/</span></a>");
|
||||
else
|
||||
tag = $("<a href='"+board.href+"'><span>"+board.uri+"</span><span class='cb-uri'><i class='fa fa-globe'></i></span></a>");
|
||||
|
||||
tag.addClass("cb-menuitem").appendTo(list)
|
||||
}
|
||||
})
|
||||
.mouseleave(function() {
|
||||
topbl.find(".cb-menu").remove();
|
||||
})[0].item = item;
|
||||
}
|
||||
}
|
||||
else if (item.name.match(/^fa_/)) {
|
||||
var icon = item.name.replace(/^fa_/, '')
|
||||
$('<a class="cb-item cb-fa" href="'+categories[i].boards[0].href+'"><i class="fa-'+icon+' fa"></i></a>')
|
||||
.appendTo(topbl)
|
||||
}
|
||||
else if (item.name.match(/^d_/)) {
|
||||
var icon = item.name.replace(/^d_/, '')
|
||||
$('<a class="cb-item cb-cat" href="'+categories[i].boards[0].href+'">'+icon+'</a>')
|
||||
.appendTo(topbl)
|
||||
}
|
||||
else {
|
||||
$("<a class='cb-item cb-cat' href='javascript:void(0)'>"+item.name+"</a>")
|
||||
.appendTo(topbl)
|
||||
.mouseenter(function() {
|
||||
var list = $("<div class='boardlist top cb-menu'></div>")
|
||||
.css("top", $(this).position().top + 13 + $(this).height())
|
||||
.css("left", $(this).position().left)
|
||||
.css("right", "auto")
|
||||
.appendTo(this);
|
||||
for (var j in this.item.boards) {
|
||||
var board = this.item.boards[j];
|
||||
|
||||
var tag;
|
||||
if (board.name) {
|
||||
tag = $("<a href='"+board.href+"'><span>"+board.name+"</span><span class='cb-uri'>/"+board.uri+"/</span></a>")
|
||||
}
|
||||
else {
|
||||
tag = $("<a href='"+board.href+"'><span>"+board.uri+"</span><span class='cb-uri'><i class='fa fa-globe'></i></span></a>")
|
||||
}
|
||||
tag
|
||||
.addClass("cb-menuitem")
|
||||
.appendTo(list)
|
||||
}
|
||||
})
|
||||
.mouseleave(function() {
|
||||
topbl.find(".cb-menu").remove();
|
||||
})[0].item = item;
|
||||
}
|
||||
}
|
||||
do_boardlist = undefined;
|
||||
};
|
||||
}
|
||||
do_boardlist = undefined;
|
||||
};
|
||||
}
|
||||
});
|
@ -6,16 +6,16 @@
|
||||
* Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
*
|
||||
* Usage:
|
||||
* $config['api']['enabled'] = true;
|
||||
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||
* $config['additional_javascript'][] = 'js/mobile-style.js';
|
||||
*/
|
||||
var device_type;
|
||||
|
||||
if(navigator.userAgent.match(/iPhone|iPod|iPad|Android|Opera Mini|Blackberry|PlayBook|Windows Phone|Tablet PC|Windows CE|IEMobile/i)) {
|
||||
$('html').addClass("mobile-style");
|
||||
device_type = "mobile";
|
||||
}
|
||||
else {
|
||||
$('html').addClass("desktop-style");
|
||||
device_type = "desktop";
|
||||
}
|
||||
onready(() => {
|
||||
if(navigator.userAgent.match(/iPhone|iPod|iPad|Android|Opera Mini|Blackberry|PlayBook|Windows Phone|Tablet PC|Windows CE|IEMobile/i)) {
|
||||
document.querySelector('html').classList.add('mobile-style');
|
||||
device_type = 'mobile';
|
||||
} else {
|
||||
document.querySelector('html').classList.add('desktop-style');
|
||||
device_type = 'desktop';
|
||||
}
|
||||
});
|
||||
|
143
js/watch.js
143
js/watch.js
@ -17,21 +17,19 @@
|
||||
*
|
||||
*/
|
||||
|
||||
$(function(){
|
||||
onready(() => {
|
||||
// migrate from old name
|
||||
if (typeof localStorage.watch == "string") {
|
||||
if (typeof localStorage.watch == 'string') {
|
||||
localStorage.watch_js = localStorage.watch;
|
||||
delete localStorage.watch;
|
||||
}
|
||||
|
||||
var window_active = true;
|
||||
$(window).focus(function() {
|
||||
let window_active = true;
|
||||
$(window).focus(() => {
|
||||
window_active = true;
|
||||
$(window).trigger('scroll');
|
||||
});
|
||||
$(window).blur(function() {
|
||||
window_active = false;
|
||||
});
|
||||
$(window).blur(() => window_active = false);
|
||||
|
||||
var status = {};
|
||||
|
||||
@ -67,14 +65,13 @@ $(function(){
|
||||
return boardconfig && boardconfig.threads && boardconfig.threads[thread];
|
||||
};
|
||||
var toggle_pinned = function(board) {
|
||||
var st = storage();
|
||||
var bc = st[board] || {};
|
||||
let st = storage();
|
||||
let bc = st[board] || {};
|
||||
if (is_pinned(bc)) {
|
||||
bc.pinned = false;
|
||||
bc.watched = false;
|
||||
bc.threads = {};
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bc.pinned = true;
|
||||
}
|
||||
st[board] = bc;
|
||||
@ -82,20 +79,19 @@ $(function(){
|
||||
return bc.pinned;
|
||||
};
|
||||
var toggle_boardwatched = function(board) {
|
||||
var st = storage();
|
||||
var bc = st[board] || {};
|
||||
let st = storage();
|
||||
let bc = st[board] || {};
|
||||
bc.watched = !is_boardwatched(bc) && Date.now();
|
||||
st[board] = bc;
|
||||
storage_save(st);
|
||||
return bc.watched;
|
||||
};
|
||||
var toggle_threadwatched = function(board, thread) {
|
||||
var st = storage();
|
||||
var bc = st[board] || {};
|
||||
let st = storage();
|
||||
let bc = st[board] || {};
|
||||
if (is_threadwatched(bc, thread)) {
|
||||
delete bc.threads[thread];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bc.threads = bc.threads || {};
|
||||
bc.threads[thread] = Date.now();
|
||||
|
||||
@ -106,52 +102,53 @@ $(function(){
|
||||
storage_save(st);
|
||||
return is_threadwatched(bc, thread);
|
||||
};
|
||||
var construct_watchlist_for = function(board, variant) {
|
||||
var list = $("<div class='boardlist top cb-menu watch-menu'></div>");
|
||||
var construct_watchlist_for = (board, variant) => {
|
||||
let list = $("<div class='boardlist top cb-menu watch-menu'></div>");
|
||||
list.attr("data-board", board);
|
||||
|
||||
if (storage()[board] && storage()[board].threads)
|
||||
for (var tid in storage()[board].threads) {
|
||||
var newposts = "(0)";
|
||||
if (status && status[board] && status[board].threads && status[board].threads[tid]) {
|
||||
if (status[board].threads[tid] == -404) {
|
||||
newposts = "<i class='fa fa-ban-circle'></i>";
|
||||
}
|
||||
else {
|
||||
newposts = "("+status[board].threads[tid]+")";
|
||||
}
|
||||
}
|
||||
if (storage()[board] && storage()[board].threads) {
|
||||
for (let tid in storage()[board].threads) {
|
||||
let newposts = "(0)";
|
||||
|
||||
var tag;
|
||||
if (variant == 'desktop') {
|
||||
tag = $("<a href='"+((storage()[board].slugs && storage()[board].slugs[tid]) || (modRoot+board+"/res/"+tid+".html"))+"'><span>#"+tid+"</span><span class='cb-uri watch-remove'>"+newposts+"</span>");
|
||||
tag.find(".watch-remove").mouseenter(function() {
|
||||
this.oldval = $(this).html();
|
||||
$(this).css("min-width", $(this).width());
|
||||
$(this).html("<i class='fa fa-minus'></i>");
|
||||
})
|
||||
.mouseleave(function() {
|
||||
$(this).html(this.oldval);
|
||||
})
|
||||
}
|
||||
else if (variant == 'mobile') {
|
||||
tag = $("<a href='"+((storage()[board].slugs && storage()[board].slugs[tid]) || (modRoot+board+"/res/"+tid+".html"))+"'><span>#"+tid+"</span><span class='cb-uri'>"+newposts+"</span>"
|
||||
+"<span class='cb-uri watch-remove'><i class='fa fa-minus'></i></span>");
|
||||
}
|
||||
if (status && status[board] && status[board].threads && status[board].threads[tid]) {
|
||||
if (status[board].threads[tid] == -404) {
|
||||
newposts = "<i class='fa fa-ban-circle'></i>";
|
||||
} else {
|
||||
newposts = "("+status[board].threads[tid]+")";
|
||||
}
|
||||
}
|
||||
|
||||
tag.attr('data-thread', tid)
|
||||
.addClass("cb-menuitem")
|
||||
.appendTo(list)
|
||||
.find(".watch-remove")
|
||||
.click(function() {
|
||||
var b = $(this).parent().parent().attr("data-board");
|
||||
var t = $(this).parent().attr("data-thread");
|
||||
toggle_threadwatched(b, t);
|
||||
$(this).parent().parent().parent().mouseleave();
|
||||
$(this).parent().remove();
|
||||
return false;
|
||||
});
|
||||
let tag;
|
||||
if (variant == 'desktop') {
|
||||
tag = $("<a href='"+((storage()[board].slugs && storage()[board].slugs[tid]) || (modRoot+board+"/res/"+tid+".html"))+"'><span>#"+tid+"</span><span class='cb-uri watch-remove'>"+newposts+"</span>");
|
||||
tag.find(".watch-remove").mouseenter(() => {
|
||||
this.oldval = $(this).html();
|
||||
$(this).css("min-width", $(this).width());
|
||||
$(this).html("<i class='fa fa-minus'></i>");
|
||||
})
|
||||
.mouseleave(() => {
|
||||
$(this).html(this.oldval);
|
||||
})
|
||||
} else if (variant == 'mobile') {
|
||||
tag = $("<a href='"+((storage()[board].slugs && storage()[board].slugs[tid]) || (modRoot+board+"/res/"+tid+".html"))+"'><span>#"+tid+"</span><span class='cb-uri'>"+newposts+"</span>"
|
||||
+"<span class='cb-uri watch-remove'><i class='fa fa-minus'></i></span>");
|
||||
}
|
||||
|
||||
tag.attr('data-thread', tid)
|
||||
.addClass("cb-menuitem")
|
||||
.appendTo(list)
|
||||
.find(".watch-remove")
|
||||
.click(() => {
|
||||
let b = $(this).parent().parent().attr("data-board");
|
||||
let t = $(this).parent().attr("data-thread");
|
||||
toggle_threadwatched(b, t);
|
||||
$(this).parent().parent().parent().mouseleave();
|
||||
$(this).parent().remove();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
};
|
||||
|
||||
@ -165,26 +162,26 @@ $(function(){
|
||||
var pinned = $('<div id="watch-pinned"></div>').appendTo(bl);
|
||||
|
||||
if (device_type == "desktop")
|
||||
bl.off().on("mouseenter", function() {
|
||||
updating_suspended = true;
|
||||
}).on("mouseleave", function() {
|
||||
updating_suspended = false;
|
||||
});
|
||||
bl.off().on("mouseenter", function() {
|
||||
updating_suspended = true;
|
||||
}).on("mouseleave", function() {
|
||||
updating_suspended = false;
|
||||
});
|
||||
|
||||
var st = storage();
|
||||
for (var i in st) {
|
||||
if (is_pinned(st[i])) {
|
||||
var link;
|
||||
if (bl.find('[href*="'+modRoot+i+'/index.html"]:not(.cb-menuitem)').length) link = bl.find('[href*="'+modRoot+i+'/"]').first();
|
||||
let link;
|
||||
|
||||
if (bl.find('[href*="'+modRoot+i+'/index.html"]:not(.cb-menuitem)').length)
|
||||
link = bl.find('[href*="'+modRoot+i+'/"]').first();
|
||||
else
|
||||
link = $('<a href="'+modRoot+i+'/" class="cb-item cb-cat">/'+i+'/</a>').appendTo(pinned);
|
||||
|
||||
else link = $('<a href="'+modRoot+i+'/" class="cb-item cb-cat">/'+i+'/</a>').appendTo(pinned);
|
||||
|
||||
if (link[0].origtitle === undefined) {
|
||||
link[0].origtitle = link.html();
|
||||
}
|
||||
else {
|
||||
link.html(link[0].origtitle);
|
||||
}
|
||||
if (link[0].origtitle === undefined)
|
||||
link[0].origtitle = link.html();
|
||||
else
|
||||
link.html(link[0].origtitle);
|
||||
|
||||
if (st[i].watched) {
|
||||
link.css("font-weight", "bold");
|
||||
|
@ -6,7 +6,7 @@
|
||||
<title>{{ board.url }} - {{ board.name }}</title>
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
{% include "boardlist.html" %}
|
||||
{% if pm %}<div class="top_notice">You have <a href="?/PM/{{ pm.id }}">an unread PM</a>{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.</div><hr />{% endif %}
|
||||
{% if config.url_banner %}<img class="banner" src="{{ config.url_banner }}" {% if config.banner_width or config.banner_height %}style="{% if config.banner_width %}width:{{ config.banner_width }}px{% endif %};{% if config.banner_width %}height:{{ config.banner_height }}px{% endif %}" {% endif %}alt="" />{% endif %}
|
||||
|
@ -16,7 +16,7 @@
|
||||
{% include 'header.html' %}
|
||||
<title>{{ board.url }} - {{ board.title|e }}</title>
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %} active-{% if not no_post_form %}index{% else %}ukko{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %} active-{% if not no_post_form %}index{% else %}ukko{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
{% include "boardlist.html" %}
|
||||
|
||||
{% if pm %}<div class="top_notice">You have <a href="?/PM/{{ pm.id }}">an unread PM</a>{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.</div><hr />{% endif %}
|
||||
|
@ -8,7 +8,7 @@
|
||||
{% include 'header.html' %}
|
||||
<title>{{ title }}</title>
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %} active-page" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %} active-page" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
{% include "boardlist.html" %}
|
||||
|
||||
{% if pm %}<div class="top_notice">You have <a href="?/PM/{{ pm.id }}">an unread PM</a>{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.</div><hr>{% endif %}
|
||||
|
@ -13,7 +13,7 @@
|
||||
{% if config.font_awesome %}<link rel="stylesheet" href="{{ config.root }}{{ config.font_awesome_css }}">{% endif %}
|
||||
{% include 'header.html' %}
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<header>
|
||||
<h1>
|
||||
<img class="banner logo" src="/static/logo/logo.png" alt="{{ settings.title }}">
|
||||
|
@ -11,7 +11,7 @@
|
||||
{% if config.default_stylesheet.1 != '' %}<link rel="stylesheet" type="text/css" id="stylesheet" href="{{ config.uri_stylesheets }}{{ config.default_stylesheet.1 }}">{% endif %}
|
||||
{% if config.font_awesome %}<link rel="stylesheet" href="{{ config.root }}{{ config.font_awesome_css }}">{% endif %}
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %}" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
{% include "boardlist.html" %}
|
||||
<header>
|
||||
<h1>{{ settings.title }}</h1>
|
||||
|
@ -10,7 +10,7 @@
|
||||
{% include 'header.html' %}
|
||||
<title>{{ board }} - Catalog</title>
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %} theme-catalog active-catalog" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %} theme-catalog active-catalog" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
{% include "boardlist.html" %}
|
||||
<header>
|
||||
<h1>{{ settings.title }} (<a href="{{link}}">/{{ board }}/</a>)</h1>
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
<title>{{ board.url }} - {{ meta_subject }}</title>
|
||||
</head>
|
||||
<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %} active-thread" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
<body class="{% if mod %}is-moderator{% else %}is-not-moderator{% endif %} active-thread" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
|
||||
{% include "boardlist.html" %}
|
||||
<a name="top"></a>
|
||||
{% if pm %}<div class="top_notice">You have <a href="?/PM/{{ pm.id }}">an unread PM</a>{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.</div><hr />{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user