2
0

Platform-Browser.js 9.5 KB

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