Commit fd95183f773f044a57c5f3787804bf33ef203c76
- Diff rendering mode:
- inline
- side by side
coefficient.rb
(45 / 0)
|   | |||
| 2 | 2 | require 'sinatra' | |
| 3 | 3 | require 'rest_client' | |
| 4 | 4 | require 'json' | |
| 5 | require 'rack/utils' | ||
| 5 | 6 | ||
| 6 | 7 | RestClient.proxy = "http://localhost:8118" | |
| 7 | 8 | set :host, 'localhost' | |
| … | … | ||
| 266 | 266 | end | |
| 267 | 267 | ||
| 268 | 268 | post '/post' do | |
| 269 | text = params[:post_textarea] | ||
| 270 | in_reply_to = params[:in_reply_to] | ||
| 271 | destination = params[:destination] | ||
| 272 | url = "" | ||
| 273 | |||
| 274 | if text.length > 140 | ||
| 275 | halt 403, "text too long" | ||
| 276 | end | ||
| 277 | |||
| 278 | if in_reply_to.empty? | ||
| 279 | send_in_reply_to = false | ||
| 280 | else | ||
| 281 | send_in_reply_to = true | ||
| 282 | end | ||
| 283 | |||
| 284 | url = @@sites[destination]['api'].dup | ||
| 285 | url.gsub!(/(https?:\/\/)(.+)/, '\1' << | ||
| 286 | @@config['credentials']['username'] << ":" << | ||
| 287 | @@config['credentials']['password'] << "@" << | ||
| 288 | '\2') | ||
| 289 | |||
| 290 | url << "/statuses/update.json" | ||
| 291 | |||
| 292 | puts "url is #{url}" | ||
| 293 | |||
| 294 | payload = {} | ||
| 295 | payload[:status] = text | ||
| 296 | |||
| 297 | if send_in_reply_to | ||
| 298 | payload[:in_reply_to_status_id] = in_reply_to | ||
| 299 | end | ||
| 300 | |||
| 301 | begin | ||
| 302 | result = RestClient.post url, payload | ||
| 303 | rescue Exception => e | ||
| 304 | halt 403, "Exception from RestClient: #{e}" | ||
| 305 | end | ||
| 306 | |||
| 307 | begin | ||
| 308 | JSON.parse(result) | ||
| 309 | rescue Exception => e | ||
| 310 | halt 403, "JSON failed to parse, may have submitted okay (#{e})" | ||
| 311 | end | ||
| 312 | |||
| 269 | 313 | return "success" | |
| 270 | 314 | end |
public/custom.js
(20 / 6)
|   | |||
| 1 | 1 | function reply(origin, reply_to_user, reply_to_id) { | |
| 2 | alert(origin + " " + reply_to_user + " " + reply_to_id); | ||
| 2 | // alert(origin + " " + reply_to_user + " " + reply_to_id); | ||
| 3 | 3 | update_destination(origin); | |
| 4 | 4 | update_in_reply_to(reply_to_id); | |
| 5 | 5 | $("#post_textarea").val("@" + reply_to_user + " "); | |
| 6 | $(".post").toggle(); | ||
| 6 | $(".post").fadeToggle("fast"); | ||
| 7 | 7 | $("#post_textarea").focus(); | |
| 8 | 8 | } | |
| 9 | 9 | ||
| … | … | ||
| 19 | 19 | $("#displayed_destination").html(dest); | |
| 20 | 20 | } | |
| 21 | 21 | ||
| 22 | function clear_textentry() { | ||
| 23 | $("#post_textarea").val(""); | ||
| 24 | count_chars(); | ||
| 25 | } | ||
| 26 | |||
| 22 | 27 | function count_chars() { | |
| 23 | 28 | var len = $("#post_textarea").val().length; | |
| 24 | 29 | var html = $("#num_of_chars").html(); | |
| … | … | ||
| 44 | 44 | ||
| 45 | 45 | $(document).ready( | |
| 46 | 46 | function() { | |
| 47 | jQuery.fn.fadeToggle = function(speed, easing, callback) { | ||
| 48 | return this.animate({opacity: 'toggle'}, speed, easing, callback); | ||
| 49 | } | ||
| 47 | 50 | ||
| 48 | 51 | $('.domw_reply_to').openDOMWindow( | |
| 49 | 52 | { | |
| … | … | ||
| 85 | 85 | resetForm: true, | |
| 86 | 86 | beforeSubmit: function(formData, jqForm, options) { | |
| 87 | 87 | var queryString = $.param(formData); | |
| 88 | alert('About to submit: \n\n' + queryString); | ||
| 88 | // alert('About to submit: \n\n' + queryString); | ||
| 89 | 89 | return true; | |
| 90 | 90 | }, | |
| 91 | 91 | success: function() { | |
| 92 | 92 | count_chars(); | |
| 93 | 93 | update_destination("identica"); | |
| 94 | $(".post").toggle(); | ||
| 94 | update_in_reply_to(""); | ||
| 95 | $(".post").fadeToggle("fast"); | ||
| 96 | }, | ||
| 97 | error: function(xhr, textStatus, errorThrown) { | ||
| 98 | alert("Failure: " + xhr.responseText); | ||
| 95 | 99 | } | |
| 96 | 100 | }; | |
| 97 | 101 | ||
| … | … | ||
| 110 | 110 | ||
| 111 | 111 | $("#button_paulv").click( | |
| 112 | 112 | function () { | |
| 113 | $(".paulv").toggle("fast"); | ||
| 113 | $(".paulv").fadeToggle("fast"); | ||
| 114 | 114 | }); | |
| 115 | 115 | ||
| 116 | 116 | $(window).load( | |
| … | … | ||
| 136 | 136 | $("#post_link").click( | |
| 137 | 137 | function () { | |
| 138 | 138 | update_destination("identica"); | |
| 139 | $(".post").toggle(); | ||
| 139 | update_in_reply_to(""); | ||
| 140 | clear_textentry(); | ||
| 141 | $(".post").fadeToggle("fast"); | ||
| 140 | 142 | // $("#post_textarea").focus(); | |
| 141 | 143 | }); | |
| 142 | 144 | }); |
public/main.css
(9 / 0)
|   | |||
| 133 | 133 | text-align: right; | |
| 134 | 134 | } | |
| 135 | 135 | ||
| 136 | .post_parent { | ||
| 137 | margin: auto; | ||
| 138 | width: 450px; | ||
| 139 | background-color: #ffffff; | ||
| 140 | -moz-border-radius: 6px; | ||
| 141 | /* vertical-align: middle; */ | ||
| 142 | /* display: none; */ | ||
| 143 | } | ||
| 144 | |||
| 136 | 145 | .post { | |
| 137 | 146 | margin: auto; | |
| 138 | 147 | width: 450px; |
views/timeline.html.erb
(12 / 11)
|   | |||
| 15 | 15 | </head> | |
| 16 | 16 | ||
| 17 | 17 | <body> | |
| 18 | |||
| 19 | <div class="post"> | ||
| 20 | <div class="post_textarea"> | ||
| 21 | <form id="post_form" action="/post" method="post"> | ||
| 22 | <div id="num_of_chars">140</div><div id="displayed_in_reply_to"></div><div id="displayed_destination"></div> | ||
| 23 | <textarea id="post_textarea" cols="50" rows="5" | ||
| 24 | name="post_textarea"></textarea> | ||
| 25 | <input type="hidden" id="destination" name="destination" value="identica" /> | ||
| 26 | <input type="hidden" id="in_reply_to" name="in_reply_to" value="" /> | ||
| 27 | <div id="post_submit"><button id="post_submitx">submit</button></div> | ||
| 28 | </form> | ||
| 18 | <div class="post_parent"> | ||
| 19 | <div class="post"> | ||
| 20 | <div class="post_textarea"> | ||
| 21 | <form id="post_form" action="/post" method="post"> | ||
| 22 | <div id="num_of_chars">140</div><div id="displayed_in_reply_to"></div><div id="displayed_destination"></div> | ||
| 23 | <textarea id="post_textarea" cols="50" rows="5" | ||
| 24 | name="post_textarea"></textarea> | ||
| 25 | <input type="hidden" id="destination" name="destination" value="identica" /> | ||
| 26 | <input type="hidden" id="in_reply_to" name="in_reply_to" value="" /> | ||
| 27 | <div id="post_submit"><button id="post_submitx">submit</button></div> | ||
| 28 | </form> | ||
| 29 | </div> | ||
| 29 | 30 | </div> | |
| 30 | 31 | </div> | |
| 31 | 32 |

