From 80c6d525ce945dce11d019ae1e7e9622163552a9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 5 Sep 2012 19:35:47 +0400 Subject: [PATCH] re-did ids, fixed sorting... Signed-off-by: Alex A. Naanou --- ui/gallery-prototype.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/ui/gallery-prototype.js b/ui/gallery-prototype.js index a9b4e4be..07fe5d85 100755 --- a/ui/gallery-prototype.js +++ b/ui/gallery-prototype.js @@ -433,7 +433,8 @@ jQuery.fn.sortChildren = function(func){ function getImageOrder(img){ // XXX HACK need to parseInt this because '13' is less than '2'... // ...figure a way out of this!!! - return parseInt($(img).attr('id')) + //return parseInt($(img).attr('id')) + return $(img).attr('id') } @@ -447,6 +448,14 @@ function cmpImageOrder(a, b){ } +function cmpImagePaths(a, b){ + a = getURL($(a).attr('id')) + b = getURL($(b).attr('id')) + return a > b ? 1 : a < b ? -1 : 0 +} + + + // NOTE: don't understand why am I the one who has to write this... var SPECIAL_KEYS = { 9: 'Tab', @@ -1383,13 +1392,14 @@ function loadJSON(data, position, set_order){ for(var j in images){ var image = images[j] // update index... - new_images[order] = image + //new_images[order] = image // create image... - makeImage(order, set_order) + //makeImage(order, set_order) + makeImage(j, set_order) .appendTo(ribbon) order++ } - ribbons[i] = new_images + //ribbons[i] = new_images } console.log('loaded: ', order) if(position != null && $('#' + position).length != 0){ @@ -2182,11 +2192,8 @@ ImageGrid.GROUP('Image manipulation', display: false, }, function sortImagesVia(cmp){ - // reverse ID order... - $($('.image').get().sort(cmp)) - .each(function(i, e){e.id = i})}) - // resort the images... - ImageGrid.sortImages() + $('.ribbon').sortChildren(cmp) + updateRibbonImages($('.current.image').click()) }), ImageGrid.ACTION({ title: 'Sort images', @@ -2194,9 +2201,12 @@ ImageGrid.GROUP('Image manipulation', 'NOTE: this will only realign three ribbons.' }, function sortImages(){ + /* XXX this is broken: need a good default... $('.ribbon').sortChildren(cmpImageOrder) // compensate for offset cange... - $('.current.image').click() + updateRibbonImages($('.current.image').click()) + */ + return ImageGrid.sortImagesByPath() }), ImageGrid.ACTION({ title: 'Reverse order of images', @@ -2204,18 +2214,14 @@ ImageGrid.GROUP('Image manipulation', }, function reverseImageOrder(){ // this is done by reversing their id attr - ImageGrid.sortImagesVia(function(a, b){return cmpImageOrder(b, a)}) + ImageGrid.sortImagesVia(function(a, b){return cmpImagePaths(b, a)}) }), ImageGrid.ACTION({ title: 'Sort images by their full path', }, // XXX this should use a normalized path... function sortImagesByPath(){ - ImageGrid.sortImagesVia(function(a, b){ - a = getURL($(a).attr('id')) - b = getURL($(b).attr('id')) - return a > b ? 1 : a < b ? -1 : 0 - }) + ImageGrid.sortImagesVia(cmpImagePaths) }))