TwitterWall.deploy.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. smalltalk.addPackage('TwitterWall', {});
  2. smalltalk.addClass('Tweet', smalltalk.Widget, ['json'], 'TwitterWall');
  3. smalltalk.addMethod(
  4. '_renderOn_',
  5. smalltalk.method({
  6. selector: 'renderOn:',
  7. fn: function (tr) {
  8. var self = this;
  9. var tdUser = nil;
  10. var tdMessage = nil;
  11. var img = nil;
  12. var a = nil;
  13. var pMessage = nil;
  14. var pDate = nil;
  15. tdUser = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_td", []);
  16. smalltalk.send(smalltalk.send(tdUser, "_element", []), "_id_", ["user"]);
  17. tdMessage = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_td", []);
  18. smalltalk.send(smalltalk.send(tdMessage, "_element", []), "_id_", ["messageBox"]);
  19. smalltalk.send(tr, "_append_", [tdUser]);
  20. smalltalk.send(tr, "_append_", [tdMessage]);
  21. img = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_img", []), "_src_", [smalltalk.send(self['@json'], "_at_", ["profile_image_url"])]);
  22. smalltalk.send(smalltalk.send(img, "_element", []), "_title_", [smalltalk.send(self['@json'], "_at_", ["from_user"])]);
  23. smalltalk.send(smalltalk.send(img, "_element", []), "_longDesc_", [smalltalk.send(unescape("http%3A//twitter.com/"), "__comma", [smalltalk.send(self['@json'], "_at_", ["from_user"])])]);
  24. 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"])])]);
  25. smalltalk.send(a, "_append_", [img]);
  26. smalltalk.send(tdUser, "_append_", [a]);
  27. pMessage = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_p", []);
  28. smalltalk.send(smalltalk.send(pMessage, "_element", []), "_id_", ["message"]);
  29. smalltalk.send(pMessage, "_append_", [smalltalk.send(self['@json'], "_at_", ["text"])]);
  30. smalltalk.send(tdMessage, "_append_", [pMessage]);
  31. pDate = smalltalk.send(smalltalk.send(smalltalk.HTMLCanvas || HTMLCanvas, "_new", []), "_p", []);
  32. smalltalk.send(smalltalk.send(pDate, "_element", []), "_id_", ["date"]);
  33. smalltalk.send(pDate, "_append_", [smalltalk.send(self['@json'], "_at_", ["created_at"])]);
  34. smalltalk.send(tdMessage, "_append_", [pDate]);
  35. return self;
  36. }
  37. }),
  38. smalltalk.Tweet);
  39. smalltalk.addMethod(
  40. '_json',
  41. smalltalk.method({
  42. selector: 'json',
  43. fn: function () {
  44. var self = this;
  45. return self['@json'];
  46. return self;
  47. }
  48. }),
  49. smalltalk.Tweet);
  50. smalltalk.addMethod(
  51. '_json_',
  52. smalltalk.method({
  53. selector: 'json:',
  54. fn: function (aJson) {
  55. var self = this;
  56. self['@json'] = aJson;
  57. return self;
  58. }
  59. }),
  60. smalltalk.Tweet);
  61. smalltalk.addMethod(
  62. '_openAt_with_',
  63. smalltalk.method({
  64. selector: 'openAt:with:',
  65. fn: function (tr, aJson) {
  66. var self = this;
  67. var tweet = nil;
  68. tweet = smalltalk.send(self, "_new", []);
  69. smalltalk.send(tweet, "_json_", [aJson]);
  70. smalltalk.send(tweet, "_renderOn_", [tr]);
  71. return tr;
  72. return self;
  73. }
  74. }),
  75. smalltalk.Tweet.klass);
  76. smalltalk.addClass('TwitterSearch', smalltalk.Object, ['queryString'], 'TwitterWall');
  77. smalltalk.addMethod(
  78. '_success_',
  79. smalltalk.method({
  80. selector: 'success:',
  81. fn: function (tweets) {
  82. var self = this;
  83. var playground = nil;
  84. var table = nil;
  85. var tr = nil;
  86. playground = smalltalk.send(unescape("%23playground"), "_asJQuery", []);
  87. smalltalk.send(playground, "_empty", []);
  88. 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]);
  89. return self;
  90. }
  91. }),
  92. smalltalk.TwitterSearch);
  93. smalltalk.addMethod(
  94. '_query',
  95. smalltalk.method({
  96. selector: 'query',
  97. fn: function () {
  98. var self = this;
  99. var result = nil;
  100. var queryString = nil;
  101. self['@queryString'] = smalltalk.send(smalltalk.send(smalltalk.send(unescape("%23searchQuery"), "_asJQuery", []), "_val", []), "_replace_with_", [unescape("%23"), unescape("%2523")]);
  102. 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"])])]);
  103. return self;
  104. }
  105. }),
  106. smalltalk.TwitterSearch);