From e508f9848a5faf233a39fdd30b22cb2dbba873b8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 24 Sep 2017 02:17:44 +0300 Subject: [PATCH] refactoring browse.js + lots of bugfixes... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/collections.js | 29 +++++++++++++++++++---------- ui (gen4)/imagegrid/data.js | 6 ++++-- ui (gen4)/lib/util.js | 19 +++++++++++++++---- ui (gen4)/lib/widget/browse.js | 25 +++++++++++++++++++------ 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index 29dc3556..d5f3bbe4 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -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... diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 9f820831..c2adfc0f 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -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' diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index 5e16d550..0bf88dcc 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -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() diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 35c7549d..28dcde97 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -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] : $('') .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 = $('') .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 ? `${k}` : 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...