fix #728 check if thumbExtractor is supported

remove fileReader its not needed

fix unit tests

fix typo

remove unecessary message
This commit is contained in:
Nicolas Le Goff
2012-06-18 16:11:28 +02:00
parent 44c34b2b75
commit 4edb26c6c6
8 changed files with 318 additions and 298 deletions

View File

@@ -1,30 +1,30 @@
;
(function(document){
/*****************
* Canva Object
*****************/
var Canva = function(domCanva){
this.domCanva = domCanva;
}
Canva.prototype = {
resize : function(elementDomNode){
var h = elementDomNode.getHeight();
var w = elementDomNode.getWidth();
this.domCanva.setAttribute("width", w);
this.domCanva.setAttribute("height", h);
return this;
},
getContext2d : function(){
if (this.domCanva.getContext == undefined)
if (this.domCanva.getContext == undefined)
{
return G_vmlCanvasManager
.initElement(this.domCanva)
.getContext("2d");
.getContext("2d");
}
return this.domCanva.getContext('2d');
@@ -36,17 +36,17 @@
var context = this.getContext2d();
var w = this.getWidth();
var h = this.getHeight();
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
context.clearRect(0, 0, w, h);
context.restore();
return this;
},
copy : function(elementDomNode){
var context = this.getContext2d();
context.drawImage(
elementDomNode.getDomElement()
, 0
@@ -54,7 +54,7 @@
, this.getWidth()
, this.getHeight()
);
return this;
},
getDomElement : function(){
@@ -67,15 +67,15 @@
return this.domCanva.offsetWidth;
}
};
/******************
* Image Object
******************/
var Image = function(domElement){
this.domElement = domElement;
};
Image.prototype = {
getDomElement : function(){
return this.domElement;
@@ -87,28 +87,28 @@
return this.domElement.offsetWidth;
}
};
/******************
* Video Object inherits from Image object
******************/
var Video = function(domElement){
Image.call(this, domElement);
};
Video.prototype = new Image();
Video.prototype.constructor = Video;
Video.prototype.getCurrentTime = function(){
return Math.floor(this.domElement.currentTime);
};
/******************
* Cache Object
******************/
var Store = function(){
this.datas = {};
};
Store.prototype = {
set : function(id, item){
this.datas[id] = item;
@@ -133,23 +133,23 @@
return count;
}
};
/******************
* Screenshot Object
******************/
var ScreenShot = function(id, canva, video){
var date = new Date();
canva.resize(video);
canva.copy(video);
this.id = id;
this.timestamp = date.getTime();
this.dataURI = canva.extractImage();
this.videoTime = video.getCurrentTime();
}
ScreenShot.prototype = {
getId:function(){
return this.id;
@@ -164,29 +164,34 @@
return this.videoTime;
}
};
/**
* THUMB EDITOR
*/
var ThumbEditor = function(videoId, canvaId){
var editorVideo = new Video(document.getElementById(videoId));
var store = new Store();
function getCanva(){
return document.getElementById(canvaId);
}
return {
isSupported : function () {
var elem = document.createElement('canvas');
return !! elem.getContext && !! elem.getContext('2d');
},
screenshot : function(){
var screenshot = new ScreenShot(
store.getLength() + 1,
new Canva(getCanva()),
editorVideo
);
store.set(screenshot.getId(), screenshot);
return screenshot;
},
store : store,
@@ -213,6 +218,6 @@
};
document.THUMB_EDITOR = ThumbEditor;
})(document);