Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding an option to open links in a new window #55

Open
wants to merge 7 commits into from

2 participants

@stevenleeg

This has always been a feature that I've looked for in HN. It just adds a simple checkbox to the user's preferences page which allows them to decide whether or not they want links to open in new windows.

public/js/app.js
@@ -48,9 +48,12 @@ function submit() {
}
function update_profile() {
+ var checked = '0';
+ if($('input[name=new_window]').is(':checked')) checked = '1';

You're aware that you've used mis-matched whitespace correct?

Contrary to the rest of the code...

  • You've omitted curly braces
  • You're using a different quote style (single? the rest uses double)

Ah! I hope you'll excuse my newness to contributing to open-source, I didn't even realize things like these mattered. I'll get right on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 6 deletions.
  1. +1 −0  README.md
  2. +21 −5 app.rb
  3. +6 −1 public/js/app.js
View
1  README.md
@@ -64,6 +64,7 @@ A Redis hash named `user:<user id>` 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:
View
26 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)
"&#9650;"
}+" "+
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
View
7 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({
Something went wrong with that request. Please try again.