From 2a22cd975c629ef76a9a8617cda5eaf628e5e10a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 8 Sep 2017 21:32:52 +0300 Subject: [PATCH] cleanup and refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 8 +-- ui (gen4)/features/marks.js | 8 +-- ui (gen4)/imagegrid/data.js | 107 +++++++++--------------------------- 3 files changed, 35 insertions(+), 88 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index 3a0b487e..7cc43f65 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -826,13 +826,13 @@ actions.Actions({ // corresponding normal shift operations... // XXX .undoLast(..) on these for some reason skips... // ...e.g. two shifts are undone with three calls to .undoLast()... - shiftImageUpNewRibbon: ['Edit|Ribbon/Shift image up to a new empty ribbon', + shiftImageUpNewRibbon: ['Edit|Image/Shift image up to a new empty ribbon', {journal: true}, function(target){ this.data.newRibbon(target) this.shiftImageUp(target) }], - shiftImageDownNewRibbon: ['Edit|Ribbon/Shift image down to a new empty ribbon', + shiftImageDownNewRibbon: ['Edit|Image/Shift image down to a new empty ribbon', {journal: true}, function(target){ this.data.newRibbon(target, 'below') @@ -877,14 +877,14 @@ actions.Actions({ }], // these operate on the current image... - travelImageUp: ['Edit/Travel with the current image up (Shift up and keep focus)', + travelImageUp: ['Edit|Image/Travel with the current image up (Shift up and keep focus)', {undo: undoShift('travelImageDown')}, function(target){ target = target || this.current this.shiftImageUp(target) this.focusImage(target) }], - travelImageDown: ['Edit/Travel with the current image down (Shift down and keep focus)', + travelImageDown: ['Edit|Image/Travel with the current image down (Shift down and keep focus)', {undo: undoShift('travelImageUp')}, function(target){ target = target || this.current diff --git a/ui (gen4)/features/marks.js b/ui (gen4)/features/marks.js index 3770f930..ae427a6b 100755 --- a/ui (gen4)/features/marks.js +++ b/ui (gen4)/features/marks.js @@ -338,22 +338,22 @@ var ImageMarkEditActions = actions.Actions({ }) }], - shiftMarkedUp: ['Mark|Ribbon/Shift marked $up', + shiftMarkedUp: ['Mark/Shift marked $up', {undo: undoShift('shiftMarkedDown'), browseMode: 'cropMarked'}, shiftMarked('up')], - shiftMarkedDown: ['Mark|Ribbon/Shift marked $down', + shiftMarkedDown: ['Mark/Shift marked $down', {undo: undoShift('shiftMarkedUp'), browseMode: 'cropMarked'}, shiftMarked('down')], // XXX undo... - shiftMarkedAfter: ['Mark|Ribbon|Image/Shift marked after', + shiftMarkedAfter: ['Mark|Image/Shift marked after', {browseMode: 'cropMarked'}, function(target){ this.shiftImageTo(this.marked, target || 'current', 'after') }], // XXX undo... - shiftMarkedBefore: ['Mark|Ribbon|Image/Shift marked before', + shiftMarkedBefore: ['Mark|Image/Shift marked before', {browseMode: 'cropMarked'}, function(target){ this.shiftImageTo(this.marked, target || 'current', 'before') }], diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 00213f93..809bf836 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -1576,70 +1576,6 @@ var DataPrototype = { this.ribbon_order.reverse() }, - // Gather gids into a connected section... - // - // The section is positioned relative to a reference gid, which also - // determines the ribbon. - // - // Gather images relative to current image - // .gatherImages(images) - // .gatherImages(images, 'current') - // -> data - // - // Gather images relative to image/ribbon - // .gatherImages(images, image|ribbon) - // -> data - // - // Gather images relative to first/last image in given images - // .gatherImages(images, 'first') - // .gatherImages(images, 'last') - // -> data - // - // Gather images relative to image/ribbon and place them strictly - // after (default) or before it... - // .gatherImages(images, 'auto') - // .gatherImages(images, 'after') - // .gatherImages(images, 'before') - // .gatherImages(images, image|ribbon, 'auto') - // .gatherImages(images, image|ribbon, 'after') - // .gatherImages(images, image|ribbon, 'before') - // -> data - // - // Gather images only in one explicit dimension... - // .gatherImages(.., 'horizontal') - // .gatherImages(.., 'vertical') - // -> data - // - // NOTE: if mode is 'vertical' then place is ignored... - // NOTE: this is a different interface to .placeImage(..) - gatherImages: function(images, reference, place, mode){ - var that = this - var args = [].slice.call(arguments) - - var modes = /vertical|horizontal|both/ - var placements = /before|after|auto/ - - // get trailing args first, if given... - mode = modes.test(args.slice(-1)[0]) ? args.pop() : mode - place = placements.test(args.slice(-1)[0]) ? args.pop() : place - place = place || 'after' - - reference = args[1] || 'current' - reference = (reference == 'first' || reference == 'last') ? - this.makeSparseImages(images).compact()[reference == 'first' ? 0 : images.length-1] - : this.getImage(reference) - - return this.placeImage( - images, - mode == 'horizontal' ? - 'keep' : - this.getRibbon(reference), - mode == 'vertical' ? - 'keep' - : reference, - place) - }, - // Place image at position... // // Place images at order into ribbon... @@ -1742,15 +1678,24 @@ var DataPrototype = { // Shift image... // - // Shift image to target position: + // Shift image(s) to after target position: // .shiftImage(from, gid|order|ribbon) - // .shiftImage(from, gid|order|ribbon, 'before') // .shiftImage(from, gid|order|ribbon, 'after') - // -> data // - // Shift image by offset: + // Shift image(s) to before target position: + // .shiftImage(from, gid|order|ribbon, 'before') + // -> this + // + // Shift vertically only -- keep image order... + // .shiftImage(from, gid|order|ribbon, 'vertical') + // + // Shift horizontally only -- keep image(s) in same ribbons... + // .shiftImage(from, gid|order|ribbon, 'horizontal') + // + // + // Shift image(s) by offset: // .shiftImage(from, offset, 'offset') - // -> data + // -> this // // // order is expected to be ribbon order. @@ -1765,29 +1710,27 @@ var DataPrototype = { // // // NOTE: this will not create new ribbons. - // NOTE: .getImage(..) defaults to 'before' thus this to defaults - // to 'after' + // NOTE: this is a different interface to .placeImage(..) // - // XXX needs better docs... - shiftImage: function(from, target, mode, direction){ + // XXX should we use .placeImage(..) instead??? + shiftImage: function(from, target, mode){ from = from == null || from == 'current' ? this.current : from if(from == null){ return } from = from instanceof Array ? from : [from] - var place - // target is an offset... if(mode == 'offset'){ if(target > 0){ var t = this.getImage(from.slice(-1)[0], target) || this.getImage('last', from.slice(-1)[0]) - place = from.indexOf(t) >= 0 ? null : 'after' + var direction = from.indexOf(t) >= 0 ? null : 'after' + } else { var t = this.getImage(from[0], target) || this.getImage('first', from[0]) - place = from.indexOf(t) >= 0 ? null : 'before' + var direction = from.indexOf(t) >= 0 ? null : 'before' } // target is ribbon index... @@ -1795,15 +1738,19 @@ var DataPrototype = { var t = this.getImage(this.getRibbon(target)) // in case of an empty ribbon... || this.getRibbon(target) - place = mode || 'after' + var direction = mode == 'before' || mode == 'after' ? mode : 'after' // target is an image... } else { var t = this.getImage(target) - place = mode || 'after' + var direction = mode == 'before' || mode == 'after' ? mode : 'after' } - return this.gatherImages(from, t, place, direction) + return this.placeImage( + from, + mode == 'horizontal' ? 'keep' : t, + mode == 'vertical' ? 'keep' : t, + direction) }, // Shorthand actions...