merging changes (api, app, video)

This commit is contained in:
rlx 2011-12-21 13:44:22 +00:00
commit fe303bf2b0
8 changed files with 126 additions and 68 deletions

View file

@ -0,0 +1,75 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
/*@
Ox.Api <o> bin remote api to object
options <o> Options object
timeout <n|60000> request timeout
url <s> request url
callback <f> called once api discover is done
@*/
Ox.Api = function(options, callback) {
var self = {
options: Ox.extend({
timeout: 60000,
type: 'POST',
url: '/api/'
}, options || {}),
time: new Date()
},
that = {
api: function(callback) {
Ox.Request.send({
url: self.options.url,
data: {
action: 'api'
},
callback: callback
});
},
cancel: function(id) {
Ox.Request.cancel(id);
}
};
$.ajaxSetup({
timeout: self.options.timeout,
type: self.options.type,
url: self.options.url
});
/*@
api <o> bakcend API
[action] <f> all api requests available on backend
cancel <f> cancel a request
options <f> get or set options
@*/
that.api(function(result) {
Ox.forEach(result.data.actions, function(val, key) {
that[key] = function(/*data, age, callback*/) {
var data = {}, age = -1, callback = null;
Ox.forEach(arguments, function(argument) {
if (Ox.isObject(argument)) {
data = argument;
} else if (Ox.isNumber(argument)) {
age = argument;
} else if (Ox.isFunction(argument)) {
callback = argument;
}
});
return Ox.Request.send(Ox.extend({
age: age,
callback: callback,
data: {
action: key,
data: JSON.stringify(data)
},
url: self.options.url
}, !val.cache ? {age: 0}: {}));
};
});
callback && callback();
});
return that;
};

View file

