diff options
Diffstat (limited to 'node_modules/montage/examples/youtube-channel-example/youtube-channel.reel')
2 files changed, 135 insertions, 0 deletions
diff --git a/node_modules/montage/examples/youtube-channel-example/youtube-channel.reel/youtube-channel.html b/node_modules/montage/examples/youtube-channel-example/youtube-channel.reel/youtube-channel.html new file mode 100644 index 00000000..8514f5ce --- /dev/null +++ b/node_modules/montage/examples/youtube-channel-example/youtube-channel.reel/youtube-channel.html | |||
@@ -0,0 +1,34 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <!-- <copyright> | ||
3 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
4 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
5 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
6 | </copyright> --> | ||
7 | <html> | ||
8 | <head> | ||
9 | <title></title> | ||
10 | <script type="text/montage-serialization"> | ||
11 | { | ||
12 | "player": { | ||
13 | "prototype": "montage/ui/youtube-player.reel", | ||
14 | "properties": { | ||
15 | "element": {"#": "player"} | ||
16 | } | ||
17 | }, | ||
18 | |||
19 | "owner": { | ||
20 | "prototype": "youtube-channel.reel", | ||
21 | "properties": { | ||
22 | "element": {"#": "container"}, | ||
23 | "player": {"@": "player"} | ||
24 | } | ||
25 | } | ||
26 | } | ||
27 | </script> | ||
28 | </head> | ||
29 | <body> | ||
30 | <div data-montage-id="container" class="montage-youtube-channel"> | ||
31 | <div data-montage-id="player"></div> | ||
32 | </div> | ||
33 | </body> | ||
34 | </html> | ||
diff --git a/node_modules/montage/examples/youtube-channel-example/youtube-channel.reel/youtube-channel.js b/node_modules/montage/examples/youtube-channel-example/youtube-channel.reel/youtube-channel.js new file mode 100644 index 00000000..1f5aa2d1 --- /dev/null +++ b/node_modules/montage/examples/youtube-channel-example/youtube-channel.reel/youtube-channel.js | |||
@@ -0,0 +1,101 @@ | |||
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*/ | ||
7 | var Montage = require("montage").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | Uuid = require("montage/core/uuid").Uuid; | ||
10 | |||
11 | |||
12 | var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, { | ||
13 | |||
14 | _userRe: { | ||
15 | enumerable: false, | ||
16 | value: /youtube.com\/(user\/)?([a-z0-9]+)/i | ||
17 | }, | ||
18 | |||
19 | _channelUrl: { | ||
20 | enumerable: false, | ||
21 | value: null | ||
22 | }, | ||
23 | channelUrl: { | ||
24 | depends: ["channel"], | ||
25 | get: function() { | ||
26 | return this._channelUrl; | ||
27 | }, | ||
28 | set: function(value, fromChannel) { | ||
29 | if (this._channelUrl !== value) { | ||
30 | this._channelUrl = value; | ||
31 | |||
32 | // prevent infinite loop | ||
33 | if (!fromChannel) { | ||
34 | var match = this._userRe.exec(value); | ||
35 | if (match && match[2]) { | ||
36 | Object.getPropertyDescriptor(this, "channel").set.call(this, match[2], true); | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | }, | ||
42 | |||
43 | _channel: { | ||
44 | enumerable: false, | ||
45 | value: null | ||
46 | }, | ||
47 | channel: { | ||
48 | get: function() { | ||
49 | return this._channel; | ||
50 | }, | ||
51 | set: function(value, fromUrl) { | ||
52 | if (this._channel !== value) { | ||
53 | this._channel = value; | ||
54 | |||
55 | // prevent infinite loop | ||
56 | if (!fromUrl) { | ||
57 | Object.getPropertyDescriptor(this, "channelUrl").set.call(this, "http://www.youtube.com/user/" + value, true); | ||
58 | } | ||
59 | |||
60 | this._loadChannel(); | ||
61 | } | ||
62 | } | ||
63 | }, | ||
64 | |||
65 | _loadChannel: { | ||
66 | enumerable: false, | ||
67 | value: function() { | ||
68 | var self = this; | ||
69 | |||
70 | var callbackName = "scriptCallback" + Uuid.generate().replace(/-/g, "_"); | ||
71 | |||
72 | window[callbackName] = function(data) { | ||
73 | self.handleData(data); | ||
74 | delete window[callbackName]; | ||
75 | }; | ||
76 | |||
77 | // create url | ||
78 | var url = "http://gdata.youtube.com/feeds/api/users/" + this._channel + "/uploads?v=2&alt=json-in-script&callback=" + callbackName; | ||
79 | |||
80 | var script = document.createElement("script"); | ||
81 | script.src = url; | ||
82 | this._element.appendChild(script); | ||
83 | } | ||
84 | }, | ||
85 | |||
86 | handleData: { | ||
87 | value: function(data) { | ||
88 | var entries = data.feed.entry || []; | ||
89 | |||
90 | var playlist = []; | ||
91 | |||
92 | for (var i = 0, len = entries.length; i < len; i++) { | ||
93 | var id = entries[i]["media$group"]["yt$videoid"]["$t"]; | ||
94 | playlist.push(id); | ||
95 | } | ||
96 | |||
97 | this.player.playlist = playlist; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | }); \ No newline at end of file | ||