Move left bar collapsing to server-side preference.

This commit is contained in:
Max Goodman
2013-08-30 16:12:55 -07:00
parent 980113c89e
commit 07366ac83e
6 changed files with 28 additions and 11 deletions

View File

@@ -3495,3 +3495,13 @@ class ApiController(RedditController, OAuth2ResourceController):
giftmessage=None,
comment=comment._fullname,
))
@json_validate(
VUser(),
VModhash(),
collapsed=VBoolean('collapsed'),
)
def POST_set_left_bar_collapsed(self, responder, collapsed):
c.user.pref_collapse_left_bar = collapsed
c.user._commit()

View File

@@ -616,6 +616,8 @@ class Reddit(Templated):
if self.show_chooser:
classes.add('with-listing-chooser')
if c.user.pref_collapse_left_bar:
classes.add('listing-chooser-collapsed')
if self.extra_page_classes:
classes.update(self.extra_page_classes)

View File

@@ -91,6 +91,7 @@ class Account(Thing):
pref_show_sponsorships = True,
pref_highlight_new_comments = True,
pref_monitor_mentions=True,
pref_collapse_left_bar=False,
mobile_compress = False,
mobile_thumbnail = True,
trusted_sponsor = False,

View File

@@ -609,6 +609,12 @@ r.multi.ListingChooser = Backbone.View.extend({
initialize: function() {
this.$el.addClass('initialized')
// transition collapsed state to server pref
if (store.get('ui.collapse.listingchooser') == true) {
this.toggleCollapsed(true)
store.remove('ui.collapse.listingchooser')
}
// HACK: fudge page heights for long lists of multis / short pages
var thisHeight = this.$('.contents').height(),
bodyHeight = $('body').height()
@@ -629,8 +635,14 @@ r.multi.ListingChooser = Backbone.View.extend({
}
},
toggleCollapsed: function() {
$('body').toggleClass('listing-chooser-collapsed')
store.set('ui.collapse.listingchooser', $('body').is('.listing-chooser-collapsed'))
toggleCollapsed: function(value) {
$('body').toggleClass('listing-chooser-collapsed', value)
Backbone.ajax({
type: 'POST',
url: '/api/set_left_bar_collapsed.json',
data: {
'collapsed': $('body').is('.listing-chooser-collapsed')
}
})
}
})

View File

@@ -91,10 +91,3 @@ r.ui.Summarize.prototype = {
e.preventDefault()
}
}
r.ui.collapseListingChooser = function() {
if (store.get('ui.collapse.listingchooser') == true) {
$('body').addClass('listing-chooser-collapsed')
}
}

View File

@@ -37,7 +37,6 @@
%endfor
</%def>
<script>r.ui.collapseListingChooser()</script>
<div class="listing-chooser">
<div class="grippy"></div>
<div class="contents">