cleaned up select a bit...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-06-18 17:13:04 +03:00
parent 97150a7985
commit 3d62b28108

View File

@ -44,10 +44,11 @@ var BrowserClassPrototype = {
}, },
} }
// XXX need to scroll only the list, keeping the path allways in view...
// XXX need to handle long paths -- smart shortening or auto scroll...
// XXX Q: should we make a base list dialog and build this on that or // XXX Q: should we make a base list dialog and build this on that or
// simplify this to implement a list (removing the path and disbling // simplify this to implement a list (removing the path and disbling
// traversal)?? // traversal)??
// XXX need a search/filter field...
// XXX need base events: // XXX need base events:
// - open // - open
// - update // - update
@ -80,6 +81,8 @@ var BrowserPrototype = {
'Backspace', 'Backspace',
'Left', 'Left',
'Right', 'Right',
'Home',
'End',
'Enter', 'Enter',
'Esc', 'Esc',
'/', '/',
@ -98,6 +101,14 @@ var BrowserPrototype = {
Left: 'pop', Left: 'pop',
Right: 'push', Right: 'push',
Home: 'select!: "first"',
End: 'select!: "last"',
// XXX add page up and page down...
// XXX
// XXX ctrl-Left to go to root/base/home
// XXX
Enter: 'action', Enter: 'action',
Esc: 'close', Esc: 'close',
@ -179,6 +190,7 @@ var BrowserPrototype = {
.forEach(function(e){ .forEach(function(e){
l.append($('<div>') l.append($('<div>')
.click(function(){ .click(function(){
// handle clicks ONLY when not disabled...
if(!$(this).hasClass('disabled')){ if(!$(this).hasClass('disabled')){
that.update(that.path.concat([$(this).text()])) that.update(that.path.concat([$(this).text()]))
} }
@ -202,7 +214,8 @@ var BrowserPrototype = {
// - best match // - best match
// XXX add deep-mode filtering... // XXX add deep-mode filtering...
// if '/' is in the pattern then we list down and combine paths... // if '/' is in the pattern then we list down and combine paths...
filter: function(pattern, non_matched, sort){ // XXX might be good to use the same mechanism for this and .select(..)
filter: function(pattern){
var that = this var that = this
var browser = this.dom var browser = this.dom
@ -228,8 +241,8 @@ var BrowserPrototype = {
.removeClass('selected') .removeClass('selected')
} else { } else {
e.html(t.replace(pattern, pattern.bold())) e.removeClass('filtered-out')
.removeClass('filtered-out') .html(t.replace(pattern, pattern.bold()))
} }
}) })
} }
@ -237,15 +250,7 @@ var BrowserPrototype = {
return this return this
}, },
// XXX start search/filter... // XXX make this a toggler... (???)
// - set content editable
// - triger filterig on modified
// - disable nav in favor of editing
// - enter/blur to exit edit mode
// - esc to cancel and reset
// XXX BUG: when starting with '/' key the '/' gets appended to the
// field...
// XXX make this a toggler...
startFilter: function(){ startFilter: function(){
var range = document.createRange() var range = document.createRange()
var selection = window.getSelection() var selection = window.getSelection()
@ -307,7 +312,7 @@ var BrowserPrototype = {
// //
// Deselect // Deselect
// .select('none') // .select('none')
// -> elem // -> $()
// //
// Select element by sequence number // Select element by sequence number
// NOTE: negative numbers count from the tail. // NOTE: negative numbers count from the tail.
@ -324,21 +329,24 @@ var BrowserPrototype = {
// -> elem // -> elem
// //
// Select element via a regular expression... // Select element via a regular expression...
// .select(<elem>) // .select(<regexp>)
// -> elem // -> elem
// -> $()
// //
// Select jQuery object...
// .select(<elem>) // .select(<elem>)
// -> elem // -> elem
// -> $()
// //
// This will return a jQuery object. // This will return a jQuery object.
// //
// NOTE: if multiple matches occur this will select the first. // NOTE: if multiple matches occur this will select the first.
// NOTE: 'none' will always return an empty jQuery object, to get
// the selection state before deselecting use .select('!')
// //
// //
// XXX revise return values...
// XXX Q: should this trigger a "select" event??? // XXX Q: should this trigger a "select" event???
// XXX on string/regexp mismatch this will select the first, is this correct??? // XXX the scroll handling might be a bit inaccurate...
// XXX handle scrollTop to show the selected element...
select: function(elem, filtering){ select: function(elem, filtering){
var pattern = '.list div:not(.disabled):not(.filtered-out)' var pattern = '.list div:not(.disabled):not(.filtered-out)'
var browser = this.dom var browser = this.dom
@ -350,10 +358,10 @@ var BrowserPrototype = {
return $() return $()
} }
elem = elem == 0 ? 'first' : elem // empty list/string selects none...
elem = elem || this.select('!') elem = elem != null && elem.length == 0 ? 'none' : elem
// if none selected get the first... // 0 or no args (null) selects first...
elem = elem.length == 0 ? 'first' : elem elem = elem == 0 || elem == null ? 'first' : elem
// first/last... // first/last...
if(elem == 'first' || elem == 'last'){ if(elem == 'first' || elem == 'last'){
@ -373,9 +381,10 @@ var BrowserPrototype = {
if(!filtering){ if(!filtering){
browser.find('.path .dir.cur').empty() browser.find('.path .dir.cur').empty()
} }
return elems elems
.filter('.selected') .filter('.selected')
.removeClass('selected') .removeClass('selected')
return $()
// strict... // strict...
} else if(elem == '!'){ } else if(elem == '!'){
@ -387,7 +396,6 @@ var BrowserPrototype = {
return this.select($(elems.slice(elem)[0] || elems.slice(-1)[0] ), filtering) return this.select($(elems.slice(elem)[0] || elems.slice(-1)[0] ), filtering)
// string... // string...
// XXX on mismatch this will select the first, is this correct???
} else if(typeof(elem) == typeof('str')){ } else if(typeof(elem) == typeof('str')){
if(/^'.*'$|^".*"$/.test(elem.trim())){ if(/^'.*'$|^".*"$/.test(elem.trim())){
elem = elem.trim().slice(1, -1) elem = elem.trim().slice(1, -1)
@ -398,7 +406,6 @@ var BrowserPrototype = {
}), filtering) }), filtering)
// regexp... // regexp...
// XXX on mismatch this will select the first, is this correct???
} else if(elem.constructor === RegExp){ } else if(elem.constructor === RegExp){
return this.select(browser.find(pattern) return this.select(browser.find(pattern)
.filter(function(i, e){ .filter(function(i, e){
@ -429,7 +436,6 @@ var BrowserPrototype = {
var D = 3 * h var D = 3 * h
// XXX there is an error here...
// too low... // too low...
if(t+h+D > H){ if(t+h+D > H){
p.scrollTop(S + (t+h+D) - H) p.scrollTop(S + (t+h+D) - H)