Platform-DOM.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. define(["amber/boot", "amber_core/Kernel-Collections", "amber_core/Kernel-Infrastructure", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!("nilAsValue" in $boot))$boot.nilAsValue=$boot.nilAsReceiver;
  3. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. $core.addPackage("Platform-DOM");
  5. ($core.packageDescriptors||$core.packages)["Platform-DOM"].innerEval = function (expr) { return eval(expr); };
  6. ($core.packageDescriptors||$core.packages)["Platform-DOM"].transport = {"type":"amd","amdNamespace":"amber_core"};
  7. $core.addClass("PlatformDom", $globals.Object, [], "Platform-DOM");
  8. $core.addMethod(
  9. $core.method({
  10. selector: "isDomNode:",
  11. protocol: "testing",
  12. fn: function (anObject){
  13. var self=this,$self=this;
  14. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  15. return $core.withContext(function($ctx1) {
  16. //>>excludeEnd("ctx");
  17. return anObject.nodeType > 0 &&
  18. Object.prototype.toString.call(anObject) !== "[object Object]";
  19. return self;
  20. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  21. }, function($ctx1) {$ctx1.fill(self,"isDomNode:",{anObject:anObject},$globals.PlatformDom.a$cls)});
  22. //>>excludeEnd("ctx");
  23. },
  24. //>>excludeStart("ide", pragmas.excludeIdeData);
  25. args: ["anObject"],
  26. source: "isDomNode: anObject\x0a<inlineJS: '\x0a\x09return anObject.nodeType > 0 &&\x0a\x09\x09Object.prototype.toString.call(anObject) !== \x22[object Object]\x22\x0a'>",
  27. referencedClasses: [],
  28. //>>excludeEnd("ide");
  29. messageSends: []
  30. }),
  31. $globals.PlatformDom.a$cls);
  32. $core.addMethod(
  33. $core.method({
  34. selector: "isFeasible",
  35. protocol: "testing",
  36. fn: function (){
  37. var self=this,$self=this;
  38. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  39. return $core.withContext(function($ctx1) {
  40. //>>excludeEnd("ctx");
  41. if (typeof document === "undefined") return false;
  42. try {
  43. var d = document.createElement("div"),
  44. f = document.createDocumentFragment(),
  45. t = document.createTextNode("Hello, Amber!");
  46. f.appendChild(t);
  47. d.insertBefore(f, null);
  48. return d.innerHTML === "Hello, Amber!";
  49. } catch (e) {
  50. return false;
  51. };
  52. return self;
  53. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  54. }, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.PlatformDom.a$cls)});
  55. //>>excludeEnd("ctx");
  56. },
  57. //>>excludeStart("ide", pragmas.excludeIdeData);
  58. args: [],
  59. source: "isFeasible\x0a<inlineJS: '\x0a if (typeof document === \x22undefined\x22) return false;\x0a try {\x0a var d = document.createElement(\x22div\x22),\x0a\x09 f = document.createDocumentFragment(),\x0a\x09 t = document.createTextNode(\x22Hello, Amber!\x22);\x0a\x09f.appendChild(t);\x0a\x09d.insertBefore(f, null);\x0a\x09return d.innerHTML === \x22Hello, Amber!\x22;\x0a } catch (e) {\x0a return false;\x0a }\x0a'>",
  60. referencedClasses: [],
  61. //>>excludeEnd("ide");
  62. messageSends: []
  63. }),
  64. $globals.PlatformDom.a$cls);
  65. $core.addMethod(
  66. $core.method({
  67. selector: "newCustomEvent:detail:",
  68. protocol: "creation",
  69. fn: function (aString,anObject){
  70. var self=this,$self=this;
  71. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  72. return $core.withContext(function($ctx1) {
  73. //>>excludeEnd("ctx");
  74. return new CustomEvent(aString, {detail: anObject});
  75. return self;
  76. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  77. }, function($ctx1) {$ctx1.fill(self,"newCustomEvent:detail:",{aString:aString,anObject:anObject},$globals.PlatformDom.a$cls)});
  78. //>>excludeEnd("ctx");
  79. },
  80. //>>excludeStart("ide", pragmas.excludeIdeData);
  81. args: ["aString", "anObject"],
  82. source: "newCustomEvent: aString detail: anObject\x0a<inlineJS: 'return new CustomEvent(aString, {detail: anObject})'>",
  83. referencedClasses: [],
  84. //>>excludeEnd("ide");
  85. messageSends: []
  86. }),
  87. $globals.PlatformDom.a$cls);
  88. $core.addMethod(
  89. $core.method({
  90. selector: "toArray:",
  91. protocol: "converting",
  92. fn: function (aDomList){
  93. var self=this,$self=this;
  94. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  95. return $core.withContext(function($ctx1) {
  96. //>>excludeEnd("ctx");
  97. return Array.prototype.slice.call(aDomList);
  98. return self;
  99. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  100. }, function($ctx1) {$ctx1.fill(self,"toArray:",{aDomList:aDomList},$globals.PlatformDom.a$cls)});
  101. //>>excludeEnd("ctx");
  102. },
  103. //>>excludeStart("ide", pragmas.excludeIdeData);
  104. args: ["aDomList"],
  105. source: "toArray: aDomList\x0a<inlineJS: 'return Array.prototype.slice.call(aDomList)'>",
  106. referencedClasses: [],
  107. //>>excludeEnd("ide");
  108. messageSends: []
  109. }),
  110. $globals.PlatformDom.a$cls);
  111. $core.addMethod(
  112. $core.method({
  113. selector: "asDomNode",
  114. protocol: "*Platform-DOM",
  115. fn: function (){
  116. var self=this,$self=this;
  117. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  118. return $core.withContext(function($ctx1) {
  119. //>>excludeEnd("ctx");
  120. return $recv(document)._createTextNode_($self._asString());
  121. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  122. }, function($ctx1) {$ctx1.fill(self,"asDomNode",{},$globals.CharacterArray)});
  123. //>>excludeEnd("ctx");
  124. },
  125. //>>excludeStart("ide", pragmas.excludeIdeData);
  126. args: [],
  127. source: "asDomNode\x0a\x09^ document createTextNode: self asString",
  128. referencedClasses: [],
  129. //>>excludeEnd("ide");
  130. messageSends: ["createTextNode:", "asString"]
  131. }),
  132. $globals.CharacterArray);
  133. $core.addMethod(
  134. $core.method({
  135. selector: "asDomNode",
  136. protocol: "*Platform-DOM",
  137. fn: function (){
  138. var self=this,$self=this;
  139. var fragment;
  140. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  141. return $core.withContext(function($ctx1) {
  142. //>>excludeEnd("ctx");
  143. fragment=$recv(document)._createDocumentFragment();
  144. $self._do_((function(each){
  145. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  146. return $core.withContext(function($ctx2) {
  147. //>>excludeEnd("ctx");
  148. return $recv(fragment)._appendChild_($recv(each)._asDomNode());
  149. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  150. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  151. //>>excludeEnd("ctx");
  152. }));
  153. return fragment;
  154. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  155. }, function($ctx1) {$ctx1.fill(self,"asDomNode",{fragment:fragment},$globals.Collection)});
  156. //>>excludeEnd("ctx");
  157. },
  158. //>>excludeStart("ide", pragmas.excludeIdeData);
  159. args: [],
  160. source: "asDomNode\x0a\x09| fragment |\x0a\x09fragment := document createDocumentFragment.\x0a\x09self do: [ :each | fragment appendChild: each asDomNode ].\x0a\x09^ fragment",
  161. referencedClasses: [],
  162. //>>excludeEnd("ide");
  163. messageSends: ["createDocumentFragment", "do:", "appendChild:", "asDomNode"]
  164. }),
  165. $globals.Collection);
  166. $core.addMethod(
  167. $core.method({
  168. selector: "asDomNode",
  169. protocol: "*Platform-DOM",
  170. fn: function (){
  171. var self=this,$self=this;
  172. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  173. return $core.withContext(function($ctx1) {
  174. //>>excludeEnd("ctx");
  175. var $1,$2;
  176. $1=$recv($globals.PlatformDom)._isDomNode_($self["@jsObject"]);
  177. if($core.assert($1)){
  178. return $self["@jsObject"];
  179. } else {
  180. $2=(
  181. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  182. $ctx1.supercall = true,
  183. //>>excludeEnd("ctx");
  184. ($globals.JSObjectProxy.superclass||$boot.nilAsClass).fn.prototype._asDomNode.apply($self, []));
  185. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  186. $ctx1.supercall = false;
  187. //>>excludeEnd("ctx");;
  188. return $2;
  189. }
  190. return self;
  191. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  192. }, function($ctx1) {$ctx1.fill(self,"asDomNode",{},$globals.JSObjectProxy)});
  193. //>>excludeEnd("ctx");
  194. },
  195. //>>excludeStart("ide", pragmas.excludeIdeData);
  196. args: [],
  197. source: "asDomNode\x0a\x09(PlatformDom isDomNode: jsObject)\x0a\x09\x09ifTrue: [ ^ jsObject ]\x0a\x09\x09ifFalse: [ ^ super asDomNode ]",
  198. referencedClasses: ["PlatformDom"],
  199. //>>excludeEnd("ide");
  200. messageSends: ["ifTrue:ifFalse:", "isDomNode:", "asDomNode"]
  201. }),
  202. $globals.JSObjectProxy);
  203. $core.addMethod(
  204. $core.method({
  205. selector: "htmlTextContent",
  206. protocol: "*Platform-DOM",
  207. fn: function (){
  208. var self=this,$self=this;
  209. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  210. return $core.withContext(function($ctx1) {
  211. //>>excludeEnd("ctx");
  212. var d=document.createElement("div");d.innerHTML=self;return d.textContent||d.innerText;;
  213. return self;
  214. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  215. }, function($ctx1) {$ctx1.fill(self,"htmlTextContent",{},$globals.String)});
  216. //>>excludeEnd("ctx");
  217. },
  218. //>>excludeStart("ide", pragmas.excludeIdeData);
  219. args: [],
  220. source: "htmlTextContent\x0a<inlineJS: 'var d=document.createElement(\x22div\x22);d.innerHTML=self;return d.textContent||d.innerText;'>",
  221. referencedClasses: [],
  222. //>>excludeEnd("ide");
  223. messageSends: []
  224. }),
  225. $globals.String);
  226. });