-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpage-title.html
112 lines (99 loc) · 2.62 KB
/
page-title.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
<link rel="import" href="../polymer/polymer-element.html">
<!--
A headless element for updating the title of a webpage declaratively, possibly
automatically, using Polymer bindings. Example:
<page-title base-title="zacharytamas" page-title="Home"></page-title>
@group utility
@element page-title
@demo demo/page-title.html
-->
<dom-module id="page-title">
<script>
class PageTitle extends Polymer.Element {
static get is() {return 'page-title'}
static get properties() {
return {
/**
* The base title of your webpage which never changes. Possibly the
* name of your application. Optional.
*
* @type String
* @default ''
*/
baseTitle: {
type: String,
value: ''
},
/**
* The divider to be used between your base title and title, if a
* base title is supplied. Optional.
*
* @type String
* @default ' - '
*/
divider: {
type: String,
value: ' - '
},
/**
* The current title of your webpage.
*
* @type String
*/
pageTitle: {
type: String
},
/**
* The direction your base title and title should be shown.
* Defaults to `standard`. Can be one of these values:
*
* | Value | Meaning |
* | standard | `baseTitle` comes first. |
* | reversed | `pageTitle` comes first. |
*
* @type String
* @default 'standard'
*/
direction: {
type: String,
value: 'standard'
},
/**
* The current title as computed by the element.
*/
computedTitle: {
type: String,
readOnly: true,
notify: true
}
}
}
static get observers() {
return [
'_updatePageTitle(baseTitle, divider, pageTitle, direction)'
]
}
_updatePageTitle(baseTitle, divider, pageTitle, direction) {
var pieces = [];
if (pageTitle) {
pieces.push(pageTitle);
}
if (direction == 'standard') {
if (baseTitle) {
pieces.unshift(baseTitle)
}
} else if (direction == 'reversed') {
if (baseTitle) {
pieces.push(baseTitle)
}
} else {
console.warn("page-title - Did not recognize `direction` property.");
return;
}
document.title = pieces.join(divider);
this._setComputedTitle(document.title);
}
}
window.customElements.define(PageTitle.is, PageTitle);
</script>
</dom-module>