Platform-Browser.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. define("amber_core/Platform-Browser", ["amber/boot"
  2. //>>excludeStart("imports", pragmas.excludeImports);
  3. , "amber-contrib-jquery/Wrappers-JQuery"
  4. //>>excludeEnd("imports");
  5. , "amber_core/Kernel-Objects"], function($boot
  6. //>>excludeStart("imports", pragmas.excludeImports);
  7. //>>excludeEnd("imports");
  8. ){
  9. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  10. $core.addPackage('Platform-Browser');
  11. $core.packages["Platform-Browser"].innerEval = function (expr) { return eval(expr); };
  12. $core.packages["Platform-Browser"].imports = ["amber-contrib-jquery/Wrappers-JQuery"];
  13. $core.packages["Platform-Browser"].transport = {"type":"amd","amdNamespace":"amber_core"};
  14. $core.addClass('BrowserInterface', $globals.Object, [], 'Platform-Browser');
  15. //>>excludeStart("ide", pragmas.excludeIdeData);
  16. $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 }.";
  17. //>>excludeEnd("ide");
  18. $core.addMethod(
  19. $core.method({
  20. selector: "ajax:",
  21. protocol: 'actions',
  22. fn: function (anObject){
  23. var self=this;
  24. function $JQuery(){return $globals.JQuery||(typeof JQuery=="undefined"?nil:JQuery)}
  25. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  26. return $core.withContext(function($ctx1) {
  27. //>>excludeEnd("ctx");
  28. var $1;
  29. $1=$recv($recv($JQuery())._current())._ajax_(anObject);
  30. return $1;
  31. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  32. }, function($ctx1) {$ctx1.fill(self,"ajax:",{anObject:anObject},$globals.BrowserInterface)});
  33. //>>excludeEnd("ctx");
  34. },
  35. //>>excludeStart("ide", pragmas.excludeIdeData);
  36. args: ["anObject"],
  37. source: "ajax: anObject\x0a\x09^ JQuery current ajax: anObject",
  38. referencedClasses: ["JQuery"],
  39. //>>excludeEnd("ide");
  40. messageSends: ["ajax:", "current"]
  41. }),
  42. $globals.BrowserInterface);
  43. $core.addMethod(
  44. $core.method({
  45. selector: "alert:",
  46. protocol: 'actions',
  47. fn: function (aString){
  48. var self=this;
  49. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  50. return $core.withContext(function($ctx1) {
  51. //>>excludeEnd("ctx");
  52. var $1;
  53. $1=$recv(window)._alert_(aString);
  54. return $1;
  55. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  56. }, function($ctx1) {$ctx1.fill(self,"alert:",{aString:aString},$globals.BrowserInterface)});
  57. //>>excludeEnd("ctx");
  58. },
  59. //>>excludeStart("ide", pragmas.excludeIdeData);
  60. args: ["aString"],
  61. source: "alert: aString\x0a\x09^ window alert: aString",
  62. referencedClasses: [],
  63. //>>excludeEnd("ide");
  64. messageSends: ["alert:"]
  65. }),
  66. $globals.BrowserInterface);
  67. $core.addMethod(
  68. $core.method({
  69. selector: "confirm:",
  70. protocol: 'actions',
  71. fn: function (aString){
  72. var self=this;
  73. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  74. return $core.withContext(function($ctx1) {
  75. //>>excludeEnd("ctx");
  76. var $1;
  77. $1=$recv(window)._confirm_(aString);
  78. return $1;
  79. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  80. }, function($ctx1) {$ctx1.fill(self,"confirm:",{aString:aString},$globals.BrowserInterface)});
  81. //>>excludeEnd("ctx");
  82. },
  83. //>>excludeStart("ide", pragmas.excludeIdeData);
  84. args: ["aString"],
  85. source: "confirm: aString\x0a\x09^ window confirm: aString",
  86. referencedClasses: [],
  87. //>>excludeEnd("ide");
  88. messageSends: ["confirm:"]
  89. }),
  90. $globals.BrowserInterface);
  91. $core.addMethod(
  92. $core.method({
  93. selector: "isAvailable",
  94. protocol: 'testing',
  95. fn: function (){
  96. var self=this;
  97. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  98. return $core.withContext(function($ctx1) {
  99. //>>excludeEnd("ctx");
  100. return typeof window !== "undefined" && typeof jQuery !== "undefined";
  101. return self;
  102. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  103. }, function($ctx1) {$ctx1.fill(self,"isAvailable",{},$globals.BrowserInterface)});
  104. //>>excludeEnd("ctx");
  105. },
  106. //>>excludeStart("ide", pragmas.excludeIdeData);
  107. args: [],
  108. source: "isAvailable\x0a<return typeof window !== \x22undefined\x22 && typeof jQuery !== \x22undefined\x22>",
  109. referencedClasses: [],
  110. //>>excludeEnd("ide");
  111. messageSends: []
  112. }),
  113. $globals.BrowserInterface);
  114. $core.addMethod(
  115. $core.method({
  116. selector: "prompt:",
  117. protocol: 'actions',
  118. fn: function (aString){
  119. var self=this;
  120. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  121. return $core.withContext(function($ctx1) {
  122. //>>excludeEnd("ctx");
  123. var $1;
  124. $1=$recv(window)._prompt_(aString);
  125. return $1;
  126. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  127. }, function($ctx1) {$ctx1.fill(self,"prompt:",{aString:aString},$globals.BrowserInterface)});
  128. //>>excludeEnd("ctx");
  129. },
  130. //>>excludeStart("ide", pragmas.excludeIdeData);
  131. args: ["aString"],
  132. source: "prompt: aString\x0a\x09^ window prompt: aString",
  133. referencedClasses: [],
  134. //>>excludeEnd("ide");
  135. messageSends: ["prompt:"]
  136. }),
  137. $globals.BrowserInterface);
  138. $core.addMethod(
  139. $core.method({
  140. selector: "prompt:default:",
  141. protocol: 'actions',
  142. fn: function (aString,defaultString){
  143. var self=this;
  144. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  145. return $core.withContext(function($ctx1) {
  146. //>>excludeEnd("ctx");
  147. var $1;
  148. $1=$recv(window)._prompt_default_(aString,defaultString);
  149. return $1;
  150. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  151. }, function($ctx1) {$ctx1.fill(self,"prompt:default:",{aString:aString,defaultString:defaultString},$globals.BrowserInterface)});
  152. //>>excludeEnd("ctx");
  153. },
  154. //>>excludeStart("ide", pragmas.excludeIdeData);
  155. args: ["aString", "defaultString"],
  156. source: "prompt: aString default: defaultString\x0a\x09^ window prompt: aString default: defaultString",
  157. referencedClasses: [],
  158. //>>excludeEnd("ide");
  159. messageSends: ["prompt:default:"]
  160. }),
  161. $globals.BrowserInterface);
  162. $core.addMethod(
  163. $core.method({
  164. selector: "postMessageTo:",
  165. protocol: '*Platform-Browser',
  166. fn: function (aFrame){
  167. var self=this;
  168. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  169. return $core.withContext(function($ctx1) {
  170. //>>excludeEnd("ctx");
  171. var $1;
  172. $1=self._postMessageTo_origin_(aFrame,"*");
  173. return $1;
  174. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  175. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:",{aFrame:aFrame},$globals.Object)});
  176. //>>excludeEnd("ctx");
  177. },
  178. //>>excludeStart("ide", pragmas.excludeIdeData);
  179. args: ["aFrame"],
  180. source: "postMessageTo: aFrame\x0a^ self postMessageTo: aFrame origin: '*'",
  181. referencedClasses: [],
  182. //>>excludeEnd("ide");
  183. messageSends: ["postMessageTo:origin:"]
  184. }),
  185. $globals.Object);
  186. $core.addMethod(
  187. $core.method({
  188. selector: "postMessageTo:origin:",
  189. protocol: '*Platform-Browser',
  190. fn: function (aFrame,aString){
  191. var self=this;
  192. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  193. return $core.withContext(function($ctx1) {
  194. //>>excludeEnd("ctx");
  195. return aFrame.postMessage(self, aString);
  196. return self;
  197. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  198. }, function($ctx1) {$ctx1.fill(self,"postMessageTo:origin:",{aFrame:aFrame,aString:aString},$globals.Object)});
  199. //>>excludeEnd("ctx");
  200. },
  201. //>>excludeStart("ide", pragmas.excludeIdeData);
  202. args: ["aFrame", "aString"],
  203. source: "postMessageTo: aFrame origin: aString\x0a<return aFrame.postMessage(self, aString)>",
  204. referencedClasses: [],
  205. //>>excludeEnd("ide");
  206. messageSends: []
  207. }),
  208. $globals.Object);
  209. });