Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
//= require sticky
//= require overlay
//= require cookie
//= require newsletter
//= require notice
//= require front
//= require front
18 changes: 18 additions & 0 deletions app/assets/javascripts/newsletter.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$(document).on 'ready turbolinks:load', ->
'use strict'

$('[data-action="closeNewsletterNotice"]').on 'click', (e) ->
noticeEl = $(e.currentTarget).parents('.front-subscribe-newsletter')
noticeEl.css 'bottom', '-100%'
e.preventDefault()

$.ajax
url: '/dismiss-newsletter-subscribe'
type: 'PUT'
data: {}
success: (data) ->
return

setTimeout ->
noticeEl.detach()
, 500
9 changes: 9 additions & 0 deletions app/assets/stylesheets/components/_newsletter.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.front-subscribe-newsletter
background-color: white
text-align: center

@media screen and (min-width: $small)
width: 400px

.content
text-align: left
24 changes: 24 additions & 0 deletions app/assets/stylesheets/layouts/_fixed-bottom.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.-fixed-bottom
position: fixed
left: 2rem
right: 2rem
bottom: 2rem
z-index: 999
padding: 0

.close
float: left
margin-left: 1rem
margin-top: 1rem

.icon
width: 2.25rem
height: 2.25rem

.content
padding-left: 4rem

@media screen and (min-width: $small)
@media screen and (min-width: $medium)
.content
padding-left: 5.25rem
12 changes: 9 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
impersonates :user
before_action :log_out_deleted_users
helper_method :current_visitor, :remaining_reads, :read_count, :permission_for_cookie?
helper_method :current_visitor, :remaining_reads, :read_count, :permission_for_cookie?, :newsletter_subscribe_dismissed?

def log_out_deleted_users
return true unless logged_in?
Expand Down Expand Up @@ -39,12 +39,18 @@ def permission_for_cookie?
false
end

def newsletter_subscribe_dismissed?
return true if cookies.has_key? 'newsletter_subscribe_dismissed'

false
end

def setup_legacy_account(user)
user.generate_reset_password_token!
UserMailer.migrate_account_email(user).deliver_later
redirect_to :migrate_hold
end

def visitor_is_probable_bot?
return true if cookies.permanent.signed[:probable_bot] == 'true'
false
Expand All @@ -61,7 +67,7 @@ def find_or_create_current_visitor
v = Visitor.where(id: cookies.signed[:visitor_id]).take
return v if v.present?
end

visitor = Visitor.create!
cookies.permanent.signed[:visitor_id] = visitor.id
return visitor
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UserSessionsController < ApplicationController
before_action :require_login, only: [:destroy]
skip_before_action :verify_authenticity_token, only: [:accept_cookies]
skip_before_action :verify_authenticity_token, only: [:accept_cookies, :dismiss_newsletter_subscribe]

layout 'modal'

Expand Down Expand Up @@ -34,4 +34,12 @@ def accept_cookies
cookies.permanent[:accepts_cookies] = "yes"
render plain: 'noted.'
end

def dismiss_newsletter_subscribe
if permission_for_cookie?
cookies[:newsletter_subscribe_dismissed] = { expires: 1.day }
end

render plain: 'noted.'
end
end
7 changes: 5 additions & 2 deletions app/views/layouts/front.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
.block.-bt
= render partial: 'layouts/partials/primary-footer'

= render partial: 'user_sessions/cookies'
= render layout: 'layouts/partials/fixed-bottom' do
= render partial: 'newsletter/front-subscribe-newsletter'
= render partial: 'user_sessions/cookies-content'

- if permission_for_cookie?
= render partial: 'user_sessions/delinquent'

= render partial: 'layouts/partials/search'
= render partial: 'layouts/partials/expansive-nav'
= render partial: 'layouts/snippets/analytics'
= render partial: 'layouts/snippets/analytics'
2 changes: 2 additions & 0 deletions app/views/layouts/partials/_fixed-bottom.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.-fixed-bottom
= yield
11 changes: 11 additions & 0 deletions app/views/newsletter/_front-subscribe-newsletter.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- if !logged_in? && !newsletter_subscribe_dismissed?
.front-subscribe-newsletter
%nav.close
%a.icon{'data-action': 'closeNewsletterNotice'}
%svg{height: "242px", version: "1.1", viewbox: "0 0 242 242", width: "242px", xmlns: "http://www.w3.org/2000/svg", "xmlns:xlink" => "http://www.w3.org/1999/xlink"}
%rect{fill: "#000000", height: "20", transform: "translate(121.208153, 121.208153) rotate(45.000000) translate(-121.208153, -121.208153) ", width: "320", x: "-38.7918472", y: "111.208153"}
%rect{fill: "#000000", height: "20", transform: "translate(121.000000, 121.000000) rotate(-45.000000) translate(-121.000000, -121.000000) ", width: "320", x: "-39", y: "111"}

.content.block.-p1
.p.-t4
Sign up for our free email newsletter. Get our weekly headlines and more, each Wednesday, in your inbox.
14 changes: 14 additions & 0 deletions app/views/user_sessions/_cookies-content.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- if !permission_for_cookie?
.notice.block.-bg-black
%nav.close
%a.icon{'data-action': 'acceptCookies'}
%svg{height: "242px", version: "1.1", viewbox: "0 0 242 242", width: "242px", xmlns: "http://www.w3.org/2000/svg", "xmlns:xlink" => "http://www.w3.org/1999/xlink"}
%rect{fill: "#fafafa", height: "20", transform: "translate(121.208153, 121.208153) rotate(45.000000) translate(-121.208153, -121.208153) ", width: "320", x: "-38.7918472", y: "111.208153"}
%rect{fill: "#fafafa", height: "20", transform: "translate(121.000000, 121.000000) rotate(-45.000000) translate(-121.000000, -121.000000) ", width: "320", x: "-39", y: "111"}

.content.block.-p1
.p.-centered.-t4
:markdown
We use first-party cookies to allow visitors to log in to our website and read our articles.

.block.-my1 #{ link_to "I understand", :accept_cookies, 'data-action': 'acceptCookies', class: 'button -white' }
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
get 'login' => 'user_sessions#new', as: :login
get 'logout' => 'user_sessions#destroy', as: :logout
put 'accept' => 'user_sessions#accept_cookies', as: :accept_cookies
put 'dismiss-newsletter-subscribe' => 'user_sessions#dismiss_newsletter_subscribe'

# user migration

Expand Down