mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
refactoring browse.js + lots of bugfixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
7e50cf2591
commit
e508f9848a
@ -46,7 +46,7 @@ var widgets = require('features/ui-widgets')
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
var MAIN_COLLECTION_TITLE = 'ALL'
|
var MAIN_COLLECTION_TITLE = '$ALL'
|
||||||
|
|
||||||
// XXX undo...
|
// XXX undo...
|
||||||
var CollectionActions = actions.Actions({
|
var CollectionActions = actions.Actions({
|
||||||
@ -1596,6 +1596,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
})],
|
})],
|
||||||
|
|
||||||
// XXX need .changes format...
|
// XXX need .changes format...
|
||||||
|
// XXX BUG: adding a new collections kills sort...
|
||||||
browseCollections: ['Collections/$Collec$tions...',
|
browseCollections: ['Collections/$Collec$tions...',
|
||||||
core.doc`Collection list...
|
core.doc`Collection list...
|
||||||
|
|
||||||
@ -1605,7 +1606,13 @@ var UICollectionActions = actions.Actions({
|
|||||||
var that = this
|
var that = this
|
||||||
var to_remove = []
|
var to_remove = []
|
||||||
|
|
||||||
|
var collections = that.collection_order =
|
||||||
|
(that.collection_order || []).slice()
|
||||||
|
|
||||||
var defaults = this.config['default-collections']
|
var defaults = this.config['default-collections']
|
||||||
|
if(defaults){
|
||||||
|
collections = collections.concat(defaults).unique()
|
||||||
|
}
|
||||||
|
|
||||||
return browse.makeLister(null,
|
return browse.makeLister(null,
|
||||||
function(path, make){
|
function(path, make){
|
||||||
@ -1617,6 +1624,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
})
|
})
|
||||||
|
|
||||||
var openHandler = function(_, title){
|
var openHandler = function(_, title){
|
||||||
|
var title = $(this).find('.text').attr('text') || title
|
||||||
// create collection if it does not exist...
|
// create collection if it does not exist...
|
||||||
if(!that.collections
|
if(!that.collections
|
||||||
|| !(title in that.collections)){
|
|| !(title in that.collections)){
|
||||||
@ -1651,12 +1659,8 @@ var UICollectionActions = actions.Actions({
|
|||||||
&& text.attr('cropped', cs.length)
|
&& text.attr('cropped', cs.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
//var collections = Object.keys(that.collections || {})
|
// XXX should we update collections if they changed outside???
|
||||||
var collections = that.collection_order = that.collection_order || []
|
// XXX
|
||||||
|
|
||||||
if(defaults){
|
|
||||||
collections = collections.concat(defaults).unique()
|
|
||||||
}
|
|
||||||
|
|
||||||
// main collection...
|
// main collection...
|
||||||
!action
|
!action
|
||||||
@ -1708,9 +1712,14 @@ var UICollectionActions = actions.Actions({
|
|||||||
selected: that.collection || MAIN_COLLECTION_TITLE,
|
selected: that.collection || MAIN_COLLECTION_TITLE,
|
||||||
})
|
})
|
||||||
.close(function(){
|
.close(function(){
|
||||||
to_remove.forEach(function(title){
|
// XXX for some reason when an item is added collections
|
||||||
that.removeCollection(title)
|
// reverts to the pre-sorted state and all
|
||||||
})
|
// consecutive sorts are ignored...
|
||||||
|
console.log('>>>', collections)
|
||||||
|
that.collection_order = collections
|
||||||
|
|
||||||
|
to_remove
|
||||||
|
.forEach(function(title){ that.removeCollection(title) })
|
||||||
})
|
})
|
||||||
})],
|
})],
|
||||||
// XXX mark unsaved (*) collections...
|
// XXX mark unsaved (*) collections...
|
||||||
|
|||||||
@ -1594,8 +1594,8 @@ var DataPrototype = {
|
|||||||
// ribbon is .getRibbon(..) compatible or 'keep'.
|
// ribbon is .getRibbon(..) compatible or 'keep'.
|
||||||
// order is .getImageOrder(..) compatible or 'keep'.
|
// order is .getImageOrder(..) compatible or 'keep'.
|
||||||
//
|
//
|
||||||
// This will not change the order of images unless (special case)
|
// This will not change the relative order of input images unless
|
||||||
// the target image is in the images.
|
// (special case) the target image is in the images.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// NOTE: if images is a list, all images will be placed in the order
|
// NOTE: if images is a list, all images will be placed in the order
|
||||||
@ -1603,6 +1603,8 @@ var DataPrototype = {
|
|||||||
// NOTE: this can affect element indexes, thus for example element
|
// NOTE: this can affect element indexes, thus for example element
|
||||||
// at input order may be at a different position after this is
|
// at input order may be at a different position after this is
|
||||||
// run.
|
// run.
|
||||||
|
// NOTE: this will clear empty ribbons. This can happen when the input
|
||||||
|
// images contain all of the images of one or more ribbons...
|
||||||
placeImage: function(images, ribbon, reference, mode){
|
placeImage: function(images, ribbon, reference, mode){
|
||||||
var that = this
|
var that = this
|
||||||
mode = mode || 'before'
|
mode = mode || 'before'
|
||||||
|
|||||||
@ -451,6 +451,8 @@ if(typeof(jQuery) != typeof(undefined)){
|
|||||||
// anything is changed, gets passed the
|
// anything is changed, gets passed the
|
||||||
// original text value (same as 'edit-abort')
|
// original text value (same as 'edit-abort')
|
||||||
//
|
//
|
||||||
|
// This will try and preserve element content DOM when resetting.
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// NOTE: removing tabindex will reset focus, so this will attempt to
|
// NOTE: removing tabindex will reset focus, so this will attempt to
|
||||||
// focus the first [tabindex] element up the tree...
|
// focus the first [tabindex] element up the tree...
|
||||||
@ -484,7 +486,16 @@ if(typeof(jQuery) != typeof(undefined)){
|
|||||||
|
|
||||||
options = options || {}
|
options = options || {}
|
||||||
|
|
||||||
var original = this.text()
|
var original_text = this.text()
|
||||||
|
var original_dom = document.createDocumentFragment()
|
||||||
|
this[0].childNodes
|
||||||
|
.forEach(function(node){
|
||||||
|
original_dom.appendChild(node.cloneNode(true)) })
|
||||||
|
var resetOriginal = function(){
|
||||||
|
//that.text(original_text)
|
||||||
|
that[0].innerHTML = ''
|
||||||
|
that[0].appendChild(original_dom.cloneNode(true))
|
||||||
|
}
|
||||||
|
|
||||||
this.prop('contenteditable', true)
|
this.prop('contenteditable', true)
|
||||||
|
|
||||||
@ -515,7 +526,7 @@ if(typeof(jQuery) != typeof(undefined)){
|
|||||||
|
|
||||||
// abort...
|
// abort...
|
||||||
if((options.abort_keys || ['Esc']).indexOf(n) >= 0){
|
if((options.abort_keys || ['Esc']).indexOf(n) >= 0){
|
||||||
that.trigger('edit-abort', original)
|
that.trigger('edit-abort', original_text)
|
||||||
|
|
||||||
// done -- single line...
|
// done -- single line...
|
||||||
} else if(n == 'Enter'
|
} else if(n == 'Enter'
|
||||||
@ -556,7 +567,7 @@ if(typeof(jQuery) != typeof(undefined)){
|
|||||||
|
|
||||||
// reset original value...
|
// reset original value...
|
||||||
options.reset_on_abort !== false
|
options.reset_on_abort !== false
|
||||||
&& that.text(original)
|
&& resetOriginal()
|
||||||
options.blur_on_abort !== false
|
options.blur_on_abort !== false
|
||||||
&& this.blur()
|
&& this.blur()
|
||||||
|
|
||||||
@ -575,7 +586,7 @@ if(typeof(jQuery) != typeof(undefined)){
|
|||||||
|
|
||||||
// reset original value...
|
// reset original value...
|
||||||
options.reset_on_commit !== false
|
options.reset_on_commit !== false
|
||||||
&& that.text(original)
|
&& resetOriginal()
|
||||||
options.blur_on_commit !== false
|
options.blur_on_commit !== false
|
||||||
&& this.blur()
|
&& this.blur()
|
||||||
|
|
||||||
|
|||||||
@ -913,7 +913,10 @@ function(list, options){
|
|||||||
update: function(evt, ui){
|
update: function(evt, ui){
|
||||||
var order = ui.item.parent()
|
var order = ui.item.parent()
|
||||||
.find('.item')
|
.find('.item')
|
||||||
.map(function(){ return $(this).find('.text').text() })
|
.map(function(){
|
||||||
|
//return $(this).find('.text').text() })
|
||||||
|
return $(this).find('.text').attr('text')
|
||||||
|
|| $(this).find('.text').text() })
|
||||||
.toArray()
|
.toArray()
|
||||||
var l = dialog.__list[id]
|
var l = dialog.__list[id]
|
||||||
l.splice.apply(l, [0, l.length].concat(order))
|
l.splice.apply(l, [0, l.length].concat(order))
|
||||||
@ -929,14 +932,15 @@ function(list, options){
|
|||||||
})
|
})
|
||||||
|
|
||||||
options.itemopen
|
options.itemopen
|
||||||
&& res.on('open', function(evt){ options.itemopen(evt, dialog.selected) })
|
&& res.on('open', function(evt){
|
||||||
|
options.itemopen.call(this, evt, dialog.selected) })
|
||||||
|
|
||||||
res = res.toArray()
|
res = res.toArray()
|
||||||
|
|
||||||
// new button...
|
// new button...
|
||||||
if(options.new_item !== false){
|
if(options.new_item !== false){
|
||||||
var new_item = options.new_item || true
|
var new_item = options.new_item || true
|
||||||
new_item = new_item === true ? 'New...' : new_item
|
new_item = new_item === true ? '$New...' : new_item
|
||||||
res.push(make.Editable(
|
res.push(make.Editable(
|
||||||
new_item,
|
new_item,
|
||||||
{
|
{
|
||||||
@ -1007,7 +1011,8 @@ function(list, options){
|
|||||||
// update list and select new value...
|
// update list and select new value...
|
||||||
dialog.update()
|
dialog.update()
|
||||||
.done(function(){
|
.done(function(){
|
||||||
dialog.select('"'+txt+'"')
|
//dialog.select('"'+txt+'"')
|
||||||
|
dialog.select('"'+txt.replace(/\$/g, '')+'"')
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -1208,6 +1213,8 @@ Buttons.markForRemoval = function(list, html){
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = e.find('.text').attr('text') || p
|
||||||
|
|
||||||
if(e.hasClass('strike-out')){
|
if(e.hasClass('strike-out')){
|
||||||
list.indexOf(p) < 0
|
list.indexOf(p) < 0
|
||||||
&& list.push(p)
|
&& list.push(p)
|
||||||
@ -2333,6 +2340,7 @@ var BrowserPrototype = {
|
|||||||
t[0]
|
t[0]
|
||||||
: $('<span>')
|
: $('<span>')
|
||||||
.addClass('text')
|
.addClass('text')
|
||||||
|
.attr('text', t || '')
|
||||||
// here we also replace empty strings with ...
|
// here we also replace empty strings with ...
|
||||||
[t ? 'text' : 'html'](t || ' ')[0]
|
[t ? 'text' : 'html'](t || ' ')[0]
|
||||||
}))
|
}))
|
||||||
@ -2354,6 +2362,7 @@ var BrowserPrototype = {
|
|||||||
traversable = traversable == null ? false : traversable
|
traversable = traversable == null ? false : traversable
|
||||||
p = $('<span>')
|
p = $('<span>')
|
||||||
.addClass('text')
|
.addClass('text')
|
||||||
|
.attr('text', p.replace(dir, ''))
|
||||||
.text(p.replace(dir, ''))
|
.text(p.replace(dir, ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2391,9 +2400,10 @@ var BrowserPrototype = {
|
|||||||
e.html(e.html().replace(item_shortcut_marker,
|
e.html(e.html().replace(item_shortcut_marker,
|
||||||
function(){
|
function(){
|
||||||
var k = _replace.apply(this, arguments)
|
var k = _replace.apply(this, arguments)
|
||||||
|
var nk = keyboard.normalizeKey(k)
|
||||||
// only mark the first occurrence...
|
// only mark the first occurrence...
|
||||||
var mark = !!(registered_shortcuts.indexOf(k) < 0
|
var mark = !!(registered_shortcuts.indexOf(nk) < 0
|
||||||
&& registered_shortcuts.push(k))
|
&& registered_shortcuts.push(nk))
|
||||||
return mark ?
|
return mark ?
|
||||||
`<span class="keyboard-shortcut">${k}</span>`
|
`<span class="keyboard-shortcut">${k}</span>`
|
||||||
: k
|
: k
|
||||||
@ -2786,6 +2796,9 @@ var BrowserPrototype = {
|
|||||||
} 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()
|
var pl = pattern.trim()
|
||||||
|
// allow pattern matching regardless of special chars...
|
||||||
|
// XXX not sure about this...
|
||||||
|
.replace(/\$/g, '')
|
||||||
// split on whitespace but keep quoted chars...
|
// split on whitespace but keep quoted chars...
|
||||||
.split(/\s*((?:\\\s|[^\s])*)\s*/g)
|
.split(/\s*((?:\\\s|[^\s])*)\s*/g)
|
||||||
// remove empty strings...
|
// remove empty strings...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user