Skip to content

Commit

Permalink
polymer-element supports new requirements for type extension custom e…
Browse files Browse the repository at this point in the history
…lements
  • Loading branch information
sorvell committed Sep 12, 2013
1 parent 8bdd036 commit 90ecb3d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/declaration/polymer-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
Platform.ShadowCSS.shimStyling(this.templateContent(), name, extendee);
}
// register our custom element
this.registerPrototype(name);
this.registerPrototype(name, extendee);
// reference constructor in a global named by 'constructor' attribute
this.publishConstructor();
// subclasses may now register themselves
Expand Down
13 changes: 9 additions & 4 deletions src/declaration/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@
prototype[name] = extend({}, Object.getPrototypeOf(prototype)[name]);
},
// register 'prototype' to custom element 'name', store constructor
registerPrototype: function(name) {
// register the custom type
this.ctor = document.register(name, {
registerPrototype: function(name, extendee) {
var info = {
prototype: this.prototype
});
}
// native element must be specified in extends
if (extendee && extendee.indexOf('-') < 0) {
info.extends = extendee;
}
// 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
Expand Down
14 changes: 14 additions & 0 deletions test/html/element-registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<x-blarg></x-blarg>
<hr>
<li is="my-li"></li>

<!-- script follows declaration -->
<polymer-element name="x-foo">
Expand Down Expand Up @@ -130,6 +131,17 @@
</script>
</polymer-element>

<polymer-element name="my-li" extends="li">
<template>
Hello World
</template>
<script>
Polymer('my-li', {
custom: true
});
</script>
</polymer-element>

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

0 comments on commit 90ecb3d

Please sign in to comment.