mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
263 lines
3.8 KiB
HTML
263 lines
3.8 KiB
HTML
<!--
|
|
@license
|
|
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
Code distributed by Google as part of the polymer project is also
|
|
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
-->
|
|
|
|
<script>
|
|
|
|
Polymer.BehaviorA = {
|
|
|
|
properties: {
|
|
|
|
label: {
|
|
type: String,
|
|
observer: '_labelChanged'
|
|
},
|
|
|
|
hasOptionsA: {
|
|
readOnly: true,
|
|
notify: true
|
|
},
|
|
|
|
overridableProperty: {
|
|
value: false
|
|
},
|
|
|
|
overridablePropertyB: {
|
|
value: false
|
|
},
|
|
|
|
hasBehaviorA: {
|
|
value: true
|
|
}
|
|
},
|
|
|
|
_simpleProperty: 'A',
|
|
|
|
hostAttributes: {
|
|
behavior: 'A',
|
|
user: 'A'
|
|
},
|
|
|
|
listeners: {
|
|
change: '_changeHandler'
|
|
},
|
|
|
|
ready: function() {
|
|
this.__readyA = true;
|
|
},
|
|
|
|
_labelChanged: function(label) {
|
|
this.__label = label;
|
|
},
|
|
|
|
_changeHandler: function(e) {
|
|
this.__change = e.detail.value;
|
|
},
|
|
|
|
_toOverride: function() {
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
Polymer.BehaviorB = {
|
|
|
|
properties: {
|
|
|
|
disabled: {
|
|
type: Boolean,
|
|
value: false,
|
|
observer: '_disabledChanged'
|
|
},
|
|
|
|
hasOptionsB: {
|
|
readOnly: true,
|
|
notify: true
|
|
},
|
|
|
|
hasBehaviorB: {
|
|
value: true
|
|
},
|
|
|
|
overridablePropertyB: {
|
|
value: true
|
|
},
|
|
|
|
},
|
|
|
|
hostAttributes: {
|
|
behavior: 'B',
|
|
user: 'B'
|
|
},
|
|
|
|
_simpleProperty: 'B',
|
|
|
|
_disabledChanged: function(disabled) {
|
|
this.__disabled = disabled
|
|
},
|
|
|
|
ready: function() {
|
|
this.__readyB = true;
|
|
},
|
|
|
|
_toOverride: function() {}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<dom-module id="single-behavior">
|
|
|
|
<script>
|
|
|
|
Polymer({
|
|
|
|
behaviors: [
|
|
Polymer.BehaviorA
|
|
]
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</dom-module>
|
|
|
|
<dom-module id="multi-behaviors">
|
|
|
|
<script>
|
|
|
|
Polymer({
|
|
|
|
behaviors: [
|
|
Polymer.BehaviorA,
|
|
Polymer.BehaviorB
|
|
],
|
|
|
|
properties: {
|
|
|
|
foo: {
|
|
type: String,
|
|
reflectToAttribute: true,
|
|
readOnly: true,
|
|
observer: '_fooChanged'
|
|
},
|
|
|
|
overridableProperty: {
|
|
value: true
|
|
}
|
|
|
|
},
|
|
|
|
_fooChanged: function(foo) {
|
|
this.__foo = foo;
|
|
},
|
|
|
|
_toOverride: Polymer._toOverride
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</dom-module>
|
|
|
|
<script>
|
|
|
|
Polymer.BehaviorC = {
|
|
|
|
properties: {
|
|
|
|
hasBehaviorC: {
|
|
value: true
|
|
}
|
|
|
|
},
|
|
|
|
_simpleProperty: 'C'
|
|
|
|
};
|
|
|
|
Polymer.BehaviorD = {
|
|
|
|
properties: {
|
|
|
|
hasBehaviorD: {
|
|
value: true
|
|
}
|
|
|
|
},
|
|
|
|
_simpleProperty: 'D'
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<dom-module id="nested-behaviors">
|
|
|
|
<script>
|
|
|
|
Polymer({
|
|
|
|
behaviors: [
|
|
[[Polymer.BehaviorC, Polymer.BehaviorB], Polymer.BehaviorA],
|
|
Polymer.BehaviorD
|
|
]
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</dom-module>
|
|
|
|
<dom-module id="behavior-as-is">
|
|
|
|
<template><div id="content"></div></template>
|
|
|
|
</dom-module>
|
|
|
|
<script>
|
|
|
|
Polymer.registerBehavior ={
|
|
beforeRegister: function() {
|
|
this.is = this.as;
|
|
this.properties = {
|
|
prop: {
|
|
observer: 'propChanged1'
|
|
}
|
|
};
|
|
this.hostAttributes = {
|
|
attr: true
|
|
};
|
|
this.observers = [
|
|
'propChanged2(prop)'
|
|
];
|
|
},
|
|
propChanged1: function() {
|
|
this.propChanged1Called = true;
|
|
},
|
|
propChanged2: function() {
|
|
this.propChanged2Called = true;
|
|
}
|
|
};
|
|
|
|
Polymer({
|
|
|
|
behaviors: [
|
|
Polymer.registerBehavior
|
|
],
|
|
|
|
as: 'behavior-as-is'
|
|
|
|
});
|
|
|
|
</script>
|