Skip to content

Instantly share code, notes, and snippets.

@ColinCampbell
Created April 5, 2011 21:10
Show Gist options
  • Select an option

  • Save ColinCampbell/904562 to your computer and use it in GitHub Desktop.

Select an option

Save ColinCampbell/904562 to your computer and use it in GitHub Desktop.
diff --git a/frameworks/core_foundation/tests/views/template/handlebars.js b/frameworks/core_foundation/tests/views/template/handlebars.js
index 3d56746..b8f203a 100644
--- a/frameworks/core_foundation/tests/views/template/handlebars.js
+++ b/frameworks/core_foundation/tests/views/template/handlebars.js
@@ -633,6 +633,27 @@ test("Child views created using the view helper should have their parent view se
equals(childView, childView.childViews[0].parentView, 'parent view is correct');
});
+test("Child views created using the view helper should have their IDs registered for events", function() {
+ TemplateTests = {};
+
+ var template = '{{view "SC.TemplateView"}}{{view "SC.TemplateView" id="templateViewTest"}}';
+
+ var view = SC.TemplateView.create({
+ template: SC.Handlebars.compile(template)
+ });
+
+ view.createLayer();
+
+ var childView = view.childViews[0];
+ var id = childView.$()[0].id;
+ equals(SC.View.views[id], childView, 'childView without passed ID is registered with SC.View.views so that it can properly receive events from RootResponder');
+
+ childView = view.childViews[1];
+ id = childView.$()[0].id;
+ equals(id, 'templateViewTest', 'precond -- id of childView should be set correctly');
+ equals(SC.View.views[id], childView, 'childView with passed ID is registered with SC.View.views so that it can properly receive events from RootResponder');
+});
+
test("Collection views that specify an example view class have their children be of that class", function() {
TemplateTests.ExampleViewCollection = SC.TemplateCollectionView.create({
itemView: SC.TemplateView.extend({
diff --git a/frameworks/handlebars/extensions/view.js b/frameworks/handlebars/extensions/view.js
index a9eac47..b82f050 100644
--- a/frameworks/handlebars/extensions/view.js
+++ b/frameworks/handlebars/extensions/view.js
@@ -28,6 +28,8 @@ SC.Handlebars.ViewHelper = SC.Object.create({
if (!newView) { throw "Unable to find view at path '" + path + "'"; }
}
+ if (hash.id) hash.layerId = hash.id;
+
var contextOptions = {
'id': hash.id,
'class': hash['class'],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment