From 268b44ba638fe491912c41fc549589d7e4eee8c8 Mon Sep 17 00:00:00 2001 From: Matt Lee Date: Fri, 5 Jun 2015 10:41:01 -0700 Subject: [PATCH] Cleanup: Remove unused javascript. A pass at cleaning up some frontend code by removing unused functions. All of these functions are either 1. not referenced anywhere or 2. referenced somewhere, but don't actually _do_ anything. In the latter case, the reference is removed as well. The list of functions removed: - hover_open_menu - update_user - emptyInput - clear_all_langs - check_some_langs - show_unfriend - pure_domain - parse_domain - save_usertext - save_thing - unsave_thing - $.fn.same_author - tool_cover - fire_success - check_name - too_big Additionally, the 'success_field' template in utils.html is removed, as it is imported several places but never rendered (and was the only place the fire_success function was being called). --- r2/r2/public/static/js/compact.js | 22 ------- r2/r2/public/static/js/jquery.reddit.js | 9 --- r2/r2/public/static/js/reddit.js | 73 ------------------------ r2/r2/templates/navmenu.html | 3 +- r2/r2/templates/password.html | 2 +- r2/r2/templates/resetpassword.html | 2 +- r2/r2/templates/subredditstylesheet.html | 24 -------- r2/r2/templates/thanks.html | 2 +- r2/r2/templates/utils.html | 16 ------ 9 files changed, 4 insertions(+), 149 deletions(-) diff --git a/r2/r2/public/static/js/compact.js b/r2/r2/public/static/js/compact.js index 034a3be5f..1b4280c27 100644 --- a/r2/r2/public/static/js/compact.js +++ b/r2/r2/public/static/js/compact.js @@ -1,27 +1,5 @@ /*This hides the url bar on mobile*/ (function($) { - /* - Creates an element on the body that works to create a modal box - The callback function runs when the cover is clicked - Use it, for example, to hide your modal box. - - It is kind of tricky to use on mobile platforms, subject to many odd bugs, likely caused by the way mobile platforms handle z-index - */ - function tool_cover(callback) { - var toolcover = $("#toolcover"); - if (toolcover.length == 0) { - $("body").prepend("
"); - toolcover = $("#toolcover"); - } - toolcover.css("height", $(document).height()) - .show().one("click", function() { - $(this).hide(); - if (callback) callback(); - return false; - }); - } - - ; $.fn.show_toolbar = function() { var tb = this; $(this).show(); diff --git a/r2/r2/public/static/js/jquery.reddit.js b/r2/r2/public/static/js/jquery.reddit.js index 15af7d812..43c3347d8 100644 --- a/r2/r2/public/static/js/jquery.reddit.js +++ b/r2/r2/public/static/js/jquery.reddit.js @@ -350,15 +350,6 @@ $.things = function() { return $(sel); }; -$.fn.same_author = function() { - var aid = $(this).thing_id("author"); - var ids = []; - $(".author.id-" + aid).each(function() { - ids.push(".thing.id-" + $(this).thing_id()); - }); - return $(ids.join(", ")); -}; - $.fn.things = function() { /* * try to find all things that occur below a given selector, like: diff --git a/r2/r2/public/static/js/reddit.js b/r2/r2/public/static/js/reddit.js index 516fe7e6f..ed8e489d7 100644 --- a/r2/r2/public/static/js/reddit.js +++ b/r2/r2/public/static/js/reddit.js @@ -36,8 +36,6 @@ function close_menus(event) { } }; -function hover_open_menu(menu) { }; - function select_tab_menu(tab_link, tab_name) { var target = "tabbedpane-" + tab_name; var menu = $(tab_link).parent().parent().parent(); @@ -48,17 +46,6 @@ function select_tab_menu(tab_link, tab_name) { }); } -function update_user(form) { - try { - var user = $(form).find('input[name="user"]').val(); - form.action += "/" + user; - } catch (e) { - // ignore - } - - return true; -} - function post_user(form, where) { var user = $(form).find('input[name="user"]').val(); @@ -143,14 +130,6 @@ function post_multipart_form(form, where) { return true; } -function emptyInput(elem, msg) { - if (! $(elem).val() || $(elem).val() == msg ) - $(elem).addClass("gray").val(msg).attr("rows", 3); - else - $(elem).focus(function(){}); -}; - - function showlang() { var content = $('#lang-popup').prop('innerHTML'); var popup = new r.ui.Popup({ @@ -216,14 +195,6 @@ function read_thing(elem) { $.request("read_message", {"id": $(t).thing_id()}); } -function save_thing(elem) { - $(elem).thing().addClass("saved"); -} - -function unsave_thing(elem) { - $(elem).thing().removeClass("saved"); -} - function click_thing(elem) { var t = $(elem); if (!t.hasClass("thing")) { @@ -865,11 +836,6 @@ function cancel_usertext(elem) { hide_edit_usertext(t.closest(".usertext")); } -function save_usertext(elem) { - var t = $(elem).thing(); - t.find(".edit-usertext:first").parent("li").addBack().show(); -} - function reply(elem) { var form = comment_reply_for_elem(elem); @@ -1051,14 +1017,6 @@ var toolbar_p = function(expanded_size, collapsed_size) { }; }; -function clear_all_langs(elem) { - $(elem).parents("td").find('input[type="checkbox"]').prop("checked", false); -} - -function check_some_langs(elem) { - $(elem).parents("td").find("#some-langs").prop("checked", true); -} - function fetch_parent(elem, parent_permalink, parent_id) { var thing = $(elem).thing(); var parent = ''; @@ -1266,40 +1224,9 @@ function show_friend(account_fullname) { }); } -function show_unfriend(account_fullname) { - var ua = $(".author.id-" + account_fullname).removeClass("friend") - .next(".userattrs"); - ua.each(function() { - $(this).find("a.friend").remove(); - if ($(this).find("a").length == 0) { - $(this).html(""); - } - }); -} - function save_href(link) { if (!link.attr("srcurl")){ link.attr("srcurl", link.attr("href")); } return link; } - -function pure_domain(url) { - var domain = url.match(/:\/\/([^/]+)/) - if (domain) { - domain = domain[1].replace(/^www\./, ''); - } - return domain; -} - -function parse_domain(url) { - var domain = pure_domain(url); - if (!domain) { - /* Internal link? Get the SR name, if there is one */ - var reddit = url.match(/\/r\/([^/]+)/) - if (reddit) { - domain = "self." + reddit[1].toLowerCase(); - } - } - return domain; -} diff --git a/r2/r2/templates/navmenu.html b/r2/r2/templates/navmenu.html index 028bb491f..70fcc5de8 100644 --- a/r2/r2/templates/navmenu.html +++ b/r2/r2/templates/navmenu.html @@ -34,8 +34,7 @@