diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index 4f1b760b6..85d150992 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -107,7 +107,7 @@ from r2.models import ( NEVER = datetime(2037, 12, 31, 23, 59, 59) DELETE = datetime(1970, 01, 01, 0, 0, 1) -cache_affecting_cookies = ('reddit_first', 'over18', '_options') +cache_affecting_cookies = ('over18', '_options') class Cookies(dict): def add(self, name, value, *k, **kw): @@ -287,45 +287,6 @@ def read_mod_cookie(): if cook: set_user_cookie('mod', '') -def firsttime(): - if (request.user_agent and - ('iphone' in request.user_agent.lower() or - 'android' in request.user_agent.lower()) and - not get_redditfirst('mobile_suggest')): - set_redditfirst('mobile_suggest', 'first') - return 'mobile_suggest' - elif get_redditfirst('firsttime'): - return False - else: - set_redditfirst('firsttime', 'first') - return True - -def get_redditfirst(key, default=None): - try: - val = c.cookies['reddit_first'].value - # on cookie presence, return as much - if default is None: - default = True - cookie = simplejson.loads(val) - return cookie[key] - except (ValueError, TypeError, KeyError), e: - # it's not a proper json dict, or the cookie isn't present, or - # the key isn't part of the cookie; we don't really want a - # broken cookie to propogate an exception up - return default - -def set_redditfirst(key, val): - try: - cookie = simplejson.loads(c.cookies['reddit_first'].value) - cookie[key] = val - except (ValueError, TypeError, KeyError), e: - # invalid JSON data; we'll just construct a new cookie - cookie = {key: val} - - c.cookies['reddit_first'] = Cookie(simplejson.dumps(cookie), - expires=NEVER) - - def over18(): if c.user.pref_over_18 or c.user_is_admin: return True @@ -693,7 +654,6 @@ class MinimalController(BaseController): c.cname, request.fullpath, c.over18, - c.firsttime, c.extension, c.render_style, cookies_key) @@ -940,8 +900,6 @@ class RedditController(MinimalController): for cookietype, count in cookie_counts.iteritems(): g.stats.simple_event("cookie.%s" % cookietype, count) - c.firsttime = firsttime() - # the user could have been logged in via one of the feeds maybe_admin = False is_otpcookie_valid = False diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index e79da22f1..fd26d2f22 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -170,9 +170,6 @@ class Reddit(Templated): infotext = strings.heavy_load_msg elif g.read_only_mode: infotext = strings.read_only_msg - elif (c.firsttime == 'mobile_suggest' and - c.render_style != 'compact'): - infotext = strings.iphone_first elif g.live_config.get("announcement_message"): infotext = g.live_config["announcement_message"] @@ -189,7 +186,7 @@ class Reddit(Templated): if not self.infobar: self.infobar = InfoBar(message=strings.all_minus_gold_only, extra_class="gold") - if c.firsttime: + if not c.user_is_loggedin: self.welcomebar = WelcomeBar() self.srtopbar = None diff --git a/r2/r2/lib/strings.py b/r2/r2/lib/strings.py index 71c3ecafc..2ef983c7d 100644 --- a/r2/r2/lib/strings.py +++ b/r2/r2/lib/strings.py @@ -121,7 +121,7 @@ string_dict = dict( submit_link = _("""You are submitting a link. The key to a successful submission is interesting content and a descriptive title."""), submit_text = _("""You are submitting a text-based post. Speak your mind. A title is required, but expanding further in the text field is not. Beginning your title with "vote up if" is violation of intergalactic law."""), - iphone_first = _("You should consider using [reddit's mobile interface](http://i.reddit.com/)."), + compact_suggest = _("Looks like you're browsing on a small screen. Would you like to try [reddit's mobile interface](%(url)s)?"), verify_email = _("we're going to need to verify your email address for you to proceed."), verify_email_submit = _("you'll be able to submit more frequently once you verify your email address"), email_verified = _("your email address has been verfied"), diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index b1bf976a4..7620a4fe8 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -1170,6 +1170,7 @@ a.author { margin-right: 0.5em; } } .infobar.welcome { + display: none; background: url(../welcome-lines.png) top center; border: 1px solid #ff8b60; padding: 0; diff --git a/r2/r2/public/static/js/ui.js b/r2/r2/public/static/js/ui.js index 754686f91..945fd834e 100644 --- a/r2/r2/public/static/js/ui.js +++ b/r2/r2/public/static/js/ui.js @@ -1,3 +1,33 @@ +r.ui.init = function() { + // welcome bar + if ($.cookie('reddit_first')) { + // save welcome seen state and delete obsolete cookie + $.cookie('reddit_first', null, {domain: r.config.cur_domain}) + store.set('ui.shown.welcome', true) + } else if (store.get('ui.shown.welcome') != true) { + $('.infobar.welcome').show() + store.set('ui.shown.welcome', true) + } + + // mobile suggest infobar + var smallScreen = window.matchMedia + ? matchMedia('(max-device-width: 700px)').matches + : $(window).width() < 700, + onFrontPage = $.url().attr('path') == '/' + if (smallScreen && onFrontPage && r.config.renderstyle != 'compact') { + var infobar = $('