Platform-Browser.js 9.4 KB

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