2
0

TwitterWall.deploy.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. smalltalk.addPackage('TwitterWall');
  2. smalltalk.addClass('Tweet', smalltalk.Widget, ['json'], 'TwitterWall');
  3. smalltalk.addMethod(
  4. smalltalk.method({
  5. selector: "json",
  6. fn: function () {
  7. var self = this;
  8. return self['@json'];
  9. return self;
  10. },
  11. messageSends: []}),
  12. smalltalk.Tweet);
  13. smalltalk.addMethod(
  14. smalltalk.method({
  15. selector: "json:",
  16. fn: function (aJson) {
  17. var self = this;
  18. self['@json'] = aJson;
  19. return self;
  20. },
  21. messageSends: []}),
  22. smalltalk.Tweet);
  23. smalltalk.addMethod(
  24. smalltalk.method({
  25. selector: "renderOn:",
  26. fn: function (tr) {
  27. var self = this;
  28. var tdUser = nil;
  29. var tdMessage = nil;
  30. var img = nil;
  31. var a = nil;
  32. var pMessage = nil;
  33. var pDate = nil;
  34. tdUser = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_td", []);
  35. smalltalk.send(smalltalk.send(tdUser, "_element", []), "_id_", ["user"]);
  36. tdMessage = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_td", []);
  37. smalltalk.send(smalltalk.send(tdMessage, "_element", []), "_id_", ["messageBox"]);
  38. smalltalk.send(tr, "_append_", [tdUser]);
  39. smalltalk.send(tr, "_append_", [tdMessage]);
  40. img = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_img", []), "_src_", [smalltalk.send(self['@json'], "_at_", ["profile_image_url"])]);
  41. smalltalk.send(smalltalk.send(img, "_element", []), "_title_", [smalltalk.send(self['@json'], "_at_", ["from_user"])]);
  42. smalltalk.send(smalltalk.send(img, "_element", []), "_longDesc_", [smalltalk.send(unescape("http%3A//twitter.com/"), "__comma", [smalltalk.send(self['@json'], "_at_", ["from_user"])])]);
  43. a = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_a", []), "_href_", [smalltalk.send(unescape("http%3A//twitter.com/"), "__comma", [smalltalk.send(self['@json'], "_at_", ["from_user"])])]);
  44. smalltalk.send(a, "_append_", [img]);
  45. smalltalk.send(tdUser, "_append_", [a]);
  46. pMessage = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_p", []);
  47. smalltalk.send(smalltalk.send(pMessage, "_element", []), "_id_", ["message"]);
  48. smalltalk.send(pMessage, "_append_", [smalltalk.send(self['@json'], "_at_", ["text"])]);
  49. smalltalk.send(tdMessage, "_append_", [pMessage]);
  50. pDate = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_p", []);
  51. smalltalk.send(smalltalk.send(pDate, "_element", []), "_id_", ["date"]);
  52. smalltalk.send(pDate, "_append_", [smalltalk.send(self['@json'], "_at_", ["created_at"])]);
  53. smalltalk.send(tdMessage, "_append_", [pDate]);
  54. return self;
  55. },
  56. messageSends: ["td", "new", "id:", "element", "append:", "src:", "img", "at:", "title:", "longDesc:", ",", "href:", "a", "p"]}),
  57. smalltalk.Tweet);
  58. smalltalk.addMethod(
  59. smalltalk.method({
  60. selector: "openAt:with:",
  61. fn: function (tr, aJson) {
  62. var self = this;
  63. var tweet = nil;
  64. tweet = smalltalk.send(self, "_new", []);
  65. smalltalk.send(tweet, "_json_", [aJson]);
  66. smalltalk.send(tweet, "_renderOn_", [tr]);
  67. return tr;
  68. return self;
  69. },
  70. messageSends: ["new", "json:", "renderOn:"]}),
  71. smalltalk.Tweet.klass);
  72. smalltalk.addClass('TwitterSearch', smalltalk.Object, [], 'TwitterWall');
  73. smalltalk.addMethod(
  74. smalltalk.method({
  75. selector: "query",
  76. fn: function () {
  77. var self = this;
  78. var result = nil;
  79. var queryString = nil;
  80. self['@queryString'] = smalltalk.send(smalltalk.send(smalltalk.send(unescape("%23searchQuery"), "_asJQuery", []), "_val", []), "_replace_with_", [unescape("%23"), unescape("%2523")]);
  81. result = smalltalk.send(typeof jQuery == "undefined" ? nil : jQuery, "_ajax_options_", [smalltalk.send(unescape("http%3A//search.twitter.com/search.json%3Frpp%3D5%26q%3D"), "__comma", [self['@queryString']]), smalltalk.HashedCollection._fromPairs_([smalltalk.send("type", "__minus_gt", ["GET"]), smalltalk.send("success", "__minus_gt", [function (tmp) {return smalltalk.send(self, "_success_", [smalltalk.send(tmp, "_results", [])]);}]), smalltalk.send("error", "__minus_gt", [function () {return smalltalk.send(typeof window == "undefined" ? nil : window, "_alert_", ["error"]);}]), smalltalk.send("dataType", "__minus_gt", ["jsonp"])])]);
  82. return self;
  83. },
  84. messageSends: ["replace:with:", "val", "asJQuery", "ajax:options:", ",", "->", "success:", "results", "alert:"]}),
  85. smalltalk.TwitterSearch);
  86. smalltalk.addMethod(
  87. smalltalk.method({
  88. selector: "success:",
  89. fn: function (tweets) {
  90. var self = this;
  91. var playground = nil;
  92. var table = nil;
  93. var tr = nil;
  94. playground = smalltalk.send(unescape("%23playground"), "_asJQuery", []);
  95. smalltalk.send(playground, "_empty", []);
  96. smalltalk.send(function (html) {table = smalltalk.send(html, "_table", []);smalltalk.send(smalltalk.send(table, "_element", []), "_id_", ["twitterwall"]);return smalltalk.send(tweets, "_do_", [function (tweet) {tr = smalltalk.send(html, "_tr", []);smalltalk.send(table, "_append_", [tr]);return smalltalk.send(smalltalk.Tweet || Tweet, "_openAt_with_", [tr, tweet]);}]);}, "_appendToJQuery_", [playground]);
  97. return self;
  98. },
  99. messageSends: ["asJQuery", "empty", "appendToJQuery:", "table", "id:", "element", "do:", "tr", "append:", "openAt:with:"]}),
  100. smalltalk.TwitterSearch);