trying to see if we can do appendchild ok

This commit is contained in:
Danny Yoo 2011-08-29 07:23:24 -04:00
parent 9f6d9ae1f6
commit c00a64d078
4 changed files with 75 additions and 2 deletions

View File

@ -23,8 +23,8 @@
;; until we're all done.
(define (draw w v)
(cond [(< w (length dwarf-names))
(view-append (view-focus v "ul")
(make-item (list-ref dwarf-names w)))]
(view-append-child (view-focus v "ul")
(make-item (list-ref dwarf-names w)))]
[else
v]))

View File

@ -45,4 +45,5 @@
view-form-value
update-view-form-value
view-append-child
))

View File

@ -322,6 +322,30 @@
};
MockView.prototype.appendChild = function(domNode) {
return this.act(
function(cursor) {
if (cursor.canDown()) {
cursor = cursor.down();
while (cursor.canRight()) {
cursor = cursor.right();
}
return cursor.insertRight(domNode);
} else {
return cursor.insertDown(domNode);
}
},
function(eventHandlers) { return eventHandlers; },
function(view) {
var clone = $(domNode).clone(true);
clone.appendTo(view.focus);
view.focus = clone;
}
)
};
//////////////////////////////////////////////////////////////////////
@ -444,6 +468,40 @@
};
var coerseToDomNode = function(x, onSuccess, onFail) {
var dom;
if (isDomNode(x)) {
return onSuccess(x);
} else if (isResource(x)) {
try {
dom = $(resourceContent(x).toString())
.css("margin", "0px")
.css("padding", "0px")
.css("border", "0px");
} catch (exn) {
return onFail(exn);
}
return onSuccess(dom);
} else if (isMockView(x)) {
return onSuccess(x.cursor.top().node);
} else {
try {
dom = $(plt.baselib.format.toDomNode(x))
} catch (exn) {
return onFail(exn);
}
return onSuccess(dom);
}
};
var isDomNode = function(x) {
if (return x.hasOwnProperty(nodeType) &&
x.nodeType === 1);
};
@ -1166,6 +1224,15 @@
});
EXPORTS['view-append-child'] = makePrimitiveProcedure(
'view-append-child',
2,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-append-child', 1);
var dom = coerseToDomNode(MACHINE.env[MACHINE.env.length - 2]);
return view.appendChild(dom);
});

View File

@ -13,6 +13,7 @@
view-show
view-hide
view-append-child
)
@ -86,3 +87,7 @@
(define (view-hide)
(error 'view-hide "Please run in JavaScript context."))
(define (view-append-child dom)
(error 'view-append "Please run in JavaScript context."))