diff options
author | Valerio Virgillito | 2012-03-19 15:23:32 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-03-19 15:23:32 -0700 |
commit | 38a3258239aef114c23fe0ce179257639a74d96b (patch) | |
tree | 8ac886989eac57126bc48099ec395c9f14c9c829 /node_modules/montage/ui/youtube-channel.reel/youtube-channel.js | |
parent | e9244d5a0f681ddde5896392c17738add2948687 (diff) | |
parent | f9e31800b1dedd7904e6e23c575c94ed4a72abdb (diff) | |
download | ninja-38a3258239aef114c23fe0ce179257639a74d96b.tar.gz |
Merge branch 'master' of github.com:francoisfrisch/ninja-internal into montage-integration
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.js | 128 |
1 files changed, 112 insertions, 16 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 3e20c406..3d9f7f2f 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*/ |
7 | var Montage = require("montage").Montage, | 7 | var 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 | ||
12 | var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, { | 11 | var 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,37 +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 | this.script = document.createElement("script"); | 98 | this._script = document.createElement("script"); |
81 | this.script.src = url; | 99 | this._script.src = url; |
82 | this.needsDraw = true; | 100 | this.needsDraw = true; |
83 | } | 101 | } |
84 | }, | 102 | }, |
85 | 103 | ||
86 | script: { | 104 | _script: { |
105 | enumerable: false, | ||
87 | value: null | 106 | value: null |
88 | }, | 107 | }, |
89 | 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 | |||
90 | draw: { | 117 | draw: { |
91 | value: function() { | 118 | value: function() { |
92 | if (this.script) { | 119 | if (this._script) { |
93 | this._element.appendChild(this.script); | 120 | this._element.appendChild(this._script); |
94 | this.script = null; | 121 | this._script = null; |
95 | } | 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._popupElement.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._popupElement.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 | |||
96 | } | 156 | } |
97 | }, | 157 | }, |
98 | 158 | ||
99 | handleData: { | 159 | _entries: { |
100 | value: function(data) { | 160 | enumerable: false, |
101 | var entries = data.feed.entry || []; | 161 | value: null |
162 | }, | ||
102 | 163 | ||
103 | var playlist = []; | 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 | }, | ||
104 | 181 | ||
105 | for (var i = 0, len = entries.length; i < len; i++) { | 182 | handleTouchStart: { |
106 | var id = entries[i]["media$group"]["yt$videoid"]["$t"]; | 183 | value: function(event) { |
107 | playlist.push(id); | 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; | ||
108 | } | 193 | } |
194 | } | ||
195 | }, | ||
196 | handleKeyup: { | ||
197 | value: function(event) { | ||
198 | this._shouldShowPopup = false; | ||
199 | this.needsDraw = true; | ||
200 | } | ||
201 | }, | ||
109 | 202 | ||
110 | this.player.playlist = playlist; | 203 | handleData: { |
204 | value: function(data) { | ||
205 | this._entries = data.feed.entry || []; | ||
206 | this.needsDraw = true; | ||
111 | } | 207 | } |
112 | } | 208 | } |
113 | 209 | ||