-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxenon-querystring.html
39 lines (34 loc) · 1.24 KB
/
xenon-querystring.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
<link rel="import" href="../polymer/polymer.html" />
<!--
Querystring component example. Given the following query string:
blah.html?lastname=Archer
The component will bind the value property.
<xenon-querystring key="lastname" value="{{lastname}}"/>
@group Xenon Elements
@element xenon-querystring
@demo demo/index.html
-->
<dom-module id="xenon-querystring">
<script>
Polymer({
is: "xenon-querystring",
properties: {
/* Query string key to fetch. */
key: String,
/* Output value of the query string value specified by the key. */
value: { type: String, notify: true, readOnly: true }
},
ready: function () {
var query = window.location.search.substring(1);
var items = query.split('&');
for (var i = 0; i < items.length; i++) {
var key = items[i].split('=')[0];
var value = items[i].split('=')[1];
if (key.toLowerCase() == this.key.toLowerCase()) {
this._setValue(decodeURI(value));
}
}
}
});
</script>
</dom-module>