Platform-DOM.js 8.3 KB

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