|
@@ -8,6 +8,70 @@ $core.addClass('Domite', $globals.ProtoStream, ['element', 'reference'], 'DOMite
|
|
|
//>>excludeStart("ide", pragmas.excludeIdeData);
|
|
|
$globals.Domite.comment="I am (hopefully thin) wrapper around the notion of \x22cursor in a page\x22.\x0aI represent a DOM node _and_ a point where\x0ato insert new content into it.\x0a\x0aSo I play both the role of a container that inserts\x0aas well as the role of an element being inserted.\x0a\x0aI inherit from `ProtoStream`.\x0a\x0aCreation API:\x0a\x0a - `Domite new` creates an insertion point at the bottom of `<body>`.\x0a - `Domite newStream` is unique way to create pieces of content. It creates an instance \x22floating in thin air\x22 (wrapper around DOM DocumentFragment) that can be filled with any contents and then inserted in a page.\x0a - `Domite fromElement: aDomElement` wraps an element and set the cursor to its end.\x0a\x0aCSS selector API:\x0a\x0a - `Domite at: aSelector` wraps an element found by `document.querySelector(aSelector)`.\x0a\x0aManipulation API:\x0a\x0a - `aDomite << obj` inserts obj at the insertion point.\x0a - `aDomite resetContents` deletes contents of the wrapped element.\x0a\x0aCursor moving API:\x0a\x0aTake this sample HTML, where `[n]` are just markers, not real content:\x0a\x0a```\x0a<body>\x0a <h1>header</h1>\x0a [4]<p>[2]Hello[1]world[3]</p>[5]\x0a <small>footer</small>\x0a</body>\x0a```\x0a\x0aIf `d` is a `Domite` representing `[1]`, then:\x0a\x0a - `d setToStart` would move `d` to be at `[2]`,\x0a - `d setToEnd` would move `d` to be at `[3]`,\x0a - `d setToBefore` would move `d` to be at `[4]`, and\x0a - `d setToAfter` would move `d` to be at `[5]`.\x0a\x0aIt is not presumed one would use `setToXxx`\x0ato actually move around in a single instance.\x0aIt is envisioned this API will be used mostly\x0ain combination with `copy`, like\x0a`afterMe := self copy setToAfter`.";
|
|
|
//>>excludeEnd("ide");
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "=",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (aDomite){
|
|
|
+var self=this;
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+var $3,$2,$5,$4,$6,$1;
|
|
|
+$3=self._class();
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+$ctx1.sendIdx["class"]=1;
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+$2=$recv($3).__eq($recv(aDomite)._class());
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+$ctx1.sendIdx["="]=1;
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+$1=$recv($2)._and_((function(){
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+$5=self._element();
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+$ctx2.sendIdx["element"]=1;
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+$4=$recv($5).__eq($recv(aDomite)._element());
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+$ctx2.sendIdx["="]=2;
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+return $recv($4)._and_((function(){
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+return $core.withContext(function($ctx3) {
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+$6=self._reference();
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+$ctx3.sendIdx["reference"]=1;
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+return $recv($6).__eq($recv(aDomite)._reference());
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+}));
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+}));
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+$ctx1.sendIdx["and:"]=1;
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+return $1;
|
|
|
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"=",{aDomite:aDomite},$globals.Domite)});
|
|
|
+//>>excludeEnd("ctx");
|
|
|
+},
|
|
|
+//>>excludeStart("ide", pragmas.excludeIdeData);
|
|
|
+args: ["aDomite"],
|
|
|
+source: "= aDomite\x0a\x09^ self class = aDomite class and: [\x0a\x09\x09self element = aDomite element and: [\x0a\x09\x09\x09self reference = aDomite reference ]]",
|
|
|
+referencedClasses: [],
|
|
|
+//>>excludeEnd("ide");
|
|
|
+messageSends: ["and:", "=", "class", "element", "reference"]
|
|
|
+}),
|
|
|
+$globals.Domite);
|
|
|
+
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "at:",
|