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.js210
1 files changed, 210 insertions, 0 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
new file mode 100644
index 00000000..ccbd9978
--- /dev/null
+++ b/node_modules/montage/ui/youtube-channel.reel/youtube-channel.js
@@ -0,0 +1,210 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6/*global require,exports*/
7var Montage = require("montage").Montage,
8 Component = require("ui/component").Component,
9 Uuid = require("core/Uuid");
10
11var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, {
12
13 _userRe: {
14 enumerable: false,
15 value: /youtube.com\/(user\/)?([a-z0-9]+)/i
16 },
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
37 _channelUrl: {
38 enumerable: false,
39 value: null
40 },
41 channelUrl: {
42 depends: ["channel"],
43 get: function() {
44 return this._channelUrl;
45 },
46 set: function(value, fromChannel) {
47 if (this._channelUrl !== value) {
48 this._channelUrl = value;
49
50 // prevent infinite loop
51 if (!fromChannel) {
52 var match = this._userRe.exec(value);
53 if (match && match[2]) {
54 Object.getPropertyDescriptor(this, "channel").set.call(this, match[2], true);
55 }
56 }
57 }
58 }
59 },
60
61 _channel: {
62 enumerable: false,
63 value: null
64 },
65 channel: {
66 get: function() {
67 return this._channel;
68 },
69 set: function(value, fromUrl) {
70 if (this._channel !== value) {
71 this._channel = value;
72
73 // prevent infinite loop
74 if (!fromUrl) {
75 Object.getPropertyDescriptor(this, "channelUrl").set.call(this, "http://www.youtube.com/user/" + value, true);
76 }
77
78 this._loadChannel();
79 }
80 }
81 },
82
83 _loadChannel: {
84 enumerable: false,
85 value: function() {
86 var self = this;
87
88 var callbackName = "scriptCallback" + Uuid.generate().replace(/-/g, "_");
89
90 window[callbackName] = function(data) {
91 self.handleData(data);
92 delete window[callbackName];
93 };
94
95 // create url
96 var url = "http://gdata.youtube.com/feeds/api/users/" + this._channel + "/uploads?v=2&alt=json-in-script&callback=" + callbackName;
97
98 this._script = document.createElement("script");
99 this._script.src = url;
100 this.needsDraw = true;
101 }
102 },
103
104 _script: {
105 enumerable: false,
106 value: null
107 },
108
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 }
129
130 if (this._videoId) {
131 this.player.videoId = this._videoId;
132 this._videoId = null;
133 }
134
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;
207 }
208 }
209
210}); \ No newline at end of file