forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
(function() { | ||
$(document).ready(function() { | ||
var update, updateCounter; | ||
var focusTextArea, shareText, textarea, updateCounter, update_field; | ||
$("html").removeClass("no-js").addClass("js"); | ||
update = $("#update-textarea"); | ||
textarea = $("#update-form textarea"); | ||
update_field = $("#update-form #update-referral"); | ||
updateCounter = function() { | ||
$("#update-count").text((140 - update.val().length) + "/140"); | ||
return $("#update-info").toggleClass("negative", update.val().length > 140); | ||
$("#update-count").text((140 - textarea.val().length) + "/140"); | ||
return $("#update-info").toggleClass("negative", textarea.val().length > 140); | ||
}; | ||
update.keypress(updateCounter).keyup(updateCounter); | ||
return $("#update-form").submit(function() { | ||
if (update.val().length <= 0 || update.val().length > 140) { | ||
textarea.keypress(updateCounter).keyup(updateCounter); | ||
$("#update-form").submit(function() { | ||
if (textarea.val().length <= 0 || textarea.val().length > 140) { | ||
return false; | ||
} | ||
}); | ||
shareText = function(update) { | ||
return "RT @" + $(update).data("name") + ": " + $(update).find(".text").text().trim(); | ||
}; | ||
focusTextArea = function() { | ||
textarea.keypress(); | ||
return textarea.focus(); | ||
}; | ||
return $(".update").each(function() { | ||
var update; | ||
update = $(this); | ||
$(this).find(".reply").bind("click", function(ev) { | ||
ev.preventDefault(); | ||
textarea.text("@" + $(update).data("name") + " "); | ||
return focusTextArea(); | ||
}); | ||
return $(this).find(".share").bind("click", function(ev) { | ||
ev.preventDefault(); | ||
textarea.text(shareText(update)); | ||
return focusTextArea(); | ||
}); | ||
}); | ||
}); | ||
}).call(this); | ||
|
||
// TODO: MOVE TO COFFEE-SCRIPT FOO | ||
function reply(username) { | ||
var update = $("#update-textarea"); | ||
update.text("@" + username + " "); | ||
update.keypress(); | ||
update.focus(); | ||
} | ||
|
||
function share_text(username, update_id) { | ||
var update_text = $("#update-" + update_id).text().trim(); | ||
return "RT @" + username + ": " + update_text; | ||
} | ||
|
||
function share(username, update_id) { | ||
var update = $("#update-textarea"); | ||
update.text(share_text(username, update_id)); | ||
update.keypress(); | ||
update.focus(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
$(document).ready -> | ||
$("html").removeClass("no-js").addClass("js") | ||
update = $("#update-textarea") | ||
|
||
textarea = $("#update-form textarea") | ||
update_field = $("#update-form #update-referral") | ||
|
||
updateCounter = -> | ||
$("#update-count").text((140 - update.val().length) + "/140") | ||
$("#update-info").toggleClass "negative", update.val().length > 140 | ||
$("#update-count").text((140 - textarea.val().length) + "/140") | ||
$("#update-info").toggleClass "negative", textarea.val().length > 140 | ||
|
||
update.keypress(updateCounter).keyup(updateCounter) | ||
textarea.keypress(updateCounter).keyup(updateCounter) | ||
|
||
$("#update-form").submit -> | ||
false if update.val().length <= 0 || update.val().length > 140 | ||
false if textarea.val().length <= 0 || textarea.val().length > 140 | ||
|
||
shareText = (update) -> | ||
"RT @" + $(update).data("name") + ": " + $(update).find(".text").text().trim(); | ||
|
||
focusTextArea = -> | ||
textarea.keypress() | ||
textarea.focus() | ||
|
||
$(".update").each -> | ||
update = $(this) | ||
|
||
$(this).find(".reply").bind "click", (ev) -> | ||
ev.preventDefault(); | ||
textarea.text("@" + $(update).data("name") + " ") | ||
focusTextArea() | ||
|
||
$(this).find(".share").bind "click", (ev) -> | ||
ev.preventDefault(); | ||
textarea.text(shareText(update)) | ||
focusTextArea() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
- updates.each do |update| | ||
- mentioned = current_user.nil? ? false : update.mentioned?(current_user.username) | ||
.update{:class => mentioned ? "mention" : ""} | ||
.update{:class => mentioned ? "mention" : "", :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author.username} | ||
.avatar | ||
%a{:href => update.author.url} | ||
%img{:alt => "avatar", :src => update.author.avatar_url}/ | ||
.content | ||
.name= "#{update.author.name} (#{update.author.username})" | ||
.text{:id => "update-#{update.id}"} | ||
.text | ||
!= update.to_html | ||
.date | ||
%a{:href => update.url}= update.created_at.ago_in_words | ||
.reply | ||
.links | ||
-# when @timeline is true, this is a list on the user's page | ||
-unless current_user.nil? or (current_user.author.id == update.author.id) | ||
-unless @timeline.nil? | ||
%a{:href => "javascript:share('#{update.author.username}', '#{update.id}')"} share | ||
| | ||
%a{:href => "javascript:reply('#{update.author.username}')"} reply | ||
-else | ||
%a{:href => "/?share=#{update.id}"} share | ||
| | ||
%a{:href => "/?reply=#{update.author.username}"} reply | ||
%a.share{:href => "/?share=#{update.id}"} share | ||
| | ||
%a.reply{:href => "/?reply=#{update.id}"} reply | ||
- if updates.empty? | ||
.empty | ||
There's no updates here yet |