-
Notifications
You must be signed in to change notification settings - Fork 11
/
gdg-logo.html
185 lines (151 loc) · 4.2 KB
/
gdg-logo.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!--
@license
Copyright (c) 2016 Abdón Rodríguez Davila (@abdonrd). All rights reserved.
This code may only be used under the MIT style license found at https://abdonrd.github.io/LICENSE.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="webfontloader-import.html">
<!--
Polymer element to generate the Google Developer Group logo.
Example to get the Google Developer Group program logo:
```html
<gdg-logo></gdg-logo>
```
Example to generate the Google Developer Group chapter logo:
```html
<gdg-logo name="Spain"></gdg-logo>
```
@demo demo/index.html
-->
<dom-module id="gdg-logo">
<template>
<style>
#image {
max-width: 100%;
max-height: 100%;
}
</style>
<img id="image">
<div hidden>
<img id="gdgIcon" src="images/gdg_icon.svg">
<img id="gdgLogotype" src="images/gdg_logotype.svg">
</div>
</template>
<script>
/* global WebFont:false */
Polymer({
is: 'gdg-logo',
properties: {
/**
* The name of the GDG chapter.
*/
name: {
type: String,
value: '',
observer: '_nameChanged'
},
/**
* The canvas
*/
_canvas: {
type: Object,
value: function() {
return document.createElement('canvas');
}
},
/**
* The scale of the output image.
*/
_scale: {
type: Number,
value: 2
},
/**
* Flag to know if the resources have been loaded.
*/
_resourcesLoaded: {
type: Boolean,
value: false,
computed: '_computedResourcesLoaded(_fontLoaded, _gdgIconLoaded, _gdgLogotypeLoaded)'
},
/**
* Flag to know if the 'Product Sans' family font has been loaded.
*/
_fontLoaded: {
type: Boolean,
value: false
},
/**
* Flag to know if the icon image has been loaded.
*/
_gdgIconLoaded: {
type: Boolean,
value: false
},
/**
* Flag to know if the logotype image has been loaded.
*/
_gdgLogotypeLoaded: {
type: Boolean,
value: false
}
},
ready: function() {
this._loadResources();
},
_nameChanged: function() {
if (this._resourcesLoaded) {
this._drawImage();
}
},
// eslint-disable-next-line max-len
_computedResourcesLoaded: function(_fontLoaded, _gdgIconLoaded, _gdgLogotypeLoaded) {
if (_fontLoaded && _gdgIconLoaded && _gdgLogotypeLoaded) {
this._drawImage();
}
return _fontLoaded && _gdgIconLoaded && _gdgLogotypeLoaded;
},
_loadResources: function() {
this._loadImages();
this._loadFont();
},
_loadImages: function() {
this.$.gdgIcon.addEventListener('load', function() {
this._gdgIconLoaded = true;
}.bind(this));
this.$.gdgLogotype.addEventListener('load', function() {
this._gdgLogotypeLoaded = true;
}.bind(this));
},
_loadFont: function() {
WebFont.load({
google: {
families: ['Product Sans']
},
fontactive: function() {
this._fontLoaded = true;
}.bind(this)
});
},
_drawImage: function() {
var canvasWith;
var ctx = this._canvas.getContext('2d');
ctx.font = '128px "Product Sans"';
if (this.name) {
canvasWith = ctx.measureText(this.name).width + 460 + 128;
} else {
canvasWith = 532 + 15;
}
this._canvas.setAttribute('width', canvasWith * this._scale);
this._canvas.setAttribute('height', 190 * this._scale);
ctx.scale(this._scale, this._scale);
ctx.font = '128px "Product Sans"';
ctx.fillStyle = 'rgba(0, 0, 0, 0.54)';
ctx.drawImage(this.$.gdgIcon, 0, 0);
ctx.drawImage(this.$.gdgLogotype, 183.242, 40.847);
ctx.fillText(this.name, 532, 143);
this.$.image.setAttribute('src', this._canvas.toDataURL());
}
});
</script>
</dom-module>