var proxy = {
ids: [],
delay: 50,
timeout: null,
callback: null,
context: null,
// 设置请求的id和callback以便在播放的时候触发回调
makeRequest: function (id, callback, context) {
// 添加到队列dd to the queue
this.ids.push(id);
this.callback = callback;
this.context = context;
// 设置timeout
if (!this.timeout) {
this.timeout = setTimeout(function () {
proxy.flush();
}, this.delay);
}
},
// 触发请求,使用代理职责调用了http.makeRequest
flush: function () {
// proxy.handler为请求yahoo时的callback
http.makeRequest(this.ids, 'proxy.handler');
// 请求数据以后,紧接着执行proxy.handler方法(里面有另一个设置的callback)
// 清楚timeout和队列
this.timeout = null;
this.ids = [];
},
handler: function (data) {
var i, max;
// 单个视频的callback调用
if (parseInt(data.query.count, 10) === 1) {
proxy.callback.call(proxy.context, data.query.results.Video);
return;
}
// 多个视频的callback调用
for (i = 0, max = data.query.results.Video.length; i < max; i += 1) {
proxy.callback.call(proxy.context, data.query.results.Video[i]);
}
}
};
视频处理模块主要有3种子功能:获取信息、展示信息、播放视频:
复制代码 代码如下:
var videos = {
// 初始化播放器代码,开始播放
getPlayer: function (id) {
return '' +
'<object allowFullScreen="true">' +
'<param value="http://d.yimg.com/m/up/fop/embedflv/swf/fop.swf"\/>' +
'<param value="id=v' + id + '&eID=1301797&lang=us&enableFullScreen=0&shareEnable=1"\/>' +
'<param value="transparent"\/>' +
'<embed ' +
'height="255" ' +
'width="400" ' +
'id="uvp_fop" ' +
'allowFullScreen="true" ' +
'src="http://d.yimg.com/m/up/fop/embedflv/swf/fop.swf" ' +
'type="application/x-shockwave-flash" ' +
'flashvars="id=v' + id + '&eID=1301797&lang=us&ympsc=4195329&enableFullScreen=1&shareEnable=1"' +
'\/>' +
'<\/object>';
},
// 拼接信息显示内容,然后在append到li的底部里显示
updateList: function (data) {
var id,
html = '',
info;