2
0

Platform-Browser.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. function $XMLHttpRequest(){return $globals.XMLHttpRequest||(typeof XMLHttpRequest=="undefined"?nil:XMLHttpRequest)}
  33. function $NativeFunction(){return $globals.NativeFunction||(typeof NativeFunction=="undefined"?nil:NativeFunction)}
  34. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  35. return $core.withContext(function($ctx1) {
  36. //>>excludeEnd("ctx");
  37. var $receiver;
  38. if(($receiver = $XMLHttpRequest()) == null || $receiver.isNil){
  39. self._error_("XMLHttpRequest not available.");
  40. } else {
  41. return $recv($NativeFunction())._constructorOf_($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. function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
  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($Platform())._registerIfNone_(self._new());
  70. };
  71. return self;
  72. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  73. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.BrowserPlatform.klass)});
  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.klass);
  84. $core.addMethod(
  85. $core.method({
  86. selector: "isFeasible",
  87. protocol: 'testing',
  88. fn: function (){
  89. var 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.klass)});
  97. //>>excludeEnd("ctx");
  98. },
  99. //>>excludeStart("ide", pragmas.excludeIdeData);
  100. args: [],
  101. source: "isFeasible\x0a<return typeof window !== \x22undefined\x22>",
  102. referencedClasses: [],
  103. //>>excludeEnd("ide");
  104. messageSends: []
  105. }),
  106. $globals.BrowserPlatform.klass);
  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;
  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;
  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;
  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;
  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;
  205. function $Terminal(){return $globals.Terminal||(typeof Terminal=="undefined"?nil:Terminal)}
  206. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  207. return $core.withContext(function($ctx1) {
  208. //>>excludeEnd("ctx");
  209. var $1;
  210. $1=self._isFeasible();
  211. if($core.assert($1)){
  212. $recv($Terminal())._registerIfNone_(self._new());
  213. };
  214. return self;
  215. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  216. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.BrowserTerminal.klass)});
  217. //>>excludeEnd("ctx");
  218. },
  219. //>>excludeStart("ide", pragmas.excludeIdeData);
  220. args: [],
  221. source: "initialize\x0a\x09self isFeasible ifTrue: [ Terminal registerIfNone: self new ]",
  222. referencedClasses: ["Terminal"],
  223. //>>excludeEnd("ide");
  224. messageSends: ["ifTrue:", "isFeasible", "registerIfNone:", "new"]
  225. }),
  226. $globals.BrowserTerminal.klass);
  227. $core.addMethod(
  228. $core.method({
  229. selector: "isFeasible",
  230. protocol: 'testing',
  231. fn: function (){
  232. var self=this;
  233. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  234. return $core.withContext(function($ctx1) {
  235. //>>excludeEnd("ctx");
  236. return typeof window !== "undefined";
  237. return self;
  238. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  239. }, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.BrowserTerminal.klass)});
  240. //>>excludeEnd("ctx");
  241. },
  242. //>>excludeStart("ide", pragmas.excludeIdeData);
  243. args: [],
  244. source: "isFeasible\x0a<return typeof window !== \x22undefined\x22>",
  245. referencedClasses: [],
  246. //>>excludeEnd("ide");
  247. messageSends: []
  248. }),
  249. $globals.BrowserTerminal.klass);
  250. $core.addMethod(
  251. $core.method({
  252. selector: "postMessageTo:",
  253. protocol: '*Platform-Browser',
  254. fn: function (aFrame){
  255. var self=this;
  256. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  257. return $core.withContext(function($ctx1) {
  258. //>>excludeEnd("ctx");
  259. return self._postMessageTo_origin_(aFrame,"*");
  260. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  261. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:",{aFrame:aFrame},$globals.Object)});
  262. //>>excludeEnd("ctx");
  263. },
  264. //>>excludeStart("ide", pragmas.excludeIdeData);
  265. args: ["aFrame"],
  266. source: "postMessageTo: aFrame\x0a^ self postMessageTo: aFrame origin: '*'",
  267. referencedClasses: [],
  268. //>>excludeEnd("ide");
  269. messageSends: ["postMessageTo:origin:"]
  270. }),
  271. $globals.Object);
  272. $core.addMethod(
  273. $core.method({
  274. selector: "postMessageTo:origin:",
  275. protocol: '*Platform-Browser',
  276. fn: function (aFrame,aString){
  277. var self=this;
  278. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  279. return $core.withContext(function($ctx1) {
  280. //>>excludeEnd("ctx");
  281. return aFrame.postMessage(self, aString);
  282. return self;
  283. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  284. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:origin:",{aFrame:aFrame,aString:aString},$globals.Object)});
  285. //>>excludeEnd("ctx");
  286. },
  287. //>>excludeStart("ide", pragmas.excludeIdeData);
  288. args: ["aFrame", "aString"],
  289. source: "postMessageTo: aFrame origin: aString\x0a<return aFrame.postMessage(self, aString)>",
  290. referencedClasses: [],
  291. //>>excludeEnd("ide");
  292. messageSends: []
  293. }),
  294. $globals.Object);
  295. });