From 5258797173c774dfb0d72a0152b8fda999f74053 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 10 Jul 2013 00:30:33 +0400 Subject: [PATCH] some refactoring and cleanup... Signed-off-by: Alex A. Naanou --- ui/compatibility.js | 10 +++++++++- ui/data.js | 15 --------------- ui/files.js | 22 ++++++++++++++-------- ui/lib/jli.js | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/ui/compatibility.js b/ui/compatibility.js index db6956ae..e5f8cd95 100755 --- a/ui/compatibility.js +++ b/ui/compatibility.js @@ -427,10 +427,12 @@ if(window.CEF_dumpJSON != null){ getVipsField('exif-ifd0-Artist', source), getVipsField('exif-ifd0-Date and Time', source)) .done(function(artist, date){ + // Artist... artist = artist .replace(/\([^)]*\)/, '') .trim() artist = artist == '' ? 'Unknown' : artist + // Date... // format: "20130102-122315" // XXX if not set, get ctime... date = date @@ -438,6 +440,7 @@ if(window.CEF_dumpJSON != null){ .trim() .replace(/:/g, '') .replace(/ /g, '-') + // File name... var name = source.split(/[\\\/]/).pop().split('.')[0] var text_gid = artist +'-'+ date +'-'+ name @@ -455,6 +458,10 @@ if(window.CEF_dumpJSON != null){ getter.resolve(hex_gid) } }) + // XXX handle arrors in a more informative way... + .fail(function(){ + getter.reject() + }) return getter } @@ -491,7 +498,6 @@ if(window.CEF_dumpJSON != null){ - // PhoneGap } else if(false){ @@ -504,6 +510,8 @@ if(window.CEF_dumpJSON != null){ window.showDevTools = function(){} window.reload = function(){} + + // Bare Chrome... } else { console.log('Chrome mode: loading...') diff --git a/ui/data.js b/ui/data.js index 5013f9d7..8d5303ba 100755 --- a/ui/data.js +++ b/ui/data.js @@ -139,21 +139,6 @@ var DATA_FILE_PATTERN = /^[0-9]*-data.json$/ var IMAGE_PATTERN = /.*\.(jpg|jpeg|png|gif)$/i - -/* -var UI_IMAGE_CACHE = [] -$.each([ - 'images/loding.gif', - 'images/loding-90deg.gif', - 'images/loding-180deg.gif', - 'images/loding-270deg.gif' -], function(i, e){ - var img = new Image() - img.src = e - UI_IMAGE_CACHE.push(img) -}) -*/ - var UPDATE_SORT_ENABLED = false // XXX for some reason the sync version appears to work faster... var UPDATE_SYNC = false diff --git a/ui/files.js b/ui/files.js index a446bd76..b9d7f671 100755 --- a/ui/files.js +++ b/ui/files.js @@ -683,7 +683,7 @@ function updateImageOrientation(gid, no_update_loaded){ IMAGES_UPDATED.push(gid) } - // update loaded images... + // update image if loaded... if(!no_update_loaded){ var o = getImage(gid) if(o.length > 0){ @@ -708,26 +708,32 @@ function updateImagesOrientation(gids, no_update_loaded){ // queued version of updateImagesOrientation(...) // +// NOTE: this will ignore errors. +// // XXX need a way to cancel this... +// - one way is to .reject(...) any of the still pending elements, +// but there appears no way of getting the list out of when... function updateImagesOrientationQ(gids, no_update_loaded){ gids = gids == null ? getClosestGIDs() : gids - var res = [] + //var res = [] var last = $.Deferred().resolve() $.each(gids, function(_, gid){ var cur = $.Deferred() last.done(function(){ - last = updateImageOrientation(gid, no_update_loaded) - .done(function(o){ - cur.resolve() - }) + updateImageOrientation(gid, no_update_loaded) + .done(function(o){ cur.resolve(o) }) + .fail(function(){ cur.resolve('fail') }) }) - res.push(cur) + last = cur + //res.push(cur) }) - return $.when.apply(null, res) + // NOTE: .when(...) is used to add more introspecitve feedback... + //return $.when.apply(null, res) + return last } diff --git a/ui/lib/jli.js b/ui/lib/jli.js index 9d691bf1..631f05cc 100755 --- a/ui/lib/jli.js +++ b/ui/lib/jli.js @@ -678,6 +678,24 @@ function assyncCall(func){ } +/* +function chainDeferreds(deferred, after){ + after = after == null ? $.Deferred.resolve() : after + + $.each(deferred, function(_, d){ + var cur = $.Deferred() + after.done(function(){ + d() + .done(function(){ cur.resolve() }) + .fail(function(){ cur.reject() }) + }) + after = cur + }) + + return after +} +*/ + /**********************************************************************