wokring on page up/down actions for browse...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-10-13 02:41:47 +03:00
parent 5618addf35
commit ca8724f2a7
2 changed files with 151 additions and 30 deletions

View File

@ -26,6 +26,7 @@ var browse = require('./browse')
// XXX mostly works, does not list drive letter root dirs, deeper paths
// work...
// XXX appears to hang and crash on large lists....
var listDirGlob =
module.listDirGlob =
function(path, make){
@ -36,25 +37,29 @@ function(path, make){
var fullpath = path.indexOf('*') >= 0
path = path.indexOf('*') < 0 ? path + '/*' : path
guaranteeEvents([
'match',
'error',
],
glob.glob(path))
.on('match', function(path){
fs.stat(path, function(err, stat){
if(err){
make(fullpath ? path : path.split(/[\\\/]/).pop(), null, true)
} else {
make(fullpath ? path : path.split(/[\\\/]/).pop()
+ (stat.isDirectory() ? '/' : ''))
}
return new promise(function(resolve, reject){
// XXX do we need this???
/*guaranteeEvents([
'match',
'error',
],
glob.glob(path))*/
glob.glob(path)
.on('match', function(path){
fs.stat(path, function(err, stat){
if(err){
make(fullpath ? path : path.split(/[\\\/]/).pop(), null, true)
} else {
make(fullpath ? path : path.split(/[\\\/]/).pop()
+ (stat.isDirectory() ? '/' : ''))
}
})
})
})
// XXX finalize...
// ...and do this after all the stats are done...
.on('end', function(){
})
// XXX do this after all the stats are done...
.on('end', function(){
resolve()
})
})
}
// XXX might be good to add some caching...
@ -68,7 +73,6 @@ function(path, make){
// XXX expose these as config...
var fullpath = false
var showfiles = true
var stat = promise.denodeify(fs.stat)
@ -82,11 +86,11 @@ function(path, make){
.forEach(function(drive){
stat(drive+':/')
// XXX
.catch(function(err){
})
.catch(function(err){ })
.then(function(data){
data && make(drive+':/')
// resolve when we are done...
if(drive == 'Z'){
resolve()
}
@ -113,16 +117,9 @@ function(path, make){
: file, null, true)
})
.then(function(res){
if(!res){
return
}
var dir = res.isDirectory()
if(!dir && !showfiles) {
return
}
make(fullpath
res && make(fullpath
? path +'/'+ file
: file + (dir ? '/' : ''))
: file + (res.isDirectory() ? '/' : ''))
})
// NOTE: we are not using promise.all(..) here because it
// triggers BEFORE the first make(..) is called...
@ -191,6 +188,7 @@ function(path, make){
//var listDir = module.listDir = listDirBrowser
//var listDir = module.listDir = listDirGlob
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 : */
return module })

View File

@ -270,6 +270,10 @@ var BrowserPrototype = {
Backspace: 'Left',
Right: 'push',
// XXX
PgUp: 'prevPage!',
PgDown: 'nextPage!',
Home: 'select!: "first"',
End: 'select!: "last"',
@ -1226,6 +1230,116 @@ var BrowserPrototype = {
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...
//
// This will trigger the 'push' event.