Platform-Browser.js 9.8 KB

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