mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
fixed several bugs in sort...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
29c090298f
commit
3b1a91a085
@ -57,11 +57,11 @@ module.SortActions = actions.Actions({
|
|||||||
'sort-methods': {
|
'sort-methods': {
|
||||||
'none': '',
|
'none': '',
|
||||||
// NOTE: this is descending by default...
|
// NOTE: this is descending by default...
|
||||||
'Date': 'metadata.createDate birthtime reverse',
|
'Date': 'metadata.createDate birthtime keep-position reverse',
|
||||||
'File date': 'birthtime reverse',
|
'File date': 'birthtime keep-position reverse',
|
||||||
'Name (XP-style)': 'name-leading-sequence name path',
|
'Name (XP-style)': 'name-leading-sequence name path keep-position',
|
||||||
'File sequence number': 'name-sequence name path',
|
'File sequence number': 'name-sequence name path keep-position',
|
||||||
'Name': 'name path',
|
'Name': 'name path keep-position',
|
||||||
// XXX sequence number with overflow...
|
// XXX sequence number with overflow...
|
||||||
//'File sequence number with overflow': 'name-leading-sequence name path',
|
//'File sequence number with overflow': 'name-leading-sequence name path',
|
||||||
},
|
},
|
||||||
@ -98,6 +98,15 @@ module.SortActions = actions.Actions({
|
|||||||
|
|
||||||
return a - b
|
return a - b
|
||||||
},
|
},
|
||||||
|
// this will sort items via their index...
|
||||||
|
'keep-position': function(a, b){
|
||||||
|
a = this.data.order.indexOf(a)
|
||||||
|
b = this.data.order.indexOf(b)
|
||||||
|
|
||||||
|
return a - b
|
||||||
|
},
|
||||||
|
|
||||||
|
'dummy': function(){ return 0 },
|
||||||
},
|
},
|
||||||
// Sort images...
|
// Sort images...
|
||||||
//
|
//
|
||||||
@ -134,6 +143,8 @@ module.SortActions = actions.Actions({
|
|||||||
// .sortImages('reverse')
|
// .sortImages('reverse')
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// NOTE: if a sort method name contains a space it must be quoted either
|
||||||
|
// in '"'s or in "'"s.
|
||||||
// NOTE: reverse is calculated by oddity -- if an odd number indicated
|
// NOTE: reverse is calculated by oddity -- if an odd number indicated
|
||||||
// then the result is reversed, otherwise it is not.
|
// then the result is reversed, otherwise it is not.
|
||||||
// e.g. adding:
|
// e.g. adding:
|
||||||
@ -179,12 +190,16 @@ module.SortActions = actions.Actions({
|
|||||||
// XXX should this be recursive???
|
// XXX should this be recursive???
|
||||||
method = typeof(method) == typeof('str') ?
|
method = typeof(method) == typeof('str') ?
|
||||||
method
|
method
|
||||||
.split(/ +/g)
|
.split(/'([^']*)'|"([^"]*)"| +/)
|
||||||
|
.filter(function(e){ return e && e.trim() != '' && !/['"]/.test(e) })
|
||||||
.map(function(m){
|
.map(function(m){
|
||||||
return that.config['sort-methods'][m] || m })
|
return that.config['sort-methods'][m] || m })
|
||||||
.join(' ')
|
.join(' ')
|
||||||
: method
|
: method
|
||||||
method = typeof(method) == typeof('str') ? method.split(/ +/g) : method
|
method = typeof(method) == typeof('str') ?
|
||||||
|
method.split(/'([^']*)'|"([^"]*)"| +/)
|
||||||
|
.filter(function(e){ return e && e.trim() != '' && !/['"]/.test(e) })
|
||||||
|
: method
|
||||||
|
|
||||||
// get the reverse arity...
|
// get the reverse arity...
|
||||||
var i = method.indexOf('reverse')
|
var i = method.indexOf('reverse')
|
||||||
@ -226,7 +241,11 @@ module.SortActions = actions.Actions({
|
|||||||
a = _get(this.images[a])
|
a = _get(this.images[a])
|
||||||
b = _get(this.images[b])
|
b = _get(this.images[b])
|
||||||
|
|
||||||
if(a == b){
|
// not enough data to compare items, test next...
|
||||||
|
if(a == null || b == null){
|
||||||
|
return 0
|
||||||
|
|
||||||
|
} else if(a == b){
|
||||||
return 0
|
return 0
|
||||||
} else if(a < b){
|
} else if(a < b){
|
||||||
return -1
|
return -1
|
||||||
@ -253,10 +272,9 @@ module.SortActions = actions.Actions({
|
|||||||
|
|
||||||
// do the sort (in place)...
|
// do the sort (in place)...
|
||||||
if(method && method.length > 0 && this.images){
|
if(method && method.length > 0 && this.images){
|
||||||
this.data.order = this.data.order.slice()
|
this.data.order = reverse ?
|
||||||
reverse ?
|
this.data.order.slice().sort(cmp.bind(this)).reverse()
|
||||||
this.data.order.sort(cmp.bind(this)).reverse()
|
: this.data.order.slice().sort(cmp.bind(this))
|
||||||
: this.data.order.sort(cmp.bind(this))
|
|
||||||
|
|
||||||
// just reverse...
|
// just reverse...
|
||||||
} else if(method.length <= 0 && reverse) {
|
} else if(method.length <= 0 && reverse) {
|
||||||
@ -280,7 +298,13 @@ module.SortActions = actions.Actions({
|
|||||||
// XXX currently this will not toggle past 'none'
|
// XXX currently this will not toggle past 'none'
|
||||||
toggleImageSort: ['- Edit|Sort/Toggle image sort method',
|
toggleImageSort: ['- Edit|Sort/Toggle image sort method',
|
||||||
toggler.Toggler(null,
|
toggler.Toggler(null,
|
||||||
function(){ return (this.data && this.data.sort_method) || 'none' },
|
function(){
|
||||||
|
return (this.data
|
||||||
|
&& this.data.sort_method
|
||||||
|
&& (this.data.sort_method
|
||||||
|
.split(/'([^']*)'|"([^"]*)"| +/)
|
||||||
|
.filter(function(e){ return e && e.trim() != '' && !/['"]/.test(e) })[0]))
|
||||||
|
|| 'none' },
|
||||||
function(){
|
function(){
|
||||||
return Object.keys(this.config['sort-methods'])
|
return Object.keys(this.config['sort-methods'])
|
||||||
.concat((this.data
|
.concat((this.data
|
||||||
@ -310,7 +334,7 @@ module.SortActions = actions.Actions({
|
|||||||
this.data.sort_method = mode
|
this.data.sort_method = mode
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.sortImages(mode + (reverse ? ' reverse' : ''))
|
this.sortImages('"'+mode+'"' + (reverse ? ' reverse' : ''))
|
||||||
}
|
}
|
||||||
})],
|
})],
|
||||||
|
|
||||||
@ -383,10 +407,10 @@ var SortUIActions = actions.Actions({
|
|||||||
return function(){
|
return function(){
|
||||||
var txt = $(this).find('.text').first().text()
|
var txt = $(this).find('.text').first().text()
|
||||||
that[toggler]()
|
that[toggler]()
|
||||||
o.client.update()
|
o.update()
|
||||||
.then(function(){ o.client.select(txt) })
|
.then(function(){ o.select(txt) })
|
||||||
that.toggleSlideshow('?') == 'on'
|
that.toggleSlideshow('?') == 'on'
|
||||||
&& o.close()
|
&& o.parent.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +445,7 @@ var SortUIActions = actions.Actions({
|
|||||||
make('Reverse ribbons')
|
make('Reverse ribbons')
|
||||||
.on('open', function(){
|
.on('open', function(){
|
||||||
that.reverseRibbons()
|
that.reverseRibbons()
|
||||||
o.close()
|
lister.parent.close()
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@ -2149,13 +2149,13 @@ var BrowserPrototype = {
|
|||||||
parent.append(dom)
|
parent.append(dom)
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the initial state...
|
|
||||||
//this.update(options.path || this.path || '/')
|
|
||||||
// XXX is this the right way to go???
|
// XXX is this the right way to go???
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
// load the initial state...
|
||||||
that.update(options.path || that.path || '/')
|
that.update(options.path || that.path || '/')
|
||||||
|
|
||||||
// in case we have a manually selected item but not aligned...
|
// in case we have a manually selected item but that was
|
||||||
|
// not aligned...
|
||||||
that.selected && that.select()
|
that.selected && that.select()
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user