Platform-Browser.st 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. ! !