2
0

Platform-Browser.st 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. prompt: aString
  28. ^ window prompt: aString
  29. !
  30. prompt: aString default: defaultString
  31. ^ window prompt: aString default: defaultString
  32. ! !
  33. !BrowserInterface methodsFor: 'testing'!
  34. isAvailable
  35. <return typeof window !!== "undefined" && typeof jQuery !!== "undefined">
  36. ! !
  37. !Object methodsFor: '*Platform-Browser'!
  38. postMessageTo: aFrame
  39. ^ self postMessageTo: aFrame origin: '*'
  40. !
  41. postMessageTo: aFrame origin: aString
  42. <return aFrame.postMessage(self, aString)>
  43. ! !