mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +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...
|
||||
var CollectionActions = actions.Actions({
|
||||
@ -1596,6 +1596,7 @@ var UICollectionActions = actions.Actions({
|
||||
})],
|
||||
|
||||
// XXX need .changes format...
|
||||
// XXX BUG: adding a new collections kills sort...
|
||||
browseCollections: ['Collections/$Collec$tions...',
|
||||
core.doc`Collection list...
|
||||
|
||||
@ -1605,7 +1606,13 @@ var UICollectionActions = actions.Actions({
|
||||
var that = this
|
||||
var to_remove = []
|
||||
|
||||
var collections = that.collection_order =
|
||||
(that.collection_order || []).slice()
|
||||
|
||||
var defaults = this.config['default-collections']
|
||||
if(defaults){
|
||||
collections = collections.concat(defaults).unique()
|
||||
}
|
||||
|
||||
return browse.makeLister(null,
|
||||
function(path, make){
|
||||
@ -1617,6 +1624,7 @@ var UICollectionActions = actions.Actions({
|
||||
})
|
||||
|
||||
var openHandler = function(_, title){
|
||||
var title = $(this).find('.text').attr('text') || title
|
||||
// create collection if it does not exist...
|
||||
if(!that.collections
|
||||
|| !(title in that.collections)){
|
||||
@ -1651,12 +1659,8 @@ var UICollectionActions = actions.Actions({
|
||||
&& text.attr('cropped', cs.length)
|
||||
}
|
||||
|
||||
//var collections = Object.keys(that.collections || {})
|
||||
var collections = that.collection_order = that.collection_order || []
|
||||
|
||||
if(defaults){
|
||||
collections = collections.concat(defaults).unique()
|
||||
}
|
||||
// XXX should we update collections if they changed outside???
|
||||
// XXX
|
||||
|
||||
// main collection...
|
||||
!action
|
||||
@ -1708,9 +1712,14 @@ var UICollectionActions = actions.Actions({
|
||||
selected: that.collection || MAIN_COLLECTION_TITLE,
|
||||
})
|
||||
.close(function(){
|
||||
to_remove.forEach(function(title){
|
||||
that.removeCollection(title)
|
||||
})
|
||||
// XXX for some reason when an item is added collections
|
||||
// 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...
|
||||
|
||||
@ -1594,8 +1594,8 @@ var DataPrototype = {
|
||||
// ribbon is .getRibbon(..) compatible or 'keep'.
|
||||
// order is .getImageOrder(..) compatible or 'keep'.
|
||||
//
|
||||
// This will not change the order of images unless (special case)
|
||||
// the target image is in the images.
|
||||
// This will not change the relative order of input images unless
|
||||
// (special case) the target image is in the images.
|
||||
//
|
||||
//
|
||||
// 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
|
||||
// at input order may be at a different position after this is
|
||||
// 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){
|
||||
var that = this
|
||||
mode = mode || 'before'
|
||||
|
||||
@ -451,6 +451,8 @@ if(typeof(jQuery) != typeof(undefined)){
|
||||
// anything is changed, gets passed the
|
||||
// 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
|
||||
// focus the first [tabindex] element up the tree...
|
||||
@ -484,7 +486,16 @@ if(typeof(jQuery) != typeof(undefined)){
|
||||
|
||||
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)
|
||||
|
||||
@ -515,7 +526,7 @@ if(typeof(jQuery) != typeof(undefined)){
|
||||
|
||||
// abort...
|
||||
if((options.abort_keys || ['Esc']).indexOf(n) >= 0){
|
||||
that.trigger('edit-abort', original)
|
||||
that.trigger('edit-abort', original_text)
|
||||
|
||||
// done -- single line...
|
||||
} else if(n == 'Enter'
|
||||
@ -556,7 +567,7 @@ if(typeof(jQuery) != typeof(undefined)){
|
||||
|
||||
// reset original value...
|
||||
options.reset_on_abort !== false
|
||||
&& that.text(original)
|
||||
&& resetOriginal()
|
||||
options.blur_on_abort !== false
|
||||
&& this.blur()
|
||||
|
||||
@ -575,7 +586,7 @@ if(typeof(jQuery) != typeof(undefined)){
|
||||
|
||||
// reset original value...
|
||||
options.reset_on_commit !== false
|
||||
&& that.text(original)
|
||||
&& resetOriginal()
|
||||
options.blur_on_commit !== false
|
||||
&& this.blur()
|
||||
|
||||
|
||||
@ -913,7 +913,10 @@ function(list, options){
|
||||
update: function(evt, ui){
|
||||
var order = ui.item.parent()
|
||||
.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()
|
||||
var l = dialog.__list[id]
|
||||
l.splice.apply(l, [0, l.length].concat(order))
|
||||
@ -929,14 +932,15 @@ function(list, options){
|
||||
})
|
||||
|
||||
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()
|
||||
|
||||
// new button...
|
||||
if(options.new_item !== false){
|
||||
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(
|
||||
new_item,
|
||||
{
|
||||
@ -1007,7 +1011,8 @@ function(list, options){
|
||||
// update list and select new value...
|
||||
dialog.update()
|
||||
.done(function(){
|
||||
dialog.select('"'+txt+'"')
|
||||
//dialog.select('"'+txt+'"')
|
||||
dialog.select('"'+txt.replace(/\$/g, '')+'"')
|
||||
})
|
||||
}))
|
||||
}
|
||||
@ -1208,6 +1213,8 @@ Buttons.markForRemoval = function(list, html){
|
||||
return
|
||||
}
|
||||
|
||||
p = e.find('.text').attr('text') || p
|
||||
|
||||
if(e.hasClass('strike-out')){
|
||||
list.indexOf(p) < 0
|
||||
&& list.push(p)
|
||||
@ -2333,6 +2340,7 @@ var BrowserPrototype = {
|
||||
t[0]
|
||||
: $('<span>')
|
||||
.addClass('text')
|
||||
.attr('text', t || '')
|
||||
// here we also replace empty strings with ...
|
||||
[t ? 'text' : 'html'](t || ' ')[0]
|
||||
}))
|
||||
@ -2354,6 +2362,7 @@ var BrowserPrototype = {
|
||||
traversable = traversable == null ? false : traversable
|
||||
p = $('<span>')
|
||||
.addClass('text')
|
||||
.attr('text', p.replace(dir, ''))
|
||||
.text(p.replace(dir, ''))
|
||||
}
|
||||
|
||||
@ -2391,9 +2400,10 @@ var BrowserPrototype = {
|
||||
e.html(e.html().replace(item_shortcut_marker,
|
||||
function(){
|
||||
var k = _replace.apply(this, arguments)
|
||||
var nk = keyboard.normalizeKey(k)
|
||||
// only mark the first occurrence...
|
||||
var mark = !!(registered_shortcuts.indexOf(k) < 0
|
||||
&& registered_shortcuts.push(k))
|
||||
var mark = !!(registered_shortcuts.indexOf(nk) < 0
|
||||
&& registered_shortcuts.push(nk))
|
||||
return mark ?
|
||||
`<span class="keyboard-shortcut">${k}</span>`
|
||||
: k
|
||||
@ -2786,6 +2796,9 @@ var BrowserPrototype = {
|
||||
} else if(typeof(pattern) == typeof('str')){
|
||||
//var pl = pattern.trim().split(/\s+/)
|
||||
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(/\s*((?:\\\s|[^\s])*)\s*/g)
|
||||
// remove empty strings...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user