1
0

TwitterWall.st 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Smalltalk current createPackage: 'TwitterWall' properties: #{}!
  2. Widget subclass: #Tweet
  3. instanceVariableNames: 'json'
  4. category: 'TwitterWall'!
  5. !Tweet methodsFor: 'not yet classified'!
  6. renderOn: tr
  7. | tdUser tdMessage img a pMessage pDate |
  8. tdUser := HTMLCanvas new td.
  9. tdUser element id: 'user'.
  10. tdMessage := HTMLCanvas new td.
  11. tdMessage element id: 'messageBox'.
  12. tr append: tdUser.
  13. tr append: tdMessage.
  14. img := HTMLCanvas new img src: (json at: 'profile_image_url') .
  15. img element title: (json at: 'from_user').
  16. img element longDesc: ('http://twitter.com/', (json at: 'from_user')).
  17. a := HTMLCanvas new a href: ('http://twitter.com/', (json at: 'from_user')).
  18. a append: img.
  19. tdUser append: a.
  20. pMessage := HTMLCanvas new p.
  21. pMessage element id: 'message'.
  22. pMessage append: (json at: 'text').
  23. tdMessage append: pMessage.
  24. pDate := HTMLCanvas new p.
  25. pDate element id: 'date'.
  26. pDate append: (json at: 'created_at').
  27. tdMessage append: pDate.
  28. !
  29. json
  30. ^json
  31. !
  32. json: aJson
  33. json := aJson
  34. ! !
  35. !Tweet class methodsFor: 'not yet classified'!
  36. openAt: tr with: aJson
  37. | tweet |
  38. tweet := self new.
  39. tweet json: aJson.
  40. tweet renderOn: tr.
  41. ^tr
  42. ! !
  43. Object subclass: #TwitterSearch
  44. instanceVariableNames: 'queryString'
  45. category: 'TwitterWall'!
  46. !TwitterSearch methodsFor: 'not yet classified'!
  47. success: tweets
  48. | playground table tr |
  49. playground := '#playground' asJQuery.
  50. playground empty.
  51. [:html |
  52. table := html table.
  53. table element id: 'twitterwall'.
  54. tweets do: [ :tweet |
  55. tr := html tr.
  56. table append: tr.
  57. Tweet openAt: tr with: tweet
  58. ]
  59. ] appendToJQuery: playground.
  60. !
  61. query
  62. | result queryString |
  63. queryString := ('#searchQuery' asJQuery val) replace: '#' with: '%23'.
  64. result := jQuery
  65. ajax: 'http://search.twitter.com/search.json?rpp=5&q=', queryString
  66. options: #{
  67. 'type' -> 'GET'.
  68. 'success' -> [ :tmp | self success: (tmp results)].
  69. 'error' -> [window alert: 'error'].
  70. 'dataType' -> 'jsonp'
  71. }.
  72. ! !