From 6d80a86ab20edf3293ae7dfbdd1772794869313b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 21 Sep 2013 05:47:54 +0400 Subject: [PATCH] made crop modes alot more generic... Signed-off-by: Alex A. Naanou --- ui/data.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui/index.html | 2 +- ui/marks.js | 24 +++------------------- ui/modes.js | 40 +++--------------------------------- 4 files changed, 63 insertions(+), 59 deletions(-) diff --git a/ui/data.js b/ui/data.js index ccfee879..7d1b116e 100755 --- a/ui/data.js +++ b/ui/data.js @@ -111,6 +111,8 @@ var MARKED = [] var CROP_STACK = [] +var CROP_MODES = [] + // NOTE: these are named: - var SETTINGS = { 'global-theme': null, @@ -1639,6 +1641,60 @@ function showAllData(){ } +// Helpers for making crop modes and using crop... + +// Make a generic crop mode toggler +// +// NOTE: This will add the toggler to CROP_MODES, for use by +// uncropLastState(...) +function makeCropModeToggler(cls, crop){ + var res = createCSSClassToggler( + '.viewer', + cls + ' cropped-mode', + function(action){ + // prevent mixing marked-only and single-ribbon modes... + if(action == 'on' + && $('.viewer').hasClass('cropped-mode') + && res('?') != 'on'){ + return false + } + }, + function(action){ + if(action == 'on'){ + showStatusQ('Cropping current ribbon...') + crop() + } else { + showStatusQ('Uncropping to all data...') + showAllData() + } + }) + CROP_MODES.push(res) + return res +} + + +// Uncrop to last state and there is no states to uncrop then exit +// cropped mode. +// +// NOTE: this will exit all crop modes when uncropping the last step. +function uncropLastState(){ + // do nothing if we aren't in a crop mode... + if(!$('.viewer').hasClass('cropped-mode')){ + return + } + + // exit cropped all modes... + if(CROP_STACK.length == 1){ + $.each(CROP_MODES, function(_, e){ e('off') }) + + // ucrop one state... + } else { + showStatusQ('Uncropping...') + uncropData() + } +} + + /********************************************************* Workers ***/ diff --git a/ui/index.html b/ui/index.html index de068303..642a3ed9 100755 --- a/ui/index.html +++ b/ui/index.html @@ -22,9 +22,9 @@ + - diff --git a/ui/marks.js b/ui/marks.js index e86b6808..c406dcce 100755 --- a/ui/marks.js +++ b/ui/marks.js @@ -46,27 +46,9 @@ function cropMarkedImages(cmp, no_cleanout_marks){ */ // XXX is this a mode??? -var toggleMarkedOnlyView = createCSSClassToggler( - '.viewer', - 'marked-only-view cropped-mode', - function(action){ - // prevent mixing marked-only and single-ribbon modes... - if(action == 'on' - && $('.viewer').hasClass('cropped-mode') - && toggleMarkedOnlyView('?') != 'on'){ - return false - } - }, - function(action){ - if(action == 'on'){ - // XXX do we need to keep ribbons here??? - showStatusQ('Cropping marked images...') - cropMarkedImages() - } else { - showStatusQ('Uncropping to all data...') - showAllData() - } - }) +var toggleMarkedOnlyView = makeCropModeToggler( + 'marked-only-view', + cropMarkedImages) // XXX shifting images and unmarking in this mode do not work correctly... diff --git a/ui/modes.js b/ui/modes.js index 189148fc..4e7ebc97 100755 --- a/ui/modes.js +++ b/ui/modes.js @@ -173,47 +173,13 @@ var toggleSingleImageMode = createCSSClassToggler( // XXX make this not conflict with marked-only-mode, better yet, make them // one single mode... // XXX is this a mode??? -var toggleSingleRibbonMode = createCSSClassToggler( - '.viewer', - 'single-ribbon-mode cropped-mode', - function(action){ - // prevent mixing marked-only and single-ribbon modes... - if(action == 'on' - && $('.viewer').hasClass('cropped-mode') - && toggleSingleRibbonMode('?') != 'on'){ - return false - } - }, - function(action){ - if(action == 'on'){ - showStatusQ('Cropping current ribbon...') +var toggleSingleRibbonMode = makeCropModeToggler( + 'single-ribbon-mode', + function(){ cropDataTo(DATA.ribbons[getRibbonIndex()].slice()) - } else { - showStatusQ('Uncropping to all data...') - showAllData() - } }) -function uncropLastState(){ - if(toggleSingleRibbonMode('?') == 'off' - && toggleMarkedOnlyView('?') == 'off'){ - return - } - - // exit cropped mode... - if(CROP_STACK.length == 1){ - toggleSingleRibbonMode('off') - toggleMarkedOnlyView('off') - - // ucrop one state... - } else { - showStatusQ('Uncropping...') - uncropData() - } -} - - // TODO transitions... // TODO a real setup UI (instead of prompt) var toggleSlideShowMode = createCSSClassToggler(