Commit fd95183f773f044a57c5f3787804bf33ef203c76

  • Tree SHA1: a24c045
  • Parent SHA1: 6ea1437 (Add config.ru to run under rackup and add Sinatra::Reloader to get pre sinatra 0.9.2 style reloading when files change.)
  • raw diff | raw patch
You can post now. Tweaked some animation stuff as well.
  
22require 'sinatra'
33require 'rest_client'
44require 'json'
5require 'rack/utils'
56
67RestClient.proxy = "http://localhost:8118"
78set :host, 'localhost'
266266end
267267
268268post '/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
269313 return "success"
270314end
  
11function 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);
33 update_destination(origin);
44 update_in_reply_to(reply_to_id);
55 $("#post_textarea").val("@" + reply_to_user + " ");
6 $(".post").toggle();
6 $(".post").fadeToggle("fast");
77 $("#post_textarea").focus();
88}
99
1919 $("#displayed_destination").html(dest);
2020}
2121
22function clear_textentry() {
23 $("#post_textarea").val("");
24 count_chars();
25}
26
2227function count_chars() {
2328 var len = $("#post_textarea").val().length;
2429 var html = $("#num_of_chars").html();
4444
4545$(document).ready(
4646 function() {
47 jQuery.fn.fadeToggle = function(speed, easing, callback) {
48 return this.animate({opacity: 'toggle'}, speed, easing, callback);
49 }
4750
4851 $('.domw_reply_to').openDOMWindow(
4952 {
8585 resetForm: true,
8686 beforeSubmit: function(formData, jqForm, options) {
8787 var queryString = $.param(formData);
88 alert('About to submit: \n\n' + queryString);
88// alert('About to submit: \n\n' + queryString);
8989 return true;
9090 },
9191 success: function() {
9292 count_chars();
9393 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);
9599 }
96100 };
97101
110110
111111 $("#button_paulv").click(
112112 function () {
113 $(".paulv").toggle("fast");
113 $(".paulv").fadeToggle("fast");
114114 });
115115
116116 $(window).load(
136136 $("#post_link").click(
137137 function () {
138138 update_destination("identica");
139 $(".post").toggle();
139 update_in_reply_to("");
140 clear_textentry();
141 $(".post").fadeToggle("fast");
140142// $("#post_textarea").focus();
141143 });
142144 });
  
133133 text-align: right;
134134}
135135
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
136145.post {
137146 margin: auto;
138147 width: 450px;
  
1515 </head>
1616
1717 <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>
2930 </div>
3031 </div>
3132