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).
This commit is contained in:
Matt Lee
2015-06-05 10:41:01 -07:00
parent 4245fde3e1
commit 268b44ba63
9 changed files with 4 additions and 149 deletions

View File

@@ -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("<div class='cover' id='toolcover'></div>");
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();

View File

@@ -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:

View File

@@ -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;
}

View File

@@ -34,8 +34,7 @@
<div class="dropdown ${css_class}"
${"id='%s'" % thing._id if thing._id else ""}
onclick="open_menu(this)"
onmouseover="hover_open_menu(this)">
onclick="open_menu(this)">
%if thing.selected:
<span class="selected">${thing.selected.selected_title()}</span>

View File

@@ -20,7 +20,7 @@
## reddit Inc. All Rights Reserved.
###############################################################################
<%namespace file="utils.html" import="error_field, success_field"/>
<%namespace file="utils.html" import="error_field"/>
<%namespace name="utils" file="utils.html"/>
<form id="passform" action="/api/password" method="post"

View File

@@ -20,7 +20,7 @@
## reddit Inc. All Rights Reserved.
###############################################################################
<%namespace file="utils.html" import="error_field, success_field"/>
<%namespace file="utils.html" import="error_field"/>
<%namespace name="utils" file="utils.html"/>
%if thing.done:

View File

@@ -154,12 +154,6 @@
$(img).parent("a").attr("href", $(img).attr("src"));
}
function too_big() {
$(".IMAGE_ERROR").innerHTML = "image too big: there is a 500k cap";
$(".img-status").innerHTML = "";
}
function paste_url(source) {
var txt = $(source).siblings("pre:first").html();
$("#stylesheet_contents").insertAtCursor(txt);
@@ -190,24 +184,6 @@
}
}
}
function check_name(form) {
var name = form.name.value;
var r = new RegExp(/[^a-zA-Z0-9\-]/);
if (name == "" || name.match(r)) {
$(".img-status").html("").hide();
$(".BAD_CSS_NAME").show().html("${_('bad image name')}");
return false;
}
else if(form.srfile.value) {
$(".BAD_CSS_NAME").html("").hide();
$(".IMAGE_ERROR").html("").hide();
return true;
} else {
$(".img-status").html("").hide();
$(".IMAGE_ERROR").show().html("${_('please select an image')}");
return false;
}
}
/* ]]> */
</script>
<ul id="image-preview-list" class="image-list">

View File

@@ -20,7 +20,7 @@
## reddit Inc. All Rights Reserved.
###############################################################################
<%namespace file="utils.html" import="error_field, success_field, radio_type"/>
<%namespace file="utils.html" import="error_field, radio_type"/>
<%namespace name="utils" file="utils.html"/>
<%! from r2.lib.strings import strings %>

View File

@@ -114,22 +114,6 @@ ${first_defined(kw[1:])}
</${kind}>
</%def>
<%def name="success_field(success_str, kind='p', successful=False, hide='')">
<${kind} class="error success">
%if successful:
${success_str}
%endif
</${kind}>
<script type="text/javascript">
function fire_success() {
$('success').innerHTML = "${success_str}";
%if hide:
hide(document.getElementById('${hide}'));
%endif
}
</script>
</%def>
<%def name="img_link(link_text, img, path, _id='', target='', img_id=None, size=None, **kw)">
<%
if (not target or target == '_parent') and c.cname: