diff --git a/README.md b/README.md index 738bfc6..f1e9a65 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ A Redis hash named `user:` with the following fields: apisecret -> api POST requests secret code, to prevent CSRF attacks. flags -> flags used to mark users as admins and so forth karma_incr_time -> last time karma was incremented + new_window -> (1/0) Open news links in a new window? Additionally the user has an additional key: diff --git a/app.rb b/app.rb index 0bd8d8c..1178254 100644 --- a/app.rb +++ b/app.rb @@ -304,7 +304,16 @@ H.li {H.b {"posted comments "}+posted_comments.to_s} } }+if $user and $user['id'].to_i == user['id'].to_i - H.br+H.form(:name=>"f") { + H.form(:name=>"f") { + H.label(:for => "new_window") { + "Open links in new window?" + }+if $user['new_window'] == '1' + H.checkbox(:name => "new_window", + :value => "1", :checked => "1") + else + H.checkbox(:name => "new_window", :value => 1) + end + + H.br + H.label(:for => "email") { "email (not visible, used for gravatar)" }+H.br+ @@ -482,12 +491,13 @@ post '/api/updateprofile' do return {:status => "err", :error => "Not authenticated."}.to_json if !$user - if !check_params(:about, :email) + if !check_params(:about, :email, :new_window) return {:status => "err", :error => "Missing parameters."}.to_json end $r.hmset("user:#{$user['id']}", "about", params[:about][0..4095], - "email", params[:email][0..255]) + "email", params[:email][0..255], + "new_window", (params[:new_window] == "1" ? "1" : "0")) return {:status => "ok"}.to_json end @@ -945,9 +955,15 @@ def news_to_html(news) "▲" }+" "+ H.h2 { - H.a(:href=>news["url"]) { - H.entities news["title"] + if $user['new_window'] == '1' + H.a(:href=>news['url'], :target=>'_blank') { + H.entities news['title'] } + else + H.a(:href=>news["url"]) { + H.entities news["title"] + } + end }+" "+ H.address { if domain diff --git a/public/js/app.js b/public/js/app.js index adc2dc0..0012e04 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -48,9 +48,14 @@ function submit() { } function update_profile() { + var checked = "0"; + if($("input[name=new_window]").is(":checked")) { + checked = "1"; + } var data = { email: $("input[name=email]").val(), - about: $("textarea[name=about]").val(), + about: $("textarea[name=about]").val(), + new_window: checked, apisecret: apisecret }; $.ajax({