TwitterWall.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. smalltalk.addPackage('TwitterWall');
  2. smalltalk.addClass('Tweet', smalltalk.Widget, ['json'], 'TwitterWall');
  3. smalltalk.addMethod(
  4. smalltalk.method({
  5. selector: "json",
  6. category: 'not yet classified',
  7. fn: function (){
  8. var self=this;
  9. return smalltalk.withContext(function($ctx1) {
  10. var $1;
  11. $1=self["@json"];
  12. return $1;
  13. }, function($ctx1) {$ctx1.fill(self,"json",{},smalltalk.Tweet)})},
  14. args: [],
  15. source: "json\x0a^json",
  16. messageSends: [],
  17. referencedClasses: []
  18. }),
  19. smalltalk.Tweet);
  20. smalltalk.addMethod(
  21. smalltalk.method({
  22. selector: "json:",
  23. category: 'not yet classified',
  24. fn: function (aJson){
  25. var self=this;
  26. return smalltalk.withContext(function($ctx1) {
  27. self["@json"]=aJson;
  28. return self}, function($ctx1) {$ctx1.fill(self,"json:",{aJson:aJson},smalltalk.Tweet)})},
  29. args: ["aJson"],
  30. source: "json: aJson\x0ajson := aJson",
  31. messageSends: [],
  32. referencedClasses: []
  33. }),
  34. smalltalk.Tweet);
  35. smalltalk.addMethod(
  36. smalltalk.method({
  37. selector: "renderOn:",
  38. category: 'not yet classified',
  39. fn: function (tr){
  40. var self=this;
  41. var tdUser,tdMessage,img,a,pMessage,pDate;
  42. function $HTMLCanvas(){return smalltalk.HTMLCanvas||(typeof HTMLCanvas=="undefined"?nil:HTMLCanvas)}
  43. return smalltalk.withContext(function($ctx1) {
  44. tdUser=_st(_st($HTMLCanvas())._new())._td();
  45. _st(_st(tdUser)._element())._id_("user");
  46. tdMessage=_st(_st($HTMLCanvas())._new())._td();
  47. _st(_st(tdMessage)._element())._id_("messageBox");
  48. _st(tr)._append_(tdUser);
  49. _st(tr)._append_(tdMessage);
  50. img=_st(_st(_st($HTMLCanvas())._new())._img())._src_(_st(self["@json"])._at_("profile_image_url"));
  51. _st(_st(img)._element())._title_(_st(self["@json"])._at_("from_user"));
  52. _st(_st(img)._element())._longDesc_("http://twitter.com/".__comma(_st(self["@json"])._at_("from_user")));
  53. a=_st(_st(_st($HTMLCanvas())._new())._a())._href_("http://twitter.com/".__comma(_st(self["@json"])._at_("from_user")));
  54. _st(a)._append_(img);
  55. _st(tdUser)._append_(a);
  56. pMessage=_st(_st($HTMLCanvas())._new())._p();
  57. _st(_st(pMessage)._element())._id_("message");
  58. _st(pMessage)._append_(_st(self["@json"])._at_("text"));
  59. _st(tdMessage)._append_(pMessage);
  60. pDate=_st(_st($HTMLCanvas())._new())._p();
  61. _st(_st(pDate)._element())._id_("date");
  62. _st(pDate)._append_(_st(self["@json"])._at_("created_at"));
  63. _st(tdMessage)._append_(pDate);
  64. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{tr:tr,tdUser:tdUser,tdMessage:tdMessage,img:img,a:a,pMessage:pMessage,pDate:pDate},smalltalk.Tweet)})},
  65. args: ["tr"],
  66. source: "renderOn: tr\x0a\x0a| tdUser tdMessage img a pMessage pDate |\x0atdUser := HTMLCanvas new td.\x0atdUser element id: 'user'.\x0atdMessage := HTMLCanvas new td.\x0atdMessage element id: 'messageBox'.\x0a\x0atr append: tdUser.\x0atr append: tdMessage.\x0a\x0aimg := HTMLCanvas new img src: (json at: 'profile_image_url') .\x0aimg element title: (json at: 'from_user').\x0aimg element longDesc: ('http://twitter.com/', (json at: 'from_user')).\x0a\x0aa := HTMLCanvas new a href: ('http://twitter.com/', (json at: 'from_user')).\x0aa append: img.\x0a\x0atdUser append: a.\x0a\x0apMessage := HTMLCanvas new p.\x0apMessage element id: 'message'.\x0apMessage append: (json at: 'text').\x0atdMessage append: pMessage.\x0a\x0apDate := HTMLCanvas new p.\x0apDate element id: 'date'.\x0apDate append: (json at: 'created_at').\x0atdMessage append: pDate.",
  67. messageSends: ["td", "new", "id:", "element", "append:", "src:", "at:", "img", "title:", "longDesc:", ",", "href:", "a", "p"],
  68. referencedClasses: ["HTMLCanvas"]
  69. }),
  70. smalltalk.Tweet);
  71. smalltalk.addMethod(
  72. smalltalk.method({
  73. selector: "openAt:with:",
  74. category: 'not yet classified',
  75. fn: function (tr,aJson){
  76. var self=this;
  77. var tweet;
  78. return smalltalk.withContext(function($ctx1) {
  79. var $1;
  80. tweet=self._new();
  81. _st(tweet)._json_(aJson);
  82. _st(tweet)._renderOn_(tr);
  83. $1=tr;
  84. return $1;
  85. }, function($ctx1) {$ctx1.fill(self,"openAt:with:",{tr:tr,aJson:aJson,tweet:tweet},smalltalk.Tweet.klass)})},
  86. args: ["tr", "aJson"],
  87. source: "openAt: tr with: aJson\x0a| tweet |\x0atweet := self new.\x0atweet json: aJson.\x0atweet renderOn: tr.\x0a^tr",
  88. messageSends: ["new", "json:", "renderOn:"],
  89. referencedClasses: []
  90. }),
  91. smalltalk.Tweet.klass);
  92. smalltalk.addClass('TwitterSearch', smalltalk.Object, [], 'TwitterWall');
  93. smalltalk.addMethod(
  94. smalltalk.method({
  95. selector: "query",
  96. category: 'not yet classified',
  97. fn: function (){
  98. var self=this;
  99. var result,queryString;
  100. return smalltalk.withContext(function($ctx1) {
  101. queryString=_st(_st("#searchQuery"._asJQuery())._val())._replace_with_("#","%23");
  102. result=_st(jQuery)._ajax_options_("http://search.twitter.com/search.json?rpp=5&q=".__comma(queryString),smalltalk.HashedCollection._from_(["type".__minus_gt("GET"),"success".__minus_gt((function(tmp){
  103. return smalltalk.withContext(function($ctx2) {
  104. return self._success_(_st(tmp)._results());
  105. }, function($ctx2) {$ctx2.fillBlock({tmp:tmp},$ctx1)})})),"error".__minus_gt((function(){
  106. return smalltalk.withContext(function($ctx2) {
  107. return _st(window)._alert_("error");
  108. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})),"dataType".__minus_gt("jsonp")]));
  109. return self}, function($ctx1) {$ctx1.fill(self,"query",{result:result,queryString:queryString},smalltalk.TwitterSearch)})},
  110. args: [],
  111. source: "query\x0a| result queryString |\x0aqueryString := ('#searchQuery' asJQuery val) replace: '#' with: '%23'.\x0aresult := jQuery \x0a\x09\x09\x09ajax: 'http://search.twitter.com/search.json?rpp=5&q=', queryString\x0a\x09\x09\x09options: #{\x0a\x09\x09\x09\x09'type' -> 'GET'.\x0a\x09\x09\x09\x09'success' -> [ :tmp | self success: (tmp results)].\x0a\x09\x09\x09\x09'error' -> [window alert: 'error'].\x0a\x09\x09\x09\x09'dataType' -> 'jsonp'\x0a\x09\x09\x09}.",
  112. messageSends: ["replace:with:", "val", "asJQuery", "ajax:options:", ",", "->", "success:", "results", "alert:"],
  113. referencedClasses: []
  114. }),
  115. smalltalk.TwitterSearch);
  116. smalltalk.addMethod(
  117. smalltalk.method({
  118. selector: "success:",
  119. category: 'not yet classified',
  120. fn: function (tweets){
  121. var self=this;
  122. var playground,table,tr;
  123. function $Tweet(){return smalltalk.Tweet||(typeof Tweet=="undefined"?nil:Tweet)}
  124. return smalltalk.withContext(function($ctx1) {
  125. playground="#playground"._asJQuery();
  126. _st(playground)._empty();
  127. _st((function(html){
  128. return smalltalk.withContext(function($ctx2) {
  129. table=_st(html)._table();
  130. table;
  131. _st(_st(table)._element())._id_("twitterwall");
  132. return _st(tweets)._do_((function(tweet){
  133. return smalltalk.withContext(function($ctx3) {
  134. tr=_st(html)._tr();
  135. tr;
  136. _st(table)._append_(tr);
  137. return _st($Tweet())._openAt_with_(tr,tweet);
  138. }, function($ctx3) {$ctx3.fillBlock({tweet:tweet},$ctx2)})}));
  139. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}))._appendToJQuery_(playground);
  140. return self}, function($ctx1) {$ctx1.fill(self,"success:",{tweets:tweets,playground:playground,table:table,tr:tr},smalltalk.TwitterSearch)})},
  141. args: ["tweets"],
  142. source: "success: tweets\x0a| playground table tr |\x0aplayground := '#playground' asJQuery.\x0aplayground empty.\x0a [:html | \x0a\x09table := html table.\x0a\x09table element id: 'twitterwall'.\x0a\x0a\x09tweets do: [ :tweet | \x0a \x09 tr := html tr.\x0a\x09 table append: tr.\x0a \x09 Tweet openAt: tr with: tweet\x0a ]\x0a] appendToJQuery: playground.",
  143. messageSends: ["asJQuery", "empty", "appendToJQuery:", "table", "id:", "element", "do:", "tr", "append:", "openAt:with:"],
  144. referencedClasses: ["Tweet"]
  145. }),
  146. smalltalk.TwitterSearch);