diff --git a/public/js/kilo.js b/public/js/kilo.js index 7a66fa59..0a93ac50 100644 --- a/public/js/kilo.js +++ b/public/js/kilo.js @@ -208,7 +208,7 @@ var Kilo = function (params) { } } var langCat = langValue !== 'other' ? (langValue > 1 ? 'multiple' : langValue) : 'other' - document.getElementsByClassName('table-torrent-flag')[0].className = 'table-torrent-flag flag flag-' + flagCode(langCat) + document.getElementsByClassName('table-torrent-flag')[0].className = 'table-torrent-flag flag flag-' + Templates.FlagCode(langCat) document.getElementsByClassName('table-torrent-flag')[0].title = langTitle } } diff --git a/public/js/main.js b/public/js/main.js index 28a29357..17e5d4ae 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -4,103 +4,95 @@ // Switches between themes when a new one is selected function switchThemes(){ themeName = document.getElementById("theme-selector").value - var head = document.getElementsByTagName("head")[0]; + var head = document.getElementsByTagName("head")[0] // Remove the theme in place, it fails if one isn't set try{ - head.removeChild(document.getElementById("theme")); + head.removeChild(document.getElementById("theme")) } catch(err){} // Don't add a node if we don't want extra styling if(themeName === ""){ - return; + return } // Create the new one and put it back - var newTheme = document.createElement("link"); - newTheme.setAttribute("rel", "stylesheet"); - newTheme.setAttribute("href", "/css/"+ themeName + ".css"); - newTheme.setAttribute("id", "theme"); - head.appendChild(newTheme); + var newTheme = document.createElement("link") + newTheme.setAttribute("rel", "stylesheet") + newTheme.setAttribute("href", "/css/"+ themeName + ".css") + newTheme.setAttribute("id", "theme") + head.appendChild(newTheme) } // Used by spoiler tags function toggleLayer(elem) { if (elem.classList.contains("hide")) { - elem.classList.remove("hide"); + elem.classList.remove("hide") } else { - elem.classList.add("hide"); + elem.classList.add("hide") } } function parseAllDates() { // Date formatting - var lang = document.getElementsByTagName("html")[0].getAttribute("lang"); - var ymdOpt = { year: "numeric", month: "short", day: "numeric" }; - var hmOpt = { hour: "numeric", minute: "numeric" }; + var lang = document.getElementsByTagName("html")[0].getAttribute("lang") + var ymdOpt = { year: "numeric", month: "short", day: "numeric" } + var hmOpt = { hour: "numeric", minute: "numeric" } - var list = document.getElementsByClassName("date-short"); + var list = document.getElementsByClassName("date-short") for(var i in list) { - var e = list[i]; - e.title = e.innerText; - e.innerText = new Date(e.innerText).toLocaleString(lang, ymdOpt); + var e = list[i] + e.title = e.innerText + e.innerText = new Date(e.innerText).toLocaleString(lang, ymdOpt) } - var list = document.getElementsByClassName("date-full"); + var list = document.getElementsByClassName("date-full") for(var i in list) { - var e = list[i]; - e.title = e.innerText; - e.innerText = new Date(e.innerText).toLocaleString(lang); + var e = list[i] + e.title = e.innerText + e.innerText = new Date(e.innerText).toLocaleString(lang) } } -parseAllDates(); +parseAllDates() /*Fixed-Navbar offset fix*/ document.addEventListener("DOMContentLoaded", function(event) { - var shiftWindow = function() { scrollBy(0, -70) }; - if (location.hash) shiftWindow(); - window.addEventListener("hashchange", shiftWindow); + var shiftWindow = function() { scrollBy(0, -70) } + if (location.hash) shiftWindow() + window.addEventListener("hashchange", shiftWindow) document.getElementsByClassName("search-box")[0].addEventListener("focus", function (e) { - var w = document.getElementsByClassName("h-user")[0].offsetWidth; - document.getElementsByClassName("h-user")[0].style.display = "none"; - document.getElementsByClassName("search-box")[0].style.width = document.getElementsByClassName("search-box")[0].offsetWidth + w + "px"; - }); + var w = document.getElementsByClassName("h-user")[0].offsetWidth + document.getElementsByClassName("h-user")[0].style.display = "none" + document.getElementsByClassName("search-box")[0].style.width = document.getElementsByClassName("search-box")[0].offsetWidth + w + "px" + }) document.getElementsByClassName("search-box")[0].addEventListener("blur", function (e) { - document.getElementsByClassName("search-box")[0].style.width = ""; - document.getElementsByClassName("h-user")[0].style.display = "inline-block"; - }); + document.getElementsByClassName("search-box")[0].style.width = "" + document.getElementsByClassName("h-user")[0].style.display = "inline-block" + }) -}); +}) function playVoice() { - var mascotAudio = document.getElementById("explosion") || document.getElementById("nyanpassu")|| document.getElementById("nyanpassu2") || document.getElementById("kawaii"); + var mascotAudio = document.getElementById("explosion") || document.getElementById("nyanpassu")|| document.getElementById("nyanpassu2") || document.getElementById("kawaii") if (mascotAudio !== undefined) { - mascotAudio.volume = 0.2; - mascotAudio.play(); + mascotAudio.volume = 0.2 + mascotAudio.play() } else { console.log("Your mascot doesn't support yet audio files!") } } document.getElementsByClassName("form-input refine")[0].addEventListener("click", function (e) { - document.getElementsByClassName("box refine")[0].style.display = document.getElementsByClassName("box refine")[0].style.display == "none" ? "block" : "none"; + document.getElementsByClassName("box refine")[0].style.display = document.getElementsByClassName("box refine")[0].style.display == "none" ? "block" : "none" if(document.getElementsByClassName("form-input refine-searchbox")[0].value != document.getElementsByClassName("form-input search-box")[0].value) - document.getElementsByClassName("form-input refine-searchbox")[0].value = document.getElementsByClassName("form-input search-box")[0].value; + document.getElementsByClassName("form-input refine-searchbox")[0].value = document.getElementsByClassName("form-input search-box")[0].value if(document.getElementsByClassName("form-input refine-category")[0].selectedIndex != document.getElementsByClassName("form-input form-category")[0].selectedIndex) - document.getElementsByClassName("form-input refine-category")[0].selectedIndex = document.getElementsByClassName("form-input form-category")[0].selectedIndex; - e.preventDefault(); + document.getElementsByClassName("form-input refine-category")[0].selectedIndex = document.getElementsByClassName("form-input form-category")[0].selectedIndex + e.preventDefault() if(document.getElementsByClassName("box refine")[0].style.display == "block") - scrollTo(0, 0); -}); - function humanFileSize(bytes, si) { - var k = si ? 1000 : 1024; - var i = ~~(Math.log(bytes) / Math.log(k)); - return i == 0 ? bytes + " B" : (bytes / Math.pow(k, i)).toFixed(1) + " " + "KMGTPEZY"[i - 1] + (si ? "" : "i") + "B"; - } - - function flagCode(language) { - split = language.split("-"); - if (split.length > 1) { - return split[0]; - } - return language; - } + scrollTo(0, 0) +}) +function humanFileSize(bytes, si) { + var k = si ? 1000 : 1024 + var i = ~~(Math.log(bytes) / Math.log(k)) + return i == 0 ? bytes + " B" : (bytes / Math.pow(k, i)).toFixed(1) + " " + "KMGTPEZY"[i - 1] + (si ? "" : "i") + "B" +} // @license-end diff --git a/public/js/template.js b/public/js/template.js index fbb4083e..b3838478 100644 --- a/public/js/template.js +++ b/public/js/template.js @@ -38,6 +38,13 @@ var Templates = { }). replace(//g, '>'); + }, + FlagCode: function(language) { + var split = language.split("-") + if (split.length > 1) { + return split[1] + } + return language } }; // @license-end diff --git a/templates/layouts/partials/torrent_item.jet.html b/templates/layouts/partials/torrent_item.jet.html index c7929070..b0e95b0c 100644 --- a/templates/layouts/partials/torrent_item.jet.html +++ b/templates/layouts/partials/torrent_item.jet.html @@ -21,7 +21,7 @@ Templates.Add("torrents.item", function(torrent) { "
"+ {{end}} ""+ - ((torrent.languages[0] != "") ? "\""+torrent.languages.map(function" : "") + + ((torrent.languages[0] != "") ? "\""+torrent.languages.map(function" : "") + ""+ "
"+ ""+Templates.EncodeEntities(torrent.name) +""+ diff --git a/templates/layouts/partials/torrent_item_upload.jet.html b/templates/layouts/partials/torrent_item_upload.jet.html index aa3d90fe..587ad71b 100644 --- a/templates/layouts/partials/torrent_item_upload.jet.html +++ b/templates/layouts/partials/torrent_item_upload.jet.html @@ -16,7 +16,7 @@ Templates.Add("torrents.item", function(torrent) { "
"+ {{end}} ""+ - ((torrent.languages[0] != "") ? "" : "") + + ((torrent.languages[0] != "") ? "" : "") + ""+ "
"+ ""+Templates.EncodeEntities(torrent.name) +""+