Platform-Browser.st 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Smalltalk createPackage: 'Platform-Browser'!
  2. (Smalltalk packageAt: 'Platform-Browser') imports: {'amber-contrib-jquery/Wrappers-JQuery'}!
  3. Object subclass: #BrowserInterface
  4. instanceVariableNames: ''
  5. package: 'Platform-Browser'!
  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 current 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 methodsFor: '*Platform-Browser'!
  37. postMessageTo: aFrame
  38. ^ self postMessageTo: aFrame origin: '*'
  39. !
  40. postMessageTo: aFrame origin: aString
  41. <return aFrame.postMessage(self, aString)>
  42. ! !