aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/youtube-channel.reel/youtube-channel.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/youtube-channel.reel/youtube-channel.js')
-rw-r--r--node_modules/montage/ui/youtube-channel.reel/youtube-channel.js135
1 files changed, 122 insertions, 13 deletions
diff --git a/node_modules/montage/ui/youtube-channel.reel/youtube-channel.js b/node_modules/montage/ui/youtube-channel.reel/youtube-channel.js
index fd642290..ccbd9978 100644
--- a/node_modules/montage/ui/youtube-channel.reel/youtube-channel.js
+++ b/node_modules/montage/ui/youtube-channel.reel/youtube-channel.js
@@ -6,8 +6,7 @@
6/*global require,exports*/ 6/*global require,exports*/
7var Montage = require("montage").Montage, 7var Montage = require("montage").Montage,
8 Component = require("ui/component").Component, 8 Component = require("ui/component").Component,
9 Uuid = require("core/uuid").Uuid; 9 Uuid = require("core/Uuid");
10
11 10
12var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, { 11var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, {
13 12
@@ -16,6 +15,25 @@ var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, {
16 value: /youtube.com\/(user\/)?([a-z0-9]+)/i 15 value: /youtube.com\/(user\/)?([a-z0-9]+)/i
17 }, 16 },
18 17
18 imageA: {
19 value: null
20 },
21 imageB: {
22 value: null
23 },
24 imageC: {
25 value: null
26 },
27 _popupElement: {
28 enumerable: false,
29 value: null
30 },
31
32 _shouldShowPopup: {
33 enumerable: false,
34 value: false
35 },
36
19 _channelUrl: { 37 _channelUrl: {
20 enumerable: false, 38 enumerable: false,
21 value: null 39 value: null
@@ -77,24 +95,115 @@ var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, {
77 // create url 95 // create url
78 var url = "http://gdata.youtube.com/feeds/api/users/" + this._channel + "/uploads?v=2&alt=json-in-script&callback=" + callbackName; 96 var url = "http://gdata.youtube.com/feeds/api/users/" + this._channel + "/uploads?v=2&alt=json-in-script&callback=" + callbackName;
79 97
80 var script = document.createElement("script"); 98 this._script = document.createElement("script");
81 script.src = url; 99 this._script.src = url;
82 this._element.appendChild(script); 100 this.needsDraw = true;
83 } 101 }
84 }, 102 },
85 103
86 handleData: { 104 _script: {
87 value: function(data) { 105 enumerable: false,
88 var entries = data.feed.entry || []; 106 value: null
107 },
89 108
90 var playlist = []; 109 prepareForDraw: {
110 value: function() {
111 this.imageA.element.addEventListener("click", this, false);
112 this.imageB.element.addEventListener("click", this, false);
113 this.imageC.element.addEventListener("click", this, false);
114 }
115 },
116
117 draw: {
118 value: function() {
119 if (this._script) {
120 this._element.appendChild(this._script);
121 this._script = null;
122 }
123
124 if (this._entries) {
125 this.imageA.src = this._entries[0]["media$group"]["media$thumbnail"][0].url;
126 this.imageB.src = this._entries[1]["media$group"]["media$thumbnail"][0].url;
127 this.imageC.src = this._entries[2]["media$group"]["media$thumbnail"][0].url;
128 }
91 129
92 for (var i = 0, len = entries.length; i < len; i++) { 130 if (this._videoId) {
93 var id = entries[i]["media$group"]["yt$videoid"]["$t"]; 131 this.player.videoId = this._videoId;
94 playlist.push(id); 132 this._videoId = null;
95 } 133 }
96 134
97 this.player.playlist = playlist; 135 if (this._shouldShowPopup) {
136 this._element.classList.add("show");
137 if (window.Touch) {
138 document.addEventListener('touchstart', this, false);
139 } else {
140 document.addEventListener('mousedown', this, false);
141 document.addEventListener('keyup', this, false);
142 }
143 } else {
144 this._element.classList.remove("show");
145 this.player.stop();
146
147 if (window.Touch) {
148 document.removeEventListener('touchstart', this);
149 } else {
150 document.removeEventListener('mousedown', this);
151 document.removeEventListener('keyup', this);
152 }
153
154 }
155
156 }
157 },
158
159 _entries: {
160 enumerable: false,
161 value: null
162 },
163
164 handleClick: {
165 value: function(event) {
166 switch(event.target.dataset.montageId) {
167 case "imageA":
168 this._videoId = this._entries[0]["media$group"]["yt$videoid"]["$t"];
169 break;
170 case "imageB":
171 this._videoId = this._entries[1]["media$group"]["yt$videoid"]["$t"];
172 break;
173 case "imageC":
174 this._videoId = this._entries[2]["media$group"]["yt$videoid"]["$t"];
175 break;
176 }
177 this._shouldShowPopup = true;
178 this.needsDraw = true;
179 }
180 },
181
182 handleTouchStart: {
183 value: function(event) {
184 this._shouldShowPopup = false;
185 this.needsDraw = true;
186 }
187 },
188 handleMousedown: {
189 value: function(event) {
190 if (event.button === 0) {
191 this._shouldShowPopup = false;
192 this.needsDraw = true;
193 }
194 }
195 },
196 handleKeyup: {
197 value: function(event) {
198 this._shouldShowPopup = false;
199 this.needsDraw = true;
200 }
201 },
202
203 handleData: {
204 value: function(data) {
205 this._entries = data.feed.entry || [];
206 this.needsDraw = true;
98 } 207 }
99 } 208 }
100 209