@ -20,63 +20,17 @@ Ox.App = function(options) {
options: Ox.extend({ options: Ox.extend({
timeout: 60000, timeout: 60000,
type: 'POST', type: 'POST',
url: '/api/', url: '/api/'
}, options || {}), }, options || {}),
time: new Date() time: new Date()
}, },
that = Ox.Element({}, Ox.extend({}, self)); that = Ox.Element({}, Ox.extend({}, self));
that.api = { that.api = Ox.Api({
api: function(callback) {
Ox.Request.send({
url: self.options.url,
data: {
action: 'api'
},
callback: callback
});
},
cancel: function(id) {
Ox.Request.cancel(id);
}
};
$.ajaxSetup({
timeout: self.options.timeout,
type: self.options.type, type: self.options.type,
timeout: self.options.timeout,
url: self.options.url url: self.options.url
}); }, function() {
/*@
api <o> bakcend API
[action] <f> all api requests available on backend
cancel <f> cancel a request
options <f> get or set options
@*/
that.api.api(function(result) {
Ox.forEach(result.data.actions, function(val, key) {
that.api[key] = function(/*data, age, callback*/) {
var data = {}, age = -1, callback = null;
Ox.forEach(arguments, function(argument) {
if (Ox.isObject(argument)) {
data = argument;
} else if (Ox.isNumber(argument)) {
age = argument;
} else if (Ox.isFunction(argument)) {
callback = argument;
}
});
return Ox.Request.send(Ox.extend({
age: age,
callback: callback,
data: {
action: key,
data: JSON.stringify(data)
},
url: self.options.url
}, !val.cache ? {age: 0}: {}));
};
});
that.api.init(getUserData(), function(result) { that.api.init(getUserData(), function(result) {
//Ox.UI.hideLoadingScreen(); //Ox.UI.hideLoadingScreen();
that.triggerEvent({ that.triggerEvent({

View file

@ -113,18 +113,30 @@ Ox.MenuButton = function(options, self) {
} }
} }
/*@
checkItem <f>
@*/
that.checkItem = function(id) { that.checkItem = function(id) {
self.$menu.checkItem(id); self.$menu.checkItem(id);
}; };
/*@
disableItem <f>
@*/
that.disableItem = function(id) { that.disableItem = function(id) {
self.$menu.getItem(id).options({disabled: true}); self.$menu.getItem(id).options({disabled: true});
}; };
/*@
enableItem <f>
@*/
that.enableItem = function(id) { that.enableItem = function(id) {
self.$menu.getItem(id).options({disabled: false}); self.$menu.getItem(id).options({disabled: false});
}; };
/*@
remove <f>
@*/
self.superRemove = that.remove; self.superRemove = that.remove;
that.remove = function() { that.remove = function() {
self.$menu.remove(); self.$menu.remove();

View file

@ -78,12 +78,7 @@ Ox.AnnotationPanel = function(options, self) {
.addClass('OxAnnotation OxTarget'); .addClass('OxAnnotation OxTarget');
return $item; return $item;
}, },
items: self.options.items.map(function(v, i) { items: self.options.items,
return {
id: v.id || i + '',
value: v.value
};
}),
max: 1, max: 1,
unique: 'id' unique: 'id'
}) })

View file

@ -35,6 +35,7 @@ Ox.VideoEditor = function(options, self) {
position: 0, position: 0,
posterFrame: 0, posterFrame: 0,
posterFrameControls: false, posterFrameControls: false,
resolution: 0,
showAnnotations: false, showAnnotations: false,
showLargeTimeline: true, showLargeTimeline: true,
subtitles: [], subtitles: [],
@ -190,6 +191,7 @@ Ox.VideoEditor = function(options, self) {
paused: true, paused: true,
position: type == 'play' ? self.options.position : self.options[type], position: type == 'play' ? self.options.position : self.options[type],
posterFrame: self.options.posterFrame, posterFrame: self.options.posterFrame,
resolution: self.options.resolution,
showMarkers: true, showMarkers: true,
showMilliseconds: 3, showMilliseconds: 3,
sizeIsLarge: self.options.videoSize == 'large', sizeIsLarge: self.options.videoSize == 'large',
@ -215,6 +217,9 @@ Ox.VideoEditor = function(options, self) {
changePlayer(data); changePlayer(data);
that.triggerEvent('position', data); that.triggerEvent('position', data);
}, },
resolution: function(data) {
that.triggerEvent('resolution', data);
},
size: toggleSize, size: toggleSize,
volume: function(data) { volume: function(data) {
that.triggerEvent('volume', data); that.triggerEvent('volume', data);
@ -326,9 +331,10 @@ Ox.VideoEditor = function(options, self) {
self.resolutions = []; self.resolutions = [];
Ox.forEach(self.options.video, function(url, resolution) { Ox.forEach(self.options.video, function(url, resolution) {
Ox.Log('Video', url, resolution) Ox.Log('Video', url, resolution);
self.resolutions.push( self.resolutions.push(
{id: resolution + '', title: resolution + 'p'} {id: resolution + '', title: resolution + 'p',
checked: self.options.resolution == resolution}
); );
}); });
@ -390,7 +396,10 @@ Ox.VideoEditor = function(options, self) {
{id: 'toggleSize', title: 'Large Player', selected: self.options.playerSize == 'large', keyboard: 'shift +'}, {id: 'toggleSize', title: 'Large Player', selected: self.options.playerSize == 'large', keyboard: 'shift +'},
{} {}
], ],
self.resolutions, {
'id': 'resolution', title:'Resolution',
items: [ { group: 'resolution', min: 1, max: 1, items: self.resolutions } ]
},
[ [
{}, {},
{id: 'largeTimeline', title: 'Hide Large Timeline', disabled: true}, {id: 'largeTimeline', title: 'Hide Large Timeline', disabled: true},
@ -425,6 +434,9 @@ Ox.VideoEditor = function(options, self) {
title: 'Keyboard Shortcuts', title: 'Keyboard Shortcuts',
width: 256 width: 256
}).open(); }).open();
} else if (id == 'resolution') {
self.options.resolution = parseInt(data.checked[0].id);
self.$player[0].options({resolution: self.options.resolution});
} }
} }
}) })
@ -445,13 +457,12 @@ Ox.VideoEditor = function(options, self) {
self.$resolutionSelect = Ox.Select({ self.$resolutionSelect = Ox.Select({
items: [{id: '96', title: '96p'},{id: '240', title: '240p'}],//self.resolutions, items: self.resolutions,
width: 48 width: 48,
}) })
.css({float: 'left'}) .css({float: 'left'})
.bindEvent({ .bindEvent({
change: function() { change: function(data) {
} }
}); });
//.appendTo(self.$videobar); //.appendTo(self.$videobar);

View file

@ -418,12 +418,12 @@ Ox.VideoElement = function(options, self) {
ret = self.video.src; ret = self.video.src;
} else { } else {
self.options.src = Ox.isArray(arguments[0]) ? arguments[0] : [arguments[0]]; self.options.src = Ox.isArray(arguments[0]) ? arguments[0] : [arguments[0]];
self.videos[currentPart].src = self.options.src[currentPart]; self.$video[self.currentPart].src = self.options.src[self.currentPart];
self.videos.forEach(function(video, i) { self.$video.each(function(video, i) {
if (i != currentPart) { if (i != self.currentPart) {
video.src = self.options.src[i]; video.src = self.options.src[i];
} }
}) });
ret = that; ret = that;
} }
return ret; return ret;

