Browse Source

main.js: trim

fix-hud-dash
Zankaria 1 month ago
parent
commit
8fcad42ba2
  1. 45
      templates/main.js

45
templates/main.js

@ -45,7 +45,7 @@ function ago($timestamp) {
switch(true){ switch(true){
case ($difference < 60) : case ($difference < 60) :
return "" + $difference + ' ' + _('second(s)'); return "" + $difference + ' ' + _('second(s)');
case ($difference < 3600): //60*60 = 3600 case ($difference < 3600): //60*60 = 3600
return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)');
case ($difference < 86400): //60*60*24 = 86400 case ($difference < 86400): //60*60*24 = 86400
return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)');
@ -136,7 +136,7 @@ function changeStyle(styleName, link) {
localStorage.stylesheet = styleName; localStorage.stylesheet = styleName;
{% endif %} {% endif %}
{% raw %} {% raw %}
// Main stylesheet // Main stylesheet
if (!document.getElementById('stylesheet')) { if (!document.getElementById('stylesheet')) {
var s = document.createElement('link'); var s = document.createElement('link');
@ -161,18 +161,18 @@ function changeStyle(styleName, link) {
} }
document.getElementById('code_stylesheet').href = codestyles[styleName]; document.getElementById('code_stylesheet').href = codestyles[styleName];
if (document.getElementsByClassName('styles').length != 0) { if (document.getElementsByClassName('styles').length != 0) {
var styleLinks = document.getElementsByClassName('styles')[0].childNodes; var styleLinks = document.getElementsByClassName('styles')[0].childNodes;
for (var i = 0; i < styleLinks.length; i++) { for (var i = 0; i < styleLinks.length; i++) {
styleLinks[i].className = ''; styleLinks[i].className = '';
} }
} }
if (link) { if (link) {
link.className = 'selected'; link.className = 'selected';
} }
if (typeof $ != 'undefined') if (typeof $ != 'undefined')
$(window).trigger('stylesheet', styleName); $(window).trigger('stylesheet', styleName);
} }
@ -181,11 +181,11 @@ function changeStyle(styleName, link) {
{% endraw %} {% endraw %}
{% if config.stylesheets_board %} {% if config.stylesheets_board %}
{% raw %} {% raw %}
if (!localStorage.board_stylesheets) { if (!localStorage.board_stylesheets) {
localStorage.board_stylesheets = '{}'; localStorage.board_stylesheets = '{}';
} }
var stylesheet_choices = JSON.parse(localStorage.board_stylesheets); var stylesheet_choices = JSON.parse(localStorage.board_stylesheets);
if (board_name && stylesheet_choices[board_name]) { if (board_name && stylesheet_choices[board_name]) {
for (var styleName in styles) { for (var styleName in styles) {
@ -213,7 +213,7 @@ function changeStyle(styleName, link) {
function init_stylechooser() { function init_stylechooser() {
var newElement = document.createElement('div'); var newElement = document.createElement('div');
newElement.className = 'styles'; newElement.className = 'styles';
for (styleName in styles) { for (styleName in styles) {
var style = document.createElement('a'); var style = document.createElement('a');
style.innerHTML = '[' + styleName + ']'; style.innerHTML = '[' + styleName + ']';
@ -225,8 +225,8 @@ function init_stylechooser() {
} }
style.href = 'javascript:void(0);'; style.href = 'javascript:void(0);';
newElement.appendChild(style); newElement.appendChild(style);
} }
document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling); document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling);
} }
@ -243,7 +243,7 @@ function highlightReply(id) {
// don't highlight on middle click // don't highlight on middle click
return true; return true;
} }
var divs = document.getElementsByTagName('div'); var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) for (var i = 0; i < divs.length; i++)
{ {
@ -279,10 +279,10 @@ function dopost(form) {
if (form.elements['email'] && form.elements['email'].value != 'sage') { if (form.elements['email'] && form.elements['email'].value != 'sage') {
localStorage.email = form.elements['email'].value; localStorage.email = form.elements['email'].value;
} }
saved[document.location] = form.elements['body'].value; saved[document.location] = form.elements['body'].value;
sessionStorage.body = JSON.stringify(saved); sessionStorage.body = JSON.stringify(saved);
return form.elements['body'].value != "" || (form.elements['file'] && form.elements['file'].value != "") || (form.elements.file_url && form.elements['file_url'].value != ""); return form.elements['body'].value != "" || (form.elements['file'] && form.elements['file'].value != "") || (form.elements.file_url && form.elements['file_url'].value != "");
} }
@ -301,7 +301,7 @@ function citeReply(id, with_link) {
var textarea = document.getElementById('body'); var textarea = document.getElementById('body');
if (!textarea) return false; if (!textarea) return false;
if (document.selection) { if (document.selection) {
// IE // IE
textarea.focus(); textarea.focus();
@ -311,7 +311,7 @@ function citeReply(id, with_link) {
var start = textarea.selectionStart; var start = textarea.selectionStart;
var end = textarea.selectionEnd; var end = textarea.selectionEnd;
textarea.value = textarea.value.substring(0, start) + '>>' + id + '\n' + textarea.value.substring(end, textarea.value.length); textarea.value = textarea.value.substring(0, start) + '>>' + id + '\n' + textarea.value.substring(end, textarea.value.length);
textarea.selectionStart += ('>>' + id).length + 1; textarea.selectionStart += ('>>' + id).length + 1;
textarea.selectionEnd = textarea.selectionStart; textarea.selectionEnd = textarea.selectionStart;
} else { } else {
@ -344,15 +344,15 @@ function rememberStuff() {
localStorage.password = generatePassword(); localStorage.password = generatePassword();
document.forms.post.password.value = localStorage.password; document.forms.post.password.value = localStorage.password;
} }
if (localStorage.name && document.forms.post.elements['name']) if (localStorage.name && document.forms.post.elements['name'])
document.forms.post.elements['name'].value = localStorage.name; document.forms.post.elements['name'].value = localStorage.name;
if (localStorage.email && document.forms.post.elements['email']) if (localStorage.email && document.forms.post.elements['email'])
document.forms.post.elements['email'].value = localStorage.email; document.forms.post.elements['email'].value = localStorage.email;
if (window.location.hash.indexOf('q') == 1) if (window.location.hash.indexOf('q') == 1)
citeReply(window.location.hash.substring(2), true); citeReply(window.location.hash.substring(2), true);
if (sessionStorage.body) { if (sessionStorage.body) {
var saved = JSON.parse(sessionStorage.body); var saved = JSON.parse(sessionStorage.body);
if (get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) { if (get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) {
@ -362,14 +362,14 @@ function rememberStuff() {
saved[url] = null; saved[url] = null;
} }
sessionStorage.body = JSON.stringify(saved); sessionStorage.body = JSON.stringify(saved);
document.cookie = '{% endraw %}{{ config.cookies.js }}{% raw %}={};expires=0;path=/;'; document.cookie = '{% endraw %}{{ config.cookies.js }}{% raw %}={};expires=0;path=/;';
} }
if (saved[document.location]) { if (saved[document.location]) {
document.forms.post.body.value = saved[document.location]; document.forms.post.body.value = saved[document.location];
} }
} }
if (localStorage.body) { if (localStorage.body) {
document.forms.post.body.value = localStorage.body; document.forms.post.body.value = localStorage.body;
localStorage.body = ''; localStorage.body = '';
@ -391,14 +391,14 @@ var script_settings = function(script_name) {
function init() { function init() {
init_stylechooser(); init_stylechooser();
{% endraw %} {% endraw %}
{% if config.allow_delete %} {% if config.allow_delete %}
if (document.forms.postcontrols) { if (document.forms.postcontrols) {
document.forms.postcontrols.password.value = localStorage.password; document.forms.postcontrols.password.value = localStorage.password;
} }
{% endif %} {% endif %}
{% raw %} {% raw %}
if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1)) if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1))
highlightReply(window.location.hash.substring(1)); highlightReply(window.location.hash.substring(1));
} }
@ -436,4 +436,3 @@ sc.innerHTML = 'var sc_project={{ config.statcounter_project }};var sc_invisible
var s = document.getElementsByTagName('script')[0]; var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(sc, s); s.parentNode.insertBefore(sc, s);
{% endif %} {% endif %}

Loading…
Cancel
Save