mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-17 16:51:40 +00:00
wokring on page up/down actions for browse...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5618addf35
commit
ca8724f2a7
@ -26,6 +26,7 @@ var browse = require('./browse')
|
|||||||
|
|
||||||
// XXX mostly works, does not list drive letter root dirs, deeper paths
|
// XXX mostly works, does not list drive letter root dirs, deeper paths
|
||||||
// work...
|
// work...
|
||||||
|
// XXX appears to hang and crash on large lists....
|
||||||
var listDirGlob =
|
var listDirGlob =
|
||||||
module.listDirGlob =
|
module.listDirGlob =
|
||||||
function(path, make){
|
function(path, make){
|
||||||
@ -36,25 +37,29 @@ function(path, make){
|
|||||||
var fullpath = path.indexOf('*') >= 0
|
var fullpath = path.indexOf('*') >= 0
|
||||||
path = path.indexOf('*') < 0 ? path + '/*' : path
|
path = path.indexOf('*') < 0 ? path + '/*' : path
|
||||||
|
|
||||||
guaranteeEvents([
|
return new promise(function(resolve, reject){
|
||||||
'match',
|
// XXX do we need this???
|
||||||
'error',
|
/*guaranteeEvents([
|
||||||
],
|
'match',
|
||||||
glob.glob(path))
|
'error',
|
||||||
.on('match', function(path){
|
],
|
||||||
fs.stat(path, function(err, stat){
|
glob.glob(path))*/
|
||||||
if(err){
|
glob.glob(path)
|
||||||
make(fullpath ? path : path.split(/[\\\/]/).pop(), null, true)
|
.on('match', function(path){
|
||||||
} else {
|
fs.stat(path, function(err, stat){
|
||||||
make(fullpath ? path : path.split(/[\\\/]/).pop()
|
if(err){
|
||||||
+ (stat.isDirectory() ? '/' : ''))
|
make(fullpath ? path : path.split(/[\\\/]/).pop(), null, true)
|
||||||
}
|
} else {
|
||||||
|
make(fullpath ? path : path.split(/[\\\/]/).pop()
|
||||||
|
+ (stat.isDirectory() ? '/' : ''))
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
// XXX do this after all the stats are done...
|
||||||
// XXX finalize...
|
.on('end', function(){
|
||||||
// ...and do this after all the stats are done...
|
resolve()
|
||||||
.on('end', function(){
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX might be good to add some caching...
|
// XXX might be good to add some caching...
|
||||||
@ -68,7 +73,6 @@ function(path, make){
|
|||||||
|
|
||||||
// XXX expose these as config...
|
// XXX expose these as config...
|
||||||
var fullpath = false
|
var fullpath = false
|
||||||
var showfiles = true
|
|
||||||
|
|
||||||
var stat = promise.denodeify(fs.stat)
|
var stat = promise.denodeify(fs.stat)
|
||||||
|
|
||||||
@ -82,11 +86,11 @@ function(path, make){
|
|||||||
.forEach(function(drive){
|
.forEach(function(drive){
|
||||||
stat(drive+':/')
|
stat(drive+':/')
|
||||||
// XXX
|
// XXX
|
||||||
.catch(function(err){
|
.catch(function(err){ })
|
||||||
})
|
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
data && make(drive+':/')
|
data && make(drive+':/')
|
||||||
|
|
||||||
|
// resolve when we are done...
|
||||||
if(drive == 'Z'){
|
if(drive == 'Z'){
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
@ -113,16 +117,9 @@ function(path, make){
|
|||||||
: file, null, true)
|
: file, null, true)
|
||||||
})
|
})
|
||||||
.then(function(res){
|
.then(function(res){
|
||||||
if(!res){
|
res && make(fullpath
|
||||||
return
|
|
||||||
}
|
|
||||||
var dir = res.isDirectory()
|
|
||||||
if(!dir && !showfiles) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
make(fullpath
|
|
||||||
? path +'/'+ file
|
? path +'/'+ file
|
||||||
: file + (dir ? '/' : ''))
|
: file + (res.isDirectory() ? '/' : ''))
|
||||||
})
|
})
|
||||||
// NOTE: we are not using promise.all(..) here because it
|
// NOTE: we are not using promise.all(..) here because it
|
||||||
// triggers BEFORE the first make(..) is called...
|
// triggers BEFORE the first make(..) is called...
|
||||||
@ -191,6 +188,7 @@ function(path, make){
|
|||||||
|
|
||||||
|
|
||||||
//var listDir = module.listDir = listDirBrowser
|
//var listDir = module.listDir = listDirBrowser
|
||||||
|
//var listDir = module.listDir = listDirGlob
|
||||||
var listDir = module.listDir = listDirfs
|
var listDir = module.listDir = listDirfs
|
||||||
|
|
||||||
|
|
||||||
@ -228,6 +226,15 @@ module.makeWalk = function(elem, path){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
|
var makeGlobList =
|
||||||
|
module.makeGlobList = function(elem, pattern, prepare){
|
||||||
|
// XXX
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
return module })
|
return module })
|
||||||
|
|||||||
@ -270,6 +270,10 @@ var BrowserPrototype = {
|
|||||||
Backspace: 'Left',
|
Backspace: 'Left',
|
||||||
Right: 'push',
|
Right: 'push',
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
PgUp: 'prevPage!',
|
||||||
|
PgDown: 'nextPage!',
|
||||||
|
|
||||||
Home: 'select!: "first"',
|
Home: 'select!: "first"',
|
||||||
End: 'select!: "last"',
|
End: 'select!: "last"',
|
||||||
|
|
||||||
@ -1226,6 +1230,116 @@ var BrowserPrototype = {
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getTopVisibleElem: function(){
|
||||||
|
var elems = this.filter('*')
|
||||||
|
|
||||||
|
var p = elems.first().scrollParent()
|
||||||
|
var S = p.scrollTop()
|
||||||
|
var T = p.offset().top
|
||||||
|
|
||||||
|
if(S == 0){
|
||||||
|
return elems.first()
|
||||||
|
}
|
||||||
|
|
||||||
|
return elems
|
||||||
|
.filter(function(i, e){
|
||||||
|
return $(e).offset().top - T >= 0
|
||||||
|
})
|
||||||
|
.first()
|
||||||
|
},
|
||||||
|
getBottomVisibleElem: function(){
|
||||||
|
var elems = this.filter('*')
|
||||||
|
|
||||||
|
var p = elems.first().scrollParent()
|
||||||
|
var S = p.scrollTop()
|
||||||
|
var T = p.offset().top
|
||||||
|
var H = p.height()
|
||||||
|
|
||||||
|
if(S + H == p[0].scrollHeight){
|
||||||
|
return elems.last()
|
||||||
|
}
|
||||||
|
|
||||||
|
return elems
|
||||||
|
.filter(function(i, e){
|
||||||
|
e = $(e)
|
||||||
|
return e.offset().top + e.height() <= T + H
|
||||||
|
})
|
||||||
|
.last()
|
||||||
|
},
|
||||||
|
|
||||||
|
// XXX merge with .select(..)...
|
||||||
|
// XXX needs testing...
|
||||||
|
prevPage: function(){
|
||||||
|
var pattern = '.list>div:not(.disabled):not(.filtered-out):visible'
|
||||||
|
var elem = this.getTopVisibleElem()
|
||||||
|
var cur = this.select('!')
|
||||||
|
|
||||||
|
var p = elem.scrollParent()
|
||||||
|
var S = p.scrollTop()
|
||||||
|
var H = p.height()
|
||||||
|
var T = p.offset().top
|
||||||
|
|
||||||
|
// jump to top visible elem if it's not the one selected...
|
||||||
|
if(cur.length == 0 || (3 * elem.height()) + S < cur.position().top ){
|
||||||
|
this.select(elem.prev(pattern).length == 0 ? elem : elem.next())
|
||||||
|
|
||||||
|
// we are at the top or we are less than a page from the top...
|
||||||
|
} else if(S <= H){
|
||||||
|
this.select('first')
|
||||||
|
|
||||||
|
// get the next page...
|
||||||
|
// XXX test...
|
||||||
|
} else {
|
||||||
|
var t = S - H
|
||||||
|
|
||||||
|
var elems = this.filter('*')
|
||||||
|
this.select(elems
|
||||||
|
.slice(0, elems.index(elem))
|
||||||
|
.reverse()
|
||||||
|
.filter(function(i, e){
|
||||||
|
return $(e).offset().top - T >= t
|
||||||
|
})
|
||||||
|
.first())
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
// XXX not finished and buggy....
|
||||||
|
// XXX merge with .select(..)...
|
||||||
|
// XXX needs testing...
|
||||||
|
nextPage: function(){
|
||||||
|
var elem = this.getBottomVisibleElem()
|
||||||
|
var cur = this.select('!')
|
||||||
|
|
||||||
|
var p = elem.scrollParent()
|
||||||
|
var S = p.scrollTop()
|
||||||
|
var H = p.height()
|
||||||
|
var T = p.offset().top
|
||||||
|
|
||||||
|
// jump to first elem if it's not the one selected...
|
||||||
|
if(cur.length == 0 || S + H - (3 * cur.height()) > cur.position().top ){
|
||||||
|
this.select(elem.prev())
|
||||||
|
|
||||||
|
// we are at the bottom or we are less than a page from the bottom...
|
||||||
|
} else if(S + H >= p[0].scrollHeight){
|
||||||
|
this.select('last')
|
||||||
|
|
||||||
|
// get the next page...
|
||||||
|
} else {
|
||||||
|
var t = S + 2 * H
|
||||||
|
|
||||||
|
var elems = this.filter('*')
|
||||||
|
this.select(elems
|
||||||
|
.slice(elems.index(elem))
|
||||||
|
.filter(function(i, e){
|
||||||
|
return $(e).offset().top - T >= t
|
||||||
|
})
|
||||||
|
.first())
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
|
||||||
// Push an element to path / go down one level...
|
// Push an element to path / go down one level...
|
||||||
//
|
//
|
||||||
// This will trigger the 'push' event.
|
// This will trigger the 'push' event.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user