Platform-Browser.st 1.4 KB

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