mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-01 03:40:09 +00:00
refactoring and minor bug fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
7eaa2374ad
commit
b94e0bf109
@ -42,7 +42,54 @@ var quoteWS = function(str){
|
|||||||
// ...it can be implemented trivially via an attribute and a :before
|
// ...it can be implemented trivially via an attribute and a :before
|
||||||
// CSS class...
|
// CSS class...
|
||||||
var BrowserClassPrototype = {
|
var BrowserClassPrototype = {
|
||||||
// construct the dom...
|
|
||||||
|
// Normalize path...
|
||||||
|
//
|
||||||
|
// This converts the path into a universal absolute array
|
||||||
|
// representation, taking care of relative path constructs including
|
||||||
|
// '.' (current path) and '..' (up one level)
|
||||||
|
//
|
||||||
|
// XXX does this need to handle trailing '/'???
|
||||||
|
// ...the problem is mainly encoding a trailing '/' into an
|
||||||
|
// array, adding a '' at the end seems both obvious and
|
||||||
|
// artificial...
|
||||||
|
// XXX is this the correct name???
|
||||||
|
// ...should this be .normalizePath(..)???
|
||||||
|
path2list: function(path){
|
||||||
|
var splitter = /[\\\/]/
|
||||||
|
|
||||||
|
if(typeof(path) == typeof('str')){
|
||||||
|
path = path
|
||||||
|
.split(splitter)
|
||||||
|
.filter(function(e){ return e != '' })
|
||||||
|
}
|
||||||
|
|
||||||
|
// we've got a relative path...
|
||||||
|
if(path[0] == '.' || path[0] == '..'){
|
||||||
|
path = this.path.concat(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
path = path
|
||||||
|
// clear the '..'...
|
||||||
|
// NOTE: we reverse to avoid setting elements with negative
|
||||||
|
// indexes if we have a leading '..'
|
||||||
|
.reverse()
|
||||||
|
.map(function(e, i){
|
||||||
|
if(e == '..'){
|
||||||
|
e = '.'
|
||||||
|
path[i] = '.'
|
||||||
|
path[i+1] = '.'
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
})
|
||||||
|
.reverse()
|
||||||
|
// filter out '.'...
|
||||||
|
.filter(function(e){ return e != '.' })
|
||||||
|
|
||||||
|
return path
|
||||||
|
},
|
||||||
|
|
||||||
|
// Construct the dom...
|
||||||
make: function(options){
|
make: function(options){
|
||||||
var browser = $('<div>')
|
var browser = $('<div>')
|
||||||
.addClass('browse-widget')
|
.addClass('browse-widget')
|
||||||
@ -254,50 +301,11 @@ var BrowserPrototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Normalize path...
|
// Call the constructor's .path2list(..)..
|
||||||
//
|
//
|
||||||
// This converts the path into a universal absolute array
|
// See: BrowserClassPrototype.path2list(..) for docs...
|
||||||
// representation, taking care of relative path constructs including
|
path2list: function(){
|
||||||
// '.' (current path) and '..' (up one level)
|
return this.constructor.path2list.apply(this, arguments)
|
||||||
//
|
|
||||||
// XXX does this need to handle trailing '/'???
|
|
||||||
// ...the problem is mainly encoding a trailing '/' into an
|
|
||||||
// array, adding a '' at the end seems both obvious and
|
|
||||||
// artificial...
|
|
||||||
// XXX is this the correct name???
|
|
||||||
// ...should this be .normalizePath(..)???
|
|
||||||
path2list: function(path){
|
|
||||||
var splitter = /[\\\/]/
|
|
||||||
|
|
||||||
if(typeof(path) == typeof('str')){
|
|
||||||
path = path
|
|
||||||
.split(splitter)
|
|
||||||
.filter(function(e){ return e != '' })
|
|
||||||
}
|
|
||||||
|
|
||||||
// we've got a relative path...
|
|
||||||
if(path[0] == '.' || path[0] == '..'){
|
|
||||||
path = this.path.concat(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
path = path
|
|
||||||
// clear the '..'...
|
|
||||||
// NOTE: we reverse to avoid setting elements with negative
|
|
||||||
// indexes if we have a leading '..'
|
|
||||||
.reverse()
|
|
||||||
.map(function(e, i){
|
|
||||||
if(e == '..'){
|
|
||||||
e = '.'
|
|
||||||
path[i] = '.'
|
|
||||||
path[i+1] = '.'
|
|
||||||
}
|
|
||||||
return e
|
|
||||||
})
|
|
||||||
.reverse()
|
|
||||||
// filter out '.'...
|
|
||||||
.filter(function(e){ return e != '.' })
|
|
||||||
|
|
||||||
return path
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Trigger jQuery events on Browser...
|
// Trigger jQuery events on Browser...
|
||||||
@ -738,12 +746,21 @@ var BrowserPrototype = {
|
|||||||
// XXX support glob...
|
// XXX support glob...
|
||||||
} else if(typeof(pattern) == typeof('str')){
|
} else if(typeof(pattern) == typeof('str')){
|
||||||
//var pl = pattern.trim().split(/\s+/)
|
//var pl = pattern.trim().split(/\s+/)
|
||||||
var pl = pattern.trim().split(/[^\\]\s/).filter(function(e){ return e.trim() != '' })
|
var pl = pattern.trim()
|
||||||
|
// split on whitespace but keep quoted chars...
|
||||||
|
.split(/\s*((?:\\\s|[^\s])*)\s*/g)
|
||||||
|
// remove empty strings...
|
||||||
|
.filter(function(e){ return e.trim() != '' })
|
||||||
|
// remove '\' -- enables direct string comparison...
|
||||||
|
.map(function(e){ return e.replace(/\\(\s)/g, '$1') })
|
||||||
var filter = function(i, e){
|
var filter = function(i, e){
|
||||||
e = $(e)
|
e = $(e)
|
||||||
var t = e.text()
|
var t = e.text()
|
||||||
for(var p=0; p < pl.length; p++){
|
for(var p=0; p < pl.length; p++){
|
||||||
var i = t.search(pl[p])
|
// NOTE: we are not using search here as it treats
|
||||||
|
// the string as a regex and we need literal
|
||||||
|
// search...
|
||||||
|
var i = t.indexOf(pl[p])
|
||||||
if(!(i >= 0)){
|
if(!(i >= 0)){
|
||||||
if(rejected){
|
if(rejected){
|
||||||
rejected.call(e, i, e)
|
rejected.call(e, i, e)
|
||||||
@ -1629,6 +1646,10 @@ ListPrototype.options = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// XXX should we inherit or copy options???
|
||||||
|
// ...inheriting might pose problems with deleting values reverting
|
||||||
|
// them to default instead of nulling them and mutable options might
|
||||||
|
// get overwritten...
|
||||||
ListPrototype.options.__proto__ = BrowserPrototype.options
|
ListPrototype.options.__proto__ = BrowserPrototype.options
|
||||||
|
|
||||||
var List =
|
var List =
|
||||||
@ -1838,6 +1859,10 @@ PathListPrototype.options = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// XXX should we inherit or copy options???
|
||||||
|
// ...inheriting might pose problems with deleting values reverting
|
||||||
|
// them to default instead of nulling them and mutable options might
|
||||||
|
// get overwritten...
|
||||||
PathListPrototype.options.__proto__ = BrowserPrototype.options
|
PathListPrototype.options.__proto__ = BrowserPrototype.options
|
||||||
|
|
||||||
var PathList =
|
var PathList =
|
||||||
|
|||||||
@ -41,7 +41,7 @@ var DrawerPrototype = {
|
|||||||
client: null,
|
client: null,
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
'close-at': 10,
|
'close-at': 40,
|
||||||
'fade-at': 100,
|
'fade-at': 100,
|
||||||
'animate': 120,
|
'animate': 120,
|
||||||
|
|
||||||
|
|||||||
@ -119,7 +119,6 @@ var WidgetPrototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Widget =
|
var Widget =
|
||||||
module.Widget =
|
module.Widget =
|
||||||
object.makeConstructor('Widget',
|
object.makeConstructor('Widget',
|
||||||
|
|||||||
@ -2237,14 +2237,38 @@ var makeActionLister = function(list, filter, pre_order){
|
|||||||
Object.keys(paths).forEach(function(k){
|
Object.keys(paths).forEach(function(k){
|
||||||
var n = paths[k][0]
|
var n = paths[k][0]
|
||||||
var k = filter ? filter(k, n) : k
|
var k = filter ? filter(k, n) : k
|
||||||
actions[k] = function(){
|
// pass args to listers...
|
||||||
return a[n]()
|
if(k.slice(-1) == '*'){
|
||||||
|
actions[k] = function(){
|
||||||
|
return a[n].apply(a, arguments)
|
||||||
|
}
|
||||||
|
// ignore args of actions...
|
||||||
|
} else {
|
||||||
|
actions[k] = function(){
|
||||||
|
return a[n]()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var closingPrevented = false
|
||||||
|
|
||||||
var o = overlay.Overlay($('body'),
|
var o = overlay.Overlay($('body'),
|
||||||
list(null, actions, path)
|
list(null, actions, path)
|
||||||
.open(function(){ o.close() }))
|
.open(function(evt){
|
||||||
|
|
||||||
|
evt.preventClosing =
|
||||||
|
event.preventClosing =
|
||||||
|
function(){ closingPrevented = true }
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
if(!closingPrevented){
|
||||||
|
o.close()
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
}))
|
||||||
|
|
||||||
|
// XXX DEBUG
|
||||||
|
window.LIST = o.client
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -2264,6 +2288,47 @@ var ActionTreeActions = actions.Actions({
|
|||||||
return a +' ('+ l.join(', ') +')'
|
return a +' ('+ l.join(', ') +')'
|
||||||
})],
|
})],
|
||||||
|
|
||||||
|
// XXX lister test...
|
||||||
|
embededListerTest: ['Interface/Lister test (embeded)/*',
|
||||||
|
function(path, make){
|
||||||
|
make('a/')
|
||||||
|
make('b/')
|
||||||
|
make('c/')
|
||||||
|
}],
|
||||||
|
floatingListerTest: ['Interface/Lister test (floating)...',
|
||||||
|
function(path){
|
||||||
|
console.log('11111111')
|
||||||
|
event
|
||||||
|
&& event.preventClosing
|
||||||
|
&& event.preventClosing()
|
||||||
|
|
||||||
|
// we got an argument and can exit...
|
||||||
|
if(path){
|
||||||
|
console.log('PATH:', path)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// load the UI...
|
||||||
|
var that = this
|
||||||
|
var list = function(path, make){
|
||||||
|
|
||||||
|
make('a/')
|
||||||
|
make('b/')
|
||||||
|
make('c/')
|
||||||
|
}
|
||||||
|
|
||||||
|
var o = overlay.Overlay($('body'),
|
||||||
|
browse.makePathList(null, {
|
||||||
|
'a/*': list,
|
||||||
|
'b/*': list,
|
||||||
|
'c/*': list,
|
||||||
|
})
|
||||||
|
.open(function(evt, path){
|
||||||
|
o.close()
|
||||||
|
that.floatingListerTest(path)
|
||||||
|
}))
|
||||||
|
}],
|
||||||
|
|
||||||
// XXX this is just a test...
|
// XXX this is just a test...
|
||||||
drawerTest:['Interface/Drawer widget test',
|
drawerTest:['Interface/Drawer widget test',
|
||||||
function(){
|
function(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user