1
0

Platform-Browser.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!("nilAsValue" in $boot))$boot.nilAsValue=$boot.nilAsReceiver;
  3. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. $core.addPackage("Platform-Browser");
  5. $core.packages["Platform-Browser"].innerEval = function (expr) { return eval(expr); };
  6. $core.packages["Platform-Browser"].transport = {"type":"amd","amdNamespace":"amber_core"};
  7. $core.addClass("BrowserPlatform", $globals.Object, [], "Platform-Browser");
  8. //>>excludeStart("ide", pragmas.excludeIdeData);
  9. $globals.BrowserPlatform.comment="I am `Platform` service implementation for browser.";
  10. //>>excludeEnd("ide");
  11. $core.addMethod(
  12. $core.method({
  13. selector: "globals",
  14. protocol: "accessing",
  15. fn: function (){
  16. var self=this,$self=this;
  17. return window;
  18. },
  19. //>>excludeStart("ide", pragmas.excludeIdeData);
  20. args: [],
  21. source: "globals\x0a\x09^ window",
  22. referencedClasses: [],
  23. //>>excludeEnd("ide");
  24. messageSends: []
  25. }),
  26. $globals.BrowserPlatform);
  27. $core.addMethod(
  28. $core.method({
  29. selector: "newXhr",
  30. protocol: "accessing",
  31. fn: function (){
  32. var self=this,$self=this;
  33. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  34. return $core.withContext(function($ctx1) {
  35. //>>excludeEnd("ctx");
  36. var $receiver;
  37. if(($receiver = $globals.XMLHttpRequest) == null || $receiver.a$nil){
  38. $self._error_("XMLHttpRequest not available.");
  39. } else {
  40. return $recv($globals.NativeFunction)._constructorOf_($globals.XMLHttpRequest);
  41. }
  42. return self;
  43. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  44. }, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.BrowserPlatform)});
  45. //>>excludeEnd("ctx");
  46. },
  47. //>>excludeStart("ide", pragmas.excludeIdeData);
  48. args: [],
  49. source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ NativeFunction constructorOf: XMLHttpRequest ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
  50. referencedClasses: ["XMLHttpRequest", "NativeFunction"],
  51. //>>excludeEnd("ide");
  52. messageSends: ["ifNotNil:ifNil:", "constructorOf:", "error:"]
  53. }),
  54. $globals.BrowserPlatform);
  55. $core.addMethod(
  56. $core.method({
  57. selector: "initialize",
  58. protocol: "testing",
  59. fn: function (){
  60. var self=this,$self=this;
  61. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  62. return $core.withContext(function($ctx1) {
  63. //>>excludeEnd("ctx");
  64. var $1;
  65. $1=$self._isFeasible();
  66. if($core.assert($1)){
  67. $recv($globals.Platform)._registerIfNone_($self._new());
  68. }
  69. return self;
  70. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  71. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.BrowserPlatform.a$cls)});
  72. //>>excludeEnd("ctx");
  73. },
  74. //>>excludeStart("ide", pragmas.excludeIdeData);
  75. args: [],
  76. source: "initialize\x0a\x09self isFeasible ifTrue: [ Platform registerIfNone: self new ]",
  77. referencedClasses: ["Platform"],
  78. //>>excludeEnd("ide");
  79. messageSends: ["ifTrue:", "isFeasible", "registerIfNone:", "new"]
  80. }),
  81. $globals.BrowserPlatform.a$cls);
  82. $core.addMethod(
  83. $core.method({
  84. selector: "isFeasible",
  85. protocol: "testing",
  86. fn: function (){
  87. var self=this,$self=this;
  88. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  89. return $core.withContext(function($ctx1) {
  90. //>>excludeEnd("ctx");
  91. return typeof window !== "undefined";
  92. return self;
  93. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  94. }, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.BrowserPlatform.a$cls)});
  95. //>>excludeEnd("ctx");
  96. },
  97. //>>excludeStart("ide", pragmas.excludeIdeData);
  98. args: [],
  99. source: "isFeasible\x0a<inlineJS: 'return typeof window !== \x22undefined\x22'>",
  100. referencedClasses: [],
  101. //>>excludeEnd("ide");
  102. messageSends: []
  103. }),
  104. $globals.BrowserPlatform.a$cls);
  105. $core.addClass("BrowserTerminal", $globals.Object, [], "Platform-Browser");
  106. //>>excludeStart("ide", pragmas.excludeIdeData);
  107. $globals.BrowserTerminal.comment="I am `Terminal` service implementation for browser.";
  108. //>>excludeEnd("ide");
  109. $core.addMethod(
  110. $core.method({
  111. selector: "alert:",
  112. protocol: "actions",
  113. fn: function (aString){
  114. var self=this,$self=this;
  115. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  116. return $core.withContext(function($ctx1) {
  117. //>>excludeEnd("ctx");
  118. return $recv(window)._alert_(aString);
  119. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  120. }, function($ctx1) {$ctx1.fill(self,"alert:",{aString:aString},$globals.BrowserTerminal)});
  121. //>>excludeEnd("ctx");
  122. },
  123. //>>excludeStart("ide", pragmas.excludeIdeData);
  124. args: ["aString"],
  125. source: "alert: aString\x0a\x09^ window alert: aString",
  126. referencedClasses: [],
  127. //>>excludeEnd("ide");
  128. messageSends: ["alert:"]
  129. }),
  130. $globals.BrowserTerminal);
  131. $core.addMethod(
  132. $core.method({
  133. selector: "confirm:",
  134. protocol: "actions",
  135. fn: function (aString){
  136. var self=this,$self=this;
  137. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  138. return $core.withContext(function($ctx1) {
  139. //>>excludeEnd("ctx");
  140. return $recv(window)._confirm_(aString);
  141. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  142. }, function($ctx1) {$ctx1.fill(self,"confirm:",{aString:aString},$globals.BrowserTerminal)});
  143. //>>excludeEnd("ctx");
  144. },
  145. //>>excludeStart("ide", pragmas.excludeIdeData);
  146. args: ["aString"],
  147. source: "confirm: aString\x0a\x09^ window confirm: aString",
  148. referencedClasses: [],
  149. //>>excludeEnd("ide");
  150. messageSends: ["confirm:"]
  151. }),
  152. $globals.BrowserTerminal);
  153. $core.addMethod(
  154. $core.method({
  155. selector: "prompt:",
  156. protocol: "actions",
  157. fn: function (aString){
  158. var self=this,$self=this;
  159. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  160. return $core.withContext(function($ctx1) {
  161. //>>excludeEnd("ctx");
  162. return $recv(window)._prompt_(aString);
  163. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  164. }, function($ctx1) {$ctx1.fill(self,"prompt:",{aString:aString},$globals.BrowserTerminal)});
  165. //>>excludeEnd("ctx");
  166. },
  167. //>>excludeStart("ide", pragmas.excludeIdeData);
  168. args: ["aString"],
  169. source: "prompt: aString\x0a\x09^ window prompt: aString",
  170. referencedClasses: [],
  171. //>>excludeEnd("ide");
  172. messageSends: ["prompt:"]
  173. }),
  174. $globals.BrowserTerminal);
  175. $core.addMethod(
  176. $core.method({
  177. selector: "prompt:default:",
  178. protocol: "actions",
  179. fn: function (aString,defaultString){
  180. var self=this,$self=this;
  181. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  182. return $core.withContext(function($ctx1) {
  183. //>>excludeEnd("ctx");
  184. return $recv(window)._prompt_default_(aString,defaultString);
  185. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  186. }, function($ctx1) {$ctx1.fill(self,"prompt:default:",{aString:aString,defaultString:defaultString},$globals.BrowserTerminal)});
  187. //>>excludeEnd("ctx");
  188. },
  189. //>>excludeStart("ide", pragmas.excludeIdeData);
  190. args: ["aString", "defaultString"],
  191. source: "prompt: aString default: defaultString\x0a\x09^ window prompt: aString default: defaultString",
  192. referencedClasses: [],
  193. //>>excludeEnd("ide");
  194. messageSends: ["prompt:default:"]
  195. }),
  196. $globals.BrowserTerminal);
  197. $core.addMethod(
  198. $core.method({
  199. selector: "initialize",
  200. protocol: "testing",
  201. fn: function (){
  202. var self=this,$self=this;
  203. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  204. return $core.withContext(function($ctx1) {
  205. //>>excludeEnd("ctx");
  206. var $1;
  207. $1=$self._isFeasible();
  208. if($core.assert($1)){
  209. $recv($globals.Terminal)._registerIfNone_($self._new());
  210. }
  211. return self;
  212. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  213. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.BrowserTerminal.a$cls)});
  214. //>>excludeEnd("ctx");
  215. },
  216. //>>excludeStart("ide", pragmas.excludeIdeData);
  217. args: [],
  218. source: "initialize\x0a\x09self isFeasible ifTrue: [ Terminal registerIfNone: self new ]",
  219. referencedClasses: ["Terminal"],
  220. //>>excludeEnd("ide");
  221. messageSends: ["ifTrue:", "isFeasible", "registerIfNone:", "new"]
  222. }),
  223. $globals.BrowserTerminal.a$cls);
  224. $core.addMethod(
  225. $core.method({
  226. selector: "isFeasible",
  227. protocol: "testing",
  228. fn: function (){
  229. var self=this,$self=this;
  230. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  231. return $core.withContext(function($ctx1) {
  232. //>>excludeEnd("ctx");
  233. return typeof window !== "undefined";
  234. return self;
  235. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  236. }, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.BrowserTerminal.a$cls)});
  237. //>>excludeEnd("ctx");
  238. },
  239. //>>excludeStart("ide", pragmas.excludeIdeData);
  240. args: [],
  241. source: "isFeasible\x0a<inlineJS: 'return typeof window !== \x22undefined\x22'>",
  242. referencedClasses: [],
  243. //>>excludeEnd("ide");
  244. messageSends: []
  245. }),
  246. $globals.BrowserTerminal.a$cls);
  247. $core.addMethod(
  248. $core.method({
  249. selector: "postMessageTo:",
  250. protocol: "*Platform-Browser",
  251. fn: function (aFrame){
  252. var self=this,$self=this;
  253. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  254. return $core.withContext(function($ctx1) {
  255. //>>excludeEnd("ctx");
  256. return $self._postMessageTo_origin_(aFrame,"*");
  257. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  258. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:",{aFrame:aFrame},$globals.Object)});
  259. //>>excludeEnd("ctx");
  260. },
  261. //>>excludeStart("ide", pragmas.excludeIdeData);
  262. args: ["aFrame"],
  263. source: "postMessageTo: aFrame\x0a^ self postMessageTo: aFrame origin: '*'",
  264. referencedClasses: [],
  265. //>>excludeEnd("ide");
  266. messageSends: ["postMessageTo:origin:"]
  267. }),
  268. $globals.Object);
  269. $core.addMethod(
  270. $core.method({
  271. selector: "postMessageTo:origin:",
  272. protocol: "*Platform-Browser",
  273. fn: function (aFrame,aString){
  274. var self=this,$self=this;
  275. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  276. return $core.withContext(function($ctx1) {
  277. //>>excludeEnd("ctx");
  278. return aFrame.postMessage(self, aString);
  279. return self;
  280. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  281. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:origin:",{aFrame:aFrame,aString:aString},$globals.Object)});
  282. //>>excludeEnd("ctx");
  283. },
  284. //>>excludeStart("ide", pragmas.excludeIdeData);
  285. args: ["aFrame", "aString"],
  286. source: "postMessageTo: aFrame origin: aString\x0a<inlineJS: 'return aFrame.postMessage(self, aString)'>",
  287. referencedClasses: [],
  288. //>>excludeEnd("ide");
  289. messageSends: []
  290. }),
  291. $globals.Object);
  292. });