Skip to content

Commit

Permalink
Fixes #347.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Nov 14, 2013
1 parent 4421b2e commit e269582
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/declaration/polymer-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
createdCallback: function() {
// fetch the element name
this.name = this.getAttribute('name');
// fetch our extendee name
this.extends = this.getAttribute('extends');
// install element definition, if ready
this.registerWhenReady();
},
Expand All @@ -35,8 +37,7 @@
if (this.waitingForPrototype(this.name)) {
return;
}
// fetch our extendee name
var extendee = this.getAttribute('extends');
var extendee = this.extends;
if (this.waitingForExtendee(extendee)) {
//console.warn(this.name + ': waitingForExtendee:' + extendee);
return;
Expand Down
20 changes: 17 additions & 3 deletions src/declaration/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
},
// build prototype combining extendee, Polymer base, and named api
generateBasePrototype: function(extnds) {
var prototype = memoizedBases[extnds];
var prototype = this.findBasePrototype(extnds);
if (!prototype) {
// create a prototype based on tag-name extension
var prototype = HTMLElement.getPrototypeForTag(extnds);
Expand All @@ -125,6 +125,9 @@
}
return prototype;
},
findBasePrototype: function(name) {
return memoizedBases[name];
},
// install Polymer instance api into prototype chain, as needed
ensureBaseApi: function(prototype) {
if (!prototype.PolymerBase) {
Expand Down Expand Up @@ -153,15 +156,26 @@
prototype: this.prototype
}
// native element must be specified in extends
if (extendee && extendee.indexOf('-') < 0) {
info.extends = extendee;
var typeExtension = this.findTypeExtension(extendee);
if (typeExtension) {
info.extends = typeExtension;
}
// register the custom type
this.ctor = document.register(name, info);
// constructor shenanigans
this.prototype.constructor = this.ctor;
// register the prototype with HTMLElement for name lookup
HTMLElement.register(name, this.prototype);
},
findTypeExtension: function(name) {
if (name && name.indexOf('-') < 0) {
return name;
} else {
var p = this.findBasePrototype(name);
if (p.element) {
return this.findTypeExtension(p.element.extends);
}
}
}
};

Expand Down
10 changes: 10 additions & 0 deletions test/html/element-registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<x-blarg></x-blarg>
<hr>
<li is="my-li"></li>
<hr>
<li is="my-sub-li"></li>

<!-- script follows declaration -->
<polymer-element name="x-foo">
Expand Down Expand Up @@ -140,6 +142,12 @@
</script>
</polymer-element>

<polymer-element name="my-sub-li" extends="my-li" noscript>
<template>
Hello Sub World
</template>
</polymer-element>

<script>
var assert = chai.assert;
function test() {
Expand All @@ -157,6 +165,8 @@
assert.equal(zzif.squid, 'zink');
var myLi = document.querySelector('[is=my-li]');
assert.equal(myLi.custom, true);
var mySubLi = document.querySelector('[is=my-sub-li]');
assert.equal(mySubLi.custom, true);
done();
}
</script>
Expand Down

0 comments on commit e269582

Please sign in to comment.