mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
cleanup and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
8efdcbd3eb
commit
0f23ba8a15
@ -1617,10 +1617,9 @@ module.CropActions = actions.Actions({
|
||||
.shift()
|
||||
crop.focusImage(
|
||||
crop.getImage(this.current, 'after', r)
|
||||
|| crop.getImage(this.current, 'before', r))
|
||||
}
|
||||
|| crop.getImage(this.current, 'before', r)) }
|
||||
|
||||
this.crop(crop, flatten)
|
||||
this.crop(crop, flatten)
|
||||
}],
|
||||
cropOutRibbonsBelow: ['Crop/Crop out ribbons be$low',
|
||||
function(ribbon, flatten){
|
||||
@ -1723,10 +1722,8 @@ module.CropActions = actions.Actions({
|
||||
// add gids to current ribbon...
|
||||
gids.forEach(function(gid){
|
||||
var i = o.indexOf(gid)
|
||||
if(i >= 0){
|
||||
r[i] = gid
|
||||
}
|
||||
})
|
||||
i >= 0
|
||||
&& (r[i] = gid) })
|
||||
|
||||
// place...
|
||||
;(ribbon || reference || mode)
|
||||
|
||||
@ -287,30 +287,31 @@ var FileSystemLoaderActions = actions.Actions({
|
||||
//console.log('FOUND INDEXES:', Object.keys(res).length)
|
||||
|
||||
// skip nested paths...
|
||||
//
|
||||
// XXX make this optional...
|
||||
// XXX this is best done BEFORE we load all the
|
||||
// indexes, e.g. in .loadIndex(..)
|
||||
var skipped = new Set()
|
||||
var paths = Object.keys(res)
|
||||
var skipped = []
|
||||
paths
|
||||
.sort()
|
||||
.forEach(function(p){
|
||||
// already removed...
|
||||
if(skipped.indexOf(p) >= 0){
|
||||
return
|
||||
}
|
||||
if(skipped.has(p) >= 0){
|
||||
return }
|
||||
|
||||
paths
|
||||
// get all paths that fully contain p...
|
||||
.filter(function(o){
|
||||
return o != p && o.indexOf(p) == 0
|
||||
})
|
||||
// drop all longer paths...
|
||||
return o != p
|
||||
&& o.indexOf(p) == 0 })
|
||||
// drop all nested (longer) paths...
|
||||
.forEach(function(e){
|
||||
skipped.push(e)
|
||||
delete res[e]
|
||||
})
|
||||
})
|
||||
skipped.add(e)
|
||||
delete res[e] }) })
|
||||
// keep only the valid paths...
|
||||
paths = Object.keys(res)
|
||||
|
||||
//console.log('SKIPPING NESTED:', skipped.length)
|
||||
|
||||
var index
|
||||
@ -325,15 +326,13 @@ var FileSystemLoaderActions = actions.Actions({
|
||||
// skip empty indexes...
|
||||
// XXX should we rebuild or list here???
|
||||
if(res[k].data == null && res[k].images == null){
|
||||
continue
|
||||
}
|
||||
continue }
|
||||
|
||||
// build the data from images...
|
||||
if(res[k].data == null){
|
||||
res[k].data = {
|
||||
order: Object.keys(res[k].images),
|
||||
}
|
||||
}
|
||||
} }
|
||||
|
||||
// prepare to do a full save if format version updated...
|
||||
if(res[k].data.version != that.data.version){
|
||||
@ -342,8 +341,7 @@ var FileSystemLoaderActions = actions.Actions({
|
||||
logger && logger.emit('Data version changed:',
|
||||
v, '->', that.data.version)
|
||||
|
||||
force_full_save = true
|
||||
}
|
||||
force_full_save = true }
|
||||
|
||||
var part = that.prepareIndexForLoad(res[k], k)
|
||||
|
||||
@ -391,9 +389,8 @@ var FileSystemLoaderActions = actions.Actions({
|
||||
loaded: loaded,
|
||||
load: 'loadIndex',
|
||||
})
|
||||
if(from_date){
|
||||
index.location.from = from_date
|
||||
}
|
||||
from_date
|
||||
&& (index.location.from = from_date)
|
||||
|
||||
// this is the critical section, after this point we
|
||||
// are doing the actual loading....
|
||||
@ -402,8 +399,7 @@ var FileSystemLoaderActions = actions.Actions({
|
||||
force_full_save
|
||||
// XXX remove as soon as merged index save is done...
|
||||
&& loaded.length == 1
|
||||
&& that.markChanged('all')
|
||||
})
|
||||
&& that.markChanged('all') })
|
||||
})
|
||||
}],
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -181,10 +181,14 @@ module.calcRelativeRotation = function(from, to){
|
||||
to = from
|
||||
from = 0
|
||||
}
|
||||
to = to == 'cw' ? 1
|
||||
: to == 'ccw' ? -1
|
||||
: [0, 90, 180, 270].indexOf(to*1) >= 0 ? to*1
|
||||
: [-90, -180, -270].indexOf(to*1) >= 0 ? 360+(to*1)
|
||||
to = to == 'cw' ?
|
||||
1
|
||||
: to == 'ccw' ?
|
||||
-1
|
||||
: [0, 90, 180, 270].includes(to*1) ?
|
||||
to*1
|
||||
: [-90, -180, -270].includes(to*1) ?
|
||||
360+(to*1)
|
||||
: null
|
||||
|
||||
// relative rotation...
|
||||
@ -201,8 +205,7 @@ module.calcRelativeRotation = function(from, to){
|
||||
var res = to
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
return res }
|
||||
|
||||
|
||||
|
||||
@ -449,8 +452,7 @@ module.ImagesPrototype = {
|
||||
var i = keys.indexOf('version')
|
||||
i >= 0
|
||||
&& keys.splice(i, 1)
|
||||
return keys
|
||||
},
|
||||
return keys },
|
||||
|
||||
// Build an image index relative to an attribute...
|
||||
//
|
||||
@ -752,16 +754,15 @@ module.ImagesPrototype = {
|
||||
//
|
||||
// NOTE: updating from legacy format...
|
||||
// XXX move this to version conversion... (???)
|
||||
if(version == null){
|
||||
Object.keys(img && img.preview || {})
|
||||
version == null
|
||||
&& Object.keys(img && img.preview || {})
|
||||
.forEach(function(res){
|
||||
var p = img.preview[res]
|
||||
img.preview[res] = p.indexOf(k+'%20-%20') >= 0 ? decodeURI(p) : p
|
||||
})
|
||||
}
|
||||
}
|
||||
return this
|
||||
},
|
||||
img.preview[res] =
|
||||
p.includes(k+'%20-%20') ?
|
||||
decodeURI(p)
|
||||
: p }) }
|
||||
return this },
|
||||
// XXX this is really odd: renaming this to 'toJSON' breaks JavaScript
|
||||
// making chrome/node just say: "<error>" and a filename...
|
||||
json: function(data){
|
||||
|
||||
@ -2309,7 +2309,7 @@ var RibbonsPrototype = {
|
||||
// NOTE: this will reuse existing marks...
|
||||
toggleImageMark: function(image, cls, action){
|
||||
var that = this
|
||||
if(cls == null || ['toggle', 'on', 'off', '?'].indexOf(cls) >= 0 ){
|
||||
if(cls == null || ['toggle', 'on', 'off', '?'].includes(cls)){
|
||||
action = cls
|
||||
cls = image
|
||||
image = null
|
||||
@ -2443,7 +2443,7 @@ var RibbonsPrototype = {
|
||||
// update existing state...
|
||||
if(set_state == null){
|
||||
var d = direction
|
||||
if(reference == 'view' && [90, 270].indexOf(that.getImageRotation(img)) > -1){
|
||||
if(reference == 'view' && [90, 270].includes(that.getImageRotation(img))){
|
||||
d = direction == 'vertical' ? 'horizontal' : 'vertical'
|
||||
}
|
||||
var state = img.attr('flipped')
|
||||
|
||||
@ -715,8 +715,8 @@ var BaseTagsPrototype = {
|
||||
res = res.unite(tags)
|
||||
return res.size != size ?
|
||||
expand(tags, res)
|
||||
: [...res]
|
||||
}
|
||||
: [...res] }
|
||||
|
||||
// Set matching...
|
||||
// a matches b iff each element of a exists in b.
|
||||
//
|
||||
@ -724,14 +724,14 @@ var BaseTagsPrototype = {
|
||||
// NOTE: this matches single tags too...
|
||||
var matchSet = function(a, b){
|
||||
a = that.splitSet(a)
|
||||
b = (no_definitions || !definitions) ?
|
||||
b = new Set((no_definitions || !definitions) ?
|
||||
that.splitSet(b)
|
||||
: expand(that.splitSet(b))
|
||||
: expand(that.splitSet(b)))
|
||||
return a.length <= b.length
|
||||
// keep only the non-matches -> if at least one exists we fail...
|
||||
&& a.filter(function(e){
|
||||
return e != '*'
|
||||
&& b.indexOf(e) < 0
|
||||
&& b.has(e) < 0
|
||||
&& !(cmp
|
||||
&& b.filter(cmp.bind(null, e)).length > 0) })
|
||||
.length == 0 }
|
||||
|
||||
@ -35,7 +35,7 @@ Object.flatCopy = function(obj){
|
||||
Object.deepKeys(obj).forEach(function(key){
|
||||
res[key] = obj[key]
|
||||
})
|
||||
return res}
|
||||
return res }
|
||||
|
||||
|
||||
|
||||
@ -94,12 +94,10 @@ Array.prototype.toKeys = function(normalize){
|
||||
return normalize ?
|
||||
this.reduce(function(r, e, i){
|
||||
r[normalize(e)] = i
|
||||
return r
|
||||
}, {})
|
||||
return r }, {})
|
||||
: this.reduce(function(r, e, i){
|
||||
r[e] = i
|
||||
return r
|
||||
}, {}) }
|
||||
return r }, {}) }
|
||||
|
||||
|
||||
// Convert an array to a map...
|
||||
@ -120,13 +118,11 @@ Array.prototype.toMap = function(normalize){
|
||||
this
|
||||
.reduce(function(m, e, i){
|
||||
m.set(normalize(e), i)
|
||||
return m
|
||||
}, new Map())
|
||||
return m }, new Map())
|
||||
: this
|
||||
.reduce(function(m, e, i){
|
||||
m.set(e, i)
|
||||
return m
|
||||
}, new Map()) }
|
||||
return m }, new Map()) }
|
||||
|
||||
|
||||
// Return an array with duplicate elements removed...
|
||||
@ -149,18 +145,13 @@ Array.prototype.tailUnique = function(normalize){
|
||||
//
|
||||
Array.prototype.cmp = function(other){
|
||||
if(this === other){
|
||||
return true
|
||||
}
|
||||
return true }
|
||||
if(this.length != other.length){
|
||||
return false
|
||||
}
|
||||
return false }
|
||||
for(var i=0; i<this.length; i++){
|
||||
if(this[i] != other[i]){
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false } }
|
||||
return true }
|
||||
|
||||
|
||||
// Compare two Arrays as sets...
|
||||
@ -185,9 +176,7 @@ Array.prototype.sortAs = function(other){
|
||||
return i < 0 && j < 0 ? 0
|
||||
: i < 0 ? 1
|
||||
: j < 0 ? -1
|
||||
: i - j
|
||||
})
|
||||
}
|
||||
: i - j }) }
|
||||
|
||||
|
||||
|
||||
@ -315,8 +304,7 @@ var quoteRegExp =
|
||||
RegExp.quoteRegExp =
|
||||
module.quoteRegExp =
|
||||
function(str){
|
||||
return str.replace(/([\.\\\/\(\)\[\]\$\*\+\-\{\}\@\^\&\?\<\>])/g, '\\$1')
|
||||
}
|
||||
return str.replace(/([\.\\\/\(\)\[\]\$\*\+\-\{\}\@\^\&\?\<\>])/g, '\\$1') }
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user