From 4e615e722d6de5055f6c024b45f50da1021c17fc Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Mon, 30 Jan 2012 20:48:19 +0000 Subject: [PATCH] fix and optimize video preview --- source/Ox.UI/css/Ox.UI.css | 2 +- source/Ox.UI/js/Calendar/Ox.Calendar.js | 6 ++-- source/Ox.UI/js/Video/Ox.VideoPreview.js | 35 +++++++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/source/Ox.UI/css/Ox.UI.css b/source/Ox.UI/css/Ox.UI.css index 2afd596b..019894e4 100644 --- a/source/Ox.UI/css/Ox.UI.css +++ b/source/Ox.UI/css/Ox.UI.css @@ -776,7 +776,7 @@ div.OxInput > input.OxInput { } /* -------------------------------------------------------------------------------- -OxEditable +OxEditableElement -------------------------------------------------------------------------------- */ diff --git a/source/Ox.UI/js/Calendar/Ox.Calendar.js b/source/Ox.UI/js/Calendar/Ox.Calendar.js index b15041d0..f99cf535 100644 --- a/source/Ox.UI/js/Calendar/Ox.Calendar.js +++ b/source/Ox.UI/js/Calendar/Ox.Calendar.js @@ -419,10 +419,10 @@ Ox.Calendar = function(options, self) { .css({bottom: 40 + (self.options.showZoombar * 16) + 'px'}) .bindEvent({ singleclick: function() { - // ... + // ... FIXME: implement }, doubleclick: function() { - // ... + // ... FIXME: implement } }) .appendTo(that), @@ -437,7 +437,7 @@ Ox.Calendar = function(options, self) { scrollBy(1); }, doubleclick: function() { - scrollTo(1000000, true) + scrollTo(1000000, true); } }) .appendTo(that), diff --git a/source/Ox.UI/js/Video/Ox.VideoPreview.js b/source/Ox.UI/js/Video/Ox.VideoPreview.js index 24edd38a..7c2b4eb0 100644 --- a/source/Ox.UI/js/Video/Ox.VideoPreview.js +++ b/source/Ox.UI/js/Video/Ox.VideoPreview.js @@ -44,10 +44,15 @@ Ox.VideoPreview = function(options, self) { self.$interface = Ox.Element({ tooltip: function(event) { - //event.offsetX does not work in Firefox - // fixme: use layerX then + // e.offsetX does not work in Firefox var position = getPosition(event.clientX - that.offset().left); - self.$frame.attr({src: self.options.getFrame(position)}); + self.$frame.attr({src: getClosestFrame(position)}); + Ox.print('closest frame:', self.$frame.attr('src')); + self.timeout && clearTimeout(self.timeout); + self.timeout = setTimeout(function() { + self.$frame.attr({src: self.options.getFrame(position)}); + Ox.print('exact frame:', self.$frame.attr('src')); + }, 250); return Ox.formatDuration(position, 2); } }) @@ -69,6 +74,14 @@ Ox.VideoPreview = function(options, self) { }); } + function getClosestFrame(position) { + return self.loaded.length == 0 + ? self.options.getFrame(self.options.position) + : self.loaded.sort(function(a, b) { + return Math.abs(a.position - position) - Math.abs(b.position - position); + })[0].frame; + } + function getFrameCSS() { var css = {}, elementWidth = self.options.width, @@ -106,23 +119,25 @@ Ox.VideoPreview = function(options, self) { } steps.forEach(function(step) { Ox.loop(0, self.options.width, step, function(x) { - var frame = self.options.getFrame(getPosition(x)); + var position = getPosition(x), + frame = self.options.getFrame(position); if ( - self.loaded.indexOf(frame) == -1 - && self.queue.indexOf(frame) == -1 + !Ox.getObject(self.loaded, 'frame', frame) + && !Ox.getObject(self.queue, 'frame', frame) ) { - self.queue.push(frame); + self.queue.push({frame: frame, position: position}); } }); }); - loadFrame(); + self.queue.length && loadFrame(); function loadFrame() { + var image = self.queue.shift(); $('') .load(function() { - self.loaded.push(self.queue.shift()); + self.loaded.push(image); self.queue.length && loadFrame(); }) - .attr({src: self.queue[0]}); + .attr({src: image.frame}) } }