From 17656e464b6b58532ba3efe6359389ffb8e4553f Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Sun, 19 Feb 2012 13:01:28 -0500 Subject: [PATCH] Fix scroll position for esc out of edit." --- snipt/media/js/src/modules/snipt.js | 10 +++++++--- snipt/snipts/views.py | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/snipt/media/js/src/modules/snipt.js b/snipt/media/js/src/modules/snipt.js index f8a9eb1..aacc35b 100644 --- a/snipt/media/js/src/modules/snipt.js +++ b/snipt/media/js/src/modules/snipt.js @@ -270,9 +270,13 @@ if ($('section#main-edit:visible').length) { $('section#main-edit').hide(); $('section#main').show(); - $('html, body').animate({ - scrollTop: $selected.offset().top - 50 - }, 0); + if (SniptList.$snipts.index($selected) === 0) { + window.scrollTo(0, 0); + } else { + $('html, body').animate({ + scrollTop: $selected.offset().top - 50 + }, 0); + } } else { if ($selected) { $selected.trigger('deselect'); diff --git a/snipt/snipts/views.py b/snipt/snipts/views.py index 4484a1e..25d6b89 100644 --- a/snipt/snipts/views.py +++ b/snipt/snipts/views.py @@ -75,14 +75,17 @@ def detail(request, username, snipt_slug): if user == request.user: tags = tags.filter(snipt__user=user) + public = False else: tags = tags.filter(snipt__user=user, snipt__public=True) + public = True tags = tags.annotate(count=Count('taggit_taggeditem_items__id')) tags = tags.order_by('-count', 'name') return { + 'public': public, 'snipt': snipt, - 'user': user, 'tags': tags, + 'user': user, }