This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
79 lines (76 loc) · 3.09 KB
/
index.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
<!DOCTYPE html>
<!--
/*
* Copyright 2013 The Polymer Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
-->
<html>
<head>
<title>Polymer YouTube Sample</title>
<!-- 1. load platform... -->
<script src="components/webcomponentsjs/webcomponents.js"></script>
<!-- 2. import elements et al. -->
<link rel="import" href="components/polymer-ajax/polymer-ajax.html">
<link rel="import" href="components/polymer-selector/polymer-selector.html">
<link rel="import" href="components/polymer-ui-scaffold/polymer-ui-scaffold.html">
<link rel="import" href="components/yt-video/yt-search.html"/>
<link rel="import" href="components/yt-video/yt-video.html"/>
<link rel="stylesheet" href="components/polymer-ui-base/base.css" shim-shadowdom>
<link rel="stylesheet" href="style.css">
</head>
<body unresolved>
<!-- 3. use the stuff! -->
<polymer-ui-scaffold id="scaffold" class="polymer-ui-fit polymer-ui-body-text" menuActive>
<div navigation>
<polymer-ui-toolbar theme="polymer-ui-dark-theme">
<input id="input" value="chrome commercial" x-webkit-speech autofocus></input>
</polymer-ui-toolbar>
<yt-search id="search"></yt-search>
<polymer-selector id="selector"></polymer-selector>
</div>
<div tool id="title"></div>
<yt-video id="video" main class="polymer-ui-fit"></yt-video>
</polymer-ui-scaffold>
<script>
document.addEventListener('polymer-ready', function() {
// get some references in a polyfill friendly way.
var input = document.getElementById('input');
var search = document.getElementById('search');
var selector = document.getElementById('selector');
var title = document.getElementById('title');
var video = document.getElementById('video');
var scaffold = document.getElementById('scaffold');
// set the search query based on user input
input.addEventListener('input', function(e) {
search.query = e.target.value;
selector.selected = null;
});
search.query = input.value;
// set the list template's model to the search response
search.addEventListener('yt-search-result', function(e) {
selector.textContent = '';
var list = e.target.list;
if (list) {
var frag = document.createDocumentFragment();
for (var i=0, d; i < list.length; i++) {
d = document.createElement('div');
d.classList.add('item');
d.textContent = list[i].title.$t;
frag.appendChild(d);
}
selector.appendChild(frag);
}
});
// set the video based on user selection in the list
selector.addEventListener('polymer-activate', function(e) {
var item = search.list[selector.selected];
video.videoEntry = item;
title.textContent = item.title.$t;
scaffold.menuActive = !scaffold.menuActive;
});
});
</script>
</body>
</html>