Wrappers-JQuery.st 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. Smalltalk createPackage: 'Wrappers-JQuery'!
  2. (Smalltalk packageAt: 'Wrappers-JQuery') imports: {'jQuery' -> 'jquery'}!
  3. Object subclass: #BrowserInterface
  4. instanceVariableNames: ''
  5. package: 'Wrappers-JQuery'!
  6. !BrowserInterface commentStamp!
  7. I am platform interface class that tries to use window and jQuery; that is, one for browser environment.
  8. ## API
  9. self isAvailable. "true if window and jQuery exist".
  10. self alert: 'Hey, there is a problem'.
  11. self confirm: 'Affirmative?'.
  12. self prompt: 'Your name:'.
  13. self ajax: #{
  14. 'url' -> '/patch.js'. 'type' -> 'GET'. dataType->'script'
  15. }.!
  16. !BrowserInterface methodsFor: 'actions'!
  17. ajax: anObject
  18. ^ jQuery ajax: anObject
  19. !
  20. alert: aString
  21. ^ window alert: aString
  22. !
  23. confirm: aString
  24. ^ window confirm: aString
  25. !
  26. prompt: aString
  27. ^ window prompt: aString
  28. !
  29. prompt: aString default: defaultString
  30. ^ window prompt: aString default: defaultString
  31. ! !
  32. !BrowserInterface methodsFor: 'testing'!
  33. isAvailable
  34. <return typeof window !!== "undefined" && typeof jQuery !!== "undefined">
  35. ! !
  36. Object subclass: #JQuery
  37. instanceVariableNames: ''
  38. package: 'Wrappers-JQuery'!
  39. !JQuery class methodsFor: 'initialization'!
  40. current
  41. ^ jQuery
  42. !
  43. initialize
  44. "Allow JS method calls for the jQuery object.
  45. See boot.js DNU handling."
  46. Smalltalk optOut: jQuery
  47. ! !
  48. !BlockClosure methodsFor: '*Wrappers-JQuery'!
  49. asJQuery
  50. ^ {self} asJQuery
  51. !
  52. asJQueryInContext: aContext
  53. ^ {self} asJQueryInContext: aContext
  54. ! !
  55. !JSObjectProxy methodsFor: '*Wrappers-JQuery'!
  56. asJQuery
  57. <return jQuery(self['@jsObject'])>
  58. !
  59. asJQueryInContext: aContext
  60. <return jQuery(self['@jsObject'], aContext)>
  61. ! !
  62. !Object methodsFor: '*Wrappers-JQuery'!
  63. asJQuery
  64. <return jQuery(self)>
  65. !
  66. asJQueryInContext: aContext
  67. <return jQuery(self, aContext)>
  68. ! !
  69. !String methodsFor: '*Wrappers-JQuery'!
  70. asJQuery
  71. <return jQuery(String(self))>
  72. !
  73. asJQueryInContext: aContext
  74. <return jQuery(String(self), aContext)>
  75. ! !