Browse Source

PlatformDom >> {isFeasible, isDomNode:}.

Herbert Vojčík 7 years ago
parent
commit
b98deeb567
5 changed files with 121 additions and 0 deletions
  1. 10 0
      API-CHANGES.txt
  2. 8 0
      CHANGELOG
  3. 72 0
      src/Platform-DOM.js
  4. 30 0
      src/Platform-DOM.st
  5. 1 0
      support/devel.js

+ 10 - 0
API-CHANGES.txt

@@ -1,3 +1,13 @@
+0.18.2:
+
+* Add Platform-DOM package with DOM-related stuff.
+  * Platform-DOM not loaded by default. Packages that will use it will import it.
+
++ PlatformDom class >>
+  + isFeasible
+  + isDomNode:
+
+
 0.18.1:
 
 + ASTNode >>

+ 8 - 0
CHANGELOG

@@ -1,3 +1,11 @@
+31 December 2016 - Release 0.18.2
+===================================
+
+* DOM-related stuff in own package (not loaded by default, use imports:).
+
+Commits: https://lolg.it/amber/amber/commits/0.18.2.
+
+
 21 November 2016 - Release 0.18.1
 ===================================
 

+ 72 - 0
src/Platform-DOM.js

@@ -0,0 +1,72 @@
+define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
+if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
+var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
+if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
+$core.addPackage('Platform-DOM');
+$core.packages["Platform-DOM"].innerEval = function (expr) { return eval(expr); };
+$core.packages["Platform-DOM"].transport = {"type":"amd","amdNamespace":"amber_core"};
+
+$core.addClass('PlatformDom', $globals.Object, [], 'Platform-DOM');
+
+$core.addMethod(
+$core.method({
+selector: "isDomNode:",
+protocol: 'testing',
+fn: function (anObject){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+
+	return anObject.nodeType > 0 &&
+		Object.prototype.toString.call(anObject) !== "[object Object]";
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isDomNode:",{anObject:anObject},$globals.PlatformDom.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "isDomNode: anObject\x0a<inlineJS: '\x0a\x09return anObject.nodeType > 0 &&\x0a\x09\x09Object.prototype.toString.call(anObject) !== \x22[object Object]\x22\x0a'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.PlatformDom.klass);
+
+$core.addMethod(
+$core.method({
+selector: "isFeasible",
+protocol: 'testing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+
+  if (typeof document === "undefined") return false;
+  try {
+    var d = document.createElement("div"),
+	  f = document.createDocumentFragment(),
+	  t = document.createTextNode("Hello, Amber!");
+	f.appendChild(t);
+	d.insertBefore(f, null);
+	return d.innerHTML === "Hello, Amber!";
+  } catch (e) {
+    return false;
+  };
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.PlatformDom.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+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'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.PlatformDom.klass);
+
+});

+ 30 - 0
src/Platform-DOM.st

@@ -0,0 +1,30 @@
+Smalltalk createPackage: 'Platform-DOM'!
+Object subclass: #PlatformDom
+	instanceVariableNames: ''
+	package: 'Platform-DOM'!
+
+!PlatformDom class methodsFor: 'testing'!
+
+isDomNode: anObject
+<inlineJS: '
+	return anObject.nodeType > 0 &&
+		Object.prototype.toString.call(anObject) !!== "[object Object]"
+'>
+!
+
+isFeasible
+<inlineJS: '
+  if (typeof document === "undefined") return false;
+  try {
+    var d = document.createElement("div"),
+	  f = document.createDocumentFragment(),
+	  t = document.createTextNode("Hello, Amber!!");
+	f.appendChild(t);
+	d.insertBefore(f, null);
+	return d.innerHTML === "Hello, Amber!!";
+  } catch (e) {
+    return false;
+  }
+'>
+! !
+

+ 1 - 0
support/devel.js

@@ -5,6 +5,7 @@ define([
     './helpers', // pre-fetch, dep of ./deploy
     './deploy', // pre-fetch, dep of ./lang
     // --- packages of the development only Amber begin here ---
+    'amber_core/Platform-DOM',
     'amber_core/SUnit',
     'amber_core/Compiler-Tests',
     'amber_core/Kernel-Tests',