/* This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
*/ /*global require,exports*/ var Montage = require("montage").Montage, Component = require("montage/ui/component").Component, Uuid = require("montage/core/uuid").Uuid; var YoutubeChannel = exports.YoutubeChannel = Montage.create(Component, { _userRe: { enumerable: false, value: /youtube.com\/(user\/)?([a-z0-9]+)/i }, _channelUrl: { enumerable: false, value: null }, channelUrl: { depends: ["channel"], get: function() { return this._channelUrl; }, set: function(value, fromChannel) { if (this._channelUrl !== value) { this._channelUrl = value; // prevent infinite loop if (!fromChannel) { var match = this._userRe.exec(value); if (match && match[2]) { Object.getPropertyDescriptor(this, "channel").set.call(this, match[2], true); } } } } }, _channel: { enumerable: false, value: null }, channel: { get: function() { return this._channel; }, set: function(value, fromUrl) { if (this._channel !== value) { this._channel = value; // prevent infinite loop if (!fromUrl) { Object.getPropertyDescriptor(this, "channelUrl").set.call(this, "http://www.youtube.com/user/" + value, true); } this._loadChannel(); } } }, _loadChannel: { enumerable: false, value: function() { var self = this; var callbackName = "scriptCallback" + Uuid.generate().replace(/-/g, "_"); window[callbackName] = function(data) { self.handleData(data); delete window[callbackName]; }; // create url var url = "http://gdata.youtube.com/feeds/api/users/" + this._channel + "/uploads?v=2&alt=json-in-script&callback=" + callbackName; var script = document.createElement("script"); script.src = url; this._element.appendChild(script); } }, handleData: { value: function(data) { var entries = data.feed.entry || []; var playlist = []; for (var i = 0, len = entries.length; i < len; i++) { var id = entries[i]["media$group"]["yt$videoid"]["$t"]; playlist.push(id); } this.player.playlist = playlist; } } });