From aadd8c8458d757a959e2158411c18d8922640073 Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 17 May 2011 12:00:49 +0200 Subject: [PATCH] don't use canvas for the timeline image --- .../Ox.UI/js/Video/Ox.BlockVideoTimeline.js | 13 +-- .../js/Video/Ox.SmallVideoTimelineImage.js | 95 ++++++++----------- 2 files changed, 44 insertions(+), 64 deletions(-) diff --git a/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js b/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js index c5e487d6..af58ca49 100644 --- a/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js +++ b/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js @@ -53,14 +53,11 @@ Ox.BlockVideoTimeline = function(options, self) { timeline: self.options.timeline, width: Math.ceil(self.options.duration), type: self.options.type - }) - .bindEvent('load', function() { - // wait until the timeline image (the one image that is async) - // has loaded, so we can clone the element - Ox.loop(self.lines, function(i) { - addLine(i); - }); - }) + }); + + Ox.loop(self.lines, function(i) { + addLine(i); + }); self.$positionMarker = $('') .attr({ diff --git a/source/Ox.UI/js/Video/Ox.SmallVideoTimelineImage.js b/source/Ox.UI/js/Video/Ox.SmallVideoTimelineImage.js index e30d6f6f..cae705e8 100644 --- a/source/Ox.UI/js/Video/Ox.SmallVideoTimelineImage.js +++ b/source/Ox.UI/js/Video/Ox.SmallVideoTimelineImage.js @@ -24,8 +24,11 @@ Ox.SmallVideoTimelineImage = function(options, self) { // fixme: timeline doesn't have to go through canvas at all, // just use one or more images + self.images = Ox.isString(self.options.timeline) ? + 1 : Math.ceil(self.options.duration / 3600); + self.imageWidth = Ox.isString(self.options.timeline) ? + 1920 : Math.round(self.options.duration); self.height = self.options.type == 'player' ? 16 : 24; - self.imageWidth = Ox.isString(self.options.timeline) ? 1920 : Math.round(self.options.duration); self.imageHeight = self.options.type == 'player' ? 16 : 18; self.imageTop = self.options.type == 'player' ? 0 : 3; @@ -33,24 +36,34 @@ Ox.SmallVideoTimelineImage = function(options, self) { height: self.height + 'px' }); - self.$timeline = $('') - .attr({ - src: Ox.UI.PATH + 'png/transparent.png' - }) - .css({ - position: 'absolute', - width: self.options.width + 'px', - height: self.imageHeight + 'px', - top: self.imageTop + 'px' - }) - .appendTo(that.$element); - - getImageURL('timeline', function(imageURL) { - self.$timeline.attr({ - src: imageURL + if (Ox.isString(self.options.timeline)) { + self.$timeline = $('') + .attr({ + src: self.options.timeline + }) + .css({ + position: 'absolute', + top: self.imageTop + 'px', + width: self.options.width + 'px', + height: self.imageHeight + 'px', + }) + .appendTo(that.$element); + } else { + Ox.loop(self.images, function(i) { + $('') + .attr({ + src: self.options.timeline(i) + }) + .css({ + position: 'absolute', + left: (i * 3600) + 'px', + top: self.imageTop + 'px', + width: (i == self.images - 1 ? self.imageWidth % 3600 : 3600) + 'px', + height: self.imageHeight + 'px', + }) + .appendTo(that.$element); }); - that.triggerEvent('load'); - }); + } self.$subtitles = $('') .attr({ @@ -58,9 +71,9 @@ Ox.SmallVideoTimelineImage = function(options, self) { }) .css({ position: 'absolute', + top: self.imageTop + 'px', width: self.options.width + 'px', - height: self.imageHeight + 'px', - top: self.imageTop + 'px' + height: self.imageHeight + 'px' }) .appendTo(that.$element); @@ -70,9 +83,9 @@ Ox.SmallVideoTimelineImage = function(options, self) { }) .css({ position: 'absolute', + top: self.imageTop + 'px', width: self.options.width + 'px', - height: self.imageHeight + 'px', - top: self.imageTop + 'px' + height: self.imageHeight + 'px' }) .appendTo(that.$element); @@ -82,9 +95,9 @@ Ox.SmallVideoTimelineImage = function(options, self) { }) .css({ position: 'absolute', + top: self.imageTop + 'px', width: self.options.width + 'px', - height: self.imageHeight + 'px', - top: self.imageTop + 'px' + height: self.imageHeight + 'px' }) .appendTo(that.$element); @@ -168,39 +181,9 @@ Ox.SmallVideoTimelineImage = function(options, self) { }); }); }); - } else if (image == 'timeline') { - var $image, counter, images, - top = self.options.type == 'player' ? 0 : 1; - if (Ox.isString(self.options.timeline)) { - $image = $('') - .attr({ - src: self.options.timeline - }) - .load(function() { - context.drawImage($image[0], 0, top) - callback(canvas.toDataURL()); - }); - } else { - counter = 0; - images = Math.ceil(self.options.duration / 3600); - Ox.loop(images, function(i) { - var $image = $('') - .attr({ - src: self.options.timeline(i) - }) - .load(function() { - context.drawImage($image[0], i * 3600, top); - if (++counter == images) { - callback(canvas.toDataURL()); - } - }); - }); - } - } - if (image != 'timeline') { - context.putImageData(imageData, 0, 0); - return canvas.toDataURL(); } + context.putImageData(imageData, 0, 0); + return canvas.toDataURL(); } function getPosition() {