Platform-DOM.js 8.1 KB

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