Platform-Browser.js 9.7 KB

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