View file

@ -30,6 +30,7 @@ Ox.VideoPanelPlayer = function(options, self) {
playInToOut: false, playInToOut: false,
position: 0, position: 0,
poster: '', poster: '',
resolution: 0,
scaleToFill: false, scaleToFill: false,
showAnnotations: true, showAnnotations: true,
showTimeline: true, showTimeline: true,
@ -77,6 +78,7 @@ Ox.VideoPanelPlayer = function(options, self) {
out: self.options.out, out: self.options.out,
paused: true, paused: true,
position: self.options.position, position: self.options.position,
resolution: self.options.resolution,
scaleToFill: self.options.scaleToFill, scaleToFill: self.options.scaleToFill,
subtitles: self.options.subtitles, subtitles: self.options.subtitles,
timeline: self.options.timeline, timeline: self.options.timeline,
@ -103,6 +105,9 @@ Ox.VideoPanelPlayer = function(options, self) {
setPosition(data); setPosition(data);
that.triggerEvent('position', data); that.triggerEvent('position', data);
}, },
resolution: function(data) {
that.triggerEvent('resolution', data);
},
scale: function(data) { scale: function(data) {
that.triggerEvent('scale', data); that.triggerEvent('scale', data);
}, },

View file

@ -1112,6 +1112,7 @@ Ox.VideoPlayer = function(options, self) {
self.iconIsVisible = true; self.iconIsVisible = true;
} }
self.options.rewind && rewind(); self.options.rewind && rewind();
that.triggerEvent('ended');
} }
function find(query) { function find(query) {
@ -1806,6 +1807,9 @@ Ox.VideoPlayer = function(options, self) {
self.$playButton && self.$playButton.options({ self.$playButton && self.$playButton.options({
disabled: true disabled: true
}); });
that.triggerEvent('resolution', {
resolution: self.options.resolution
});
} }
function setSize($element, css, animate, callback) { function setSize($element, css, animate, callback) {
@ -2244,6 +2248,8 @@ Ox.VideoPlayer = function(options, self) {
setPosition(value); setPosition(value);
} else if (key == 'posterFrame') { } else if (key == 'posterFrame') {
self.options.paused && setMarkers(); self.options.paused && setMarkers();
} else if (key == 'resolution') {
setResolution();
} else if (key == 'scaleToFill') { } else if (key == 'scaleToFill') {
toggleScale(); toggleScale();
} }