Platform-Browser.st 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Smalltalk createPackage: 'Platform-Browser'!
  2. (Smalltalk packageAt: 'Platform-Browser' ifAbsent: [ self error: 'Package not created: Platform-Browser' ]) imports: {'amber_core/Platform-Services'}!
  3. Object subclass: #BrowserPlatform
  4. instanceVariableNames: ''
  5. package: 'Platform-Browser'!
  6. !BrowserPlatform commentStamp!
  7. I am `Platform` service implementation for browser.!
  8. !BrowserPlatform methodsFor: 'accessing'!
  9. globals
  10. ^ window
  11. !
  12. newXhr
  13. XMLHttpRequest
  14. ifNotNil: [ ^ NativeFunction constructorOf: XMLHttpRequest ]
  15. ifNil: [ self error: 'XMLHttpRequest not available.' ]
  16. ! !
  17. !BrowserPlatform class methodsFor: 'testing'!
  18. initialize
  19. self isFeasible ifTrue: [ Platform registerIfNone: self new ]
  20. !
  21. isFeasible
  22. <inlineJS: 'return typeof window !!== "undefined"'>
  23. ! !
  24. Object subclass: #BrowserTerminal
  25. instanceVariableNames: ''
  26. package: 'Platform-Browser'!
  27. !BrowserTerminal commentStamp!
  28. I am `Terminal` service implementation for browser.!
  29. !BrowserTerminal methodsFor: 'actions'!
  30. alert: aString
  31. ^ window alert: aString
  32. !
  33. confirm: aString
  34. ^ window confirm: aString
  35. !
  36. prompt: aString
  37. ^ window prompt: aString
  38. !
  39. prompt: aString default: defaultString
  40. ^ window prompt: aString default: defaultString
  41. ! !
  42. !BrowserTerminal class methodsFor: 'testing'!
  43. initialize
  44. self isFeasible ifTrue: [ Terminal registerIfNone: self new ]
  45. !
  46. isFeasible
  47. <inlineJS: 'return typeof window !!== "undefined"'>
  48. ! !
  49. !Object methodsFor: '*Platform-Browser'!
  50. postMessageTo: aFrame
  51. ^ self postMessageTo: aFrame origin: '*'
  52. !
  53. postMessageTo: aFrame origin: aString
  54. <inlineJS: 'return aFrame.postMessage(self, aString)'>
  55. ! !