Platform-Browser.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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('BrowserInterface', $globals.Object, [], 'Platform-Browser');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.BrowserInterface.comment="I am platform interface class that tries to use window and jQuery; that is, one for browser environment.\x0a\x0a## API\x0a\x0a self isAvailable. \x22true if window and jQuery exist\x22.\x0a\x0a self alert: 'Hey, there is a problem'.\x0a self confirm: 'Affirmative?'.\x0a self prompt: 'Your name:'.\x0a\x0a self ajax: #{\x0a 'url' -> '/patch.js'. 'type' -> 'GET'. dataType->'script'\x0a }.";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "ajax:",
  13. protocol: 'actions',
  14. fn: function (anObject){
  15. var self=this;
  16. function $JQuery(){return $globals.JQuery||(typeof JQuery=="undefined"?nil:JQuery)}
  17. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  18. return $core.withContext(function($ctx1) {
  19. //>>excludeEnd("ctx");
  20. var $1,$receiver;
  21. if(($receiver = $JQuery()) == null || $receiver.isNil){
  22. $1=self._error_("JQuery wrapper not loaded, cannot do AJAX.");
  23. } else {
  24. $1=$recv($recv($JQuery())._current())._ajax_(anObject);
  25. };
  26. return $1;
  27. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  28. }, function($ctx1) {$ctx1.fill(self,"ajax:",{anObject:anObject},$globals.BrowserInterface)});
  29. //>>excludeEnd("ctx");
  30. },
  31. //>>excludeStart("ide", pragmas.excludeIdeData);
  32. args: ["anObject"],
  33. source: "ajax: anObject\x0a\x09^ JQuery\x0a\x09\x09ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]\x0a\x09\x09ifNotNil: [ JQuery current ajax: anObject ]",
  34. referencedClasses: ["JQuery"],
  35. //>>excludeEnd("ide");
  36. messageSends: ["ifNil:ifNotNil:", "error:", "ajax:", "current"]
  37. }),
  38. $globals.BrowserInterface);
  39. $core.addMethod(
  40. $core.method({
  41. selector: "alert:",
  42. protocol: 'actions',
  43. fn: function (aString){
  44. var self=this;
  45. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  46. return $core.withContext(function($ctx1) {
  47. //>>excludeEnd("ctx");
  48. var $1;
  49. $1=$recv(window)._alert_(aString);
  50. return $1;
  51. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  52. }, function($ctx1) {$ctx1.fill(self,"alert:",{aString:aString},$globals.BrowserInterface)});
  53. //>>excludeEnd("ctx");
  54. },
  55. //>>excludeStart("ide", pragmas.excludeIdeData);
  56. args: ["aString"],
  57. source: "alert: aString\x0a\x09^ window alert: aString",
  58. referencedClasses: [],
  59. //>>excludeEnd("ide");
  60. messageSends: ["alert:"]
  61. }),
  62. $globals.BrowserInterface);
  63. $core.addMethod(
  64. $core.method({
  65. selector: "confirm:",
  66. protocol: 'actions',
  67. fn: function (aString){
  68. var self=this;
  69. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  70. return $core.withContext(function($ctx1) {
  71. //>>excludeEnd("ctx");
  72. var $1;
  73. $1=$recv(window)._confirm_(aString);
  74. return $1;
  75. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  76. }, function($ctx1) {$ctx1.fill(self,"confirm:",{aString:aString},$globals.BrowserInterface)});
  77. //>>excludeEnd("ctx");
  78. },
  79. //>>excludeStart("ide", pragmas.excludeIdeData);
  80. args: ["aString"],
  81. source: "confirm: aString\x0a\x09^ window confirm: aString",
  82. referencedClasses: [],
  83. //>>excludeEnd("ide");
  84. messageSends: ["confirm:"]
  85. }),
  86. $globals.BrowserInterface);
  87. $core.addMethod(
  88. $core.method({
  89. selector: "isAvailable",
  90. protocol: 'testing',
  91. fn: function (){
  92. var self=this;
  93. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  94. return $core.withContext(function($ctx1) {
  95. //>>excludeEnd("ctx");
  96. return typeof window !== "undefined" && typeof jQuery !== "undefined";
  97. return self;
  98. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  99. }, function($ctx1) {$ctx1.fill(self,"isAvailable",{},$globals.BrowserInterface)});
  100. //>>excludeEnd("ctx");
  101. },
  102. //>>excludeStart("ide", pragmas.excludeIdeData);
  103. args: [],
  104. source: "isAvailable\x0a<return typeof window !== \x22undefined\x22 && typeof jQuery !== \x22undefined\x22>",
  105. referencedClasses: [],
  106. //>>excludeEnd("ide");
  107. messageSends: []
  108. }),
  109. $globals.BrowserInterface);
  110. $core.addMethod(
  111. $core.method({
  112. selector: "prompt:",
  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. var $1;
  120. $1=$recv(window)._prompt_(aString);
  121. return $1;
  122. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  123. }, function($ctx1) {$ctx1.fill(self,"prompt:",{aString:aString},$globals.BrowserInterface)});
  124. //>>excludeEnd("ctx");
  125. },
  126. //>>excludeStart("ide", pragmas.excludeIdeData);
  127. args: ["aString"],
  128. source: "prompt: aString\x0a\x09^ window prompt: aString",
  129. referencedClasses: [],
  130. //>>excludeEnd("ide");
  131. messageSends: ["prompt:"]
  132. }),
  133. $globals.BrowserInterface);
  134. $core.addMethod(
  135. $core.method({
  136. selector: "prompt:default:",
  137. protocol: 'actions',
  138. fn: function (aString,defaultString){
  139. var self=this;
  140. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  141. return $core.withContext(function($ctx1) {
  142. //>>excludeEnd("ctx");
  143. var $1;
  144. $1=$recv(window)._prompt_default_(aString,defaultString);
  145. return $1;
  146. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  147. }, function($ctx1) {$ctx1.fill(self,"prompt:default:",{aString:aString,defaultString:defaultString},$globals.BrowserInterface)});
  148. //>>excludeEnd("ctx");
  149. },
  150. //>>excludeStart("ide", pragmas.excludeIdeData);
  151. args: ["aString", "defaultString"],
  152. source: "prompt: aString default: defaultString\x0a\x09^ window prompt: aString default: defaultString",
  153. referencedClasses: [],
  154. //>>excludeEnd("ide");
  155. messageSends: ["prompt:default:"]
  156. }),
  157. $globals.BrowserInterface);
  158. $core.addMethod(
  159. $core.method({
  160. selector: "postMessageTo:",
  161. protocol: '*Platform-Browser',
  162. fn: function (aFrame){
  163. var self=this;
  164. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  165. return $core.withContext(function($ctx1) {
  166. //>>excludeEnd("ctx");
  167. var $1;
  168. $1=self._postMessageTo_origin_(aFrame,"*");
  169. return $1;
  170. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  171. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:",{aFrame:aFrame},$globals.Object)});
  172. //>>excludeEnd("ctx");
  173. },
  174. //>>excludeStart("ide", pragmas.excludeIdeData);
  175. args: ["aFrame"],
  176. source: "postMessageTo: aFrame\x0a^ self postMessageTo: aFrame origin: '*'",
  177. referencedClasses: [],
  178. //>>excludeEnd("ide");
  179. messageSends: ["postMessageTo:origin:"]
  180. }),
  181. $globals.Object);
  182. $core.addMethod(
  183. $core.method({
  184. selector: "postMessageTo:origin:",
  185. protocol: '*Platform-Browser',
  186. fn: function (aFrame,aString){
  187. var self=this;
  188. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  189. return $core.withContext(function($ctx1) {
  190. //>>excludeEnd("ctx");
  191. return aFrame.postMessage(self, aString);
  192. return self;
  193. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  194. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:origin:",{aFrame:aFrame,aString:aString},$globals.Object)});
  195. //>>excludeEnd("ctx");
  196. },
  197. //>>excludeStart("ide", pragmas.excludeIdeData);
  198. args: ["aFrame", "aString"],
  199. source: "postMessageTo: aFrame origin: aString\x0a<return aFrame.postMessage(self, aString)>",
  200. referencedClasses: [],
  201. //>>excludeEnd("ide");
  202. messageSends: []
  203. }),
  204. $globals.Object);
  205. });