From a20bd596fa927fe398adec7b61a58ed7fcc10aeb Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Tue, 5 Feb 2013 18:49:26 -0800 Subject: [PATCH] Use breadcrumbs to determine last click highlighting. Increase breadcrumb collection length to accomodate a single back/forward button usage after a click. --- r2/r2/controllers/api.py | 12 ------ r2/r2/public/static/js/analytics.js | 12 +++++- r2/r2/public/static/js/reddit.js | 67 +++-------------------------- 3 files changed, 17 insertions(+), 74 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 2d1ba3ba3..018720da1 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -3114,18 +3114,6 @@ class ApiController(RedditController, OAuth2ResourceController): jquery('.organic-listing .thing:visible').hide() jquery('.organic-listing .id-%s' % link).show() - - @validatedForm(links = VByName('links', thing_cls = Link, multiple = True), - show = VByName('show', thing_cls = Link, multiple = False)) - def POST_fetch_links(self, form, jquery, links, show): - l = wrap_links(links, listing_cls = SpotlightListing, - num_margin = 0, mid_margin = 0) - jquery(".content").replace_things(l, stubs = True) - - if show: - jquery('.organic-listing .link:visible').hide() - jquery('.organic-listing .id-%s' % show._fullname).show() - @noresponse(VUser(), ui_elem = VOneOf('id', ('organic',))) def POST_disable_ui(self, ui_elem): diff --git a/r2/r2/public/static/js/analytics.js b/r2/r2/public/static/js/analytics.js index 97e02b538..9173c15f2 100644 --- a/r2/r2/public/static/js/analytics.js +++ b/r2/r2/public/static/js/analytics.js @@ -165,7 +165,7 @@ r.analytics = { r.analytics.breadcrumbs = { selector: '.thing, .side, .sr-list, .srdrop, .tagline, .md, .organic-listing, .gadget, .sr-interest-bar, a, button, input', - maxLength: 2, + maxLength: 3, sendLength: 2, init: function() { @@ -247,6 +247,16 @@ r.analytics.breadcrumbs = { } }, + lastClickFullname: function() { + var lastClick = _.find(this.data, function(crumb) { + return crumb.click + }) + if (lastClick) { + var match = lastClick.click.match(/.*data-fullname="(\w+)"/) + return match && match[1] + } + }, + toParams: function() { params = [] for (var i = 0; i < this.sendLength; i++) { diff --git a/r2/r2/public/static/js/reddit.js b/r2/r2/public/static/js/reddit.js index 2a14345d9..60a3f1b25 100644 --- a/r2/r2/public/static/js/reddit.js +++ b/r2/r2/public/static/js/reddit.js @@ -513,9 +513,6 @@ function updateEventHandlers(thing) { $(this).addClass("click"); /* set the click cookie. */ add_thing_to_cookie(this, "recentclicks2"); - /* remember this as the last thing clicked */ - var wasorganic = $(this).parents('.organic-listing').length > 0; - last_click(thing, wasorganic); }); if (listing.filter(".organic-listing").length) { @@ -542,65 +539,13 @@ function updateEventHandlers(thing) { } }; -function last_click(thing, organic) { - /* called with zero arguments, marks the last-clicked item on this - page (to which the user probably clicked the 'back' button in - their browser). Otherwise sets the last-clicked item to the - arguments passed */ - var cookie = "last_thing"; - if(thing) { - var data = {href: window.location.href, - what: $(thing).thing_id(), - organic: organic}; - $.cookie_write({name: cookie, data: data}); - } else { - var current = $.cookie_read(cookie).data; - if(current && current.href == window.location.href) { - /* if they got there organically, make sure that it's in the - organic box */ - var olisting = $('.organic-listing'); - if(current.organic && olisting.length == 1) { - if(olisting.find('.thing:visible').thing_id() == current.what) { - /* if it's available in the organic box, *and* it's the one - that's already shown, do nothing */ - - } else { - var thing = olisting.things(current.what); - - if(thing.length > 0 && !thing.hasClass('stub')) { - /* if it's available in the organic box and not a stub, - switch index to it */ - olisting.find('.thing:visible').hide(); - thing.show(); - } else { - /* either it's available in the organic box, but the - data there is a stub, or it's not available at - all. either way, we need a server round-trip */ - - /* remove the stub if it's there */ - thing.remove(); - - /* add a new stub */ - olisting.find('.thing:visible') - .before('