TwitterWall.deploy.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 smalltalk.withContext(function($ctx1) {
  9. var $1;
  10. $1=self["@json"];
  11. return $1;
  12. }, function($ctx1) {$ctx1.fill(self,"json",{},smalltalk.Tweet)})},
  13. messageSends: []}),
  14. smalltalk.Tweet);
  15. smalltalk.addMethod(
  16. smalltalk.method({
  17. selector: "json:",
  18. fn: function (aJson){
  19. var self=this;
  20. return smalltalk.withContext(function($ctx1) {
  21. self["@json"]=aJson;
  22. return self}, function($ctx1) {$ctx1.fill(self,"json:",{aJson:aJson},smalltalk.Tweet)})},
  23. messageSends: []}),
  24. smalltalk.Tweet);
  25. smalltalk.addMethod(
  26. smalltalk.method({
  27. selector: "renderOn:",
  28. fn: function (tr){
  29. var self=this;
  30. var tdUser,tdMessage,img,a,pMessage,pDate;
  31. function $HTMLCanvas(){return smalltalk.HTMLCanvas||(typeof HTMLCanvas=="undefined"?nil:HTMLCanvas)}
  32. return smalltalk.withContext(function($ctx1) {
  33. tdUser=_st(_st($HTMLCanvas())._new())._td();
  34. _st(_st(tdUser)._element())._id_("user");
  35. tdMessage=_st(_st($HTMLCanvas())._new())._td();
  36. _st(_st(tdMessage)._element())._id_("messageBox");
  37. _st(tr)._append_(tdUser);
  38. _st(tr)._append_(tdMessage);
  39. img=_st(_st(_st($HTMLCanvas())._new())._img())._src_(_st(self["@json"])._at_("profile_image_url"));
  40. _st(_st(img)._element())._title_(_st(self["@json"])._at_("from_user"));
  41. _st(_st(img)._element())._longDesc_("http://twitter.com/".__comma(_st(self["@json"])._at_("from_user")));
  42. a=_st(_st(_st($HTMLCanvas())._new())._a())._href_("http://twitter.com/".__comma(_st(self["@json"])._at_("from_user")));
  43. _st(a)._append_(img);
  44. _st(tdUser)._append_(a);
  45. pMessage=_st(_st($HTMLCanvas())._new())._p();
  46. _st(_st(pMessage)._element())._id_("message");
  47. _st(pMessage)._append_(_st(self["@json"])._at_("text"));
  48. _st(tdMessage)._append_(pMessage);
  49. pDate=_st(_st($HTMLCanvas())._new())._p();
  50. _st(_st(pDate)._element())._id_("date");
  51. _st(pDate)._append_(_st(self["@json"])._at_("created_at"));
  52. _st(tdMessage)._append_(pDate);
  53. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{tr:tr,tdUser:tdUser,tdMessage:tdMessage,img:img,a:a,pMessage:pMessage,pDate:pDate},smalltalk.Tweet)})},
  54. messageSends: ["td", "new", "id:", "element", "append:", "src:", "at:", "img", "title:", "longDesc:", ",", "href:", "a", "p"]}),
  55. smalltalk.Tweet);
  56. smalltalk.addMethod(
  57. smalltalk.method({
  58. selector: "openAt:with:",
  59. fn: function (tr,aJson){
  60. var self=this;
  61. var tweet;
  62. return smalltalk.withContext(function($ctx1) {
  63. var $1;
  64. tweet=self._new();
  65. _st(tweet)._json_(aJson);
  66. _st(tweet)._renderOn_(tr);
  67. $1=tr;
  68. return $1;
  69. }, function($ctx1) {$ctx1.fill(self,"openAt:with:",{tr:tr,aJson:aJson,tweet:tweet},smalltalk.Tweet.klass)})},
  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,queryString;
  79. return smalltalk.withContext(function($ctx1) {
  80. queryString=_st(_st("#searchQuery"._asJQuery())._val())._replace_with_("#","%23");
  81. 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){
  82. return smalltalk.withContext(function($ctx2) {
  83. return self._success_(_st(tmp)._results());
  84. }, function($ctx2) {$ctx2.fillBlock({tmp:tmp},$ctx1)})})),"error".__minus_gt((function(){
  85. return smalltalk.withContext(function($ctx2) {
  86. return _st(window)._alert_("error");
  87. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})),"dataType".__minus_gt("jsonp")]));
  88. return self}, function($ctx1) {$ctx1.fill(self,"query",{result:result,queryString:queryString},smalltalk.TwitterSearch)})},
  89. messageSends: ["replace:with:", "val", "asJQuery", "ajax:options:", ",", "->", "success:", "results", "alert:"]}),
  90. smalltalk.TwitterSearch);
  91. smalltalk.addMethod(
  92. smalltalk.method({
  93. selector: "success:",
  94. fn: function (tweets){
  95. var self=this;
  96. var playground,table,tr;
  97. function $Tweet(){return smalltalk.Tweet||(typeof Tweet=="undefined"?nil:Tweet)}
  98. return smalltalk.withContext(function($ctx1) {
  99. playground="#playground"._asJQuery();
  100. _st(playground)._empty();
  101. _st((function(html){
  102. return smalltalk.withContext(function($ctx2) {
  103. table=_st(html)._table();
  104. table;
  105. _st(_st(table)._element())._id_("twitterwall");
  106. return _st(tweets)._do_((function(tweet){
  107. return smalltalk.withContext(function($ctx3) {
  108. tr=_st(html)._tr();
  109. tr;
  110. _st(table)._append_(tr);
  111. return _st($Tweet())._openAt_with_(tr,tweet);
  112. }, function($ctx3) {$ctx3.fillBlock({tweet:tweet},$ctx2)})}));
  113. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}))._appendToJQuery_(playground);
  114. return self}, function($ctx1) {$ctx1.fill(self,"success:",{tweets:tweets,playground:playground,table:table,tr:tr},smalltalk.TwitterSearch)})},
  115. messageSends: ["asJQuery", "empty", "appendToJQuery:", "table", "id:", "element", "do:", "tr", "append:", "openAt:with:"]}),
  116. smalltalk.TwitterSearch);