07d13c9c
isisadmin
polymer catalog
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../catalog-cart/catalog-cart.html">
<dom-module id="cart-item-icon">
<style>
iron-icon {
width: var(--cart-item-icon-size, 18px);
height: var(--cart-item-icon-size, 18px);
}
span {
@apply(--cart-item-icon-label);
}
</style>
<template>
<catalog-cart id="cart" on-item-added="_update" on-item-removed="_update" on-items-changed="_update"></catalog-cart>
<iron-icon icon="[[_icon]]" title$="[[_label]]"></iron-icon>
<span hidden$="[[noLabel]]">[[_label]]</span>
</template>
</dom-module>
<script>
Polymer({
is: 'cart-item-icon',
properties: {
element: {type: String, observer: '_update'},
presentLabel: {type: String, value: 'Remove from Collection', observer: '_update'},
absentLabel: {type: String, value: 'Add to Collection', observer: '_update'},
present: {type: Boolean, notify: true, readOnly: true, value: false},
noLabel: {type: Boolean, value: false},
tappable: {type: Boolean, value: false},
_label: String,
_icon: String
},
listeners: {
tap: '_tapped'
},
attached: function() {
this._update();
},
_update: function() {
this._setPresent(this.$.cart.includes(this.element));
this._label = this.present ? this.presentLabel : this.absentLabel;
this.setAttribute('aria-label',this._label);
this.debounce('icon', function() {
this._icon = this.present ? 'star' : 'star-border';
}, 10);
},
toggle: function(e) {
this.fire(this.present ? 'cart-remove' : 'cart-add', this.element);
},
_tapped: function() {
if (this.tappable) this.toggle();
}
});
</script>
|