2
0

Platform-Browser.st 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Smalltalk createPackage: 'Platform-Browser'!
  2. Object subclass: #BrowserInterface
  3. instanceVariableNames: ''
  4. package: 'Platform-Browser'!
  5. !BrowserInterface commentStamp!
  6. I am platform interface class that tries to use window and jQuery; that is, one for browser environment.
  7. ## API
  8. self isAvailable. "true if window and jQuery exist".
  9. self alert: 'Hey, there is a problem'.
  10. self confirm: 'Affirmative?'.
  11. self prompt: 'Your name:'.
  12. self ajax: #{
  13. 'url' -> '/patch.js'. 'type' -> 'GET'. dataType->'script'
  14. }.!
  15. !BrowserInterface methodsFor: 'actions'!
  16. ajax: anObject
  17. ^ JQuery
  18. ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]
  19. ifNotNil: [ JQuery current ajax: anObject ]
  20. !
  21. alert: aString
  22. ^ window alert: aString
  23. !
  24. confirm: aString
  25. ^ window confirm: aString
  26. !
  27. newXhr
  28. ^ XMLHttpRequest new
  29. !
  30. prompt: aString
  31. ^ window prompt: aString
  32. !
  33. prompt: aString default: defaultString
  34. ^ window prompt: aString default: defaultString
  35. ! !
  36. !BrowserInterface methodsFor: 'testing'!
  37. isAvailable
  38. <return typeof window !!== "undefined" && typeof jQuery !!== "undefined">
  39. ! !
  40. !Object methodsFor: '*Platform-Browser'!
  41. postMessageTo: aFrame
  42. ^ self postMessageTo: aFrame origin: '*'
  43. !
  44. postMessageTo: aFrame origin: aString
  45. <return aFrame.postMessage(self, aString)>
  46. ! !