Skip to content
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
45 changes: 37 additions & 8 deletions app/assets/javascripts/welcome.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,49 @@

$ ->

mode = "email"

twitterHref = (handle) ->
message = encodeURIComponent "DM #{handle} Are you interested in pairing on <DESCRIPTION>?"
"https://twitter.com/intent/tweet?text=#{message}"

emailHref = (email) ->
email = encodeURIComponent email
subject = encodeURIComponent 'Pair program with me'
"mailto:#{email}?subject=#{subject}"

formatCode = (input) ->
email = $(input).val()
code = """<a href="mailto:#{email}?subject=Pair%20program%20with%20me" title="Pair program with me!">
<img src="http://pairprogramwith.me/badge.png"
alt="Pair program with me!" />
</a>"""
value = $(input).val()
href = switch mode
when 'email'
emailHref value
when 'twitter'
twitterHref value
"""<a href="#{href}" title="Pair program with me!">
<img src="http://pairprogramwith.me/badge.png"
alt="Pair program with me!" />
</a>"""

$('#get-badge-code').on 'submit', (e) ->
$('.badge-code').html(formatCode('#badge-email')).
$('.badge-code').html(formatCode("#badge-#{mode}")).
removeAttr('disabled').
removeClass('hide').
focus().select()
false

$('#badge-email').focus ->
$('.badge-code').html('Code goes here when you submit your email').
$('#badge-email,#badge-twitter').focus ->
$('.badge-code').html('Code goes here when you submit').
attr('disabled', true)

$('#pick-email,#pick-twitter').click ({target}) ->
$('#badge-email,#badge-twitter').removeClass('hide')
$('#pick-email,#pick-twitter').removeClass('active')
switch $(target).attr('id')
when 'pick-email'
mode = 'email'
$('#badge-twitter').addClass('hide')
$('#pick-email').addClass('active')
when 'pick-twitter'
mode = 'twitter'
$('#badge-email').addClass('hide')
$('#pick-twitter').addClass('active')
6 changes: 6 additions & 0 deletions app/views/welcome/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ section#badge

form#get-badge-code
.row.collapse
.small-12.columns
button#pick-email.button.active
| Email
button#pick-twitter.button
| Twitter
.small-9.columns
input#badge-twitter.hide type="text" placeholder="@AwesomeCoder"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove @ during submit event or don't suggest to the user that they should provide one. Twitter does not allow the @ symbol as part of the DM message. For example the following is wrong:

DM @handle lorem ipsum

input#badge-email type="email" placeholder="awesome@coder.org"
.small-3.columns
button#submit-email.button.prefix
Expand Down