Skip to content

Commit

Permalink
Support attach-point in addition to data-attach-point, fixes ibm-js#175.
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh committed May 2, 2016
1 parent c501771 commit 2832a6f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions delite/createRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ define([
template._instanceData = this.instanceData;
}
this.own(template.instantiate(this).insertBefore(this))[0].content;
forEach.call(this.querySelectorAll("[data-attach-point]"), function (elem) {
var value = elem.getAttribute("data-attach-point");
forEach.call(this.querySelectorAll("[attach-point],[data-attach-point]"), function (elem) {
var value = elem.getAttribute("attach-point") || elem.getAttribute("data-attach-point");
if (value) {
this[value] = elem;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/delite/createRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define([
"../../delite/createRenderer!./templates/nestedWidgetTemplate.html",
"../../delite/createRenderer!./templates/complexAttributeTemplate.html",
"../../delite/createRenderer!./templates/attachPointTemplate.html",
"../../delite/createRenderer!./templates/dataAttachPointTemplate.html",
"../../delite/createRenderer!./templates/simpleWithAlternateBindingTemplate.html",
"../../delite/createRenderer!../templates/eventTemplate.html",
"deliteful/StarRating",
Expand Down Expand Up @@ -47,6 +48,7 @@ define([
renderNestedWidgetTemplate,
renderComplexAttributeTemplate,
renderAttachPointTemplate,
renderDataAttachPointTemplate,
renderAlternateBindingTemplate,
renderEventsTemplate
) {
Expand Down Expand Up @@ -91,6 +93,10 @@ define([
render: renderAttachPointTemplate,
baseClass: "liaison-test-attachpoint"
}),
DataAttachPointTemplateWidget = register("liaison-test-dataattachpoint", [HTMLElement, Widget], {
render: renderDataAttachPointTemplate,
baseClass: "liaison-test-dataattachpoint"
}),
AlternateBindingTemplateWidget = register("liaison-test-alternatebinding", [HTMLElement, Widget], {
render: renderAlternateBindingTemplate,
baseClass: "liaison-test-alternatebinding",
Expand Down Expand Up @@ -523,6 +529,20 @@ define([
expect(w.valueNode).to.equal(w.querySelector("input"));
});
});
it("Attach point with alternate attribute name", function () {
var w = new DataAttachPointTemplateWidget().placeAt(document.body);
this.timeout = 10000;
handles.push({
remove: function () {
w.destroy();
}
});
return waitFor(function () {
return w.valueNode;
}).then(function () {
expect(w.valueNode).to.equal(w.querySelector("input"));
});
});
it("Simple binding with default alternate binding factory", function () {
var w = new AlternateBindingTemplateWidget({
first: "John"
Expand Down
2 changes: 1 addition & 1 deletion tests/delite/templates/attachPointTemplate.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<input data-attach-point="valueNode">
<input attach-point="valueNode">
1 change: 1 addition & 0 deletions tests/delite/templates/dataAttachPointTemplate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input data-attach-point="valueNode">

0 comments on commit 2832a6f

Please sign in to comment.