Platform-DOM.js 8.9 KB

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